Introducing polls
[wolnelektury.git] / apps / polls / templatetags / polls_tags.py
diff --git a/apps/polls/templatetags/polls_tags.py b/apps/polls/templatetags/polls_tags.py
new file mode 100644 (file)
index 0000000..e69a7ce
--- /dev/null
@@ -0,0 +1,18 @@
+from django import template
+from ..forms import PollForm
+
+
+register = template.Library()
+
+@register.inclusion_tag('polls/tags/poll.html', takes_context = True)
+def poll(context, poll, show_results = True, redirect_to = ''):
+    form = None
+    voted_already = poll.voted(context.get('request').session)
+    if not voted_already:
+        form = PollForm(poll = poll, initial = dict(redirect_to = redirect_to))
+    return dict(poll = poll,
+                form = form,
+                voted_already = voted_already,
+                vote_count = poll.vote_count,
+                show_results = show_results
+           )
\ No newline at end of file