diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2013-03-22 00:10:30 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2013-03-22 00:10:30 -0400 |
commit | df2a120b28c74e3e85819294d0652759f6194af9 (patch) | |
tree | d8f962aecdb1e81f796695e6232183bb3f1f0e43 /askbot | |
parent | db7fdd122616d527f62747738c4225b03a69ab09 (diff) | |
download | askbot-df2a120b28c74e3e85819294d0652759f6194af9.tar.gz askbot-df2a120b28c74e3e85819294d0652759f6194af9.tar.bz2 askbot-df2a120b28c74e3e85819294d0652759f6194af9.zip |
allowed to enable and disable scopes on the main page
Diffstat (limited to 'askbot')
-rw-r--r-- | askbot/conf/__init__.py | 1 | ||||
-rw-r--r-- | askbot/conf/main_pages.py | 83 | ||||
-rw-r--r-- | askbot/const/__init__.py | 2 | ||||
-rw-r--r-- | askbot/doc/source/changelog.rst | 1 | ||||
-rw-r--r-- | askbot/media/style/style.less | 27 | ||||
-rw-r--r-- | askbot/models/question.py | 2 | ||||
-rw-r--r-- | askbot/search/state_manager.py | 8 | ||||
-rw-r--r-- | askbot/templates/main_page/nothing_found.html | 2 | ||||
-rw-r--r-- | askbot/templates/widgets/scope_nav.html | 42 | ||||
-rw-r--r-- | askbot/templates/widgets/search_bar.html | 10 | ||||
-rw-r--r-- | askbot/templatetags/extra_filters_jinja.py | 4 | ||||
-rw-r--r-- | askbot/tests/page_load_tests.py | 2 | ||||
-rw-r--r-- | askbot/tests/search_state_tests.py | 8 |
13 files changed, 161 insertions, 31 deletions
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 + ) +%} <div id="scopeNav"> -{% 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 %} + <a class="scope-selector {% if scope == 'all' %}on{% endif %}" + href="{{ search_state.change_scope('all').full_url() }}" + title="{% trans %}see all questions{% endtrans %}">{% trans %}ALL{% endtrans %}</a> + {% endif %} + {% if settings.UNANSWERED_SCOPE_ENABLED %} + <a class="scope-selector {% if scope == 'unanswered' %}on{% endif %}" + href="{{ search_state.change_scope('unanswered').change_sort('answers-asc').full_url() }}" + title="{% trans %}see unanswered questions{% endtrans %}">{% trans %}UNANSWERED{% endtrans %}</a> + {% endif %} + {% if request.user.is_authenticated() and settings.FOLLOWED_SCOPE_ENABLED %} + <a class="scope-selector {% if scope == 'followed' %}on{% endif %}" + href="{{ search_state.change_scope('followed').full_url() }}" + title="{% trans %}see your followed questions{% endtrans %}">{% trans %}FOLLOWED{% endtrans %}</a> + {% endif %} + {% else %} + <div class="scope-selector ask-message">{% trans %}Please ask your question here{% endtrans %}</div> {% endif %} - <a class="scope-selector {% if scope == 'all' %}on{% endif %}" - href="{{ search_state.change_scope('all').full_url() }}" title="{% trans %}see all questions{% endtrans %}">{% trans %}ALL{% endtrans %}</a> - <a class="scope-selector {% if scope == 'unanswered' %}on{% endif %}" - href="{{ search_state.change_scope('unanswered').change_sort('answers-asc').full_url() }}" title="{% trans %}see unanswered questions{% endtrans %}">{% trans %}UNANSWERED{% endtrans %}</a> - {% if request.user.is_authenticated() %} - <a class="scope-selector {% if scope == 'favorite' %}on{% endif %}" - href="{{ search_state.change_scope('favorite').full_url() }}" title="{% trans %}see your followed questions{% endtrans %}">{% trans %}FOLLOWED{% endtrans %}</a> - {% endif %} -{% else %} - <div class="scope-selector ask-message">{% trans %}Please ask your question here{% endtrans %}</div> {% endif %} </div> 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 %} -<div id="searchBar" {% if query %}class="cancelable"{% endif %}> +{% set enabled_scopes_class = 'scopes-' + + '%s'|format(settings.ALL_SCOPE_ENABLED) + '-' + + '%s'|format(settings.UNANSWERED_SCOPE_ENABLED) + '-' + + '%s'|format((request.user.is_authenticated() and settings.FOLLOWED_SCOPE_ENABLED)) +%} +<div + id="searchBar" + class="{% if query %}cancelable{% endif %} {{ enabled_scopes_class }}" +> {# url action depends on which tab is active #} {% if active_tab == "tags" %} <input type="hidden" name="t" value="tag"/> diff --git a/askbot/templatetags/extra_filters_jinja.py b/askbot/templatetags/extra_filters_jinja.py index e927ccbf..7549555a 100644 --- a/askbot/templatetags/extra_filters_jinja.py +++ b/askbot/templatetags/extra_filters_jinja.py @@ -43,6 +43,10 @@ def is_current_language(lang): return lang == django_get_language() @register.filter +def to_int(value): + return int(value) + +@register.filter def safe_urlquote(text, quote_plus = False): if quote_plus: return urllib.quote_plus(text.encode('utf8')) diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py index dca5c30f..ef43ebf8 100644 --- a/askbot/tests/page_load_tests.py +++ b/askbot/tests/page_load_tests.py @@ -256,7 +256,7 @@ class PageLoadTestCase(AskbotTestCase): template='main_page.html', ) self.try_url( - url_name=reverse('questions') + SearchState.get_empty().change_scope('favorite').query_string(), + url_name=reverse('questions') + SearchState.get_empty().change_scope('followed').query_string(), plain_url_passed=True, status_code=status_code, diff --git a/askbot/tests/search_state_tests.py b/askbot/tests/search_state_tests.py index 18f5eb36..27622629 100644 --- a/askbot/tests/search_state_tests.py +++ b/askbot/tests/search_state_tests.py @@ -64,7 +64,7 @@ class SearchStateTests(AskbotTestCase): def test_edge_cases_1(self): ss = SearchState( - scope='favorite', # this is not a valid choice for non-logger users + scope='followed', # this is not a valid choice for non-logger users sort='age-desc', query=' alfa', tags='miki, mini', @@ -83,7 +83,7 @@ class SearchStateTests(AskbotTestCase): ) ss = SearchState( - scope='favorite', + scope='followed', sort='age-desc', query=' alfa', tags='miki, mini', @@ -93,11 +93,11 @@ class SearchStateTests(AskbotTestCase): user_logged_in=True ) self.assertEqual( - 'scope:favorite/sort:age-desc/query:alfa/tags:miki,mini/author:12/page:2/', + 'scope:followed/sort:age-desc/query:alfa/tags:miki,mini/author:12/page:2/', ss.query_string() ) self.assertEqual( - 'scope:favorite/sort:age-desc/query:alfa/tags:miki,mini/author:12/page:2/', + 'scope:followed/sort:age-desc/query:alfa/tags:miki,mini/author:12/page:2/', ss.deepcopy().query_string() ) |