]> gitweb.fperrin.net Git - djsite.git/blobdiff - quotes/views.py
Initial draft of the quotes app
[djsite.git] / quotes / views.py
index 91ea44a218fbd2f408430959283f0419c921093e..615719209327f58096622d8b3d5e8b51d3928c98 100644 (file)
@@ -1,3 +1,32 @@
 from django.shortcuts import render
+from django.http import HttpResponse
+from django.template import loader
+
+from random import randint
+
+from .models import Author, Quote, Tag
 
 # Create your views here.
+def onequote(request, quote_id):
+    q = Quote.objects.get(id=quote_id)
+    context = { 'quote' : q }
+    return render(request, 'quotations/onequote.html', context)
+
+def random(request):
+    count = Quote.objects.count()
+    return onequote(request, randint(1, count))
+
+def tags(request, tag_id):
+    tag = Tag.objects.get(id=tag_id)
+    context = { 'tag' : tag }
+    return render(request, 'quotations/tag.html', context)
+
+def author(request, author_id):
+    author = Author.objects.get(id=author_id)
+    context = { 'author' : author }
+    return render(request, 'quotations/author.html', context)
+
+def all(request):
+    quotes = Quote.objects.all()
+    context = { 'quotes' : quotes }
+    return render(request, 'quotations/all.html', context)