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 %}
+
+
{{ 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 #}
@@ -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 %}