Install django-annoying, which provides some nice shortcuts for common operations

This commit is contained in:
Danielle McLean 2017-10-29 12:41:33 +11:00
parent 88bf1e580c
commit 21786d6e6c
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
5 changed files with 23 additions and 13 deletions

View file

@ -28,6 +28,7 @@ django-debug-toolbar = "*"
xrd = "*" xrd = "*"
django-push = "*" django-push = "*"
pyyaml = "*" pyyaml = "*"
django-annoying = "*"
[dev-packages] [dev-packages]

9
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "dc4aa7d01f78e031ce0e169c70b3056b8a436bfc3195126b6a801943ee39e2fb" "sha256": "60cccca3a3edbe0c10266ab3641a32cf61223145a35203eae215af023f88d350"
}, },
"host-environment-markers": { "host-environment-markers": {
"implementation_name": "cpython", "implementation_name": "cpython",
@ -76,6 +76,13 @@
], ],
"version": "==0.3.0" "version": "==0.3.0"
}, },
"django-annoying": {
"hashes": [
"sha256:07267defd06e37ad287053de4ea8c83ab4aae8114628830b7c91b70b63494572",
"sha256:5321e6e3481fc455818b935824d9cd78669a9bb6a964baf816d191745c8617a6"
],
"version": "==0.10.3"
},
"django-appconf": { "django-appconf": {
"hashes": [ "hashes": [
"sha256:ddab987d14b26731352c01ee69c090a4ebfc9141ed223bef039d79587f22acd9", "sha256:ddab987d14b26731352c01ee69c090a4ebfc9141ed223bef039d79587f22acd9",

View file

@ -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 from .models import Entry
@render_to('entries/index.html')
def index(request, kind): def index(request, kind):
entries = Entry.objects.filter(kind=kind.id) entries = Entry.objects.filter(kind=kind.id)
return render(request, 'entries/index.html', { return {'entries': entries, 'title': kind.plural}
'entries': entries,
'title': kind.plural
})
@render_to('entries/entry.html')
def entry(request, id, slug=None): def entry(request, id, slug=None):
entry = Entry.objects.get(pk=id) entry = Entry.objects.get(pk=id)
if request.path != entry.url: if request.path != entry.url:
return redirect(entry.url, permanent=True) return redirect(entry.url, permanent=True)
return render(request, 'entries/entry.html', { return {
'entry': entry, 'entry': entry,
'title': entry.title, 'title': entry.title,
'meta': entry.as_meta(request) 'meta': entry.as_meta(request)
}) }

View file

@ -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 users.models import User
from lemoncurry import breadcrumbs, utils from lemoncurry import breadcrumbs, utils
breadcrumbs.add('home:index', 'home') breadcrumbs.add('home:index', 'home')
@render_to('home/index.html')
def index(request): def index(request):
query = User.objects.prefetch_related('entries', 'profiles', 'keys') query = User.objects.prefetch_related('entries', 'profiles', 'keys')
user = get_object_or_404(query, pk=1) user = get_object_or_404(query, pk=1)
@ -22,10 +24,9 @@ def index(request):
'sameAs': [profile.url for profile in user.profiles.all()] 'sameAs': [profile.url for profile in user.profiles.all()]
} }
entries = user.entries.all() return {
return render(request, 'home/index.html', {
'user': user, 'user': user,
'person': person, 'person': person,
'entries': entries, 'entries': user.entries.all(),
'meta': user.as_meta(request), 'meta': user.as_meta(request),
}) }

View file

@ -69,6 +69,7 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'annoying',
'compressor', 'compressor',
'debug_toolbar', 'debug_toolbar',
'django_activeurl', 'django_activeurl',