From: claycarpenter Date: Mon, 31 Jan 2011 23:08:32 +0000 (+0000) Subject: Accepting incoming merge of the jambazov feature branch. Mostly includes new bug... X-Git-Tag: live~459 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/2444d6ffd7995be782615589fb1d5aef2c8277ce?ds=inline Accepting incoming merge of the jambazov feature branch. Mostly includes new bug fixes. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@718 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/feed.py b/forum/feed.py index 72e085d..02c309d 100644 --- a/forum/feed.py +++ b/forum/feed.py @@ -15,7 +15,7 @@ from forum.utils.pagination import generate_uri @decorate(add_domain, needs_origin=False) def add_domain(domain, url, *args, **kwargs): - return "%s%s" % (settings.APP_URL, url) + return "%s%s" % (settings.APP_BASE_URL, url) class BaseNodeFeed(Feed): if old_version: diff --git a/forum/forms/admin.py b/forum/forms/admin.py index a1d7b72..1ff2e85 100644 --- a/forum/forms/admin.py +++ b/forum/forms/admin.py @@ -58,9 +58,8 @@ class UrlFieldWidget(forms.TextInput): return """ - - """ % {'name': name, 'value': value, 'app_url': settings.APP_URL, - 'script_alias': settings.FORUM_SCRIPT_ALIAS} + + """ % {'name': name, 'value': value, 'app_url': settings.APP_URL} class PageForm(forms.Form): @@ -105,4 +104,4 @@ class CreateUserForm(SimpleRegistrationForm, SetPasswordForm): self.fields['email'].label = _('email address') - \ No newline at end of file + diff --git a/forum/forms/general.py b/forum/forms/general.py index c754e85..4b1133e 100644 --- a/forum/forms/general.py +++ b/forum/forms/general.py @@ -5,10 +5,10 @@ from django.utils.safestring import mark_safe from forum import settings from django.http import str_to_unicode from forum.models import User -from forum_modules.recaptcha.formfield import ReCaptchaField +from forum.modules import call_all_handlers import urllib -DEFAULT_NEXT = '/' + getattr(settings, 'FORUM_SCRIPT_ALIAS') +DEFAULT_NEXT = getattr(settings, 'APP_BASE_URL') def clean_next(next): if next is None: return DEFAULT_NEXT @@ -156,4 +156,14 @@ class SetPasswordForm(forms.Form): return self.cleaned_data['password2'] class SimpleCaptchaForm(forms.Form): - captcha = ReCaptchaField() + def __init__(self, *args, **kwargs): + spam_fields = call_all_handlers('create_anti_spam_field') + if spam_fields: + spam_fields = dict(spam_fields) + for name, field in spam_fields.items(): + self.fields[name] = field + + self._anti_spam_fields = spam_fields.keys() + else: + self._anti_spam_fields = [] + diff --git a/forum/forms/qanda.py b/forum/forms/qanda.py index b499cbd..9890640 100644 --- a/forum/forms/qanda.py +++ b/forum/forms/qanda.py @@ -8,6 +8,9 @@ from django.contrib.humanize.templatetags.humanize import apnumber from django.utils.safestring import mark_safe from general import NextUrlField, UserNameField, SetPasswordForm from forum import settings + +from forum.modules import call_all_handlers + import logging class TitleField(forms.CharField): @@ -154,6 +157,17 @@ class AskForm(forms.Form): super(AskForm, self).__init__(data, *args, **kwargs) self.fields['tags'] = TagNamesField(user) + + if int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (user.is_superuser or user.is_staff): + spam_fields = call_all_handlers('create_anti_spam_field') + if spam_fields: + spam_fields = dict(spam_fields) + for name, field in spam_fields.items(): + self.fields[name] = field + + self._anti_spam_fields = spam_fields.keys() + else: + self._anti_spam_fields = [] if settings.WIKI_ON: self.fields['wiki'] = WikiField() @@ -162,16 +176,23 @@ class AnswerForm(forms.Form): text = AnswerEditorField() wiki = WikiField() - def __init__(self, question, *args, **kwargs): - super(AnswerForm, self).__init__(*args, **kwargs) + def __init__(self, data=None, user=None, *args, **kwargs): + super(AnswerForm, self).__init__(data, *args, **kwargs) + + if int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (user.is_superuser or user.is_staff): + spam_fields = call_all_handlers('create_anti_spam_field') + if spam_fields: + spam_fields = dict(spam_fields) + for name, field in spam_fields.items(): + self.fields[name] = field + + self._anti_spam_fields = spam_fields.keys() + else: + self._anti_spam_fields = [] if settings.WIKI_ON: self.fields['wiki'] = WikiField() - #if question.nis.wiki: - # self.fields['wiki'].initial = True - - class RetagQuestionForm(forms.Form): tags = TagNamesField() # initialize the default values @@ -214,6 +235,17 @@ class EditQuestionForm(forms.Form): self.fields['tags'] = TagNamesField(user) self.fields['tags'].initial = revision.tagnames + if int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (user.is_superuser or user.is_staff): + spam_fields = call_all_handlers('create_anti_spam_field') + if spam_fields: + spam_fields = dict(spam_fields) + for name, field in spam_fields.items(): + self.fields[name] = field + + self._anti_spam_fields = spam_fields.keys() + else: + self._anti_spam_fields = [] + if settings.WIKI_ON: self.fields['wiki'] = WikiField(disabled=(question.nis.wiki and not user.can_cancel_wiki(question)), initial=question.nis.wiki) @@ -229,6 +261,17 @@ class EditAnswerForm(forms.Form): self.fields['text'].initial = revision.body + if int(user.reputation) < settings.CAPTCHA_IF_REP_LESS_THAN and not (user.is_superuser or user.is_staff): + spam_fields = call_all_handlers('create_anti_spam_field') + if spam_fields: + spam_fields = dict(spam_fields) + for name, field in spam_fields.items(): + self.fields[name] = field + + self._anti_spam_fields = spam_fields.keys() + else: + self._anti_spam_fields = [] + if settings.WIKI_ON: self.fields['wiki'] = WikiField(disabled=(answer.nis.wiki and not user.can_cancel_wiki(answer)), initial=answer.nis.wiki) diff --git a/forum/management/commands/checkinstall.py b/forum/management/commands/checkinstall.py index efb0b19..6e37d11 100644 --- a/forum/management/commands/checkinstall.py +++ b/forum/management/commands/checkinstall.py @@ -80,5 +80,6 @@ class Command(NoArgsCommand): print " Your APP_URL does not seem to be a valid url. Please fill this setting with the URL of your OSQA installation" else: print " APP_URL - %s" % settings.APP_URL + print " APP_BASE_URL - %s" % settings.APP_BASE_URL diff --git a/forum/models/node.py b/forum/models/node.py index 0dfe1d2..43d12b3 100644 --- a/forum/models/node.py +++ b/forum/models/node.py @@ -419,8 +419,6 @@ class Node(BaseModel, NodeContent): super(Node, self).delete(*args, **kwargs) def save(self, *args, **kwargs): - tags_changed = self._process_changes_in_tags() - if not self.id: self.node_type = self.get_type() super(BaseModel, self).save(*args, **kwargs) @@ -431,8 +429,11 @@ class Node(BaseModel, NodeContent): if self.parent_id and not self.abs_parent_id: self.abs_parent = self.parent.absolute_parent - + + tags_changed = self._process_changes_in_tags() + super(Node, self).save(*args, **kwargs) + if tags_changed: self.tags = list(Tag.objects.filter(name__in=self.tagname_list())) class Meta: diff --git a/forum/models/user.py b/forum/models/user.py index 8ef201d..9d63248 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -22,6 +22,8 @@ QUESTIONS_PER_PAGE_CHOICES = ( ) class AnonymousUser(DjangoAnonymousUser): + reputation = 0 + def get_visible_answers(self, question): return question.answers.filter_state(deleted=False) diff --git a/forum/settings/__init__.py b/forum/settings/__init__.py index 9b0cbed..e10fc76 100644 --- a/forum/settings/__init__.py +++ b/forum/settings/__init__.py @@ -16,7 +16,8 @@ DJSTYLE_ADMIN_INTERFACE = Setting('DJSTYLE_ADMIN_INTERFACE', True) NODE_MAN_FILTERS = Setting('NODE_MAN_FILTERS', []) APP_URL = djsettings.APP_URL -FORUM_SCRIPT_ALIAS = djsettings.FORUM_SCRIPT_ALIAS +APP_BASE_URL = djsettings.APP_BASE_URL +FORCE_SCRIPT_NAME = djsettings.FORCE_SCRIPT_NAME OSQA_SKIN = djsettings.OSQA_DEFAULT_SKIN LANGUAGE_CODE = djsettings.LANGUAGE_CODE ADMIN_MEDIA_PREFIX = djsettings.ADMIN_MEDIA_PREFIX diff --git a/forum/settings/email.py b/forum/settings/email.py index 4c9486a..5e8bddf 100644 --- a/forum/settings/email.py +++ b/forum/settings/email.py @@ -40,16 +40,16 @@ widget=PasswordInput)) EMAIL_USE_TLS = Setting('EMAIL_USE_TLS', False, EMAIL_SET, dict( label = _("Use TLS"), -help_text = _("Does your SMTP server usFes TLS for authentication."), +help_text = _("Whether to use TLS for authentication with your SMTP server."), required=False)) DEFAULT_FROM_EMAIL = Setting('DEFAULT_FROM_EMAIL', '', EMAIL_SET, dict( -label = _("Site 'from' email address"), +label = _("Site 'from' Email Address"), help_text = _("The address that will show up on the 'from' field on emails sent by your website."), required=False)) EMAIL_SUBJECT_PREFIX = Setting('EMAIL_SUBJECT_PREFIX', '', EMAIL_SET, dict( -label = _("Email subject prefix"), +label = _("Email Subject Prefix"), help_text = _("Every email sent through your website will have the subject prefixed by this string. It's usually a good idea to have such a prefix so your users can easily set up a filter on theyr email clients."), required=False)) @@ -59,17 +59,17 @@ help_text = _("Email footer text, usually \"CAN SPAM\" compliance, or the physic required=False)) EMAIL_BORDER_COLOR = Setting('EMAIL_BORDER_COLOR', '#e5ebf8', EMAIL_SET, dict( -label = _("Email Border color"), +label = _("Email Border Color"), help_text = _("The outter border color of the email base template"), required=False)) EMAIL_PARAGRAPH_STYLE = Setting('EMAIL_PARAGRAPH_STYLE', "color:#333333;font-family:'helvetica neue', arial, Helvetica, sans-serif;line-height:18px;font-size:14px;margin-top:10px;", EMAIL_SET, dict( -label = _("Email Paragraph style"), +label = _("Email Paragraph Style"), help_text = _("A valid css string to be used to style email paragraphs (the P tag)."), required=False)) EMAIL_ANCHOR_STYLE = Setting('EMAIL_ANCHOR_STYLE', "text-decoration:none;color:#3060a8;font-weight:bold;", EMAIL_SET, dict( -label = _("Email link style"), +label = _("Email Link Style"), help_text = _("A valid css string to be used to style email links (the A tag)."), required=False)) diff --git a/forum/settings/minrep.py b/forum/settings/minrep.py index b2ff60d..8206823 100644 --- a/forum/settings/minrep.py +++ b/forum/settings/minrep.py @@ -3,6 +3,10 @@ from django.utils.translation import ugettext_lazy as _ MIN_REP_SET = SettingSet('minrep', _('Minimum reputation config'), _("Configure the minimum reputation required to perform certain actions on your site."), 300) +CAPTCHA_IF_REP_LESS_THAN = Setting('CAPTCHA_IF_REP_LESS_THAN', 0, MIN_REP_SET, dict( +label = _("Show captcha if user with less reputation than"), +help_text = _("If the user has less reputation, captcha is used to when adding new content."))) + REP_TO_VOTE_UP = Setting('REP_TO_VOTE_UP', 15, MIN_REP_SET, dict( label = _("Minimum reputation to vote up"), help_text = _("The minimum reputation an user must have to be allowed to vote up."))) diff --git a/forum/skins/default/templates/answer_edit.html b/forum/skins/default/templates/answer_edit.html index c9d8466..985addd 100644 --- a/forum/skins/default/templates/answer_edit.html +++ b/forum/skins/default/templates/answer_edit.html @@ -90,6 +90,14 @@
{{ form.summary.help_text }}
+ + {% if form.recaptcha %} +
+ {{ form.recaptcha.errors }} + {{ form.recaptcha }} +
+ {% endif %} + diff --git a/forum/skins/default/templates/ask.html b/forum/skins/default/templates/ask.html index bb4ad67..fa38b76 100644 --- a/forum/skins/default/templates/ask.html +++ b/forum/skins/default/templates/ask.html @@ -148,6 +148,15 @@

{{ form.tags.help_text }}

+ + {% if form.recaptcha %} +
+ {{ form.recaptcha.errors }} + {{ form.recaptcha }} +
+
+ {% endif %} + {% if not request.user.is_authenticated %} {% else %} diff --git a/forum/skins/default/templates/base_content.html b/forum/skins/default/templates/base_content.html index 0fbcc5d..2281f0e 100644 --- a/forum/skins/default/templates/base_content.html +++ b/forum/skins/default/templates/base_content.html @@ -22,7 +22,7 @@