diff options
-rw-r--r-- | askbot/conf/site_settings.py | 19 | ||||
-rw-r--r-- | askbot/const/message_keys.py | 9 | ||||
-rw-r--r-- | askbot/doc/source/changelog.rst | 2 | ||||
-rw-r--r-- | askbot/doc/source/contributors.rst | 2 | ||||
-rw-r--r-- | askbot/locale/en/LC_MESSAGES/django.po | 8 | ||||
-rw-r--r-- | askbot/middleware/anon_user.py | 30 | ||||
-rw-r--r-- | askbot/models/__init__.py | 1 | ||||
-rw-r--r-- | askbot/models/meta.py | 4 | ||||
-rw-r--r-- | askbot/skins/default/templates/macros.html | 14 | ||||
-rw-r--r-- | askbot/tests/page_load_tests.py | 3 | ||||
-rw-r--r-- | askbot/utils/mail.py | 7 |
11 files changed, 51 insertions, 48 deletions
diff --git a/askbot/conf/site_settings.py b/askbot/conf/site_settings.py index 376c65c0..0cab800b 100644 --- a/askbot/conf/site_settings.py +++ b/askbot/conf/site_settings.py @@ -5,8 +5,6 @@ keywords from askbot.conf.settings_wrapper import settings from askbot.deps import livesettings from django.utils.translation import ugettext as _ -from django.utils.html import escape -from askbot import const QA_SITE_SETTINGS = livesettings.ConfigurationGroup( 'QA_SITE_SETTINGS', @@ -74,19 +72,16 @@ settings.register( settings.register( livesettings.StringValue( QA_SITE_SETTINGS, - 'GREETING_URL', - default='/' + _('faq/'),#cannot reverse url here, must be absolute also - hidden=True, + 'GREETING_FOR_ANONYMOUS_USER', + default='First time here? Check out the FAQ!', + hidden=False, description=_( - 'Link shown in the greeting message ' + 'Text shown in the greeting message ' 'shown to the anonymous user' ), - help_text=_('If you change this url from the default - ' - 'then you will also probably want to adjust translation of ' - 'the following string: ') + '"' - + escape(const.GREETING_FOR_ANONYMOUS_USER + '"' - ' You can find this string in your locale django.po file' - ) + help_text=_( + 'Use HTML to format the message ' + ) ) ) diff --git a/askbot/const/message_keys.py b/askbot/const/message_keys.py index f7115009..12fa0766 100644 --- a/askbot/const/message_keys.py +++ b/askbot/const/message_keys.py @@ -9,14 +9,7 @@ _ = lambda v:v #NOTE: all strings must be explicitly put into this dictionary, #because you don't want to import _ from here with import * -__all__ = ['GREETING_FOR_ANONYMOUS_USER', ] - -#this variable is shown in settings, because -#the url within is configurable, the default is reverse('faq') -#if user changes url they will have to be able to fix the -#message translation too -GREETING_FOR_ANONYMOUS_USER = \ - _('First time here? Check out the <a href="%s">FAQ</a>!') +__all__ = [] #messages loaded in the templates via direct _ calls _('most relevant questions') diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst index c1eaa158..c40f08c1 100644 --- a/askbot/doc/source/changelog.rst +++ b/askbot/doc/source/changelog.rst @@ -3,6 +3,8 @@ Changes in Askbot Development version ------------------- +* Greeting for anonymuos users can be changed from live settings (Hrishi) +* Greeting for anonymous users is shown only once (Rag Sagar) * Added support for Akismet spam detection service (Adolfo Fitoria) * Added noscript message (Arun SAG) * Support for url shortening with TinyUrl on link sharing (Rtnpro) diff --git a/askbot/doc/source/contributors.rst b/askbot/doc/source/contributors.rst index ea7ee34e..35c02be1 100644 --- a/askbot/doc/source/contributors.rst +++ b/askbot/doc/source/contributors.rst @@ -15,10 +15,12 @@ Programming and documentation * Andy Knotts * Benoit Lavine (with Windriver Software, Inc.) * Jeff Madynski +* `Hrishi <https://github.com/stultus>`_ * Andrei Mamoutkine * Ramiro Morales (with Machinalis) * `NoahY <https://github.com/NoahY>`_ * `Gael Pasgrimaud <http://www.gawel.org/>`_ (bearstech) +* `Rag Sagar <https://github.com/ragsagar>`_ * Alex Robbins (celery support) * `Tomasz Szynalski <http://antimoon.com>`_ diff --git a/askbot/locale/en/LC_MESSAGES/django.po b/askbot/locale/en/LC_MESSAGES/django.po index a1548a93..4d6cd0ba 100644 --- a/askbot/locale/en/LC_MESSAGES/django.po +++ b/askbot/locale/en/LC_MESSAGES/django.po @@ -1600,10 +1600,10 @@ msgstr "" msgid "bronze" msgstr "" -#: const/message_keys.py:19 -#, python-format -msgid "First time here? Check out the <a href=\"%s\">FAQ</a>!" -msgstr "" + + + + #: const/message_keys.py:22 skins/default/templates/main_page/tab_bar.html:27 msgid "most relevant questions" diff --git a/askbot/middleware/anon_user.py b/askbot/middleware/anon_user.py index b55a484a..d1e223b7 100644 --- a/askbot/middleware/anon_user.py +++ b/askbot/middleware/anon_user.py @@ -1,13 +1,25 @@ -from django.utils.translation import ugettext as _ +"""middleware that allows anonymous users +receive messages using the now deprecated `message_set()` +interface of the user objects. + +To allow anonymous users accept messages, a special +message manager is defined here, and :meth:`__deepcopy__()` method +added to the :class:`AnonymousUser` so that user could be pickled. + +Secondly, it sends greeting message to anonymous users. +""" from askbot.user_messages import create_message, get_and_delete_messages from askbot.conf import settings as askbot_settings -from askbot import const class AnonymousMessageManager(object): + """message manager for the anonymous user""" def __init__(self, request): self.request = request + def create(self, message=''): - create_message(self.request, message) + """send message to anonymous user""" + create_message(self.request, message) + def get_and_delete(self): messages = get_and_delete_messages(self.request) return messages @@ -19,6 +31,7 @@ def dummy_deepcopy(*arg): return None class ConnectToSessionMessagesMiddleware(object): + """middleware that attaches messages to anonymous users""" def process_request(self, request): if not request.user.is_authenticated(): #plug on deepcopy which may be called by django db "driver" @@ -30,23 +43,22 @@ class ConnectToSessionMessagesMiddleware(object): #also set the first greeting one time per session only if 'greeting_set' not in request.session and \ - 'stranger' not in request.COOKIES: + 'askbot_visitor' not in request.COOKIES: request.session['greeting_set'] = True - msg = _(const.GREETING_FOR_ANONYMOUS_USER) \ - % askbot_settings.GREETING_URL + msg = askbot_settings.GREETING_FOR_ANONYMOUS_USER request.user.message_set.create(message=msg) def process_response(self, request, response): - """ Adds the stranger key to cookie if user ever authenticates so + """ Adds the ``'askbot_visitor'``key to cookie if user ever authenticates so that the anonymous user message won't be shown. """ if request.user.is_authenticated() and \ - 'stranger' not in request.COOKIES : + 'askbot_visitor' not in request.COOKIES : #import datetime #max_age = 365*24*60*60 #expires = datetime.datetime.strftime\ # (datetime.datetime.utcnow() + # datetime.timedelta(seconds=max_age),\ # "%a, %d-%b-%Y %H:%M:%S GMT") - response.set_cookie('stranger', False) + response.set_cookie('askbot_visitor', False) return response diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index d7c034e3..17723ce5 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -2232,7 +2232,6 @@ def format_instant_notification_email( 'origin_post_title': origin_post.title, 'user_subscriptions_url': user_subscriptions_url, } - subject_line = mail.prefix_the_subject_line(subject_line) return subject_line, template.render(Context(update_data)) #todo: action diff --git a/askbot/models/meta.py b/askbot/models/meta.py index 463db0cc..9022a7ec 100644 --- a/askbot/models/meta.py +++ b/askbot/models/meta.py @@ -159,9 +159,9 @@ class Comment(base.MetaContent, base.UserContent): return self.user def get_updated_activity_data(self, created = False): - if self.content_object.__class__.__name__ == 'Question': + if self.content_object.post_type == 'question': return const.TYPE_ACTIVITY_COMMENT_QUESTION, self - elif self.content_object.__class__.__name__ == 'Answer': + elif self.content_object.post_type == 'answer': return const.TYPE_ACTIVITY_COMMENT_ANSWER, self def get_response_receivers(self, exclude_list = None): diff --git a/askbot/skins/default/templates/macros.html b/askbot/skins/default/templates/macros.html index 7ddbd70f..afa7b264 100644 --- a/askbot/skins/default/templates/macros.html +++ b/askbot/skins/default/templates/macros.html @@ -246,9 +246,9 @@ poor design of the data or methods on data objects #} <div class='post-update-info'> {% if is_wiki %} <p> - {%- if post.__class__.__name__ == 'Question' -%} + {%- if post.post_type == 'question' -%} {%- trans %}asked{% endtrans %} - {% elif post.__class__.__name__ == 'Answer' %} + {% elif post.post_type == 'answer' %} {%- trans %}answered{% endtrans %} {% else %} {%- trans %}posted{% endtrans %} @@ -265,9 +265,9 @@ poor design of the data or methods on data objects #} {% else %} <p style="line-height:12px;"> {# todo: access to class names needs to be removed here #} - {% if post.__class__.__name__=="Question" %} + {% if post.post_type == 'question' %} {% trans %}asked{% endtrans %} - {% elif post.__class__.name__=="Answer" %} + {% elif post.post_type == 'answer' %} {% trans %}answered{% endtrans %} {% else %} {% trans %}posted{% endtrans %} @@ -282,11 +282,11 @@ poor design of the data or methods on data objects #} {% endif %} </div> {% elif contributor_type=="last_updater" %} - {% if post.__class__.__name__ in ('Question', 'Answer') %} + {% if post.post_type in ('Question', 'Answer') %} {% set last_edited_at = post.last_edited_at %} {% set original_author = post.author %} {% set update_author = post.last_edited_by %} - {% elif post.__class__.__name__ in ('QuestionRevision', 'AnswerRevision') %} + {% elif post.post_type in ('QuestionRevision', 'AnswerRevision') %} {% set last_edited_at = post.revised_at %} {% set original_author = None %}{# fake value to force display widget in the revision views #} {% set update_author = post.author %} @@ -295,7 +295,7 @@ poor design of the data or methods on data objects #} <div class='post-update-info'> <p style="line-height:12px;"> <a - {% if post.__class__.__name__ == 'Question' %} + {% if post.post_type == 'Question' %} href="{% url question_revisions post.id %}" {% else %} href="{% url answer_revisions post.id %}" diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py index 4d98a971..9c107112 100644 --- a/askbot/tests/page_load_tests.py +++ b/askbot/tests/page_load_tests.py @@ -55,10 +55,11 @@ class PageLoadTestCase(TestCase): print 'templates are %s' % template_names if follow == False: self.fail( + ('Have issue accessing %s. ' 'This should not have happened, ' 'since you are not expecting a redirect ' 'i.e. follow == False, there should be only ' - 'one template' + 'one template') % url ) self.assertEqual(r.template[0].name, template) diff --git a/askbot/utils/mail.py b/askbot/utils/mail.py index ae655f4c..3eb9e97d 100644 --- a/askbot/utils/mail.py +++ b/askbot/utils/mail.py @@ -15,9 +15,9 @@ def prefix_the_subject_line(subject): EMAIL_SUBJECT_LINE_PREFIX either from from live settings, which take default from django """ - prefix = askbot_settings.EMAIL_SUBJECT_PREFIX.strip() + prefix = askbot_settings.EMAIL_SUBJECT_PREFIX if prefix != '': - subject = prefix + ' ' + subject + subject = prefix.strip() + ' ' + subject.strip() return subject def extract_first_email_address(text): @@ -89,10 +89,9 @@ def send_mail( if raise_on_failure is True, exceptions.EmailNotSent is raised """ - prefix = askbot_settings.EMAIL_SUBJECT_PREFIX.strip() + ' ' try: assert(subject_line is not None) - subject_line = prefix + subject_line + subject_line = prefix_the_subject_line(subject_line) msg = mail.EmailMessage( subject_line, body_text, |