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 ALL_KARMA_EVENT_CLASSES
context_object_name = 'user' # name passed to template
template_name = 'user_profile.html'
- @staticmethod
- def compareProfileItems(a, b):
- if a.__class__ == Note:
- timestampA = a.uploaded_at
- else:
- timestampA = a.timestamp
-
- if b.__class__ == Note:
- timestampB = b.uploaded_at
- else:
- timestampB = b.timestamp
-
- if timestampA < timestampB:
- return -1
- elif timestampA > timestampB:
- return 1
- else:
- return 0
-
def get_context_data(self, **kwargs):
- notes = [('note', o) for o in Note.objects.filter(user=self.request.user)]
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],
+ result_list = sorted(chain.from_iterable(all_events),
+ key=lambda o: o[1].timestamp,
reverse=True)
kwargs['object_list'] = result_list
<div class="small-10 columns small-centered {% cycle '' 'row_alt_on'%}">
<div class="activity_item">
- {% if item.0 == 'note' %}
- {% with note=item.1 %}
- <div class="row">
- <div class="small-12 columns activity_timestamp">
- <span class="activity_date">{{ note.uploaded_at|date:"D b j Y" }}</span>
- </div>
- <div class="small-12 columns activity_details_action">
- You uploaded <a href="{{ note.get_absolute_url }}" class="activity_target">{{ note.name }}</a>
- </div>
- <div class="small-12 columns activity_details_context">
- <a href="{{ note.course.get_absolute_url }}" class="course_link">{{ note.course.name }} // {{ note.course.school.name }}</a>
- </div>
- </div>
- {% endwith %}
- {% endif %}
-
{% if 'KarmaEvent' in item.0 %}
{% with event=item.1 %}
<div class="row">