diff options
author | luxagraf <sng@luxagraf.net> | 2019-02-07 09:54:16 -0600 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2019-02-07 09:54:16 -0600 |
commit | 27aaf92d26eb75157dcfa923a5d63ea63feeb98c (patch) | |
tree | 8f6213bc0ecd7738ad050dc4454732c4fd210ab1 /app | |
parent | 3a54cdb85027e4a59ca6d78f5b91dbf7be77afd0 (diff) |
updated stylesheets and added essays
Diffstat (limited to 'app')
-rw-r--r-- | app/essays/__init__.py | 0 | ||||
-rw-r--r-- | app/essays/admin.py | 49 | ||||
-rw-r--r-- | app/essays/build.py | 59 | ||||
-rw-r--r-- | app/essays/migrations/0001_initial.py | 51 | ||||
-rw-r--r-- | app/essays/migrations/0002_auto_20190204_1541.py | 23 | ||||
-rw-r--r-- | app/essays/migrations/0003_essay_afterword_html.py | 18 | ||||
-rw-r--r-- | app/essays/migrations/0004_auto_20190205_0830.py | 27 | ||||
-rw-r--r-- | app/essays/migrations/__init__.py | 0 | ||||
-rw-r--r-- | app/essays/models.py | 100 | ||||
-rw-r--r-- | app/essays/urls.py | 28 | ||||
-rw-r--r-- | app/essays/views.py | 56 | ||||
-rw-r--r-- | app/income/views.py | 11 | ||||
-rw-r--r-- | app/jrnl/views.py | 1 | ||||
-rw-r--r-- | app/pages/admin.py | 4 | ||||
-rw-r--r-- | app/pages/migrations/0005_auto_20190203_1434.py | 36 | ||||
-rw-r--r-- | app/pages/models.py | 7 | ||||
-rw-r--r-- | app/utils/util.py | 80 |
17 files changed, 502 insertions, 48 deletions
diff --git a/app/essays/__init__.py b/app/essays/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/essays/__init__.py diff --git a/app/essays/admin.py b/app/essays/admin.py new file mode 100644 index 0000000..f326092 --- /dev/null +++ b/app/essays/admin.py @@ -0,0 +1,49 @@ +from django.contrib import admin +from .models import Essay, PostType +from utils.widgets import LGEntryForm + + +@admin.register(PostType) +class PostTypeAdmin(admin.ModelAdmin): + prepopulated_fields = {"slug": ('name',)} + + +@admin.register(Essay) +class EssayAdmin(admin.ModelAdmin): + form = LGEntryForm + list_display = ('title', 'pub_date', 'enable_comments', 'status') + list_filter = ('pub_date', 'enable_comments', 'status') + prepopulated_fields = {"slug": ('title',)} + fieldsets = ( + ('Entry', { + 'fields': ( + 'title', + 'sub_title', + 'body_markdown', + ('pub_date', 'status'), + 'meta_description', + ('slug', 'enable_comments', 'has_code', 'post_type'), + ), + 'classes': ( + 'show', + 'extrapretty', + 'wide' + ) + }), + ('meta', { + 'fields': ( + 'originally_published_by', + 'originally_published_by_url', + 'afterword', + ('field_notes', 'books'), + ), + 'classes': ( + 'hide', + 'extrapretty', + 'wide' + ) + }), + ) + + class Media: + js = ('image-loader.js', 'next-prev-links.js') diff --git a/app/essays/build.py b/app/essays/build.py new file mode 100644 index 0000000..cd6cc28 --- /dev/null +++ b/app/essays/build.py @@ -0,0 +1,59 @@ +import os +from builder.base import BuildNew +from django.urls import reverse +from . import models + + +class BuildSrc(BuildNew): + + def build(self): + self.build_list_view( + base_path=reverse("src:list"), + paginate_by=99999 + ) + self.build_list_view( + base_path=reverse("src:list_books"), + paginate_by=99999 + ) + self.build_detail_view() + # These are the unique classes for this model: + # self.build_books_view() + self.build_topic_view() + self.build_feed("src:feed") + + def build_topic_view(self): + for topic in models.Topic.objects.all(): + url = reverse("src:list_topics", kwargs={'slug': topic.slug, }) + path, slug = os.path.split(url) + response = self.client.get(url, HTTP_HOST='127.0.0.1') + self.write_file('%s/' % path, response.content, filename=slug) + + def build_books_view(self): + for obj in models.Book.objects.all(): + url = reverse("src:detail_book", kwargs={'slug': obj.slug, }) + path, slug = os.path.split(url) + response = self.client.get(url, HTTP_HOST='127.0.0.1') + self.write_file('%s/' % path, response.content, filename=slug) + + +def builder(): + j = BuildSrc("src", "post") + j.build() + + +""" + + + + + def build_books(self): + path = 'src/books/' + c = Context({ + 'object_list': Book.objects.filter(status__exact=1), + 'MEDIA_URL': settings.BAKED_MEDIA_URL, + 'IMAGES_URL': settings.BAKED_IMAGES_URL + }) + t = render_to_string('archives/src_books.html', c).encode('utf-8') + self.write_file(path, t) + +""" diff --git a/app/essays/migrations/0001_initial.py b/app/essays/migrations/0001_initial.py new file mode 100644 index 0000000..e315809 --- /dev/null +++ b/app/essays/migrations/0001_initial.py @@ -0,0 +1,51 @@ +# Generated by Django 2.1.5 on 2019-02-04 14:08 + +from django.db import migrations, models +import django.db.models.deletion +import taggit.managers + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('photos', '0018_auto_20161130_1218'), + ('sketches', '0002_auto_20180208_0743'), + ('books', '0007_auto_20190131_2351'), + ('taxonomy', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Essay', + 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)), + ('has_code', 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)), + ('post_type', models.IntegerField(choices=[(0, 'essay'), (1, 'tools'), (2, 'figment')], default=0)), + ('elsewhere', models.CharField(blank=True, max_length=400)), + ('has_video', models.BooleanField(blank=True, default=False)), + ('afterword', models.TextField(blank=True)), + ('books', models.ManyToManyField(blank=True, to='books.Book')), + ('featured_image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='photos.LuxImage')), + ('field_notes', models.ManyToManyField(blank=True, to='sketches.Sketch')), + ('tags', taggit.managers.TaggableManager(blank=True, help_text='Topics Covered', through='taxonomy.TaggedItems', to='taxonomy.LuxTag', verbose_name='Tags')), + ], + options={ + 'verbose_name_plural': 'Essays', + 'ordering': ('-pub_date',), + 'get_latest_by': 'pub_date', + }, + ), + ] diff --git a/app/essays/migrations/0002_auto_20190204_1541.py b/app/essays/migrations/0002_auto_20190204_1541.py new file mode 100644 index 0000000..f4e6744 --- /dev/null +++ b/app/essays/migrations/0002_auto_20190204_1541.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1.5 on 2019-02-04 15:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('essays', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='essay', + old_name='elsewhere', + new_name='originally_published_by', + ), + migrations.AddField( + model_name='essay', + name='originally_published_by_url', + field=models.CharField(blank=True, max_length=400), + ), + ] diff --git a/app/essays/migrations/0003_essay_afterword_html.py b/app/essays/migrations/0003_essay_afterword_html.py new file mode 100644 index 0000000..5f8301b --- /dev/null +++ b/app/essays/migrations/0003_essay_afterword_html.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.5 on 2019-02-04 16:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('essays', '0002_auto_20190204_1541'), + ] + + operations = [ + migrations.AddField( + model_name='essay', + name='afterword_html', + field=models.TextField(blank=True), + ), + ] diff --git a/app/essays/migrations/0004_auto_20190205_0830.py b/app/essays/migrations/0004_auto_20190205_0830.py new file mode 100644 index 0000000..65e2e5d --- /dev/null +++ b/app/essays/migrations/0004_auto_20190205_0830.py @@ -0,0 +1,27 @@ +# Generated by Django 2.1.5 on 2019-02-05 08:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('essays', '0003_essay_afterword_html'), + ] + + operations = [ + migrations.CreateModel( + name='PostType', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ('dek', models.TextField(blank=True)), + ('slug', models.SlugField()), + ], + ), + migrations.AlterField( + model_name='essay', + name='post_type', + field=models.IntegerField(choices=[(0, 'essays'), (1, 'tools'), (2, 'figments')], default=0), + ), + ] diff --git a/app/essays/migrations/__init__.py b/app/essays/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/essays/migrations/__init__.py diff --git a/app/essays/models.py b/app/essays/models.py new file mode 100644 index 0000000..23a4cce --- /dev/null +++ b/app/essays/models.py @@ -0,0 +1,100 @@ +from django.db import models +from django.urls import reverse +from django.contrib.sitemaps import Sitemap +import datetime +from itertools import chain + +from taggit.managers import TaggableManager + +from taxonomy.models import TaggedItems +from utils.util import render_images, markdown_to_html +from sketches.models import Sketch +from books.models import Book +from photos.models import LuxImage + + +POST_TYPE = ( + (0, 'essays'), + (1, 'tools'), + (2, 'figments'), +) + + +class PostType(models.Model): + name = models.CharField(max_length=200) + dek = models.TextField(blank=True) + slug = models.SlugField() + + def __str__(self): + return self.name + + +class Essay(models.Model): + title = models.CharField(max_length=200) + sub_title = models.CharField(max_length=200, blank=True) + 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('Date published') + last_updated = models.DateTimeField(auto_now=True) + enable_comments = models.BooleanField(default=False) + has_code = models.BooleanField(default=False) + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=0) + meta_description = models.CharField(max_length=256, null=True, blank=True) + post_type = models.IntegerField(choices=POST_TYPE, default=0) + tags = TaggableManager(through=TaggedItems, blank=True, help_text='Topics Covered') + originally_published_by = models.CharField(max_length=400, blank=True) + originally_published_by_url = models.CharField(max_length=400, blank=True) + featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True) + has_video = models.BooleanField(blank=True, default=False) + field_notes = models.ManyToManyField(Sketch, blank=True) + books = models.ManyToManyField(Book, blank=True) + afterword = models.TextField(blank=True) + afterword_html = models.TextField(blank=True) + + class Meta: + ordering = ('-pub_date',) + get_latest_by = 'pub_date' + verbose_name_plural = 'Essays' + + def __str__(self): + return self.title + + def get_absolute_url(self): + return "/%s/%s" % (self.get_post_type_display(), self.slug) + + def comment_period_open(self): + return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date + + @property + def get_previous_published(self): + return self.get_previous_by_pub_date(status__exact=1) + + @property + def get_next_published(self): + return self.get_next_by_pub_date(status__exact=1) + + def save(self): + md = render_images(self.body_markdown) + self.body_html = markdown_to_html(md) + self.afterword_html = markdown_to_html(self.afterword) + super(Essay, self).save() + + +class EssaySitemap(Sitemap): + changefreq = "never" + priority = 0.7 + protocol = "https" + + def items(self): + return list(chain( + Essay.objects.all(), + )) + + def lastmod(self, obj): + return obj.pub_date diff --git a/app/essays/urls.py b/app/essays/urls.py new file mode 100644 index 0000000..408e959 --- /dev/null +++ b/app/essays/urls.py @@ -0,0 +1,28 @@ +from django.urls import path, re_path + +from . import views + +app_name = "essays" + +urlpatterns = [ + #path( + # r'topic/<str:slug>', + # views.TopicListView.as_view(), + # name="list_topics" + #), + path( + r'<str:slug>', + views.EntryDetailView.as_view(), + name="detail" + ), + path( + r'<str:slug>.txt', + views.EntryDetailViewTXT.as_view(), + name="detail-txt" + ), + path( + r'', + views.EssayListView.as_view(), + name="list", + ), +] diff --git a/app/essays/views.py b/app/essays/views.py new file mode 100644 index 0000000..0fdaa63 --- /dev/null +++ b/app/essays/views.py @@ -0,0 +1,56 @@ +from django.views.generic import ListView +from django.views.generic.detail import DetailView +from django.contrib.syndication.views import Feed + + +from .models import Essay, PostType, POST_TYPE + + +class EssayListView(ListView): + model = Essay + + def get_queryset(self, **kwargs): + t = self.request.path.split('/')[1] + type_reverse = dict((v, k) for k, v in POST_TYPE) + self.essay_type = t + qs = Essay.objects.filter(post_type=type_reverse[t]) + return qs + + def get_context_data(self, **kwargs): + # Call the base implementation first to get a context + context = super(EssayListView, self).get_context_data(**kwargs) + context['essay_type'] = PostType.objects.get(slug=self.essay_type) + return context + + +class EntryDetailView(DetailView): + model = Essay + + +class EntryDetailViewTXT(EntryDetailView): + template_name = "essays/entry_detail.txt" + + +''' +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] +''' diff --git a/app/income/views.py b/app/income/views.py index fc22c0d..1c34068 100644 --- a/app/income/views.py +++ b/app/income/views.py @@ -4,7 +4,7 @@ from django.template.loader import render_to_string from django.http import HttpResponse from django.conf import settings -from weasyprint import HTML, CSS +#from weasyprint import HTML, CSS from .models import Invoice, InvoiceItem @@ -45,8 +45,9 @@ class DownloadMonthlyInvoiceView(MonthlyInvoiceView): 'invoice_number': self.object.id+23 } t = render_to_string('details/invoice.html', c).encode('utf-8') - html = HTML(string=t, base_url=self.request.build_absolute_uri()) - pdf = html.write_pdf(stylesheets=[CSS(settings.MEDIA_ROOT + '/pdf_gen.css')], presentational_hints=True) - response = HttpResponse(pdf, content_type='application/pdf') - response['Content-Disposition'] = 'inline; filename="invoice.pdf"' + #html = HTML(string=t, base_url=self.request.build_absolute_uri()) + #pdf = html.write_pdf(stylesheets=[CSS(settings.MEDIA_ROOT + '/pdf_gen.css')], presentational_hints=True) + #response = HttpResponse(pdf, content_type='application/pdf') + #response['Content-Disposition'] = 'inline; filename="invoice.pdf"' + response = HttpResponse('', content_type='application/pdf') return response diff --git a/app/jrnl/views.py b/app/jrnl/views.py index 5dc627e..b2b0316 100644 --- a/app/jrnl/views.py +++ b/app/jrnl/views.py @@ -73,7 +73,6 @@ class EntryMonthArchiveView(MonthArchiveView): class EntryDetailView(DetailView): model = Entry - template_name = "details/entry.html" slug_field = "slug" def get_queryset(self): diff --git a/app/pages/admin.py b/app/pages/admin.py index abe903d..809c2a6 100644 --- a/app/pages/admin.py +++ b/app/pages/admin.py @@ -6,6 +6,7 @@ from django.db import models from pages.models import Page + class PageEntryForm(forms.ModelForm): class Meta: model = Page @@ -14,6 +15,7 @@ class PageEntryForm(forms.ModelForm): 'body_markdown': forms.Textarea(attrs={'rows': 50, 'cols': 100}), } + class PageAdmin(admin.ModelAdmin): form = PageEntryForm list_display = ('title', 'slug', 'path', 'app', 'build') @@ -21,7 +23,7 @@ class PageAdmin(admin.ModelAdmin): prepopulated_fields = {"slug": ('title',)} fieldsets = ( ('Page', { - 'fields': ('title', 'body_markdown', 'build', ('slug', 'path', 'app')), + 'fields': ('title', 'sub_title', 'body_markdown', 'build', ('slug', 'path', 'app')), 'classes': ('show', 'extrapretty', 'wide') }), ('Metadata', { diff --git a/app/pages/migrations/0005_auto_20190203_1434.py b/app/pages/migrations/0005_auto_20190203_1434.py new file mode 100644 index 0000000..d1f0062 --- /dev/null +++ b/app/pages/migrations/0005_auto_20190203_1434.py @@ -0,0 +1,36 @@ +# Generated by Django 2.1.5 on 2019-02-03 14:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('pages', '0004_page_build'), + ] + + operations = [ + migrations.AddField( + model_name='page', + name='sub_title', + field=models.CharField(blank=True, max_length=300), + ), + migrations.AlterField( + model_name='page', + name='app', + field=models.CharField(blank=True, default='', max_length=50), + preserve_default=False, + ), + migrations.AlterField( + model_name='page', + name='meta_description', + field=models.CharField(blank=True, default='', max_length=256), + preserve_default=False, + ), + migrations.AlterField( + model_name='page', + name='path', + field=models.CharField(blank=True, default='', max_length=200), + preserve_default=False, + ), + ] diff --git a/app/pages/models.py b/app/pages/models.py index 73c33dd..fa2bbc3 100644 --- a/app/pages/models.py +++ b/app/pages/models.py @@ -7,12 +7,13 @@ from utils.util import markdown_to_html, render_images class Page(models.Model): title = models.CharField(max_length=200) + sub_title = models.CharField(max_length=300, blank=True) slug = models.SlugField() body_html = models.TextField(blank=True) body_markdown = models.TextField() - meta_description = models.CharField(max_length=256, null=True, blank=True) - path = models.CharField(max_length=200, null=True, blank=True) - app = models.CharField(max_length=50, null=True, blank=True) + meta_description = models.CharField(max_length=256, blank=True) + path = models.CharField(max_length=200, blank=True) + app = models.CharField(max_length=50, blank=True) build = models.BooleanField(default=True) def __str__(self): diff --git a/app/utils/util.py b/app/utils/util.py index 714403b..6d20a54 100644 --- a/app/utils/util.py +++ b/app/utils/util.py @@ -58,46 +58,50 @@ def parse_image(s): s = str(img).replace('[[base_url]]', settings.IMAGES_URL) return s else: - image_id = img['id'].split("image-")[1] - i = apps.get_model('photos', 'LuxImage').objects.get(pk=image_id) - caption = False - exif = False - cluster_class = None - is_cluster = False - extra = None - if cl[0] == 'cluster': - css_class = cl[0] - is_cluster = True - cluster_class = cl[1] - try: - if cl[2] == 'caption': + try: + image_id = img['id'].split("image-")[1] + i = apps.get_model('photos', 'LuxImage').objects.get(pk=image_id) + caption = False + exif = False + cluster_class = None + is_cluster = False + extra = None + if cl[0] == 'cluster': + css_class = cl[0] + is_cluster = True + cluster_class = cl[1] + try: + if cl[2] == 'caption': + caption = True + elif cl[2] == 'exif': + exif = True + else: + extra = cl[2] + + if len(cl) > 3: + if cl[3] == 'exif': + exif = True + except: + pass + elif cl[0] != 'cluster' and len(cl) > 1: + css_class = cl[0] + if cl[1] == 'caption': caption = True - elif cl[2] == 'exif': + if cl[1] == 'exif': exif = True - else: - extra = cl[2] - - if len(cl) > 3: - if cl[3] == 'exif': - exif = True - except: - pass - elif cl[0] != 'cluster' and len(cl) > 1: - css_class = cl[0] - if cl[1] == 'caption': - caption = True - if cl[1] == 'exif': - exif = True - elif cl[0] != 'cluster' and len(cl) > 2: - css_class = cl[0] - if cl[1] == 'caption': - caption = True - if cl[2] == 'exif': - exif = True - print('caption'+str(caption)) - else: - css_class = cl[0] - return render_to_string("lib/img_%s.html" % css_class, {'image': i, 'caption': caption, 'exif': exif, 'is_cluster': is_cluster, 'cluster_class': cluster_class, 'extra': extra}) + elif cl[0] != 'cluster' and len(cl) > 2: + css_class = cl[0] + if cl[1] == 'caption': + caption = True + if cl[2] == 'exif': + exif = True + print('caption'+str(caption)) + else: + css_class = cl[0] + return render_to_string("lib/img_%s.html" % css_class, {'image': i, 'caption': caption, 'exif': exif, 'is_cluster': is_cluster, 'cluster_class': cluster_class, 'extra': extra}) + except KeyError: + ''' regular inline image, not a luximage ''' + return str(img) def render_images(s): |