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):
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)
{% endwith %}
{% endif %}
- {% if 'karma_event' in item.0 %}
+ {% if 'KarmaEvent' in item.0 %}
{% with event=item.1 %}
<div class="row">
<div class="small-12 columns activity_timestamp">
{% endif %}
{{ event.get_message }}
</div>
- {% if item.0 == 'note_karma_event' %}
+ {% if item.0 == 'NoteKarmaEvent' %}
<div class="small-12 columns activity_details_action">
<a href="{{ event.note.get_absolute_url }}" class="activity_target">{{ event.note.name }}</a>
</div>
<a href="{{ event.note.course.get_absolute_url }}" class="course_link">{{ event.note.course.name }} // {{ event.note.course.school.name }}</a>
</div>
{% endif %}
- {% if item.0 == 'course_karma_event' %}
+ {% if item.0 == 'CourseKarmaEvent' %}
<div class="small-12 columns activity_details_action">
<a href="{{ event.course.get_absolute_url }}" class="activity_target">{{ event.course.name }}</a>
</div>