diff options
author | luxagraf <sng@luxagraf.net> | 2019-05-03 11:38:24 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2019-05-03 11:38:24 -0500 |
commit | 0e59ad7de18bffcf6a62f9ee61275b4951c27358 (patch) | |
tree | 514fca6efb90db53ca3061aa4ab8ba7d2a33cffe /app | |
parent | 86fcf7ed710f41fc5324b638d092af54f4bb756f (diff) |
finished up initial design work
Diffstat (limited to 'app')
-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 | ||||
-rw-r--r-- | app/links/__init__.py | 0 | ||||
-rw-r--r-- | app/links/admin.py | 32 | ||||
-rw-r--r-- | app/links/build.py | 22 | ||||
-rw-r--r-- | app/links/migrations/0001_initial.py | 43 | ||||
-rw-r--r-- | app/links/migrations/0002_auto_20190501_1054.py | 44 | ||||
-rw-r--r-- | app/links/migrations/__init__.py | 0 | ||||
-rw-r--r-- | app/links/models.py | 46 | ||||
-rw-r--r-- | app/links/urls.py | 39 | ||||
-rw-r--r-- | app/links/views.py | 65 |
13 files changed, 352 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' diff --git a/app/links/__init__.py b/app/links/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/links/__init__.py diff --git a/app/links/admin.py b/app/links/admin.py new file mode 100644 index 0000000..9ee9fbf --- /dev/null +++ b/app/links/admin.py @@ -0,0 +1,32 @@ +from django.contrib import admin + +from utils.widgets import LGEntryForm + +from .models import Link + + +@admin.register(Link) +class EntryAdmin(admin.ModelAdmin): + form = LGEntryForm + list_display = ('title', 'pub_date', 'status') + list_filter = ('pub_date', 'status') + prepopulated_fields = {"slug": ('title',)} + fieldsets = ( + ('Link', { + 'fields': ( + 'title', + 'body_markdown', + 'slug', + 'link_url', + ('pub_date', 'status'), + ), + 'classes': ( + 'show', + 'extrapretty', + 'wide' + ) + }), + ) + + class Media: + js = ('next-prev-links.js') diff --git a/app/links/build.py b/app/links/build.py new file mode 100644 index 0000000..392e991 --- /dev/null +++ b/app/links/build.py @@ -0,0 +1,22 @@ +import os +from builder.base import BuildNew +from django.urls import reverse +from . import models + + +class BuildEssays(BuildNew): + + def build(self): + self.build_list_view() + self.build_detail_view() + # These are the unique classes for this model: + #self.build_feed("src:feed") + + def build_list_view(self): + response = self.client.get('/essays/') + self.write_file('essays/', response.content) + + +def essaybuilder(): + j = BuildEssays("essays", "essay") + j.build() diff --git a/app/links/migrations/0001_initial.py b/app/links/migrations/0001_initial.py new file mode 100644 index 0000000..be54329 --- /dev/null +++ b/app/links/migrations/0001_initial.py @@ -0,0 +1,43 @@ +# Generated by Django 2.1.7 on 2019-03-30 17:07 + +from django.db import migrations, models +import django.db.models.deletion +import taggit.managers + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('photos', '0001_initial'), + ('taxonomy', '__first__'), + ] + + operations = [ + migrations.CreateModel( + name='Entry', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('sub_title', models.CharField(blank=True, max_length=200)), + ('dek', models.TextField(blank=True)), + ('slug', models.SlugField(unique_for_date='pub_date')), + ('body_html', models.TextField(blank=True)), + ('body_markdown', models.TextField()), + ('pub_date', models.DateTimeField(verbose_name='Date published')), + ('last_updated', models.DateTimeField(auto_now=True)), + ('enable_comments', models.BooleanField(default=False)), + ('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=0)), + ('meta_description', models.CharField(blank=True, max_length=256, null=True)), + ('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='taxonomy.Category')), + ('featured_image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='photos.LuxImage')), + ('tags', taggit.managers.TaggableManager(blank=True, help_text='Topics Covered', through='taxonomy.TaggedItems', to='taxonomy.LuxTag', verbose_name='Tags')), + ], + options={ + 'get_latest_by': 'pub_date', + 'verbose_name_plural': 'Essays', + 'ordering': ('-pub_date',), + }, + ), + ] diff --git a/app/links/migrations/0002_auto_20190501_1054.py b/app/links/migrations/0002_auto_20190501_1054.py new file mode 100644 index 0000000..b4ca5d1 --- /dev/null +++ b/app/links/migrations/0002_auto_20190501_1054.py @@ -0,0 +1,44 @@ +# Generated by Django 2.1.7 on 2019-05-01 15:54 + +from django.db import migrations, models +import taggit.managers + + +class Migration(migrations.Migration): + + dependencies = [ + ('taxonomy', '0001_initial'), + ('links', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Link', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('link_url', models.URLField(max_length=400)), + ('pub_date', models.DateTimeField(verbose_name='Date published')), + ('slug', models.SlugField(unique_for_date='pub_date')), + ('body_html', models.TextField(blank=True)), + ('body_markdown', models.TextField()), + ('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=0)), + ('tags', taggit.managers.TaggableManager(blank=True, help_text='Topics Covered', through='taxonomy.TaggedItems', to='taxonomy.LuxTag', verbose_name='Tags')), + ], + ), + migrations.RemoveField( + model_name='entry', + name='category', + ), + migrations.RemoveField( + model_name='entry', + name='featured_image', + ), + migrations.RemoveField( + model_name='entry', + name='tags', + ), + migrations.DeleteModel( + name='Entry', + ), + ] diff --git a/app/links/migrations/__init__.py b/app/links/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/links/migrations/__init__.py diff --git a/app/links/models.py b/app/links/models.py new file mode 100644 index 0000000..518ba33 --- /dev/null +++ b/app/links/models.py @@ -0,0 +1,46 @@ +from django.db import models +from django.urls import reverse +from django.contrib.sitemaps import Sitemap + +from taggit.managers import TaggableManager + +from taxonomy.models import TaggedItems +from utils.util import render_images, markdown_to_html + + +class Link(models.Model): + title = models.CharField(max_length=200) + link_url = models.URLField(max_length=400) + pub_date = models.DateTimeField('Date published') + slug = models.SlugField(unique_for_date='pub_date') + tags = TaggableManager(through=TaggedItems, blank=True, help_text='Topics Covered') + body_html = models.TextField(blank=True) + body_markdown = models.TextField() + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=0) + + def __str__(self): + return self.title + + def get_absolute_url(self): + return reverse("links:detail", kwargs={"year": self.pub_date.year, "month": self.pub_date.strftime("%m"), "slug": self.slug}) + + def save(self): + md = render_images(self.body_markdown) + self.body_html = markdown_to_html(md) + super(Link, self).save() + + +class LinkedSitemap(Sitemap): + changefreq = "weekly" + priority = 0.8 + protocol = "https" + + def items(self): + return Link.objects.filter(status=1) + + def lastmod(self, obj): + return obj.pub_date diff --git a/app/links/urls.py b/app/links/urls.py new file mode 100644 index 0000000..fb18532 --- /dev/null +++ b/app/links/urls.py @@ -0,0 +1,39 @@ +from django.urls import path, re_path + +from . import views + +app_name = "links" + +urlpatterns = [ + 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" + ), + 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" + ), + re_path( + r'', + views.EntryListView.as_view(), + {'page': 1}, + name="list" + ), +] diff --git a/app/links/views.py b/app/links/views.py new file mode 100644 index 0000000..64cc5f7 --- /dev/null +++ b/app/links/views.py @@ -0,0 +1,65 @@ +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 Link + + +class EntryListView(ListView): + model = Link + + def get_queryset(self, **kwargs): + qs = Link.objects.filter(status=1) + return qs + + +class EntryDetailView(DetailView): + model = Link + + +class EntryDetailViewTXT(EntryDetailView): + template_name = "entry_detail.txt" + + + +class EntryYearArchiveView(YearArchiveView): + queryset = Link.objects.filter(status__exact=1).select_related() + date_field = "pub_date" + make_object_list = True + allow_future = True + + +class EntryMonthArchiveView(MonthArchiveView): + queryset = Link.objects.filter(status__exact=1).select_related() + date_field = "pub_date" + allow_future = True + + + + + +''' +class TopicListView(ListView): + template_name = 'archives/src_home.html' + + def queryset(self): + return Post.objects.filter(topics__slug=self.kwargs['slug']) + + def get_context_data(self, **kwargs): + # Call the base implementation first to get a context + context = super(TopicListView, self).get_context_data(**kwargs) + context['topic'] = Topic.objects.get(slug__exact=self.kwargs['slug']) + return context + + +class SrcRSSFeedView(Feed): + title = "luxagraf:src Code and Technology" + link = "/src/" + description = "Latest postings to luxagraf.net/src" + description_template = 'feeds/blog_description.html' + + def items(self): + return Post.objects.filter(status__exact=1).order_by('-pub_date')[:10] +''' |