]> gitweb.fperrin.net Git - djsite.git/blob - quotes/views.py
Add a search page
[djsite.git] / quotes / views.py
1 from django.shortcuts import render
2
3 from random import randint
4
5 from quotes.models import Author, Work, Quote, QuoteTag
6 import quotes.search as search
7
8 # Create your views here.
9 def onequote(request, quote_id):
10     q = Quote.objects.get(id=quote_id)
11     q.incr_display()
12     context = { 'quote' : q }
13     return render(request, 'quotes/onequote.html', context)
14
15 def random(request):
16     count = Quote.objects.count()
17     return onequote(request, randint(1, count))
18
19 def tags(request, tag_id):
20     tag = QuoteTag.objects.get(id=tag_id)
21     context = { 'tag' : tag }
22     return render(request, 'quotes/tag.html', context)
23
24 def author(request, author_id):
25     author = Author.objects.get(id=author_id)
26     author.incr_display()
27     context = { 'author' : author }
28     return render(request, 'quotes/author.html', context)
29
30 def work(request, work_id):
31     work = Work.objects.get(id=work_id)
32     work.incr_display()
33     context = { 'work': work }
34     return render(request, 'quotes/work.html', context)
35
36 def all(request):
37     quotes = Quote.objects.all()
38     context = { 'quotes' : quotes }
39     return render(request, 'quotes/all.html', context)
40
41 def searchpage(request):
42     results = {}
43     if 'q' in request.POST:
44         results = search.search(request.POST['q'])
45     return render(request, 'quotes/search.html', results)