diff options
-rw-r--r-- | hyperkitty/models.py | 20 | ||||
-rw-r--r-- | hyperkitty/templates/user_profile.html | 13 | ||||
-rw-r--r-- | hyperkitty/views/accounts.py | 26 |
3 files changed, 29 insertions, 30 deletions
diff --git a/hyperkitty/models.py b/hyperkitty/models.py index 6a8bd63..c84ef51 100644 --- a/hyperkitty/models.py +++ b/hyperkitty/models.py @@ -53,26 +53,6 @@ class UserProfile(models.Model): karma = models.IntegerField(default=1) - def _get_votes(self): - "Returns all the votes by a user" - # Extract all the votes by this user - try: - votes = Rating.objects.filter(user=self.user) - except Rating.DoesNotExist: - votes = {} - - # TODO: warning, not thread-safe, should get the cached connection from - # the WSGI environment - store = get_store(settings.KITTYSTORE_URL) - for vote in votes: - list_name = vote.list_address.split('@')[0] - message = store.get_message_by_id_from_list(vote.list_address, vote.messageid) - vote.message = message - - return votes - - votes = property(_get_votes) - def __unicode__(self): """Unicode representation""" return u'%s' % (unicode(self.user)) diff --git a/hyperkitty/templates/user_profile.html b/hyperkitty/templates/user_profile.html index 3077141..8f73e81 100644 --- a/hyperkitty/templates/user_profile.html +++ b/hyperkitty/templates/user_profile.html @@ -33,12 +33,12 @@ </tr> </tbody> </table> + {% if settings.USE_MOCKUPS %} - <h3> Up Votes : </h3> + <h3> Up Votes : </h3> <ul> - {% for vote in user_profile.votes %} - {% if vote.vote == 1 %} + {% for vote in votes_up %} <li> {% if vote.message.content|trimString|length > 0 %} <a href="{% url message_index mlist_fqdn=vote.list_address, hashid=vote.messageid %}">{{ vote.message.content|truncatechars:20 }}</a> @@ -46,15 +46,12 @@ <a href="{% url message_index mlist_fqdn=vote.list_address, hashid=vote.messageid %}">Message is empty</a> {% endif %} </li> - {% endif %} {% endfor %} </ul> <h3> Down Votes : </h3> - <ul> - {% for vote in user_profile.votes %} - {% if vote.vote == -1 %} + {% for vote in votes_down %} <li> {% if vote.message.content|trimString|length > 0 %} <a href="{% url message_index mlist_fqdn=vote.list_address, hashid=vote.messageid %}">{{ vote.message.content|truncatechars:20 }}</a> @@ -62,9 +59,9 @@ <a href="{% url message_index mlist_fqdn=vote.list_address, hashid=vote.messageid %}">Message is empty</a> {% endif %} </li> - {% endif %} {% endfor %} </ul> + {% endif %} diff --git a/hyperkitty/views/accounts.py b/hyperkitty/views/accounts.py index 2c68315..49d726f 100644 --- a/hyperkitty/views/accounts.py +++ b/hyperkitty/views/accounts.py @@ -29,7 +29,7 @@ from django.contrib.auth.decorators import (login_required, permission_required, user_passes_test) from django.contrib.auth.forms import AuthenticationForm -from hyperkitty.models import UserProfile +from hyperkitty.models import UserProfile, Rating from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.http import HttpResponse, HttpResponseRedirect @@ -41,6 +41,8 @@ from urlparse import urlparse from forms import RegistrationForm from hyperkitty.utils import log +from hyperkitty.lib import get_store + def user_logout(request): logout(request) @@ -74,6 +76,7 @@ def user_login(request, template='login.html'): def user_profile(request, user_email=None): if not request.user.is_authenticated(): return redirect('user_login') + t = loader.get_template('user_profile.html') # try to render the user profile. try: @@ -82,10 +85,29 @@ def user_profile(request, user_email=None): except: user_profile = UserProfile.objects.create(user=request.user) - t = loader.get_template('user_profile.html') + try: + votes = Rating.objects.filter(user=request.user) + except Rating.DoesNotExist: + votes = {} + store = get_store(request) + votes_up = [] + votes_down = [] + for vote in votes: + message = store.get_message_by_id_from_list( + vote.list_address, vote.message_id) + vote_data = {"list_address": vote.list_address, + "message_id": vote.message_id, + "message": message, + } + if vote.vote == 1: + votes_up.append(vote_data) + elif vote.vote == -1: + votes_down.append(vote_data) c = RequestContext(request, { 'user_profile' : user_profile, + 'votes_up': votes_up, + 'votes_down': votes_down, }) return HttpResponse(t.render(c)) |