From: Charles Connell Date: Thu, 23 Jan 2014 00:48:36 +0000 (-0500) Subject: Less hardcoding X-Git-Tag: release-20150131~216 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=3950c603840cb3936c0466303ef7947f57d7c32a;p=oweals%2Fkarmaworld.git Less hardcoding --- diff --git a/karmaworld/apps/users/views.py b/karmaworld/apps/users/views.py index e2511e5..7bd02f6 100644 --- a/karmaworld/apps/users/views.py +++ b/karmaworld/apps/users/views.py @@ -7,7 +7,7 @@ from django.contrib.auth.models import User from django.views.generic import TemplateView from django.views.generic.list import MultipleObjectMixin from karmaworld.apps.notes.models import Note -from karmaworld.apps.users.models import NoteKarmaEvent, CourseKarmaEvent, GenericKarmaEvent +from karmaworld.apps.users.models import ALL_KARMA_EVENT_CLASSES class ProfileView(TemplateView, MultipleObjectMixin): @@ -36,11 +36,14 @@ class ProfileView(TemplateView, MultipleObjectMixin): def get_context_data(self, **kwargs): notes = [('note', o) for o in Note.objects.filter(user=self.request.user)] - generic_karma_events = [('generic_karma_events', o) for o in GenericKarmaEvent.objects.filter(user=self.request.user)] - note_karma_events = [('note_karma_event', o) for o in NoteKarmaEvent.objects.filter(user=self.request.user)] - course_karma_events = [('course_karma_event', o) for o in CourseKarmaEvent.objects.filter(user=self.request.user)] - - result_list = sorted(chain(notes, generic_karma_events, note_karma_events, course_karma_events), + all_events = [] + for cls in ALL_KARMA_EVENT_CLASSES: + all_events.append( + [(cls.__name__, o) for o in cls.objects.filter(user=self.request.user)] + ) + all_events = chain.from_iterable(all_events) + + result_list = sorted(chain(notes, all_events), cmp=ProfileView.compareProfileItems, key=lambda o: o[1], reverse=True) diff --git a/karmaworld/templates/user_profile.html b/karmaworld/templates/user_profile.html index dab9388..7d4bd52 100644 --- a/karmaworld/templates/user_profile.html +++ b/karmaworld/templates/user_profile.html @@ -87,7 +87,7 @@ {% endwith %} {% endif %} - {% if 'karma_event' in item.0 %} + {% if 'KarmaEvent' in item.0 %} {% with event=item.1 %}
@@ -101,7 +101,7 @@ {% endif %} {{ event.get_message }}
- {% if item.0 == 'note_karma_event' %} + {% if item.0 == 'NoteKarmaEvent' %} @@ -109,7 +109,7 @@ {{ event.note.course.name }} // {{ event.note.course.school.name }}
{% endif %} - {% if item.0 == 'course_karma_event' %} + {% if item.0 == 'CourseKarmaEvent' %}
{{ event.course.name }}