summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2010-06-11 14:42:27 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2010-06-11 14:42:27 -0400
commit3bad7a8fa7821dfe677b0a8d06c7a779a3e57483 (patch)
treeff9ab8379de6eac738b822ae6e906fc266703a90
parent7bbb038b8896413a2cff814d65a7cf2dc604e2f4 (diff)
downloadaskbot-3bad7a8fa7821dfe677b0a8d06c7a779a3e57483.tar.gz
askbot-3bad7a8fa7821dfe677b0a8d06c7a779a3e57483.tar.bz2
askbot-3bad7a8fa7821dfe677b0a8d06c7a779a3e57483.zip
added whitespace-stripping middleware and started (barely) working on revamping the individual responses page
-rw-r--r--forum/middleware/spaceless.py15
-rw-r--r--forum/skins/default/templates/user_responses.html42
-rw-r--r--forum/views/users.py98
-rw-r--r--settings.py1
4 files changed, 106 insertions, 50 deletions
diff --git a/forum/middleware/spaceless.py b/forum/middleware/spaceless.py
new file mode 100644
index 00000000..16b11522
--- /dev/null
+++ b/forum/middleware/spaceless.py
@@ -0,0 +1,15 @@
+"""
+Middleware that strips whitespace between html tags
+copied from David Cramer's blog
+http://www.davidcramer.net/code/369/spaceless-html-in-django.html
+"""
+from django.utils.html import strip_spaces_between_tags as short
+
+class SpacelessMiddleware(object):
+ def process_response(self, request, response):
+ """strips whitespace from all documents
+ whose content type is text/html
+ """
+ if 'text/html' in response['Content-Type']:
+ response.content = short(response.content)
+ return response
diff --git a/forum/skins/default/templates/user_responses.html b/forum/skins/default/templates/user_responses.html
index c4f4ffed..cf429465 100644
--- a/forum/skins/default/templates/user_responses.html
+++ b/forum/skins/default/templates/user_responses.html
@@ -1,23 +1,39 @@
{% extends "user.html" %}
<!-- user_responses.html -->
+
+{% comment %}
+This template accepts a list of response objects
+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
+{% endcomment %}
+
{% load extra_tags %}
{% load humanize %}
{% 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>
-
+ <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>
- {% endfor %}
+
</div>
+ {% endfor %}
+ </div>
{% endblock %}
<!-- end user_responses.html -->
diff --git a/forum/views/users.py b/forum/views/users.py
index 0d2c8c3f..7f5811a1 100644
--- a/forum/views/users.py
+++ b/forum/views/users.py
@@ -601,54 +601,78 @@ def user_recent(request, user_id, user_view):
"activities" : activities[:user_view.data_size]
}, context_instance=RequestContext(request))
+class Response:
+ """class that abstracts any kind of response
+ answer, comment, mention, post edits, etc.
+ """
+ def __init__(
+ self, type, title, question_id,
+ answer_id, time, username,
+ user_id, content):
+
+ self.type = type
+ self.title = title
+ self.titlelink = reverse(
+ 'question',
+ args=[question_id]) \
+ + u'%s#%s' % (slugify(title),
+ answer_id
+ )
+ self.time = time
+ self.userlink = reverse('users') + u'%s/%s/' % (user_id, username)
+ self.username = username
+ self.content = u'%s ...' % strip_tags(content)[:300]
+
+ def __unicode__(self):
+ return u'%s %s' % (self.type, self.titlelink)
+
def user_responses(request, user_id, user_view):
"""
- We list answers for question, comments, and answer accepted by others for this user.
+ We list answers for question, comments, and
+ answer accepted by others for this user.
+ as well as mentions of the user
+
+ user_id - id of the profile owner
+ user_view - id of the user who is looking at the
+ page
"""
user = get_object_or_404(models.User, id=user_id)
if request.user != user:
raise Http404
- class Response:
- def __init__(self, type, title, question_id, answer_id, time, username, user_id, content):
- self.type = type
- self.title = title
- self.titlelink = reverse('question', args=[question_id]) + u'%s#%s' % (slugify(title), answer_id)
- self.time = time
- self.userlink = reverse('users') + u'%s/%s/' % (user_id, username)
- self.username = username
- self.content = u'%s ...' % strip_tags(content)[:300]
-
- def __unicode__(self):
- return u'%s %s' % (self.type, self.titlelink)
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'
- )
+ 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:
diff --git a/settings.py b/settings.py
index ee820cd5..3546ddf7 100644
--- a/settings.py
+++ b/settings.py
@@ -35,6 +35,7 @@ MIDDLEWARE_CLASSES = (
'django.middleware.transaction.TransactionMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'forum.middleware.view_log.ViewLogMiddleware',
+ 'forum.middleware.spaceless.SpacelessMiddleware',
)
#all of these are necessary for the forum and absend in default settings.py