diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-02-14 22:44:42 -0500 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-02-14 22:44:42 -0500 |
commit | f4dceaa6cf277bb09c8c2e7b995e492b2c052c8c (patch) | |
tree | 40ff5498d9aa97c81a89c83e8da5ef6ce781a683 | |
parent | 8c1f61bcd212363720f11a65e4e43bc96a9987f7 (diff) | |
download | askbot-f4dceaa6cf277bb09c8c2e7b995e492b2c052c8c.tar.gz askbot-f4dceaa6cf277bb09c8c2e7b995e492b2c052c8c.tar.bz2 askbot-f4dceaa6cf277bb09c8c2e7b995e492b2c052c8c.zip |
finished the anonymous posting feature on the first pass
-rw-r--r-- | askbot/auth.py | 8 | ||||
-rw-r--r-- | askbot/conf/user_settings.py | 17 | ||||
-rw-r--r-- | askbot/forms.py | 6 | ||||
-rw-r--r-- | askbot/models/__init__.py | 20 | ||||
-rw-r--r-- | askbot/models/answer.py | 1 | ||||
-rw-r--r-- | askbot/models/meta.py | 1 | ||||
-rw-r--r-- | askbot/skins/default/media/images/anon.png | bin | 0 -> 687 bytes | |||
-rw-r--r-- | askbot/skins/default/media/js/live_search.js | 32 | ||||
-rwxr-xr-x | askbot/skins/default/media/style/style.css | 20 | ||||
-rw-r--r-- | askbot/skins/default/templates/macros.html | 31 | ||||
-rw-r--r-- | askbot/skins/default/templates/main_page/javascript.html | 1 | ||||
-rw-r--r-- | askbot/skins/default/templates/question_edit.html | 16 | ||||
-rw-r--r-- | askbot/views/readers.py | 2 | ||||
-rw-r--r-- | askbot/views/users.py | 6 | ||||
-rw-r--r-- | askbot/views/writers.py | 4 |
15 files changed, 120 insertions, 45 deletions
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 Binary files differnew file mode 100644 index 00000000..a2041590 --- /dev/null +++ b/askbot/skins/default/media/images/anon.png 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 '<a ' + - 'href="' + - askbot['urls']['user_url_template'] - .replace('{{user_id}}', result['u_id']) - .replace('{{slug}}', u_slug) + - '">' + - result['u_name'] + - '</a> '; + if (result['u_is_anonymous'] === true){ + return '<span class="anonymous">' + + askbot['messages']['name_of_anonymous_user'] + + '</span>'; + } else { + var u_slug = result['u_name'].toLowerCase().replace(/ +/g, '-'); + return '<a ' + + 'href="' + + askbot['urls']['user_url_template'] + .replace('{{user_id}}', result['u_id']) + .replace('{{slug}}', u_slug) + + '">' + + result['u_name'] + + '</a> '; + } } else { return ''; @@ -168,10 +174,12 @@ $(document).ready(function(){ '>' + result['timesince'] + '</span> ' + - 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) + - '</div>'; + } + user_html += '</div>'; 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 %} + <img alt="{% trans %}anonymous user{% endtrans %}" src="{{ '/images/anon.png'|media }} " class="gravatar" width="32" height="32" /> + <p>{{ user.get_anonymous_name() }}</p> + {% else %} + {{ gravatar(user, 32) }} + {{ user.get_profile_link()}}{{ user_country_flag(user) }}{% if not user.website %}<br/>{% endif %} + {{ user_score_and_badge_summary(user) }}<br/> + {{ 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 #} <strong>{{post.added_at|diff_date}}</strong> {% endif %} </p> - {{ gravatar(post.author, 32) }} - {{post.author.get_profile_link()}}{{ user_country_flag(post.author)}}{% if not post.author.website %}<br/>{% endif %} - {{ user_score_and_badge_summary(post.author) }}<br/> - {{ user_website_link(post.author) }} + {{ post_contributor_avatar_and_credentials(post, post.author) }} {% endif %} </div> {% elif contributor_type=="last_updater" %} @@ -223,10 +232,7 @@ poor design of the data or methods on data objects #} >{% trans %}updated{% endtrans %} <strong>{{ last_edited_at|diff_date }}</strong></a> </p> {% 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 %}<br/>{% endif %} - {{ user_score_and_badge_summary(update_author) }}<br/> - {{ user_website_link(update_author) }} + {{ post_contributor_avatar_and_credentials(post, update_author) }} {% endif %} </div> {% endif %} @@ -278,8 +284,12 @@ poor design of the data or methods on data objects #} <div style="clear:both"></div> <div class="userinfo"> <span class="relativetime" title="{{question.last_activity_at}}">{{ question.last_activity_at|diff_date }}</span> - <a href="{% url user_profile question.last_activity_by.id, question.last_activity_by.username|slugify %}">{{question.last_activity_by.username}}</a>{{ user_country_flag(question.last_activity_by) }} + {% if question.is_anonymous %} + <span class="anonymous">{{ question.last_activity_by.get_anonymous_name() }}</span> + {% else %} + <a href="{% url user_profile question.last_activity_by.id, question.last_activity_by.username|slugify %}">{{question.last_activity_by.username}}</a>{{ user_country_flag(question.last_activity_by) }} {#{user_score_and_badge_summary(question.last_activity_by)}#} + {% endif %} </div> </div> <h2><a title="{{question.summary|escape}}" href="{{ question.get_absolute_url() }}">{{question.get_question_title()|escape}}</a></h2> @@ -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 %} <div class="form-item"> 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 }}'; </script> <script type='text/javascript' src='{{"/js/editor.js"|media}}'></script> {% 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 @@ <div class="after-editor"> <input type="submit" value="{% trans %}Save edit{% endtrans %}" class="submit" /> <input type="button" value="{% trans %}Cancel{% endtrans %}" class="submit" onclick="history.back(-1);" /> - </div> - <div class="question-options"> - {% 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 %} + <div class="question-options"> + {% 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 %} + </div> </div> </form> {% 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, |