timer
[turniej.git] / apps / poetry / views.py
1 from django.shortcuts import render, get_object_or_404
2 from poetry.models import Poet, Poem
3
4
5 def new(request, slug=None):
6     if slug is not None:
7         poet = get_object_or_404(Poet, slug=slug)
8     else:
9         poet = Poet.objects.order_by('?')[0]
10
11     poem = poet.write()
12     return render(request, "poetry/poem.html", locals())
13
14
15 def poem(request, slug):
16     poem = get_object_or_404(Poem, slug=slug)
17     return render(request, "poetry/poem.html", locals())
18
19
20 def poet(request, slug):
21     poet = get_object_or_404(Poet, slug=slug)
22     last = poet.poem_set.order_by('-created_at')[:20]
23     in_contest = poet.poem_set.filter(in_contest=True).order_by('created_at')
24     return render(request, "poetry/poet.html", locals())
25
26
27 def main(request):
28     poets = Poet.objects.all().order_by('?')
29     last = Poem.objects.all().order_by('-created_at')[:20]
30     return render(request, "poetry/main.html", locals())
31
32
33 def contest(request):
34     poets = Poet.objects.all().order_by('?')
35     return render(request, "poetry/contest.html", locals())
36