From df2a120b28c74e3e85819294d0652759f6194af9 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Fri, 22 Mar 2013 00:10:30 -0400 Subject: allowed to enable and disable scopes on the main page --- askbot/conf/__init__.py | 1 + askbot/conf/main_pages.py | 83 +++++++++++++++++++++++++++ askbot/const/__init__.py | 2 +- askbot/doc/source/changelog.rst | 1 + askbot/media/style/style.less | 27 ++++++--- askbot/models/question.py | 2 +- askbot/search/state_manager.py | 8 ++- askbot/templates/main_page/nothing_found.html | 2 +- askbot/templates/widgets/scope_nav.html | 42 +++++++++----- askbot/templates/widgets/search_bar.html | 10 +++- askbot/templatetags/extra_filters_jinja.py | 4 ++ askbot/tests/page_load_tests.py | 2 +- askbot/tests/search_state_tests.py | 8 +-- 13 files changed, 161 insertions(+), 31 deletions(-) create mode 100644 askbot/conf/main_pages.py diff --git a/askbot/conf/__init__.py b/askbot/conf/__init__.py index fd62bc88..c1989f8d 100644 --- a/askbot/conf/__init__.py +++ b/askbot/conf/__init__.py @@ -8,6 +8,7 @@ import askbot.conf.karma_and_badges_visibility import askbot.conf.email import askbot.conf.forum_data_rules import askbot.conf.moderation +import askbot.conf.main_pages import askbot.conf.flatpages import askbot.conf.site_settings import askbot.conf.license diff --git a/askbot/conf/main_pages.py b/askbot/conf/main_pages.py new file mode 100644 index 00000000..940d2e91 --- /dev/null +++ b/askbot/conf/main_pages.py @@ -0,0 +1,83 @@ +""" +Settings responsible for display of questions lists +""" +from askbot.conf.settings_wrapper import settings +from askbot.conf.super_groups import DATA_AND_FORMATTING +from askbot.deps import livesettings +from django.utils.translation import ugettext_lazy as _ + +MAIN_PAGES = livesettings.ConfigurationGroup( + 'MAIN_PAGES', + _('Logic of the questions page'), + super_group=DATA_AND_FORMATTING + ) + +settings.register( + livesettings.BooleanValue( + MAIN_PAGES, + 'ALL_SCOPE_ENABLED', + default=True, + description=_('Enable "All Questions" selector'), + help_text=_('At least one of these selectors must be enabled') + ) +) + +settings.register( + livesettings.BooleanValue( + MAIN_PAGES, + 'UNANSWERED_SCOPE_ENABLED', + default=True, + description=_('Enable "Unanswered Questions" selector'), + help_text=_('At least one of these selectors must be enabled') + ) +) + +settings.register( + livesettings.BooleanValue( + MAIN_PAGES, + 'FOLLOWED_SCOPE_ENABLED', + default=True, + description=_('Enable "Followed Questions" selector'), + help_text=_('At least one of these selectors must be enabled') + ) +) + +def enable_default_selector_if_disabled(old_value, new_value): + scope_switch_name = new_value.upper() + '_SCOPE_ENABLED' + is_enabled = getattr(settings, scope_switch_name) + if is_enabled is False: + settings.update(scope_switch_name, True) + return new_value + +SCOPE_CHOICES_AUTHENTICATED = ( + ('all', _('All Questions')), + ('unanswered', _('Unanswered Questions')), + ('followed', _('Followed Questions')) +) + +settings.register( + livesettings.StringValue( + MAIN_PAGES, + 'DEFAULT_SCOPE_AUTHENTICATED', + choices=SCOPE_CHOICES_AUTHENTICATED, + default='all', + description=_('Default questions selector for the authenticated users'), + update_callback=enable_default_selector_if_disabled + ) +) + +SCOPE_CHOICES_ANONYMOUS = (#anonymous users can't see followed questions + ('all', _('All Questions')), + ('unanswered', _('Unanswered Questions')), +) + +settings.register( + livesettings.StringValue( + MAIN_PAGES, + 'DEFAULT_SCOPE_ANONYMOUS', + choices=SCOPE_CHOICES_ANONYMOUS, + default='all', + description=_('Default questions selector for the anonymous users'), + update_callback=enable_default_selector_if_disabled + ) +) diff --git a/askbot/const/__init__.py b/askbot/const/__init__.py index 0240d7f5..b9f9325c 100644 --- a/askbot/const/__init__.py +++ b/askbot/const/__init__.py @@ -112,7 +112,7 @@ DEFAULT_POST_SORT_METHOD = 'activity-desc' POST_SCOPE_LIST = ( ('all', _('all')), ('unanswered', _('unanswered')), - ('favorite', _('favorite')), + ('followed', _('followed')), ) DEFAULT_POST_SCOPE = 'all' diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst index 31224850..eea65ede 100644 --- a/askbot/doc/source/changelog.rst +++ b/askbot/doc/source/changelog.rst @@ -3,6 +3,7 @@ Changes in Askbot Development version ------------------- +* Allowed to enable and disable question scopes on the main page * Added full text support for some languages with Postgresql: Danish, Dutch, English, Finnish, French, German, Hungarian, Italian, Japanese (requires package textsearch_ja), Norwegian, diff --git a/askbot/media/style/style.less b/askbot/media/style/style.less index e5fdb8fd..bd3299cd 100644 --- a/askbot/media/style/style.less +++ b/askbot/media/style/style.less @@ -446,6 +446,10 @@ body.user-messages { .sprites(-51px,-36px); } +#scopeNav { + height: 41px; +} + .scope-selector { display:block; float:left; @@ -580,7 +584,7 @@ input[type="submit"].searchBtn { line-height: 22px; text-align: center; float:right; - margin: 8px 28px 0 0; + margin: -33px 28px 0 0; width: 48px; .sprites(-98px,-37px); .rounded-corners(0); @@ -693,7 +697,7 @@ input[type="submit"].link:hover { font-size: 20px; height: 42px; line-height: 44px; - margin-top: 6px; + margin-top: -35px; text-transform: uppercase; width: 200px;/* to match width of sidebar */ } @@ -718,12 +722,21 @@ input[type="submit"].link:hover { body.anon.ask-page .search-drop-menu { margin: 0; } -body.anon { - #searchBar, - .search-drop-menu { - margin-left: 227px;/* we don't have the "followed" scope */ - } +#searchBar.scopes-True-True-False { + margin-left: 228px; } +#searchBar.scopes-True-False-True { + margin-left: 203px; +} +#searchBar.scopes-False-True-True { + margin-left: 286px; +} +#searchBar.scopes-True-False-False, +#searchBar.scopes-False-True-False, +#searchBar.scopes-False-False-True { + margin-left: 52px; +} + #searchBar.cancelable { padding-right: 82px; } diff --git a/askbot/models/question.py b/askbot/models/question.py index 51a7c24b..5526d3a8 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -336,7 +336,7 @@ class ThreadManager(BaseQuerySetManager): else: raise Exception('UNANSWERED_QUESTION_MEANING setting is wrong') - elif search_state.scope == 'favorite': + elif search_state.scope == 'followed': favorite_filter = models.Q(favorited_by=request_user) if 'followit' in django_settings.INSTALLED_APPS: followed_users = request_user.get_followed_users() diff --git a/askbot/search/state_manager.py b/askbot/search/state_manager.py index 7b6b746c..efefbc40 100644 --- a/askbot/search/state_manager.py +++ b/askbot/search/state_manager.py @@ -9,6 +9,7 @@ from django.utils.encoding import smart_str import askbot import askbot.conf +from askbot.conf import settings as askbot_settings from askbot import const from askbot.utils.functions import strip_plus @@ -90,8 +91,11 @@ class SearchState(object): def __init__(self, scope, sort, query, tags, author, page, user_logged_in): # INFO: zip(*[('a', 1), ('b', 2)])[0] == ('a', 'b') - if (scope not in zip(*const.POST_SCOPE_LIST)[0]) or (scope == 'favorite' and not user_logged_in): - self.scope = const.DEFAULT_POST_SCOPE + if (scope not in zip(*const.POST_SCOPE_LIST)[0]) or (scope == 'followed' and not user_logged_in): + if user_logged_in: + self.scope = askbot_settings.DEFAULT_SCOPE_AUTHENTICATED + else: + self.scope = askbot_settings.DEFAULT_SCOPE_ANONYMOUS else: self.scope = scope diff --git a/askbot/templates/main_page/nothing_found.html b/askbot/templates/main_page/nothing_found.html index 1e2c5445..98629476 100644 --- a/askbot/templates/main_page/nothing_found.html +++ b/askbot/templates/main_page/nothing_found.html @@ -3,7 +3,7 @@ {% if search_state.scope == "unanswered" %} {% trans %}There are no unanswered questions here{% endtrans %} {% endif %} -{% if search_state.scope == "favorite" %} +{% if search_state.scope == "followed" %} {% trans %}No questions here. {% endtrans %} {% trans %}Please follow some questions or follow some users.{% endtrans %} {% endif %} diff --git a/askbot/templates/widgets/scope_nav.html b/askbot/templates/widgets/scope_nav.html index b68d899c..254c3b48 100644 --- a/askbot/templates/widgets/scope_nav.html +++ b/askbot/templates/widgets/scope_nav.html @@ -1,17 +1,33 @@ +{% set need_scope_links = ( + settings.ALL_SCOPE_ENABLED|to_int + + settings.UNANSWERED_SCOPE_ENABLED|to_int + + (request.user.is_authenticated() and settings.FOLLOWED_SCOPE_ENABLED)|to_int + > 1 + ) +%}
-{% if active_tab != "ask" %} - {% if not search_state %} {# get empty SearchState() if there's none #} - {% set search_state=search_state|get_empty_search_state %} +{% if need_scope_links %} + {% if active_tab != "ask" %} + {% if not search_state %} {# get empty SearchState() if there's none #} + {% set search_state=search_state|get_empty_search_state %} + {% endif %} + {% if settings.ALL_SCOPE_ENABLED %} + {% trans %}ALL{% endtrans %} + {% endif %} + {% if settings.UNANSWERED_SCOPE_ENABLED %} + {% trans %}UNANSWERED{% endtrans %} + {% endif %} + {% if request.user.is_authenticated() and settings.FOLLOWED_SCOPE_ENABLED %} + {% trans %}FOLLOWED{% endtrans %} + {% endif %} + {% else %} +
{% trans %}Please ask your question here{% endtrans %}
{% endif %} - {% trans %}ALL{% endtrans %} - {% trans %}UNANSWERED{% endtrans %} - {% if request.user.is_authenticated() %} - {% trans %}FOLLOWED{% endtrans %} - {% endif %} -{% else %} -
{% trans %}Please ask your question here{% endtrans %}
{% endif %}
diff --git a/askbot/templates/widgets/search_bar.html b/askbot/templates/widgets/search_bar.html index 8c485c73..d1e9e531 100644 --- a/askbot/templates/widgets/search_bar.html +++ b/askbot/templates/widgets/search_bar.html @@ -1,6 +1,14 @@ {% if active_tab != "ask" %} {% spaceless %} -