class TagNamesField(forms.CharField):
class TagNamesField(forms.CharField):
- def __init__(self, *args, **kwargs):
+ def __init__(self, user=None, *args, **kwargs):
super(TagNamesField, self).__init__(*args, **kwargs)
self.required = True
self.widget = forms.TextInput(attrs={'size' : 50, 'autocomplete' : 'off'})
super(TagNamesField, self).__init__(*args, **kwargs)
self.required = True
self.widget = forms.TextInput(attrs={'size' : 50, 'autocomplete' : 'off'})
'min': settings.FORM_MIN_NUMBER_OF_TAGS, 'max': settings.FORM_MAX_NUMBER_OF_TAGS
}
self.initial = ''
'min': settings.FORM_MIN_NUMBER_OF_TAGS, 'max': settings.FORM_MAX_NUMBER_OF_TAGS
}
self.initial = ''
def clean(self, value):
value = super(TagNamesField, self).clean(value)
def clean(self, value):
value = super(TagNamesField, self).clean(value)
if tag not in list_temp and len(tag.strip()) > 0:
list_temp.append(tag)
if tag not in list_temp and len(tag.strip()) > 0:
list_temp.append(tag)
+ if settings.LIMIT_TAG_CREATION and not self.user.can_create_tags():
+ existent = Tag.objects.filter(name__in=list_temp).values_list('name', flat=True)
+
+ if len(existent) < len(list_temp):
+ unexistent = [n for n in list_temp if not n in existent]
+ raise forms.ValidationError(_("You don't have enough reputation to create new tags. The following tags do not exist yet: %s") %
+ ', '.join(unexistent))
+
+
return u' '.join(list_temp)
class WikiField(forms.BooleanField):
return u' '.join(list_temp)
class WikiField(forms.BooleanField):
class AskForm(forms.Form):
title = TitleField()
text = QuestionEditorField()
class AskForm(forms.Form):
title = TitleField()
text = QuestionEditorField()
- def __init__(self, *args, **kwargs):
- super(AskForm, self).__init__(*args, **kwargs)
+ def __init__(self, data=None, user=None, *args, **kwargs):
+ super(AskForm, self).__init__(data, *args, **kwargs)
+
+ self.fields['tags'] = TagNamesField(user)
+
if settings.WIKI_ON:
self.fields['wiki'] = WikiField()
if settings.WIKI_ON:
self.fields['wiki'] = WikiField()
class EditQuestionForm(forms.Form):
title = TitleField()
text = QuestionEditorField()
class EditQuestionForm(forms.Form):
title = TitleField()
text = QuestionEditorField()
summary = SummaryField()
def __init__(self, question, user, revision=None, *args, **kwargs):
summary = SummaryField()
def __init__(self, question, user, revision=None, *args, **kwargs):
self.fields['title'].initial = revision.title
self.fields['text'].initial = revision.body
self.fields['title'].initial = revision.title
self.fields['text'].initial = revision.body
+
+ self.fields['tags'] = TagNamesField(user)
self.fields['tags'].initial = revision.tagnames
if settings.WIKI_ON:
self.fields['tags'].initial = revision.tagnames
if settings.WIKI_ON:
def can_accept_answer(self, answer):\r
return False\r
\r
def can_accept_answer(self, answer):\r
return False\r
\r
+ def can_create_tags(self):\r
+ return False\r
+\r
def can_edit_post(self, post):\r
return False\r
\r
def can_edit_post(self, post):\r
return False\r
\r
def can_accept_answer(self, answer):\r
return self == answer.question.author\r
\r
def can_accept_answer(self, answer):\r
return self == answer.question.author\r
\r
+ @true_if_is_super_or_staff\r
+ def can_create_tags(self):\r
+ return self.reputation >= int(settings.REP_TO_CREATE_TAGS)\r
+\r
@true_if_is_super_or_staff\r
def can_edit_post(self, post):\r
return self == post.author or self.reputation >= int(settings.REP_TO_EDIT_OTHERS\r
@true_if_is_super_or_staff\r
def can_edit_post(self, post):\r
return self == post.author or self.reputation >= int(settings.REP_TO_EDIT_OTHERS\r
help_text = _("Can questions or answers be marked as community wiki."),
required=False))
help_text = _("Can questions or answers be marked as community wiki."),
required=False))
+LIMIT_TAG_CREATION = Setting('LIMIT_TAG_CREATION', False, FORUM_SET, dict(
+label = _("Limit tag creation"),
+help_text = _("Limit tag creation to super users, staff or users with a minimum reputation."),
+required=False))
+
""" settings for questions """
FORM_MIN_QUESTION_TITLE = Setting('FORM_MIN_QUESTION_TITLE', 10, FORUM_SET, dict(
""" settings for questions """
FORM_MIN_QUESTION_TITLE = Setting('FORM_MIN_QUESTION_TITLE', 10, FORUM_SET, dict(
label = _("Minimum reputation to upload"),\r
help_text = _("The minimum reputation an user must have to be allowed to upload a file.")))\r
\r
label = _("Minimum reputation to upload"),\r
help_text = _("The minimum reputation an user must have to be allowed to upload a file.")))\r
\r
+REP_TO_CREATE_TAGS = Setting('REP_TO_CREATE_TAGS', 250, MIN_REP_SET, dict(\r
+label = _("Minimum reputation to create tags"),\r
+help_text = _("The minimum reputation an user must have to be allowed to create new tags.")))\r
+\r
REP_TO_CLOSE_OWN = Setting('REP_TO_CLOSE_OWN', 250, MIN_REP_SET, dict(\r
label = _("Minimum reputation to close own question"),\r
help_text = _("The minimum reputation an user must have to be allowed to close his own question.")))\r
REP_TO_CLOSE_OWN = Setting('REP_TO_CLOSE_OWN', 250, MIN_REP_SET, dict(\r
label = _("Minimum reputation to close own question"),\r
help_text = _("The minimum reputation an user must have to be allowed to close his own question.")))\r
settings.REP_TO_COMMENT.set_value(0)
settings.REP_TO_LIKE_COMMENT.set_value(0)
settings.REP_TO_UPLOAD.set_value(0)
settings.REP_TO_COMMENT.set_value(0)
settings.REP_TO_LIKE_COMMENT.set_value(0)
settings.REP_TO_UPLOAD.set_value(0)
+ settings.REP_TO_CREATE_TAGS.set_value(0)
settings.REP_TO_CLOSE_OWN.set_value(60)
settings.REP_TO_REOPEN_OWN.set_value(120)
settings.REP_TO_RETAG.set_value(150)
settings.REP_TO_CLOSE_OWN.set_value(60)
settings.REP_TO_REOPEN_OWN.set_value(120)
settings.REP_TO_RETAG.set_value(150)
@decoratable
def ask(request):
if request.POST and "text" in request.POST:
@decoratable
def ask(request):
if request.POST and "text" in request.POST:
- form = AskForm(request.POST)
+ form = AskForm(request.POST, user=request.user)
if form.is_valid():
if request.user.is_authenticated():
ask_action = AskAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data)
if form.is_valid():
if request.user.is_authenticated():
ask_action = AskAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data)
request.session['temp_node_type'] = 'question'
return HttpResponseRedirect(reverse('auth_action_signin', kwargs={'action': 'newquestion'}))
elif request.method == "POST" and "go" in request.POST:
request.session['temp_node_type'] = 'question'
return HttpResponseRedirect(reverse('auth_action_signin', kwargs={'action': 'newquestion'}))
elif request.method == "POST" and "go" in request.POST:
- form = AskForm({'title': request.POST['q']})
+ form = AskForm({'title': request.POST['q']}, user=request.user)
+ form = AskForm(user=request.user)
- #tags = _get_tags_cache_json()
return render_to_response('ask.html', {
'form' : form,
return render_to_response('ask.html', {
'form' : form,
'email_validation_faq_url':reverse('faq') + '#validate',
}, context_instance=RequestContext(request))
'email_validation_faq_url':reverse('faq') + '#validate',
}, context_instance=RequestContext(request))