1
|
from datetime import datetime
|
2
|
|
3
|
from django.conf import settings
|
4
|
from django.views.generic import CreateView, UpdateView, DeleteView, \
|
5
|
ListView, TemplateView
|
6
|
from django.views.generic.list import MultipleObjectMixin
|
7
|
from django.contrib.syndication.views import Feed
|
8
|
from django.utils.feedgenerator import Atom1Feed
|
9
|
|
10
|
|
11
|
import models
|
12
|
|
13
|
class HomepageView(ListView):
|
14
|
model = models.Announce
|
15
|
template_name = 'homepage.html'
|
16
|
|
17
|
homepage = HomepageView.as_view()
|
18
|
|
19
|
class AnnouncesHomepageView(ListView):
|
20
|
model = models.Announce
|
21
|
|
22
|
class AnnounceCreateView(CreateView):
|
23
|
model = models.Announce
|
24
|
|
25
|
add_announce = AnnounceCreateView.as_view()
|
26
|
|
27
|
class AnnounceEditView(UpdateView):
|
28
|
model = models.Announce
|
29
|
|
30
|
edit_announce = AnnounceEditView.as_view()
|
31
|
|
32
|
class AnnounceDeleteView(DeleteView):
|
33
|
model = models.Announce
|
34
|
|
35
|
delete_announce = AnnounceDeleteView.as_view()
|
36
|
|
37
|
edit_announce = AnnounceEditView.as_view()
|
38
|
|
39
|
class CategoryCreateView(CreateView):
|
40
|
model = models.Category
|
41
|
|
42
|
add_category = CategoryCreateView.as_view()
|
43
|
|
44
|
class CategoryEditView(UpdateView):
|
45
|
model = models.Category
|
46
|
|
47
|
edit_category = CategoryEditView.as_view()
|
48
|
|
49
|
class DeleteView(DeleteView):
|
50
|
model = models.Category
|
51
|
|
52
|
delete_category = DeleteView.as_view()
|
53
|
|
54
|
|
55
|
class ManageView(ListView, MultipleObjectMixin):
|
56
|
paginate_by = settings.ANNOUNCES_PER_PAGE
|
57
|
template_name = 'manage.html'
|
58
|
model = models.Announce
|
59
|
|
60
|
def get_context_data(self, **kwargs):
|
61
|
context = super(ManageView, self).get_context_data(**kwargs)
|
62
|
context['categories'] = models.Category.objects.all().order_by('-ctime')
|
63
|
return context
|
64
|
|
65
|
manage = ManageView.as_view()
|
66
|
|
67
|
class RssView(Feed):
|
68
|
title = settings.RSS_TITLE
|
69
|
description = settings.RSS_DESCRIPTION
|
70
|
link = settings.RSS_LINK
|
71
|
feed_item_link_template = settings.RSS_LINK_TEMPLATE
|
72
|
feed_type = Atom1Feed
|
73
|
|
74
|
def __init__(self, **kwargs):
|
75
|
self.__dict__.update(kwargs)
|
76
|
|
77
|
def items(self):
|
78
|
return models.Announce.objects.exclude(expiration_time__lt=datetime.now()).order_by('-publication_time')
|
79
|
|
80
|
def item_title(self, item):
|
81
|
return item.title
|
82
|
|
83
|
def item_description(self, item):
|
84
|
return item.text
|
85
|
|
86
|
def item_link(self, item):
|
87
|
return self.feed_item_link_template.format(item.pk)
|
88
|
|
89
|
def item_pubdate(self, item):
|
90
|
return item.publication_time or item.modification_time
|
91
|
|
92
|
rss = RssView()
|