From f4dceaa6cf277bb09c8c2e7b995e492b2c052c8c Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Mon, 14 Feb 2011 22:44:42 -0500 Subject: finished the anonymous posting feature on the first pass --- askbot/auth.py | 8 +++--- askbot/conf/user_settings.py | 17 ++++++++--- askbot/forms.py | 6 ++-- askbot/models/__init__.py | 20 +++++++++++++ askbot/models/answer.py | 1 + askbot/models/meta.py | 1 + askbot/skins/default/media/images/anon.png | Bin 0 -> 687 bytes askbot/skins/default/media/js/live_search.js | 32 +++++++++++++-------- askbot/skins/default/media/style/style.css | 20 +++++++++++-- askbot/skins/default/templates/macros.html | 31 +++++++++++++------- .../default/templates/main_page/javascript.html | 1 + askbot/skins/default/templates/question_edit.html | 16 +++++------ askbot/views/readers.py | 2 ++ askbot/views/users.py | 6 +++- askbot/views/writers.py | 4 ++- 15 files changed, 120 insertions(+), 45 deletions(-) create mode 100644 askbot/skins/default/media/images/anon.png diff --git a/askbot/auth.py b/askbot/auth.py index 6b12f08d..118810ca 100644 --- a/askbot/auth.py +++ b/askbot/auth.py @@ -167,7 +167,7 @@ def onUpVoted(vote, post, user, timestamp=None): post.score = int(post.score) + 1 post.save() - if not post.wiki: + if not (post.wiki or post.is_anonymous): author = post.author todays_rep_gain = Repute.objects.get_reputation_by_upvoted_today(author) if todays_rep_gain < askbot_settings.MAX_REP_GAIN_PER_USER_PER_DAY: @@ -200,7 +200,7 @@ def onUpVotedCanceled(vote, post, user, timestamp=None): post.score = int(post.score) - 1 post.save() - if not post.wiki: + if not (post.wiki or post.is_anonymous): author = post.author author.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_UPVOTE_CANCELATION @@ -231,7 +231,7 @@ def onDownVoted(vote, post, user, timestamp=None): post.score = int(post.score) - 1 post.save() - if not post.wiki: + if not (post.wiki or post.is_anonymous): author = post.author author.receive_reputation(askbot_settings.REP_LOSS_FOR_DOWNVOTING) author.save() @@ -273,7 +273,7 @@ def onDownVotedCanceled(vote, post, user, timestamp=None): post.score = post.score + 1 post.save() - if not post.wiki: + if not (post.wiki or post.is_anonymous): author = post.author author.receive_reputation( askbot_settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION diff --git a/askbot/conf/user_settings.py b/askbot/conf/user_settings.py index 9add71b1..142a5b16 100644 --- a/askbot/conf/user_settings.py +++ b/askbot/conf/user_settings.py @@ -2,16 +2,16 @@ User policy settings """ from askbot.conf.settings_wrapper import settings -from askbot.deps.livesettings import ConfigurationGroup, BooleanValue, IntegerValue +from askbot.deps import livesettings from django.utils.translation import ugettext as _ -USER_SETTINGS = ConfigurationGroup( +USER_SETTINGS = livesettings.ConfigurationGroup( 'USER_SETTINGS', _('User policy settings') ) settings.register( - BooleanValue( + livesettings.BooleanValue( USER_SETTINGS, 'EDITABLE_SCREEN_NAME', default=True, @@ -20,7 +20,7 @@ settings.register( ) settings.register( - IntegerValue( + livesettings.IntegerValue( USER_SETTINGS, 'MIN_USERNAME_LENGTH', hidden=True, @@ -28,3 +28,12 @@ settings.register( description=_('Minimum allowed length for screen name') ) ) + +settings.register( + livesettings.StringValue( + USER_SETTINGS, + 'NAME_OF_ANONYMOUS_USER', + default = '', + description = _('Name for the Anonymous user') + ) +) diff --git a/askbot/forms.py b/askbot/forms.py index 0f6edef4..8f23d686 100644 --- a/askbot/forms.py +++ b/askbot/forms.py @@ -169,7 +169,7 @@ class WikiField(forms.BooleanField): super(WikiField, self).__init__(*args, **kwargs) self.required = False self.initial = False - self.label = _('community wiki') + self.label = _('community wiki (karma is not awarded & many others can edit wiki post)') self.help_text = _('if you choose community wiki option, the question and answer do not generate points and name of author will not be shown') def clean(self, value): return value and askbot_settings.WIKI_ON @@ -494,7 +494,7 @@ class AskForm(forms.Form, FormWithHideableFields): tags = TagNamesField() wiki = WikiField() ask_anonymously = forms.BooleanField( - label = _('Ask anonymously'), + label = _('ask anonymously'), help_text = _( 'Check if you do not want to reveal your name ' 'when asking this question' @@ -575,7 +575,7 @@ class EditQuestionForm(forms.Form, FormWithHideableFields): 'if you decide to reveal your identity, please check ' 'this box.' ), - label = _('Reveal identity'), + label = _('reveal identity'), required = False, ) diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 260ad0c5..9dc5083f 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -1237,6 +1237,25 @@ def user_is_owner_of(self, obj): else: raise NotImplementedError() +def get_name_of_anonymous_user(): + """Returns name of the anonymous user + either comes from the live settyngs or the language + translation + + very possible that this function does not belong here + """ + if askbot_settings.NAME_OF_ANONYMOUS_USER: + return askbot_settings.NAME_OF_ANONYMOUS_USER + else: + return _('Anonymous') + +def user_get_anonymous_name(self): + """Returns name of anonymous user + - convinience method for use in the template + macros that accept user as parameter + """ + return get_name_of_anonymous_user() + def user_set_status(self, new_status): """sets new status to user @@ -1640,6 +1659,7 @@ User.add_to_class( User.add_to_class('get_absolute_url', user_get_absolute_url) User.add_to_class('get_avatar_url', user_get_avatar_url) User.add_to_class('get_gravatar_url', user_get_gravatar_url) +User.add_to_class('get_anonymous_name', user_get_anonymous_name) User.add_to_class('update_has_custom_avatar', user_update_has_custom_avatar) User.add_to_class('post_question', user_post_question) User.add_to_class('edit_question', user_edit_question) diff --git a/askbot/models/answer.py b/askbot/models/answer.py index 714ddb2a..635a999c 100644 --- a/askbot/models/answer.py +++ b/askbot/models/answer.py @@ -94,6 +94,7 @@ class Answer(content.Content, DeletableContent): parse = parse_post_text parse_and_save = parse_and_save_post + is_anonymous = False #answers are never anonymous - may change def assert_is_visible_to(self, user): """raises QuestionHidden or AnswerHidden""" diff --git a/askbot/models/meta.py b/askbot/models/meta.py index 58d56421..d1e7d44c 100644 --- a/askbot/models/meta.py +++ b/askbot/models/meta.py @@ -92,6 +92,7 @@ class Comment(base.MetaContent, base.UserContent): _urlize = True _use_markdown = False _escape_html = True + is_anonymous = False #comments are never anonymous - may change class Meta(base.MetaContent.Meta): ordering = ('-added_at',) diff --git a/askbot/skins/default/media/images/anon.png b/askbot/skins/default/media/images/anon.png new file mode 100644 index 00000000..a2041590 Binary files /dev/null and b/askbot/skins/default/media/images/anon.png differ diff --git a/askbot/skins/default/media/js/live_search.js b/askbot/skins/default/media/js/live_search.js index 20203d1f..47965b61 100644 --- a/askbot/skins/default/media/js/live_search.js +++ b/askbot/skins/default/media/js/live_search.js @@ -102,15 +102,21 @@ $(document).ready(function(){ var render_user_link = function(result){ if (result['u_id'] !== false){ - var u_slug = result['u_name'].toLowerCase().replace(/ +/g, '-'); - return '' + - result['u_name'] + - ' '; + if (result['u_is_anonymous'] === true){ + return '' + + askbot['messages']['name_of_anonymous_user'] + + ''; + } else { + var u_slug = result['u_name'].toLowerCase().replace(/ +/g, '-'); + return '' + + result['u_name'] + + ' '; + } } else { return ''; @@ -168,10 +174,12 @@ $(document).ready(function(){ '>' + result['timesince'] + ' ' + - render_user_link(result) + - render_user_flag(result) + + render_user_link(result); + if (result['u_is_anonymous'] === false){ + user_html += render_user_flag(result); //render_user_badge_and_karma(result) + - ''; + } + user_html += ''; return user_html; }; diff --git a/askbot/skins/default/media/style/style.css b/askbot/skins/default/media/style/style.css index 7a3ab944..d1dbe5c8 100755 --- a/askbot/skins/default/media/style/style.css +++ b/askbot/skins/default/media/style/style.css @@ -347,7 +347,8 @@ blockquote { } .short-summary .userinfo .relativetime, -.short-summary .userinfo a { +.short-summary .userinfo a, +.short-summary span.anonymous { font-size: 11px; clear:both; font-weight: normal; @@ -1119,7 +1120,7 @@ span.form-error { } .wmd-preview { - margin: 0; + margin: 3px 0 5px 0; padding: 6px; width: 691px; background-color: #F5F5F5; @@ -1159,6 +1160,21 @@ span.form-error { cursor:help } +.question-options { + margin-top: 1px; + float: left; + color: #666; + line-height: 13px; +} +.question-options label { + vertical-align: text-bottom; +} + +.ask-page input.submit, +.edit-question-page input.submit { + float: left; +} + .edit-content-html { border-top: 1px dotted #D8D2A9; border-bottom: 1px dotted #D8D2A9; diff --git a/askbot/skins/default/templates/macros.html b/askbot/skins/default/templates/macros.html index 84716dcf..abd4a87d 100644 --- a/askbot/skins/default/templates/macros.html +++ b/askbot/skins/default/templates/macros.html @@ -156,6 +156,18 @@ {% endif %} {%- endmacro -%} +{%- macro post_contributor_avatar_and_credentials(post, user) -%} + {% if post.is_anonymous %} + {% trans %}anonymous user{% endtrans %} +

{{ user.get_anonymous_name() }}

+ {% else %} + {{ gravatar(user, 32) }} + {{ user.get_profile_link()}}{{ user_country_flag(user) }}{% if not user.website %}
{% endif %} + {{ user_score_and_badge_summary(user) }}
+ {{ user_website_link(user) }} + {% endif %} +{%- endmacro -%} + {%- macro post_contributor_info(post, contributor_type, is_wiki, wiki_min_rep) -%} {# there is a whole bunch of trickery here, probably indicative of poor design of the data or methods on data objects #} @@ -195,10 +207,7 @@ poor design of the data or methods on data objects #} {{post.added_at|diff_date}} {% endif %}

- {{ gravatar(post.author, 32) }} - {{post.author.get_profile_link()}}{{ user_country_flag(post.author)}}{% if not post.author.website %}
{% endif %} - {{ user_score_and_badge_summary(post.author) }}
- {{ user_website_link(post.author) }} + {{ post_contributor_avatar_and_credentials(post, post.author) }} {% endif %} {% elif contributor_type=="last_updater" %} @@ -223,10 +232,7 @@ poor design of the data or methods on data objects #} >{% trans %}updated{% endtrans %} {{ last_edited_at|diff_date }}

{% if original_author != update_author or is_wiki %} - {{ gravatar(update_author, 32) }} - {{update_author.get_profile_link()}}{{ user_country_flag(update_author) }}{% if not update_author.website %}
{% endif %} - {{ user_score_and_badge_summary(update_author) }}
- {{ user_website_link(update_author) }} + {{ post_contributor_avatar_and_credentials(post, update_author) }} {% endif %} {% endif %} @@ -278,8 +284,12 @@ poor design of the data or methods on data objects #}
{{ question.last_activity_at|diff_date }} - {{question.last_activity_by.username}}{{ user_country_flag(question.last_activity_by) }} + {% if question.is_anonymous %} + {{ question.last_activity_by.get_anonymous_name() }} + {% else %} + {{question.last_activity_by.username}}{{ user_country_flag(question.last_activity_by) }} {#{user_score_and_badge_summary(question.last_activity_by)}#} + {% endif %}

{{question.get_question_title()|escape}}

@@ -443,7 +453,8 @@ poor design of the data or methods on data objects #} {%- macro edit_post( post_form, post_type=None, - edit_title=False) + edit_title=False + ) -%} {% if edit_title %}
diff --git a/askbot/skins/default/templates/main_page/javascript.html b/askbot/skins/default/templates/main_page/javascript.html index 4f123004..dc5a4bdb 100644 --- a/askbot/skins/default/templates/main_page/javascript.html +++ b/askbot/skins/default/templates/main_page/javascript.html @@ -19,6 +19,7 @@ askbot['urls']['questions'] = '{% url "questions" %}'; askbot['urls']['question_url_template'] = scriptUrl + '{% trans %}question/{% endtrans %}{{ "{{QuestionID}}/" }}'; askbot['urls']['user_url_template'] = scriptUrl + '{% trans %}users/{% endtrans %}{{ "{{user_id}}" }}/{{ "{{slug}}" }}/'; + askbot['messages']['name_of_anonymous_user'] = '{{ name_of_anonymous_user }}'; {% if request.user.is_authenticated() %} diff --git a/askbot/skins/default/templates/question_edit.html b/askbot/skins/default/templates/question_edit.html index 6a3aae0c..60396714 100644 --- a/askbot/skins/default/templates/question_edit.html +++ b/askbot/skins/default/templates/question_edit.html @@ -19,14 +19,14 @@
  -
-
- {% if settings.WIKI_ON and question.wiki == False %} - {{ macros.checkbox_in_div(form.wiki) }} - {% endif %} - {% if form.can_stay_anonymous() %} - {{ macros.checkbox_in_div(form.reveal_identity) }} - {% endif %} +
+ {% if settings.WIKI_ON and question.wiki == False %} + {{ macros.checkbox_in_div(form.wiki) }} + {% endif %} + {% if form.can_stay_anonymous() %} + {{ macros.checkbox_in_div(form.reveal_identity) }} + {% endif %} +
{% endblock %} diff --git a/askbot/views/readers.py b/askbot/views/readers.py index 16e71f3e..dc1a6587 100644 --- a/askbot/views/readers.py +++ b/askbot/views/readers.py @@ -262,6 +262,7 @@ def questions(request): 'u_bronze_badge_symbol': const.BADGE_DISPLAY_SYMBOL, 'u_bronze_css_class': bronze_badge_css_class, 'u_country_code': country_code, + 'u_is_anonymous': question.is_anonymous, } ajax_data['questions'].append(question_data) @@ -301,6 +302,7 @@ def questions(request): 'show_sort_by_relevance': askbot.conf.should_show_sort_by_relevance(), 'scope': search_state.scope, 'context' : paginator_context, + 'name_of_anonymous_user' : models.get_name_of_anonymous_user() } assert(request.is_ajax() == False) diff --git a/askbot/views/users.py b/askbot/views/users.py index 807ccc11..0db7124e 100644 --- a/askbot/views/users.py +++ b/askbot/views/users.py @@ -277,8 +277,12 @@ def edit_user(request, id): def user_stats(request, user): + question_filter = {'author': user} + if request.user != user: + question_filter['is_anonymous'] = False + questions = models.Question.objects.filter( - author = user + **question_filter ).order_by( '-score', '-last_activity_at' ).select_related( diff --git a/askbot/views/writers.py b/askbot/views/writers.py index aa062d87..a6f0a933 100644 --- a/askbot/views/writers.py +++ b/askbot/views/writers.py @@ -255,6 +255,7 @@ def ask(request):#view used to ask a new question tags = _get_tags_cache_json() data = { 'active_tab': 'ask', + 'page_class': 'ask-page', 'form' : form, 'tags' : tags, 'email_validation_faq_url':reverse('faq') + '#validate', @@ -365,7 +366,7 @@ def edit_question(request, id): if form.cleaned_data['reveal_identity']: question.remove_author_anonymity() - is_anon_edit = form.cleaned_data['edit_anonymously'] + is_anon_edit = form.cleaned_data['stay_anonymous'] is_wiki = form.cleaned_data.get('wiki', question.wiki) request.user.edit_question( question = question, @@ -387,6 +388,7 @@ def edit_question(request, id): ) data = { + 'page_class': 'edit-question-page', 'active_tab': 'questions', 'question': question, 'revision_form': revision_form, -- cgit v1.2.3-1-g7c22