diff options
Diffstat (limited to 'app/blog')
-rw-r--r-- | app/blog/admin.py | 16 | ||||
-rw-r--r-- | app/blog/models.py | 3 | ||||
-rw-r--r-- | app/blog/urls.py | 37 | ||||
-rw-r--r-- | app/blog/views.py | 34 |
4 files changed, 61 insertions, 29 deletions
diff --git a/app/blog/admin.py b/app/blog/admin.py index 6a4749f..b3093f6 100644 --- a/app/blog/admin.py +++ b/app/blog/admin.py @@ -18,8 +18,9 @@ class EntryAdmin(admin.ModelAdmin): 'sub_title', 'body_markdown', ('pub_date', 'status'), + 'tags', 'meta_description', - ('slug', 'enable_comments', 'has_code'), + 'slug', ), 'classes': ( 'show', @@ -27,19 +28,6 @@ class EntryAdmin(admin.ModelAdmin): 'wide' ) }), - ('meta', { - 'fields': ( - 'originally_published_by', - 'originally_published_by_url', - 'afterword', - ('field_notes', 'books'), - ), - 'classes': ( - 'hide', - 'extrapretty', - 'wide' - ) - }), ) class Media: diff --git a/app/blog/models.py b/app/blog/models.py index 3d1ae30..61ac407 100644 --- a/app/blog/models.py +++ b/app/blog/models.py @@ -27,7 +27,6 @@ class Entry(models.Model): status = models.IntegerField(choices=PUB_STATUS, default=0) meta_description = models.CharField(max_length=256, null=True, blank=True) tags = TaggableManager(through=TaggedItems, blank=True, help_text='Topics Covered') - featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True) category = models.ForeignKey(Category, on_delete=models.CASCADE, null=True, blank=True) class Meta: @@ -39,7 +38,7 @@ class Entry(models.Model): return self.title def get_absolute_url(self): - return reverse('essays:detail', kwargs={"slug": self.slug}) + return reverse("blog:detail", kwargs={"year": self.pub_date.year, "month": self.pub_date.strftime("%m"), "slug": self.slug}) def comment_period_open(self): return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date diff --git a/app/blog/urls.py b/app/blog/urls.py index da3e1fd..0e9a55c 100644 --- a/app/blog/urls.py +++ b/app/blog/urls.py @@ -5,24 +5,35 @@ from . import views app_name = "blog" urlpatterns = [ - #path( - # r'topic/<str:slug>', - # views.TopicListView.as_view(), - # name="list_topics" - #), - path( - r'<str:slug>', + re_path( + r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<slug>[-\w]+).txt$', + views.EntryDetailViewTXT.as_view(), + name="detail-txt" + ), + re_path( + r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<slug>[-\w]+)$', views.EntryDetailView.as_view(), name="detail" ), - path( - r'<str:slug>', - views.EntryDetailViewTXT.as_view(), - name="detail-txt" + re_path( + r'^(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$', + views.EntryMonthArchiveView.as_view(month_format='%m'), + name="list_month" + ), + re_path( + r'(?P<year>\d{4})/$', + views.EntryYearArchiveView.as_view(), + name="list_year" + ), + re_path( + r'^(?P<page>\d+)/$', + views.EntryListView.as_view(), + name="list" ), - path( + re_path( r'', views.EntryListView.as_view(), - name="list", + {'page': 1}, + name="list" ), ] diff --git a/app/blog/views.py b/app/blog/views.py index 56bd823..cf0fdf6 100644 --- a/app/blog/views.py +++ b/app/blog/views.py @@ -1,9 +1,13 @@ +from operator import attrgetter +from itertools import chain from django.views.generic import ListView from django.views.generic.detail import DetailView +from django.views.generic.dates import YearArchiveView, MonthArchiveView from django.contrib.syndication.views import Feed from .models import Entry +from links.models import Link class EntryListView(ListView): @@ -22,6 +26,36 @@ class EntryDetailViewTXT(EntryDetailView): template_name = "entry_detail.txt" +class EntryYearArchiveView(YearArchiveView): + queryset = Entry.objects.filter(status__exact=1).select_related() + date_field = "pub_date" + make_object_list = True + allow_future = True + + +class EntryMonthArchiveView(MonthArchiveView): + queryset = Entry.objects.filter(status__exact=1).select_related() + date_field = "pub_date" + allow_future = True + + +class HomePageView(ListView): + model = Entry + template_name = "homepage.html" + + def get_queryset(self, **kwargs): + entry_list = Entry.objects.filter(status=1) + link_list = Link.objects.filter(status=1) + result_list = sorted( + chain(entry_list, link_list), + key=attrgetter('pub_date') + ) + return reversed(result_list) + + + + + ''' class TopicListView(ListView): template_name = 'archives/src_home.html' |