]> git.openstreetmap.org Git - osqa.git/commitdiff
OSQA-809, Include question summaries in question and answers views, wrap that in...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Mon, 2 Apr 2012 22:43:05 +0000 (22:43 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Mon, 2 Apr 2012 22:43:05 +0000 (22:43 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1240 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/models/node.py
forum/settings/view.py
forum/skins/default/templates/question_list/item.html
forum/skins/default/templates/questions.html
forum/templatetags/question_list_tags.py
forum/views/readers.py

index 6694426a478b3738198c8f1adfca8de7b487e820..83b9ab72b3096d9ca867b8dbe168b538b0bdb006 100644 (file)
@@ -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
 
index b87c33c5c4be44835cf19ddadd78f3e478682db9..40990cea444c41d909db47204ea9c109b3e9dc97 100644 (file)
@@ -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"),
index 4eb3c3bc1c0f70d248a879c210ed3153cc5ac41e..1ad2ba5c8e98859e3da6cb9843e79e651fcec7a8 100644 (file)
     </div>\r
 \r
     <div class="question-summary-wrapper">\r
-        <h2><a title="{{ question.summary }}" href="{{ question.get_absolute_url }}">{{question.headline}}</a></h2>\r
+        <h2><a {% if not question_summary %}title="{{ question.summary }}"{% endif %} href="{{ question.get_absolute_url }}">{{question.headline}}</a></h2>\r
+        {% if question_summary %}\r
+        <div class="summary">\r
+          {{ question.summary }}\r
+        </div>\r
+        {% endif %}\r
         <div class="userinfo">\r
             <span class="relativetime" title="{{question.last_activity_at}}">{% diff_date question.last_activity_at %}</span>\r
             {% if question.last_activity_by %}{% user_signature question.last_activity_by signature_type %}{% endif %}\r
index 6b9e0a394873104747cb36128f162134ad95dacc..f470ba3ef36fb58e5ed971a911ddb8d137660c04 100644 (file)
     {{ questions.paginator.sort_tabs }}\r
 </div>\r
 <div id="listA">{% for question in questions.paginator.page %}\r
-    {% question_list_item question %}\r
+    {% if show_summary %}\r
+      {% question_list_item question question_summary=yes %}\r
+    {% else %}\r
+      {% question_list_item question %}\r
+    {% endif %}\r
 {% endfor %}</div>\r
 {% endblock %}\r
 \r
index 642a5a32e008a09bd8d7b071e195c62576759304..2f2aef9cf8c58948a57c0922ec68ee40a5b04344 100644 (file)
@@ -17,6 +17,7 @@ class QuestionItemNode(template.Node):
     def render(self, context):\r
         return self.template.render(template.Context({\r
             'question': self.question.resolve(context),\r
+            'question_summary': self.options.get('question_summary', 'no' ) == 'yes',\r
             'favorite_count': self.options.get('favorite_count', 'no') == 'yes',\r
             'signature_type': self.options.get('signature_type', 'lite'),\r
         }))\r
index 3de8c4148c4f4ebaf3fc2e9e509d8ccd3da839dd..669eaf3006a849aefdaf84d40e3adf72d6089742 100644 (file)
@@ -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)