00af109e2f
* add flake8 to pre-commit config, and fixup many things to make flake8 happy * add isort and sort all imports, add to pre-commit and requirements
46 lines
1,020 B
Python
46 lines
1,020 B
Python
from django.contrib.syndication.views import Feed
|
|
from django.utils import timezone
|
|
from django.views.generic import DetailView, ListView
|
|
|
|
from .models import NewsItem
|
|
|
|
|
|
def news_items_queryset(kwargs=None):
|
|
if not kwargs:
|
|
archived = False
|
|
else:
|
|
archived = kwargs["archived"]
|
|
|
|
return NewsItem.objects.filter(
|
|
published_at__isnull=False, published_at__lt=timezone.now(), archived=archived
|
|
)
|
|
|
|
|
|
class NewsIndex(ListView):
|
|
model = NewsItem
|
|
template_name = "news_index.html"
|
|
context_object_name = "news_items"
|
|
|
|
def get_queryset(self):
|
|
return news_items_queryset(self.kwargs)
|
|
|
|
|
|
class NewsDetail(DetailView):
|
|
model = NewsItem
|
|
template_name = "news_detail.html"
|
|
context_object_name = "news_item"
|
|
|
|
|
|
class NewsFeed(Feed):
|
|
title = "BornHack News"
|
|
link = "/news"
|
|
|
|
def items(self):
|
|
return news_items_queryset()
|
|
|
|
def item_title(self, item):
|
|
return item.title
|
|
|
|
def item_description(self, item):
|
|
return item.content
|