Skip to content

Commit

Permalink
Add a view listing a user's votes and a view listing all votes on a c…
Browse files Browse the repository at this point in the history
…ookie
  • Loading branch information
MarkusH committed Sep 29, 2013
1 parent ff6d404 commit 0d3fd7e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
13 changes: 13 additions & 0 deletions bakery/socialize/templates/socialize/voted.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "base.html" %}

{% block content %}
<h4>Votes by {{ object }}</h4>
<table class="table table-condensed cookies color1">
{% for cookie in cookies %}
<tr class="cookie">
<td class="name">{{ cookie.name }}</td>
<td class="description">{{ cookie.short_description }}</td>
</tr>
{% endfor %}
</table>
{% endblock content %}
13 changes: 13 additions & 0 deletions bakery/socialize/templates/socialize/votes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "base.html" %}

{% block content %}
<h4>Votes for {{ object }}</h4>
<table class="table table-condensed cookies color1">
{% for user in users %}
<tr class="cookie">
<td class="username">{{ user.username }}</td>
<td class="name">{{ user.name }}</td>
</tr>
{% endfor %}
</table>
{% endblock content %}
4 changes: 2 additions & 2 deletions bakery/socialize/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

urlpatterns = patterns('bakery.socialize.views',
url(r'^vote/$', 'vote', name='vote'),
# url(r'^votes/(?P<id>\d+)/$', 'votes_for_cookie', name='votes_for_cookie'),
# url(r'^voted/(?P<id>\d+)/$', 'votes_by_user', name='votes_by_user'),
url(r'^votes/(?P<pk>\d+)/$', 'votes_for_cookie', name='votes_for_cookie'),
url(r'^voted/(?P<pk>\d+)/$', 'votes_by_user', name='votes_by_user'),
)
26 changes: 26 additions & 0 deletions bakery/socialize/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponseRedirect
from django.views.decorators.http import require_POST
from django.views.generic import DetailView

from bakery.auth.models import BakeryUser
from bakery.cookies.models import Cookie


Expand All @@ -22,3 +24,27 @@ def vote(request):
return HttpResponseRedirect(redirect)
except Cookie.DoesNotExist:
raise Http404('Cookie does not exist')


class VotesView(DetailView):
model = Cookie
template_name = 'socialize/votes.html'

def get_context_data(self, **kwargs):
context = super(VotesView, self).get_context_data(**kwargs)
context['users'] = self.object.votes.all()
return context

votes_for_cookie = VotesView.as_view()


class VotedView(DetailView):
model = BakeryUser
template_name = 'socialize/voted.html'

def get_context_data(self, **kwargs):
context = super(VotedView, self).get_context_data(**kwargs)
context['cookies'] = self.object.votes.all()
return context

votes_by_user = VotedView.as_view()
1 change: 1 addition & 0 deletions bakery/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-

from django.core.urlresolvers import reverse
from django.views.generic import TemplateView, RedirectView
from django.contrib import auth
Expand Down

0 comments on commit 0d3fd7e

Please sign in to comment.