From 21786d6e6cdb3727fbf5894af81e504a7ff9dd1e Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Sun, 29 Oct 2017 12:41:33 +1100 Subject: [PATCH] Install django-annoying, which provides some nice shortcuts for common operations --- Pipfile | 1 + Pipfile.lock | 9 ++++++++- entries/views.py | 14 +++++++------- home/views.py | 11 ++++++----- lemoncurry/settings/base.py | 1 + 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Pipfile b/Pipfile index 0b7f1de..eabac3c 100644 --- a/Pipfile +++ b/Pipfile @@ -28,6 +28,7 @@ django-debug-toolbar = "*" xrd = "*" django-push = "*" pyyaml = "*" +django-annoying = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 942a002..ac62fae 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "dc4aa7d01f78e031ce0e169c70b3056b8a436bfc3195126b6a801943ee39e2fb" + "sha256": "60cccca3a3edbe0c10266ab3641a32cf61223145a35203eae215af023f88d350" }, "host-environment-markers": { "implementation_name": "cpython", @@ -76,6 +76,13 @@ ], "version": "==0.3.0" }, + "django-annoying": { + "hashes": [ + "sha256:07267defd06e37ad287053de4ea8c83ab4aae8114628830b7c91b70b63494572", + "sha256:5321e6e3481fc455818b935824d9cd78669a9bb6a964baf816d191745c8617a6" + ], + "version": "==0.10.3" + }, "django-appconf": { "hashes": [ "sha256:ddab987d14b26731352c01ee69c090a4ebfc9141ed223bef039d79587f22acd9", diff --git a/entries/views.py b/entries/views.py index e7295d6..6770053 100644 --- a/entries/views.py +++ b/entries/views.py @@ -1,21 +1,21 @@ -from django.shortcuts import redirect, render +from annoying.decorators import render_to +from django.shortcuts import redirect from .models import Entry +@render_to('entries/index.html') def index(request, kind): entries = Entry.objects.filter(kind=kind.id) - return render(request, 'entries/index.html', { - 'entries': entries, - 'title': kind.plural - }) + return {'entries': entries, 'title': kind.plural} +@render_to('entries/entry.html') def entry(request, id, slug=None): entry = Entry.objects.get(pk=id) if request.path != entry.url: return redirect(entry.url, permanent=True) - return render(request, 'entries/entry.html', { + return { 'entry': entry, 'title': entry.title, 'meta': entry.as_meta(request) - }) + } diff --git a/home/views.py b/home/views.py index bc6e3e8..aa8599c 100644 --- a/home/views.py +++ b/home/views.py @@ -1,10 +1,12 @@ -from django.shortcuts import get_object_or_404, render +from annoying.decorators import render_to +from django.shortcuts import get_object_or_404 from users.models import User from lemoncurry import breadcrumbs, utils breadcrumbs.add('home:index', 'home') +@render_to('home/index.html') def index(request): query = User.objects.prefetch_related('entries', 'profiles', 'keys') user = get_object_or_404(query, pk=1) @@ -22,10 +24,9 @@ def index(request): 'sameAs': [profile.url for profile in user.profiles.all()] } - entries = user.entries.all() - return render(request, 'home/index.html', { + return { 'user': user, 'person': person, - 'entries': entries, + 'entries': user.entries.all(), 'meta': user.as_meta(request), - }) + } diff --git a/lemoncurry/settings/base.py b/lemoncurry/settings/base.py index 17562cc..802ff90 100644 --- a/lemoncurry/settings/base.py +++ b/lemoncurry/settings/base.py @@ -69,6 +69,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', + 'annoying', 'compressor', 'debug_toolbar', 'django_activeurl',