From e43cbc1a487b8ea45c05a4b394a7c60ffc4c0ba4 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Fri, 3 May 2019 12:24:25 -0500 Subject: added build system --- app/blog/build.py | 11 ++++++++++- app/blog/models.py | 4 ++-- app/blog/views.py | 2 +- app/builder/base.py | 17 +++++++++++++++++ app/builder/views.py | 22 ++++++++++++++++++++-- app/links/build.py | 10 +++++----- app/links/views.py | 3 +-- config/base_urls.py | 11 ++++++++++- design/templates/admin/buttons.html | 6 +++--- design/templates/base.html | 2 +- design/templates/blog/entry_detail.txt | 8 ++++++++ design/templates/feed.xml | 26 ++++++++++++++++++++++++++ 12 files changed, 104 insertions(+), 18 deletions(-) create mode 100644 design/templates/blog/entry_detail.txt create mode 100644 design/templates/feed.xml diff --git a/app/blog/build.py b/app/blog/build.py index 392e991..10553a6 100644 --- a/app/blog/build.py +++ b/app/blog/build.py @@ -16,7 +16,16 @@ class BuildEssays(BuildNew): response = self.client.get('/essays/') self.write_file('essays/', response.content) + def build_homepage(self): + response = self.client.get('/') + self.write_file('', response.content) + def essaybuilder(): - j = BuildEssays("essays", "essay") + j = BuildEssays("blog", "Entry") j.build() + + +def homebuilder(): + j = BuildEssays("blog", "Entry") + j.build_homepage() diff --git a/app/blog/models.py b/app/blog/models.py index 61ac407..ee4aca0 100644 --- a/app/blog/models.py +++ b/app/blog/models.py @@ -57,13 +57,13 @@ class Entry(models.Model): super(Entry, self).save() -class GuideSitemap(Sitemap): +class BlogSitemap(Sitemap): changefreq = "never" priority = 1.0 protocol = "https" def items(self): - return Essay.objects.filter(status=1) + return Entry.objects.filter(status=1) def lastmod(self, obj): return obj.pub_date diff --git a/app/blog/views.py b/app/blog/views.py index cf0fdf6..224decb 100644 --- a/app/blog/views.py +++ b/app/blog/views.py @@ -23,7 +23,7 @@ class EntryDetailView(DetailView): class EntryDetailViewTXT(EntryDetailView): - template_name = "entry_detail.txt" + template_name = "blog/entry_detail.txt" class EntryYearArchiveView(YearArchiveView): diff --git a/app/builder/base.py b/app/builder/base.py index 0d2cb0f..839c522 100644 --- a/app/builder/base.py +++ b/app/builder/base.py @@ -1,4 +1,6 @@ import os +from operator import attrgetter +from itertools import chain from math import ceil from decimal import Decimal from django.test.client import Client @@ -150,3 +152,18 @@ class BuildPages(BuildNew): fpath = '%s' %(page.slug) self.write_file('', t, 'html', page.slug) self.write_file('', t, 'txt', page.slug) + + +class BuildRSS(BuildNew): + def build(self): + entry_list = apps.get_model('blog', 'entry').objects.filter(status=1) + link_list = apps.get_model('links', 'link').objects.filter(status=1) + result_list = sorted( + chain(entry_list, link_list), + key=attrgetter('pub_date') + ) + qs = reversed(result_list) + c = {'object_list': qs, 'SITE_URL': settings.SITE_URL} + t = render_to_string('feed.xml', c).encode('utf-8') + fpath = '%s' % ('rss/',) + self.write_file(fpath, t, 'xml') diff --git a/app/builder/views.py b/app/builder/views.py index 9d12aaa..3c63b00 100644 --- a/app/builder/views.py +++ b/app/builder/views.py @@ -1,13 +1,31 @@ from django.shortcuts import render_to_response -from django.template import RequestContext -#from src.build import builder as src_builder from pages.build import builder as page_builder +from builder.base import BuildSitemap, BuildRSS +from blog.build import essaybuilder, homebuilder +from links.build import linkbuilder def do_build(request): section = request.GET.get('id', '') context = {} + if section == 'essays': + context = {'message': 'Writing Essays to Disk'} + essaybuilder() + if section == 'links': + context = {'message': 'Writing Links to Disk'} + linkbuilder() if section == 'pages': context = {'message': 'Writing Pages to Disk'} page_builder() + if section == 'home': + context = {'message': 'Writing Homepage to Disk'} + homebuilder() + if section == 'sitemap': + context = {'message': 'Writing Sitemap to Disk'} + j = BuildSitemap("blog", "Entry") + j.build() + if section == 'rss': + context = {'message': 'Writing RSS feed to Disk'} + j = BuildRSS("blog", "Entry") + j.build() return render_to_response('admin/message.html', context) diff --git a/app/links/build.py b/app/links/build.py index 392e991..cc57884 100644 --- a/app/links/build.py +++ b/app/links/build.py @@ -4,7 +4,7 @@ from django.urls import reverse from . import models -class BuildEssays(BuildNew): +class BuildLinks(BuildNew): def build(self): self.build_list_view() @@ -13,10 +13,10 @@ class BuildEssays(BuildNew): #self.build_feed("src:feed") def build_list_view(self): - response = self.client.get('/essays/') - self.write_file('essays/', response.content) + response = self.client.get('/linked/') + self.write_file('linked/', response.content) -def essaybuilder(): - j = BuildEssays("essays", "essay") +def linkbuilder(): + j = BuildLinks("links", "link") j.build() diff --git a/app/links/views.py b/app/links/views.py index 64cc5f7..6d03d19 100644 --- a/app/links/views.py +++ b/app/links/views.py @@ -20,8 +20,7 @@ class EntryDetailView(DetailView): class EntryDetailViewTXT(EntryDetailView): - template_name = "entry_detail.txt" - + template_name = "blog/entry_detail.txt" class EntryYearArchiveView(YearArchiveView): diff --git a/config/base_urls.py b/config/base_urls.py index cbc9517..e55cd33 100644 --- a/config/base_urls.py +++ b/config/base_urls.py @@ -5,11 +5,20 @@ from django.conf import settings from django.contrib.sitemaps.views import sitemap from pages.views import PageDetailView +from pages.models import PageSitemap from blog.views import HomePageView +from blog.models import BlogSitemap +from links.models import LinkedSitemap #import builder.views import utils.views import builder.views +sitemaps = { + 'blog': BlogSitemap, + 'links': LinkedSitemap, + 'pages': PageSitemap, +} + admin.autodiscover() @@ -18,7 +27,7 @@ urlpatterns = [ path(r'admin/data/', include('utils.urls')), path(r'admin/', admin.site.urls), #path(r'luximages/insert/', utils.views.insert_image), - #path(r'sitemap.xml', sitemap, {'sitemaps': sitemaps}), + path(r'sitemap.xml', sitemap, {'sitemaps': sitemaps}), path(r'essays/', include('blog.urls')), path(r'linked/', include('links.urls')), path(r'', PageDetailView.as_view()), diff --git a/design/templates/admin/buttons.html b/design/templates/admin/buttons.html index d9d3171..7c6a115 100644 --- a/design/templates/admin/buttons.html +++ b/design/templates/admin/buttons.html @@ -39,9 +39,9 @@ {%endif%}
    -
  • Build Writing Details
  • -
  • Build Writing Archives
  • -
  • Build Homepage
  • +
  • Build Essays
  • +
  • Build links
  • +
  • Build Homepage
  • Build Sitemap
  • Build RSS
  • Build All Pages
  • diff --git a/design/templates/base.html b/design/templates/base.html index 9be4f51..7e48bc5 100644 --- a/design/templates/base.html +++ b/design/templates/base.html @@ -42,7 +42,7 @@