2016-06-05 21:20:06 +00:00
|
|
|
from django.views.generic import ListView, DetailView
|
2016-06-10 18:21:32 +00:00
|
|
|
from django.utils import timezone
|
2016-05-30 19:36:14 +00:00
|
|
|
from . import models
|
|
|
|
|
|
|
|
|
|
|
|
class NewsIndex(ListView):
|
|
|
|
model = models.NewsItem
|
|
|
|
template_name = 'news_index.html'
|
|
|
|
context_object_name = 'news_items'
|
2016-06-05 21:20:06 +00:00
|
|
|
|
2016-06-16 16:46:52 +00:00
|
|
|
def get_queryset(self):
|
|
|
|
return self.model.objects.public()
|
|
|
|
|
2016-06-05 21:20:06 +00:00
|
|
|
|
|
|
|
class NewsDetail(DetailView):
|
|
|
|
model = models.NewsItem
|
|
|
|
template_name = 'news_detail.html'
|
2016-06-05 21:34:30 +00:00
|
|
|
context_object_name = 'news_item'
|
2016-06-05 21:20:06 +00:00
|
|
|
|
2016-06-10 18:21:32 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(NewsDetail, self).get_context_data(**kwargs)
|
|
|
|
news_item = self.get_object()
|
2016-06-10 18:31:38 +00:00
|
|
|
timed = news_item.published_at > timezone.now()
|
|
|
|
|
|
|
|
if news_item.public and timed:
|
|
|
|
context['not_public'] = True
|
|
|
|
context['timed'] = True
|
|
|
|
elif not news_item.public:
|
|
|
|
context['not_public'] = True
|
|
|
|
context['timed'] = False
|
|
|
|
|
2016-06-10 18:21:32 +00:00
|
|
|
return context
|
|
|
|
|