From: jordan Date: Mon, 2 Apr 2012 22:43:05 +0000 (+0000) Subject: OSQA-809, Include question summaries in question and answers views, wrap that in... X-Git-Tag: live~77 X-Git-Url: https://git.openstreetmap.org/osqa.git/commitdiff_plain/e907efa7d02378ca6e4cbbcfacd25054faacf3bc OSQA-809, Include question summaries in question and answers views, wrap that in a setting git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1240 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/models/node.py b/forum/models/node.py index 6694426..83b9ab7 100644 --- a/forum/models/node.py +++ b/forum/models/node.py @@ -317,13 +317,16 @@ class Node(BaseModel, NodeContent): @property def summary(self): - content = strip_tags(self.html)[:SUMMARY_LENGTH] + content = strip_tags(self.html) # Remove multiple spaces. content = re.sub(' +',' ', content) - # Remove line breaks. We don't need them at all. - content = content.replace("\n", '') + # Replace line breaks with a space, we don't need them at all. + content = content.replace("\n", ' ') + + # Truncate and all an ellipsis if length greater than summary length. + content = (content[:SUMMARY_LENGTH] + '...') if len(content) > SUMMARY_LENGTH else content return content diff --git a/forum/settings/view.py b/forum/settings/view.py index b87c33c..40990ce 100644 --- a/forum/settings/view.py +++ b/forum/settings/view.py @@ -19,6 +19,11 @@ SUMMARY_LENGTH = Setting('SUMMARY_LENGTH', 300, VIEW_SET, dict( label = _("Summary Length"), help_text = _("The number of characters that are going to be displayed in order to get the content summary."))) +SHOW_SUMMARY_ON_QUESTIONS_LIST = Setting('SHOW_SUMMARY_ON_QUESTIONS_LIST', False, VIEW_SET, dict( +label = _("Question summary on questions list?"), +help_text = _("Choose whether to show the question summary on questions list"), +required=False)) + # Tag settings RECENT_TAGS_SIZE = Setting('RECENT_TAGS_SIZE', 25, VIEW_SET, dict( label = _("Recent tags block size"), diff --git a/forum/skins/default/templates/question_list/item.html b/forum/skins/default/templates/question_list/item.html index 4eb3c3b..1ad2ba5 100644 --- a/forum/skins/default/templates/question_list/item.html +++ b/forum/skins/default/templates/question_list/item.html @@ -21,7 +21,12 @@
-

{{question.headline}}

+

{{question.headline}}

+ {% if question_summary %} +
+ {{ question.summary }} +
+ {% endif %}
{% diff_date question.last_activity_at %} {% if question.last_activity_by %}{% user_signature question.last_activity_by signature_type %}{% endif %} diff --git a/forum/skins/default/templates/questions.html b/forum/skins/default/templates/questions.html index 6b9e0a3..f470ba3 100644 --- a/forum/skins/default/templates/questions.html +++ b/forum/skins/default/templates/questions.html @@ -25,7 +25,11 @@ {{ questions.paginator.sort_tabs }}
{% for question in questions.paginator.page %} - {% question_list_item question %} + {% if show_summary %} + {% question_list_item question question_summary=yes %} + {% else %} + {% question_list_item question %} + {% endif %} {% endfor %}
{% endblock %} diff --git a/forum/templatetags/question_list_tags.py b/forum/templatetags/question_list_tags.py index 642a5a3..2f2aef9 100644 --- a/forum/templatetags/question_list_tags.py +++ b/forum/templatetags/question_list_tags.py @@ -17,6 +17,7 @@ class QuestionItemNode(template.Node): def render(self, context): return self.template.render(template.Context({ 'question': self.question.resolve(context), + 'question_summary': self.options.get('question_summary', 'no' ) == 'yes', 'favorite_count': self.options.get('favorite_count', 'no') == 'yes', 'signature_type': self.options.get('signature_type', 'lite'), })) diff --git a/forum/views/readers.py b/forum/views/readers.py index 3de8c41..669eaf3 100644 --- a/forum/views/readers.py +++ b/forum/views/readers.py @@ -92,7 +92,9 @@ def unanswered(request): @decorators.render('questions.html', 'questions', _('questions'), weight=0) def questions(request): - return question_list(request, Question.objects.all(), _('questions')) + return question_list(request, + Question.objects.all(), + _('questions')) @decorators.render('questions.html') def tag(request, tag): @@ -171,10 +173,14 @@ def question_list(request, initial, allowIgnoreTags=True, feed_url=None, paginator_context=None, + show_summary=None, feed_sort=('-added_at',), feed_req_params_exclude=(_('page'), _('pagesize'), _('sort')), extra_context={}): + if show_summary is None: + show_summary = bool(settings.SHOW_SUMMARY_ON_QUESTIONS_LIST) + questions = initial.filter_state(deleted=False) if request.user.is_authenticated() and allowIgnoreTags: @@ -212,6 +218,7 @@ def question_list(request, initial, 'page_title' : page_title, 'tab' : 'questions', 'feed_url': feed_url, + 'show_summary' : show_summary, } context.update(extra_context)