From 98bfb63992324a717fa8ac550c6ff3ec1a7e3bc7 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Fri, 24 May 2013 05:31:29 -0400 Subject: added option to hide ad blocks from logged in users --- askbot/conf/sidebar_main.py | 18 +++++++++++++++ askbot/conf/sidebar_profile.py | 23 +++++++------------ askbot/conf/sidebar_question.py | 36 ++++++++++++++++++++++++++++++ askbot/doc/source/changelog.rst | 1 + askbot/templates/main_page/sidebar.html | 4 ++-- askbot/templates/question.html | 2 +- askbot/templates/question/content.html | 2 +- askbot/templates/question/sidebar.html | 4 ++-- askbot/templates/user_profile/user.html | 11 +++++---- askbot/templatetags/extra_filters_jinja.py | 9 ++++++++ 10 files changed, 83 insertions(+), 27 deletions(-) diff --git a/askbot/conf/sidebar_main.py b/askbot/conf/sidebar_main.py index 8fa4bdf0..97b89e37 100644 --- a/askbot/conf/sidebar_main.py +++ b/askbot/conf/sidebar_main.py @@ -29,6 +29,15 @@ settings.register( ) ) +settings.register( + values.BooleanValue( + SIDEBAR_MAIN, + 'SIDEBAR_MAIN_HEADER_ANON_ONLY', + description=_('Show above only to anonymous users'), + default=False + ) +) + settings.register( values.BooleanValue( SIDEBAR_MAIN, @@ -94,3 +103,12 @@ settings.register( ) ) +settings.register( + values.BooleanValue( + SIDEBAR_MAIN, + 'SIDEBAR_MAIN_FOOTER_ANON_ONLY', + default=False, + description=_('Show above only to anonymous users') + ) +) + diff --git a/askbot/conf/sidebar_profile.py b/askbot/conf/sidebar_profile.py index 948daa4a..a216de4b 100644 --- a/askbot/conf/sidebar_profile.py +++ b/askbot/conf/sidebar_profile.py @@ -16,8 +16,8 @@ SIDEBAR_PROFILE = ConfigurationGroup( settings.register( values.LongStringValue( SIDEBAR_PROFILE, - 'SIDEBAR_PROFILE_HEADER', - description = _('Custom sidebar header'), + 'SIDEBAR_PROFILE', + description = _('Custom sidebar'), default = '', help_text = _( 'Use this area to enter content at the TOP of the sidebar' @@ -25,23 +25,16 @@ settings.register( '(as well as the sidebar footer), please ' 'use the HTML validation service to make sure that ' 'your input is valid and works well in all browsers.' - ) + ) ) ) + settings.register( - values.LongStringValue( + values.BooleanValue( SIDEBAR_PROFILE, - 'SIDEBAR_PROFILE_FOOTER', - description = _('Custom sidebar footer'), - default = '', - help_text = _( - 'Use this area to enter content at the BOTTOM of the sidebar' - 'in HTML format. When using this option ' - '(as well as the sidebar header), please ' - 'use the HTML validation service to make sure that ' - 'your input is valid and works well in all browsers.' - ) + 'SIDEBAR_PROFILE_ANON_ONLY', + description=_('Show above only to anonymous users'), + default=False ) ) - diff --git a/askbot/conf/sidebar_question.py b/askbot/conf/sidebar_question.py index ffe2f783..8d38692a 100644 --- a/askbot/conf/sidebar_question.py +++ b/askbot/conf/sidebar_question.py @@ -26,6 +26,15 @@ settings.register( ) ) +settings.register( + values.BooleanValue( + SIDEBAR_QUESTION, + 'QUESTION_PAGE_TOP_BANNER_ANON_ONLY', + default=False, + description=_('Show above only to anonymous users'), + ) +) + settings.register( values.LongStringValue( SIDEBAR_QUESTION, @@ -41,6 +50,16 @@ settings.register( ) ) +settings.register( + values.BooleanValue( + SIDEBAR_QUESTION, + 'QUESTION_PAGE_ANSWER_BANNER_ANON_ONLY', + default=False, + description=_('Show above only to anonymous users'), + ) +) + + settings.register( values.LongStringValue( SIDEBAR_QUESTION, @@ -57,6 +76,15 @@ settings.register( ) ) +settings.register( + values.BooleanValue( + SIDEBAR_QUESTION, + 'SIDEBAR_QUESTION_HEADER_ANON_ONLY', + default=False, + description=_('Show above only to anonymous users') + ) +) + settings.register( values.BooleanValue( SIDEBAR_QUESTION, @@ -113,3 +141,11 @@ settings.register( ) ) +settings.register( + values.BooleanValue( + SIDEBAR_QUESTION, + 'SIDEBAR_QUESTION_FOOTER_ANON_ONLY', + default=False, + description=_('Show above only to anonymous users') + ) +) diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst index cda70e77..6d14dd36 100644 --- a/askbot/doc/source/changelog.rst +++ b/askbot/doc/source/changelog.rst @@ -3,6 +3,7 @@ Changes in Askbot Development version ------------------- +* Added option to hide ad blocks from logged in users * Applied Askbot templates to the settings control panel * Added option to auto-follow questions by the question posters with default "on" * Support for Django 1.5 diff --git a/askbot/templates/main_page/sidebar.html b/askbot/templates/main_page/sidebar.html index 7acbe091..610d2b60 100644 --- a/askbot/templates/main_page/sidebar.html +++ b/askbot/templates/main_page/sidebar.html @@ -1,6 +1,6 @@ {% import "macros.html" as macros %} -{% if settings.SIDEBAR_MAIN_HEADER %} +{% if 'SIDEBAR_MAIN_HEADER'|show_block_to(request.user) %}
{{ settings.SIDEBAR_MAIN_HEADER }}
@@ -22,7 +22,7 @@ {% include "widgets/related_tags.html" %} {% endif %} -{% if settings.SIDEBARE_MAIN_FOOTER %} +{% if 'SIDEBAR_MAIN_FOOTER'|show_block_to(request.user) %}
{{ settings.SIDEBAR_MAIN_FOOTER }}
diff --git a/askbot/templates/question.html b/askbot/templates/question.html index 13593adc..ca2f4022 100644 --- a/askbot/templates/question.html +++ b/askbot/templates/question.html @@ -285,7 +285,7 @@ {% endblock %} {% block content %} - {% if settings.QUESTION_PAGE_TOP_BANNER %} + {% if 'QUESTION_PAGE_TOP_BANNER'|show_block_to(request.user) %} {% endif %} {% if is_cacheable %} diff --git a/askbot/templates/question/content.html b/askbot/templates/question/content.html index 23286ce0..c8fef9a6 100644 --- a/askbot/templates/question/content.html +++ b/askbot/templates/question/content.html @@ -12,7 +12,7 @@
{% for answer in answers %} - {% if answers|length > 1 and loop.index == 2 %} + {% if loop.index == 2 and 'QUESTION_PAGE_ANSWER_BANNER'|show_block_to(request.user) %} {% endif %} {% include "question/answer_card.html" %} diff --git a/askbot/templates/question/sidebar.html b/askbot/templates/question/sidebar.html index c11a4336..523f01ff 100644 --- a/askbot/templates/question/sidebar.html +++ b/askbot/templates/question/sidebar.html @@ -1,5 +1,5 @@ {% import "macros.html" as macros %} -{% if settings.SIDEBAR_QUESTION_HEADER %} +{% if 'SIDEBAR_QUESTION_HEADER'|show_block_to(request.user) %}
{{ settings.SIDEBAR_QUESTION_HEADER }}
@@ -173,7 +173,7 @@ {#% endcache %#} {% endif %} -{% if settings.SIDEBAR_QUESTION_FOOTER %} +{% if 'SIDEBAR_QUESTION_FOOTER'|show_block_to(request.user) %}
{{ settings.SIDEBAR_QUESTION_FOOTER }}
diff --git a/askbot/templates/user_profile/user.html b/askbot/templates/user_profile/user.html index 3aee3cfa..c72dc857 100644 --- a/askbot/templates/user_profile/user.html +++ b/askbot/templates/user_profile/user.html @@ -36,11 +36,10 @@ {% endblock %} {% endblock %} {% block sidebar %} -
- {{ settings.SIDEBAR_PROFILE_HEADER }} -
-
- {{ settings.SIDEBAR_PROFILE_FOOTER }} -
+ {% if 'SIDEBAR_PROFILE'|show_block_to(request.user) %} +
+ {{ settings.SIDEBAR_PROFILE }} +
+ {% endif %} {% endblock %} diff --git a/askbot/templatetags/extra_filters_jinja.py b/askbot/templatetags/extra_filters_jinja.py index dccd9a2a..93acea84 100644 --- a/askbot/templatetags/extra_filters_jinja.py +++ b/askbot/templatetags/extra_filters_jinja.py @@ -78,6 +78,15 @@ def safe_urlquote(text, quote_plus = False): else: return urllib.quote(text.encode('utf8')) +@register.filter +def show_block_to(block_name, user): + block = getattr(askbot_settings, block_name) + if block: + flag_name = block_name + '_ANON_ONLY' + require_anon = getattr(askbot_settings, flag_name, False) + return (require_anon is False) or user.is_anonymous() + return False + @register.filter def strip_path(url): """removes path part of the url""" -- cgit v1.2.3-1-g7c22