diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-10-28 18:03:13 -0300 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-10-28 18:03:13 -0300 |
commit | 6e4f4482853fd20f8f8301e96174da77c528e415 (patch) | |
tree | 5b1b297ad4d078ab4edd04487606bbd8c2307862 /askbot/forms.py | |
parent | 980989b786c77ef2a7a23e23545c402e1b072591 (diff) | |
download | askbot-6e4f4482853fd20f8f8301e96174da77c528e415.tar.gz askbot-6e4f4482853fd20f8f8301e96174da77c528e415.tar.bz2 askbot-6e4f4482853fd20f8f8301e96174da77c528e415.zip |
undone the first implementation of limiting the link insertion
Diffstat (limited to 'askbot/forms.py')
-rw-r--r-- | askbot/forms.py | 54 |
1 files changed, 11 insertions, 43 deletions
diff --git a/askbot/forms.py b/askbot/forms.py index 0a0f4f33..1c5bc3d6 100644 --- a/askbot/forms.py +++ b/askbot/forms.py @@ -11,7 +11,6 @@ from django.utils.text import get_text_list from django.contrib.auth.models import User from django_countries import countries from askbot.utils.forms import NextUrlField, UserNameField -from askbot.utils.markup import URL_RE from askbot.mail import extract_first_email_address from recaptcha_works.fields import RecaptchaField from askbot.conf import settings as askbot_settings @@ -274,11 +273,6 @@ class EditorField(forms.CharField): min_length = 10 # sentinel default value def __init__(self, *args, **kwargs): - user = kwargs.pop('user', None) - if user is None: - raise ValueError('user parameter is required') - self.user = user - editor_attrs = kwargs.pop('editor_attrs', {}) super(EditorField, self).__init__(*args, **kwargs) self.required = True @@ -301,21 +295,6 @@ class EditorField(forms.CharField): self.min_length ) % self.min_length raise forms.ValidationError(msg) - - if re.search(URL_RE, value): - min_rep = askbot_settings.MIN_REP_TO_INSERT_LINK - if self.user.is_anonymous(): - raise forms.ValidationError( - _('Links or images cannot be inserted anonymously') - ) - elif self.user.reputation < min_rep: - raise forms.ValidationError( - ungettext_lazy( - 'At at least %d karma point is required to insert links', - 'At at least %d karma points are required to insert links', - min_rep - ) % min_rep - ) return value @@ -323,10 +302,7 @@ class QuestionEditorField(EditorField): """Editor field for the questions""" def __init__(self, *args, **kwargs): - user = kwargs.pop('user', None) - super(QuestionEditorField, self).__init__( - user=user, *args, **kwargs - ) + super(QuestionEditorField, self).__init__(*args, **kwargs) self.length_error_template_singular = \ 'question body must be > %d character' self.length_error_template_plural = \ @@ -501,12 +477,10 @@ class EditorForm(forms.Form): the field must be created dynamically, so it's added in the __init__() function""" - def __init__(self, user=None, editor_attrs=None): + def __init__(self, editor_attrs=None): super(EditorForm, self).__init__() editor_attrs = editor_attrs or {} - self.fields['editor'] = EditorField( - user=user, editor_attrs=editor_attrs - ) + self.fields['editor'] = EditorField(editor_attrs=editor_attrs) class DumpUploadForm(forms.Form): @@ -923,10 +897,9 @@ class AskForm(PostAsSomeoneForm, PostPrivatelyForm): ) def __init__(self, *args, **kwargs): - user = kwargs.pop('user', None) super(AskForm, self).__init__(*args, **kwargs) #it's important that this field is set up dynamically - self.fields['text'] = QuestionEditorField(user=user) + self.fields['text'] = QuestionEditorField() #hide ask_anonymously field if askbot_settings.ALLOW_ASK_ANONYMOUSLY is False: self.hide_field('ask_anonymously') @@ -959,12 +932,11 @@ class AskWidgetForm(forms.Form, FormWithHideableFields): ) def __init__(self, include_text=True, *args, **kwargs): - user = kwargs.pop('user', None) super(AskWidgetForm, self).__init__(*args, **kwargs) #hide ask_anonymously field if not askbot_settings.ALLOW_ASK_ANONYMOUSLY: self.hide_field('ask_anonymously') - self.fields['text'] = QuestionEditorField(user=user) + self.fields['text'] = QuestionEditorField() if not include_text: self.hide_field('text') #hack to make it validate @@ -1048,11 +1020,7 @@ class AskByEmailForm(forms.Form): 'required': ASK_BY_EMAIL_SUBJECT_HELP } ) - - def __init__(self, *args, **kwargs): - user = kwargs.pop('user', None) - super(AskByEmailForm, self).__init__(*args, **kwargs) - self.fields['body_text'] = QuestionEditorField(user=user) + body_text = QuestionEditorField() def clean_sender(self): """Cleans the :attr:`~askbot.forms.AskByEmail.sender` attribute @@ -1106,6 +1074,7 @@ class AskByEmailForm(forms.Form): class AnswerForm(PostAsSomeoneForm, PostPrivatelyForm): + text = AnswerEditorField() wiki = WikiField() openid = forms.CharField( required=False, max_length=255, @@ -1115,7 +1084,7 @@ class AnswerForm(PostAsSomeoneForm, PostPrivatelyForm): def __init__(self, *args, **kwargs): super(AnswerForm, self).__init__(*args, **kwargs) - self.fields['text'] = AnswerEditorField(user=kwargs['user']) + self.fields['text'] = AnswerEditorField() self.fields['email_notify'].widget.attrs['id'] = \ 'question-subscribe-updates' @@ -1200,11 +1169,11 @@ class EditQuestionForm(PostAsSomeoneForm, PostPrivatelyForm): def __init__(self, *args, **kwargs): """populate EditQuestionForm with initial data""" self.question = kwargs.pop('question') - self.user = kwargs.pop('user')#preserve for superclass + self.user = kwargs['user']#preserve for superclass revision = kwargs.pop('revision') super(EditQuestionForm, self).__init__(*args, **kwargs) #it is important to add this field dynamically - self.fields['text'] = QuestionEditorField(user=self.user) + self.fields['text'] = QuestionEditorField() self.fields['title'].initial = revision.title self.fields['text'].initial = revision.text self.fields['tags'].initial = revision.tagnames @@ -1306,10 +1275,9 @@ class EditAnswerForm(PostAsSomeoneForm, PostPrivatelyForm): def __init__(self, answer, revision, *args, **kwargs): self.answer = answer - user = kwargs.pop('user', None) super(EditAnswerForm, self).__init__(*args, **kwargs) #it is important to add this field dynamically - self.fields['text'] = AnswerEditorField(user=user) + self.fields['text'] = AnswerEditorField() self.fields['text'].initial = revision.text self.fields['wiki'].initial = answer.wiki |