def clean(self, value):
if len(value) < settings.FORM_MIN_QUESTION_TITLE:
- raise forms.ValidationError(_('title must be must be at least %s characters' % settings.FORM_MIN_QUESTION_TITLE))
+ raise forms.ValidationError(_('title must be must be at least %s characters') % settings.FORM_MIN_QUESTION_TITLE)
return value
def clean(self, value):
if self.required and (len(value) < settings.FORM_MIN_QUESTION_BODY):
- raise forms.ValidationError(_('question content must be must be at least %s characters' % settings.FORM_MIN_QUESTION_BODY))
+ raise forms.ValidationError(_('question content must be at least %s characters') % settings.FORM_MIN_QUESTION_BODY)
return value
def clean(self, value):
if len(value) < settings.FORM_MIN_QUESTION_BODY:
- raise forms.ValidationError(_('answer content must be must be at least %s characters' % settings.FORM_MIN_QUESTION_BODY))
+ raise forms.ValidationError(_('answer content must be at least %s characters') % settings.FORM_MIN_QUESTION_BODY)
return value
return u' '.join(list_temp)
class WikiField(forms.BooleanField):
- def __init__(self, *args, **kwargs):
+ def __init__(self, disabled=False, *args, **kwargs):
super(WikiField, self).__init__(*args, **kwargs)
self.required = False
self.label = _('community wiki')
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')
+ if disabled:
+ self.widget=forms.CheckboxInput(attrs={'disabled': "disabled"})
def clean(self,value):
- return value and settings.WIKI_ON
+ return value
class EmailNotifyField(forms.BooleanField):
def __init__(self, *args, **kwargs):
title = TitleField()
text = QuestionEditorField()
tags = TagNamesField()
- wiki = WikiField()
+ def __init__(self, *args, **kwargs):
+ super(AskForm, self).__init__(*args, **kwargs)
+ if settings.WIKI_ON:
+ self.fields['wiki'] = WikiField()
class AnswerForm(forms.Form):
text = AnswerEditorField()
def __init__(self, question, *args, **kwargs):
super(AnswerForm, self).__init__(*args, **kwargs)
- if question.wiki and settings.WIKI_ON:
- self.fields['wiki'].initial = True
+ if settings.WIKI_ON:
+ self.fields['wiki'] = WikiField()
+
+ if question.nis.wiki:
+ self.fields['wiki'].initial = True
class RetagQuestionForm(forms.Form):
tags = TagNamesField()
summary = SummaryField()
- def __init__(self, question, revision=None, *args, **kwargs):
+ def __init__(self, question, user, revision=None, *args, **kwargs):
super(EditQuestionForm, self).__init__(*args, **kwargs)
if revision is None:
self.fields['title'].initial = revision.title
self.fields['text'].initial = revision.body
self.fields['tags'].initial = revision.tagnames
-
- # Once wiki mode is enabled, it can't be disabled
- if not question.wiki:
- self.fields['wiki'] = WikiField()
+
+ if settings.WIKI_ON:
+ self.fields['wiki'] = WikiField(disabled=(question.nis.wiki and not user.can_cancel_wiki(question)), initial=question.nis.wiki)
class EditAnswerForm(forms.Form):
text = AnswerEditorField()
summary = SummaryField()
- def __init__(self, answer, revision=None, *args, **kwargs):
+ def __init__(self, answer, user, revision=None, *args, **kwargs):
super(EditAnswerForm, self).__init__(*args, **kwargs)
if revision is None:
self.fields['text'].initial = revision.body
+ if settings.WIKI_ON:
+ self.fields['wiki'] = WikiField(disabled=(answer.nis.wiki and not user.can_cancel_wiki(answer)), initial=answer.nis.wiki)
+
class EditUserForm(forms.Form):
email = forms.EmailField(label=u'Email', help_text=_('this email does not have to be linked to gravatar'), required=True, max_length=255, widget=forms.TextInput(attrs={'size' : 35}))
realname = forms.CharField(label=_('Real name'), required=False, max_length=255, widget=forms.TextInput(attrs={'size' : 35}))