diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-07-29 16:29:44 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-07-29 16:29:44 -0400 |
commit | 69a7fe6583e75fecadbe83053957ab93fda9d011 (patch) | |
tree | 260fe1b3d1b5ecbc93f2a162b7ef453dbbc4970b | |
parent | 4b1eb656fd9757446e17bfa469f4b07a716add35 (diff) | |
download | askbot-69a7fe6583e75fecadbe83053957ab93fda9d011.tar.gz askbot-69a7fe6583e75fecadbe83053957ab93fda9d011.tar.bz2 askbot-69a7fe6583e75fecadbe83053957ab93fda9d011.zip |
replaced use of numeric values of content type ids with more readable code in askbot.views.users.user_recent
-rw-r--r-- | askbot/skins/default/templates/user_profile/user_recent.html | 35 | ||||
-rw-r--r-- | askbot/views/users.py | 52 |
2 files changed, 50 insertions, 37 deletions
diff --git a/askbot/skins/default/templates/user_profile/user_recent.html b/askbot/skins/default/templates/user_profile/user_recent.html index 3cab29eb..9239196a 100644 --- a/askbot/skins/default/templates/user_profile/user_recent.html +++ b/askbot/skins/default/templates/user_profile/user_recent.html @@ -12,26 +12,23 @@ <span class="user-action-{{ act.type_id }}">{{ act.type }}</span> </div> <div style="float:left;overflow:hidden;"> - {% if act.type_id==7 %} + {% if act.is_badge %} <a href="{{act.badge.get_absolute_url()}}" title="{{ act.badge.get_type_display() }} : {% trans description=act.badge.description %}{{description}}{% endtrans %}" class="medal"><span class="{{ act.badge.css_class }}">●</span> {% trans name=act.badge.name %}{{name}}{% endtrans %}</a> - {% if act.cont == 31 or act.cont == 36 %} - {% if act.cont == 31 %}{# question #} - {% for question in questions %}{# could also create a new dict #} - {% if question.question_id == act.obj %} - (<a title="{{question.summary|collapse}}" - href="{% url question question.question_id %}{{question.title|slugify}}">{% trans %}source{% endtrans %}</a>) - {% endif %} - {% endfor %} - {% endif %} - {% if act.cont == 36 %}{# answer #} - {% for answer in answers %}{# could also create a new dict #} - {% if answer.answer_id == act.obj %} - (<a title="{{answer.text|collapse}}" - href="{% url question answer.question_id %}{{answer.question_title|slugify}}#{{answer.answer_id}}">{% trans %}source{% endtrans %}</a>) - {% endif %} - {% endfor %} - {% endif %} - {% endif %} + {% if act.related_object_type == 'question' %}{# question #} + {% for question in questions %}{# could also create a new dict #} + {% if question.question_id == act.obj %} + (<a title="{{question.summary|collapse}}" + href="{% url question question.question_id %}{{question.title|slugify}}">{% trans %}source{% endtrans %}</a>) + {% endif %} + {% endfor %} + {% elif act.related_object_type == 'answer' %}{# answer #} + {% for answer in answers %}{# could also create a new dict #} + {% if answer.answer_id == act.obj %} + (<a title="{{answer.text|collapse}}" + href="{% url question answer.question_id %}{{answer.question_title|slugify}}#{{answer.answer_id}}">{% trans %}source{% endtrans %}</a>) + {% endif %} + {% endfor %} + {% endif %} {% else %} <span class="post-type-{{ act.type_id }}"><a href="{{ act.title_link }}">{{ act.title|escape }}</a></span> {% if act.summary %}<span class="revision-summary">{{ act.summary|escape }}</span>{% endif %} diff --git a/askbot/views/users.py b/askbot/views/users.py index 6f147ae8..45aae274 100644 --- a/askbot/views/users.py +++ b/askbot/views/users.py @@ -52,6 +52,14 @@ question_revision_type_id = question_revision_type.id answer_revision_type_id = answer_revision_type.id repute_type_id = repute_type.id +#todo: queries in the user activity summary view must be redone +def get_related_object_type_name(content_type_id): + if content_type_id in (question_type_id, question_revision_type_id,): + return 'question' + elif content_type_id in (answer_type_id, answer_revision_type_id,): + return 'answer' + return None + def owner_or_moderator_required(f): @functools.wraps(f) def wrapped_func(request, profile_owner, context): @@ -414,6 +422,7 @@ def user_recent(request, user, context): return item[1] class Event: + is_badge = False def __init__(self, time, type, title, summary, answer_id, question_id): self.time = time self.type = get_type_name(type) @@ -429,13 +438,15 @@ def user_recent(request, user, context): self.title_link += '#%s' % answer_id class AwardEvent: - def __init__(self, time, obj, cont, type, id): + is_badge = True + def __init__(self, time, obj, cont, type, id, related_object_type = None): self.time = time self.obj = obj self.cont = cont self.type = get_type_name(type) self.type_id = type self.badge = get_object_or_404(models.BadgeData, id=id) + self.related_object_type = related_object_type activities = [] # ask questions @@ -459,21 +470,17 @@ def user_recent(request, user, context): 'active_at', 'activity_type' ) - if len(questions) > 0: - - question_activities = [] - for q in questions: - q_event = Event( - q['active_at'], - q['activity_type'], - q['title'], - '', - '0', - q['question_id'] - ) - question_activities.append(q_event) - activities.extend(question_activities) + for q in questions: + q_event = Event( + q['active_at'], + q['activity_type'], + q['title'], + '', + '0', + q['question_id'] + ) + activities.append(q_event) # answers answers = models.Activity.objects.extra( @@ -671,9 +678,18 @@ def user_recent(request, user, context): 'content_type_id', 'activity_type' ) - if len(awards) > 0: - awards = [(AwardEvent(q['awarded_at'], q['object_id'], q['content_type_id'], q['activity_type'], q['badge_id'])) for q in awards] - activities.extend(awards) + for award in awards: + related_object_type = get_related_object_type_name(award['content_type_id']) + activities.append( + AwardEvent( + award['awarded_at'], + award['object_id'], + award['content_type_id'], + award['activity_type'], + award['badge_id'], + related_object_type = related_object_type + ) + ) activities.sort(lambda x,y: cmp(y.time, x.time)) |