From b5ae845855d32f67cc829c8a5a8cabd6b9a54660 Mon Sep 17 00:00:00 2001 From: hernani Date: Wed, 16 Jun 2010 12:19:51 +0000 Subject: [PATCH] Fixes OSQA 337, We show too many tags on the /questions/ url, by adding a couple of settings to configure that and other blocks. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@430 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/settings/__init__.py | 1 + forum/settings/form.py | 5 ++++- forum/settings/view.py | 17 +++++++++++++++++ .../templates/osqaadmin/djstyle_base.html | 1 + forum/templatetags/general_sidebar_tags.py | 8 ++------ forum/templatetags/question_list_tags.py | 8 +++++++- forum/views/admin.py | 2 +- 7 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 forum/settings/view.py diff --git a/forum/settings/__init__.py b/forum/settings/__init__.py index 9880c5f..b7b4aac 100644 --- a/forum/settings/__init__.py +++ b/forum/settings/__init__.py @@ -32,6 +32,7 @@ from upload import * from about import * from faq import * from form import * +from view import * from moderation import * from users import * from static import * diff --git a/forum/settings/form.py b/forum/settings/form.py index ec21376..5f770b3 100644 --- a/forum/settings/form.py +++ b/forum/settings/form.py @@ -81,4 +81,7 @@ required=False)) FORM_GRAVATAR_IN_COMMENTS = Setting('FORM_GRAVATAR_IN_COMMENTS', False, FORUM_SET, dict( label = _("Show author gravatar in comments"), help_text = _("Show the gravatar image of a comment author."), -required=False)) \ No newline at end of file +required=False)) + + + diff --git a/forum/settings/view.py b/forum/settings/view.py new file mode 100644 index 0000000..1eb44b0 --- /dev/null +++ b/forum/settings/view.py @@ -0,0 +1,17 @@ +from base import Setting, SettingSet +from django.utils.translation import ugettext_lazy as _ + +""" view settings """ +VIEW_SET = SettingSet('view', _('View settings'), _("Set up how certain parts of the site are displayed."), 20) + +RECENT_TAGS_SIZE = Setting('RECENT_TAGS_SIZE', 25, VIEW_SET, dict( +label = _("Recent tags block size"), +help_text = _("The number of tags to display in the recent tags block in the front page."))) + +RECENT_AWARD_SIZE = Setting('RECENT_AWARD_SIZE', 15, VIEW_SET, dict( +label = _("Recent awards block size"), +help_text = _("The number of awards to display in the recent awards block in the front page."))) + +LIMIT_RELATED_TAGS = Setting('LIMIT_RELATED_TAGS', 0, VIEW_SET, dict( +label = _("Limit related tags block"), +help_text = _("Limit related tags block size in questions list pages. Set to 0 to display all all tags."))) \ No newline at end of file diff --git a/forum/skins/default/templates/osqaadmin/djstyle_base.html b/forum/skins/default/templates/osqaadmin/djstyle_base.html index 0cf3ee1..02443a7 100644 --- a/forum/skins/default/templates/osqaadmin/djstyle_base.html +++ b/forum/skins/default/templates/osqaadmin/djstyle_base.html @@ -84,6 +84,7 @@

{% trans "Forum settings" %}

diff --git a/forum/templatetags/general_sidebar_tags.py b/forum/templatetags/general_sidebar_tags.py index 09f30cc..d17f74b 100644 --- a/forum/templatetags/general_sidebar_tags.py +++ b/forum/templatetags/general_sidebar_tags.py @@ -2,19 +2,15 @@ from django import template from forum.models import Tag, Award from forum import settings -#todo: move to settings -RECENT_TAGS_SIZE = 25 -RECENT_AWARD_SIZE = 15 - register = template.Library() @register.inclusion_tag('sidebar/recent_tags.html') def recent_tags(): - return {'tags': Tag.active.order_by('-id')[:RECENT_TAGS_SIZE]} + return {'tags': Tag.active.order_by('-id')[:settings.RECENT_TAGS_SIZE]} @register.inclusion_tag('sidebar/recent_awards.html') def recent_awards(): - return {'awards': Award.objects.order_by('-awarded_at')[:RECENT_AWARD_SIZE]} + return {'awards': Award.objects.order_by('-awarded_at')[:settings.RECENT_AWARD_SIZE]} @register.inclusion_tag('sidebar/user_blocks.html') def sidebar_upper(): diff --git a/forum/templatetags/question_list_tags.py b/forum/templatetags/question_list_tags.py index e9b8032..dc735f3 100644 --- a/forum/templatetags/question_list_tags.py +++ b/forum/templatetags/question_list_tags.py @@ -3,6 +3,7 @@ from django.utils.translation import ugettext as _ from django.utils.safestring import mark_safe from forum.models import Tag, MarkedTag from forum.templatetags import argument_parser +from forum import settings register = template.Library() @@ -33,7 +34,12 @@ def question_sort_tabs(sort_context): @register.inclusion_tag('question_list/related_tags.html') def question_list_related_tags(questions): if len(questions): - return {'tags': Tag.objects.filter(nodes__id__in=[q.id for q in questions]).distinct()} + tags = Tag.objects.filter(nodes__id__in=[q.id for q in questions]).distinct() + + if settings.LIMIT_RELATED_TAGS: + tags = tags[:settings.LIMIT_RELATED_TAGS] + + return {'tags': tags} else: return {'tags': False} diff --git a/forum/views/admin.py b/forum/views/admin.py index 7297c1f..ad4f9b9 100644 --- a/forum/views/admin.py +++ b/forum/views/admin.py @@ -37,7 +37,7 @@ def admin_page(fn): context['othersets'] = sorted( [s for s in Setting.sets.values() if not s.name in ('basic', 'users', 'email', 'paths', 'extkeys', 'repgain', 'minrep', 'voting', 'badges', 'about', 'faq', 'sidebar', - 'form', 'moderation', 'css', 'headandfoot', 'head')] + 'form', 'moderation', 'css', 'headandfoot', 'head', 'view')] , lambda s1, s2: s1.weight - s2.weight) unsaved = request.session.get('previewing_settings', {}) -- 2.39.5