diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-06-05 06:33:29 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-06-05 06:33:29 -0400 |
commit | bec0efc77383afaa7fac9d668a93467e9f22c065 (patch) | |
tree | a0f03702a7484e06a29b676a88b206c00a7b4913 | |
parent | 209402f2c5086d95a760fe1007a1f34458badd99 (diff) | |
download | askbot-bec0efc77383afaa7fac9d668a93467e9f22c065.tar.gz askbot-bec0efc77383afaa7fac9d668a93467e9f22c065.tar.bz2 askbot-bec0efc77383afaa7fac9d668a93467e9f22c065.zip |
email meaningful feedback in re:ask by email when user does no have sufficient rep
-rw-r--r-- | askbot/mail/__init__.py | 15 | ||||
-rw-r--r-- | askbot/models/__init__.py | 8 | ||||
-rw-r--r-- | askbot/skins/default/templates/email/insufficient_rep_to_post_by_email.html | 13 |
3 files changed, 32 insertions, 4 deletions
diff --git a/askbot/mail/__init__.py b/askbot/mail/__init__.py index a0086a0a..7e3abbf6 100644 --- a/askbot/mail/__init__.py +++ b/askbot/mail/__init__.py @@ -10,11 +10,13 @@ from django.core.exceptions import PermissionDenied from django.forms import ValidationError from django.utils.translation import ugettext_lazy as _ from django.utils.translation import string_concat +from django.template import Context from askbot import exceptions from askbot import const from askbot.conf import settings as askbot_settings from askbot.utils import url_utils from askbot.utils.file_utils import store_file +from askbot.skins.loaders import get_template #todo: maybe send_mail functions belong to models #or the future API def prefix_the_subject_line(subject): @@ -331,6 +333,19 @@ def process_emailed_question( if user.email_isvalid == False: raise PermissionDenied('Lacking email signature') + if user.can_post_by_email() == False: + #todo: factor this code out + template = get_template('email/insufficient_rep_to_post_by_email.html') + min_rep = askbot_settings.MIN_REP_TO_POST_BY_EMAIL + min_upvotes = min_rep / askbot_settings.REP_GAIN_FOR_RECEIVING_UPVOTE + data = { + 'username': user.username, + 'site_name': askbot_settings.APP_SHORT_NAME, + 'min_upvotes': min_upvotes + } + message = template.render(Context(data)) + raise PermissionDenied(message) + tagnames = form.cleaned_data['tagnames'] title = form.cleaned_data['title'] body_text = form.cleaned_data['body_text'] diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 3319b9ae..b686818f 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -297,7 +297,7 @@ def user_can_have_strong_url(self): followed by the search engine crawlers""" return (self.reputation >= askbot_settings.MIN_REP_TO_HAVE_STRONG_URL) -def user_can_reply_by_email(self): +def user_can_post_by_email(self): """True, if reply by email is enabled and user has sufficient reputatiton""" return askbot_settings.REPLY_BY_EMAIL and \ @@ -2519,7 +2519,7 @@ User.add_to_class('is_following_question', user_is_following_question) User.add_to_class('mark_tags', user_mark_tags) User.add_to_class('update_response_counts', user_update_response_counts) User.add_to_class('can_have_strong_url', user_can_have_strong_url) -User.add_to_class('can_reply_by_email', user_can_reply_by_email) +User.add_to_class('can_post_by_email', user_can_post_by_email) User.add_to_class('can_post_comment', user_can_post_comment) User.add_to_class('is_administrator', user_is_administrator) User.add_to_class('is_administrator_or_moderator', user_is_administrator_or_moderator) @@ -2687,7 +2687,7 @@ def format_instant_notification_email( 'post_link': '<a href="%s">%s</a>' % (post_url, _(post.post_type)) } - can_reply = to_user.can_reply_by_email() + can_reply = to_user.can_post_by_email() if can_reply: reply_separator = const.SIMPLE_REPLY_SEPARATOR_TEMPLATE % \ @@ -2746,7 +2746,7 @@ def get_reply_to_addresses(user, post): #these variables will contain return values primary_addr = django_settings.DEFAULT_FROM_EMAIL secondary_addr = None - if user.can_reply_by_email(): + if user.can_post_by_email(): if user.reputation >= askbot_settings.MIN_REP_TO_POST_BY_EMAIL: reply_args = { diff --git a/askbot/skins/default/templates/email/insufficient_rep_to_post_by_email.html b/askbot/skins/default/templates/email/insufficient_rep_to_post_by_email.html new file mode 100644 index 00000000..071cbbdf --- /dev/null +++ b/askbot/skins/default/templates/email/insufficient_rep_to_post_by_email.html @@ -0,0 +1,13 @@ +{% import "email/macros.html" as macros %} +{# parameters: + * min_upvotes + * username + * site_name - for the footer +#} +<p style="{{ macros.heading_style }}"> + {% trans %}{{ username }}, your question could not be posted by email just yet{% endtrans %} +</p> +<p> + {% trans %}To make posts by email, you need to receive about {{min_upvotes}} upvotes.{% endtrans %} +</p> +{% include "email/footer.html" %} |