summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--forum/const/__init__.py1
-rw-r--r--forum/models/user.py15
-rw-r--r--forum/skins/default/templates/user_responses.html38
-rw-r--r--forum/views/users.py187
4 files changed, 70 insertions, 171 deletions
diff --git a/forum/const/__init__.py b/forum/const/__init__.py
index 0da9ec22..b1c9de7a 100644
--- a/forum/const/__init__.py
+++ b/forum/const/__init__.py
@@ -102,6 +102,7 @@ TYPE_ACTIVITY_MENTION = 19
#TYPE_ACTIVITY_EDIT_QUESTION=17
#TYPE_ACTIVITY_EDIT_ANSWER=18
+#todo: rename this to TYPE_ACTIVITY_CHOICES
TYPE_ACTIVITY = (
(TYPE_ACTIVITY_ASK_QUESTION, _('question')),
(TYPE_ACTIVITY_ANSWER, _('answer')),
diff --git a/forum/models/user.py b/forum/models/user.py
index a00271a7..c0e05144 100644
--- a/forum/models/user.py
+++ b/forum/models/user.py
@@ -13,6 +13,17 @@ from forum import const
from forum.utils import functions
+class ResponseAndMentionActivityManager(models.Manager):
+ def get_query_set(self):
+ response_types = const.RESPONSE_ACTIVITY_TYPES_FOR_DISPLAY
+ response_types += (const.TYPE_ACTIVITY_MENTION, )
+ return super(
+ ResponseAndMentionActivityManager,
+ self
+ ).get_query_set().filter(
+ activity_type__in = response_types
+ )
+
class ActivityManager(models.Manager):
def get_all_origin_posts(self):
#todo: redo this with query sets
@@ -136,6 +147,7 @@ class Activity(models.Model):
is_auditted = models.BooleanField(default=False)
objects = ActivityManager()
+ responses_and_mentions = ResponseAndMentionActivityManager()
def __unicode__(self):
return u'[%s] was active at %s' % (self.user.username, self.active_at)
@@ -150,6 +162,9 @@ class Activity(models.Model):
assert(len(user_qs) == 1)
return user_qs[0]
+ def get_absolute_url(self):
+ return self.content_object.get_absolute_url()
+
class EmailFeedSetting(models.Model):
DELTA_TABLE = {
'i':datetime.timedelta(-1),#instant emails are processed separately
diff --git a/forum/skins/default/templates/user_responses.html b/forum/skins/default/templates/user_responses.html
index cf429465..21f08046 100644
--- a/forum/skins/default/templates/user_responses.html
+++ b/forum/skins/default/templates/user_responses.html
@@ -2,36 +2,38 @@
<!-- user_responses.html -->
{% comment %}
-This template accepts a list of response objects
+This template accepts a list of response list
they are a generalized form of any response and
-are not database objects
The following properties of response object are used:
-time - when it happened
-userlink - url to the profile of whoever gave the response
-username - name of that user
-type - type of response
-titlelink - link to the question
-title - title of the question
-content - abbreviated content of the response
+timestamp - when it happened
+user - user who gave response (database object)
+response_type - type of response
+response_url - link to the question
+response_title - title of the question
+response_snippet - abbreviated content of the response
{% endcomment %}
{% load extra_tags %}
{% load humanize %}
+{% load i18n %}
{% block usercontent %}
<div style="padding-top:5px;font-size:13px;">
{% for response in responses %}
- <div style="clear:both;line-height:18px">
- <div style="width:150px;float:left">{% diff_date response.time 3 %}</div>
- <div style="width:100px;float:left"><a href="{{ response.userlink }}">{{ response.username }}</a></div>
- <div style="float:left;overflow:hidden;width:680px">
- <strong {% ifequal response.type "question_answered" %}class="user-action-2"{% endifequal %}{% ifequal response.type "answer_accepted" %}class="user-action-8"{% endifequal %}>{{ response.type }}</strong>:
- <a href="{{ response.titlelink }}">{{ response.title }}</a><br/>
- {{ response.content|safe }}
- <div style="height:10px"></div>
+ <div style="clear:both;line-height:18px;margin-bottom:15px;">
+ <div>
+ <div style="float:left; display:inline-block; text-align: center; width: 54px; padding: 3px;overflow:hidden;">
+ {% gravatar response.user 48 %}
+ </div>
+ <a style="font-size:12px" href="{{ response.user.get_absolute_url }}">{{ response.user.username }}</a>
+ <a style="text-decoration:none;" href="{{ response.response_url }}">
+ {{ response.response_type }},
+ {% diff_date response.timestamp 3 %}:<br/>
+ <strong>"{{ response.response_title }}"</strong>&nbsp;
+ {{ response.response_snippet|safe }}
+ </a>
</div>
-
</div>
{% endfor %}
</div>
diff --git a/forum/views/users.py b/forum/views/users.py
index 7f5811a1..42d406c2 100644
--- a/forum/views/users.py
+++ b/forum/views/users.py
@@ -637,162 +637,43 @@ def user_responses(request, user_id, user_view):
page
"""
user = get_object_or_404(models.User, id=user_id)
- if request.user != user:
- raise Http404
+ #if request.user != user:
+ # raise Http404
user = get_object_or_404(models.User, id=user_id)
- responses = []
-
- answers = models.Answer.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'question.id',
- 'answer_id' : 'answer.id',
- 'added_at' : 'answer.added_at',
- 'html' : 'answer.html',
- 'username' : 'auth_user.username',
- 'user_id' : 'auth_user.id'
- },
- select_params=[user_id],
- tables=['answer', 'question', 'auth_user'],
- where=['answer.question_id = question.id '\
- + 'AND answer.deleted=False' \
- + 'AND question.deleted=False '\
- + 'AND question.author_id = %s '\
- + 'AND answer.author_id != %s '\
- + 'AND answer.author_id=auth_user.id'
- ],
- params=[user_id, user_id],
- order_by=['-answer.id']
- ).values(
- 'title',
- 'question_id',
- 'answer_id',
- 'added_at',
- 'html',
- 'username',
- 'user_id'
- )
- if len(answers) > 0:
- answer_responses = []
- for a in answers:
- resp = Response(
- const.TYPE_RESPONSE['QUESTION_ANSWERED'],
- a['title'],
- a['question_id'],
- a['answer_id'],
- a['added_at'],
- a['username'],
- a['user_id'],
- a['html']
- )
- answer_responses.append(resp)
- responses.extend(answer_responses)
-
- # question comments
- comments = models.Comment.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'comment.object_id',
- 'added_at' : 'comment.added_at',
- 'comment' : 'comment.comment',
- 'username' : 'auth_user.username',
- 'user_id' : 'auth_user.id'
- },
- tables=['question', 'auth_user', 'comment'],
- where=['question.deleted=False AND question.author_id = %s AND comment.object_id=question.id AND '+
- 'comment.content_type_id=%s AND comment.user_id <> %s AND comment.user_id = auth_user.id'],
- params=[user_id, question_type_id, user_id],
- order_by=['-comment.added_at']
- ).values(
- 'title',
- 'question_id',
- 'added_at',
- 'comment',
- 'username',
- 'user_id'
- )
-
- if len(comments) > 0:
- comments = [(Response(const.TYPE_RESPONSE['QUESTION_COMMENTED'], c['title'], c['question_id'],
- '', c['added_at'], c['username'], c['user_id'], c['comment'])) for c in comments]
- responses.extend(comments)
-
- # answer comments
- comments = models.Comment.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'question.id',
- 'answer_id' : 'answer.id',
- 'added_at' : 'comment.added_at',
- 'comment' : 'comment.comment',
- 'username' : 'auth_user.username',
- 'user_id' : 'auth_user.id'
- },
- tables=['answer', 'auth_user', 'comment', 'question'],
- where=['answer.deleted=False AND answer.author_id = %s AND comment.object_id=answer.id AND '+
- 'comment.content_type_id=%s AND comment.user_id <> %s AND comment.user_id = auth_user.id '+
- 'AND question.id = answer.question_id'],
- params=[user_id, answer_type_id, user_id],
- order_by=['-comment.added_at']
- ).values(
- 'title',
- 'question_id',
- 'answer_id',
- 'added_at',
- 'comment',
- 'username',
- 'user_id'
- )
+ response_list = []
+
+ activities = list()
+ activities = models.Activity.responses_and_mentions.filter(
+ receiving_users = user
+ )
+
+ for act in activities:
+ origin_post = act.content_object.get_origin_post()
+ response = {
+ 'timestamp': act.active_at,
+ 'user': act.user,
+ 'response_url': act.get_absolute_url(),
+ 'response_snippet': strip_tags(act.content_object.html)[:300],
+ 'response_title': origin_post.title,
+ 'response_type': act.get_activity_type_display(),
+ }
+ response_list.append(response)
+
+ response_list.sort(lambda x,y: cmp(y['timestamp'], x['timestamp']))
- if len(comments) > 0:
- comments = [(Response(const.TYPE_RESPONSE['ANSWER_COMMENTED'], c['title'], c['question_id'],
- c['answer_id'], c['added_at'], c['username'], c['user_id'], c['comment'])) for c in comments]
- responses.extend(comments)
-
- # answer has been accepted
- answers = models.Answer.objects.extra(
- select={
- 'title' : 'question.title',
- 'question_id' : 'question.id',
- 'answer_id' : 'answer.id',
- 'added_at' : 'answer.accepted_at',
- 'html' : 'answer.html',
- 'username' : 'auth_user.username',
- 'user_id' : 'auth_user.id'
- },
- select_params=[user_id],
- tables=['answer', 'question', 'auth_user'],
- where=['answer.question_id = question.id AND answer.deleted=False AND question.deleted=False AND '+
- 'answer.author_id = %s AND answer.accepted=True AND question.author_id=auth_user.id'],
- params=[user_id],
- order_by=['-answer.id']
- ).values(
- 'title',
- 'question_id',
- 'answer_id',
- 'added_at',
- 'html',
- 'username',
- 'user_id'
- )
- if len(answers) > 0:
- answers = [(Response(const.TYPE_RESPONSE['ANSWER_ACCEPTED'], a['title'], a['question_id'],
- a['answer_id'], a['added_at'], a['username'], a['user_id'], a['html'])) for a in answers]
- responses.extend(answers)
-
- # sort posts by time
- responses.sort(lambda x,y: cmp(y.time, x.time))
-
- return render_to_response(user_view.template_file,{
- 'active_tab':'users',
- "tab_name" : user_view.id,
- "tab_description" : user_view.tab_description,
- "page_title" : user_view.page_title,
- "view_user" : user,
- "responses" : responses[:user_view.data_size],
-
- }, context_instance=RequestContext(request))
+ return render_to_response(
+ user_view.template_file,
+ {
+ 'active_tab':'users',
+ 'tab_name' : user_view.id,
+ 'tab_description' : user_view.tab_description,
+ 'page_title' : user_view.page_title,
+ 'view_user' : user,
+ 'responses' : response_list[:user_view.data_size],
+ },
+ context_instance=RequestContext(request)
+ )
def user_votes(request, user_id, user_view):
user = get_object_or_404(models.User, id=user_id)