forked from rc/aircox
add website app, move articles to it, fix programs.models
This commit is contained in:
0
website/__init__.py
Normal file
0
website/__init__.py
Normal file
15
website/admin.py
Normal file
15
website/admin.py
Normal file
@ -0,0 +1,15 @@
|
||||
import copy
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
from programs.admin import PublicationAdmin
|
||||
from website.models import *
|
||||
|
||||
@admin.register(Article)
|
||||
class ArticleAdmin (PublicationAdmin):
|
||||
fieldsets = copy.deepcopy(PublicationAdmin.fieldsets)
|
||||
|
||||
fieldsets[1][1]['fields'] += ['static_page']
|
||||
|
||||
|
||||
|
35
website/models.py
Normal file
35
website/models.py
Normal file
@ -0,0 +1,35 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||
|
||||
from programs.models import Publication
|
||||
|
||||
|
||||
class Article (Publication):
|
||||
parent = models.ForeignKey(
|
||||
'self',
|
||||
verbose_name = _('parent'),
|
||||
blank = True, null = True,
|
||||
help_text = _('parent article'),
|
||||
)
|
||||
static_page = models.BooleanField(
|
||||
_('static page'),
|
||||
default = False,
|
||||
)
|
||||
focus = models.BooleanField(
|
||||
_('article is focus'),
|
||||
default = False,
|
||||
)
|
||||
referring_tag = models.CharField(
|
||||
_('referring tag'),
|
||||
max_length = 32,
|
||||
blank = True, null = True,
|
||||
help_text = _('tag used by other to refers to this article'),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Article')
|
||||
verbose_name_plural = _('Articles')
|
||||
|
||||
|
||||
|
||||
|
3
website/tests.py
Normal file
3
website/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
83
website/utils.py
Normal file
83
website/utils.py
Normal file
@ -0,0 +1,83 @@
|
||||
from django.db import models
|
||||
from django.utils import timezone, dateformat
|
||||
from programs.models import *
|
||||
|
||||
|
||||
class ListQueries:
|
||||
@staticmethod
|
||||
def search (qs, q):
|
||||
qs = qs.filter(tags__slug__in = re.compile(r'(\s|\+)+').split(q)) | \
|
||||
qs.filter(title__icontains = q) | \
|
||||
qs.filter(subtitle__icontains = q) | \
|
||||
qs.filter(content__icontains = q)
|
||||
qs.distinct()
|
||||
return qs
|
||||
|
||||
@staticmethod
|
||||
def thread (qs, q):
|
||||
return qs.filter(parent = q)
|
||||
|
||||
@staticmethod
|
||||
def next (qs, q):
|
||||
qs = qs.filter(date__gte = timezone.now())
|
||||
if q:
|
||||
qs = qs.filter(parent = q)
|
||||
return qs
|
||||
|
||||
@staticmethod
|
||||
def prev (qs, q):
|
||||
qs = qs.filter(date__lte = timezone.now())
|
||||
if q:
|
||||
qs = qs.filter(parent = q)
|
||||
return qs
|
||||
|
||||
@staticmethod
|
||||
def date (qs, q):
|
||||
if not q:
|
||||
q = timezone.datetime.today()
|
||||
if type(q) is str:
|
||||
q = timezone.datetime.strptime(q, '%Y/%m/%d').date()
|
||||
|
||||
return qs.filter(date__startswith = q)
|
||||
|
||||
class Diffusion:
|
||||
@staticmethod
|
||||
def episode (qs, q):
|
||||
return qs.filter(episode = q)
|
||||
|
||||
@staticmethod
|
||||
def program (qs, q):
|
||||
return qs.filter(program = q)
|
||||
|
||||
class ListQuery:
|
||||
model = None
|
||||
qs = None
|
||||
|
||||
def __init__ (self, model, *kwargs):
|
||||
self.model = model
|
||||
self.__dict__.update(kwargs)
|
||||
|
||||
def get_queryset (self, by, q):
|
||||
qs = model.objects.all()
|
||||
if model._meta.get_field_by_name('public'):
|
||||
qs = qs.filter(public = True)
|
||||
|
||||
# run query set
|
||||
queries = Queries.__dict__.get(self.model) or Queries
|
||||
filter = queries.__dict__.get(by)
|
||||
if filter:
|
||||
qs = filter(qs, q)
|
||||
|
||||
# order
|
||||
if self.sort == 'asc':
|
||||
qs = qs.order_by('date', 'id')
|
||||
else:
|
||||
qs = qs.order_by('-date', '-id')
|
||||
|
||||
# exclude
|
||||
qs = qs.exclude(id = exclude)
|
||||
|
||||
self.qs = qs
|
||||
return qs
|
||||
|
||||
|
3
website/views.py
Normal file
3
website/views.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
Reference in New Issue
Block a user