From a7ef44e7769429470cbf5c8708be37f6ca098ab3 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 14 Oct 2011 15:06:32 +0200 Subject: [PATCH] #1753: require author info when not logged in --- apps/wiki/forms.py | 12 ++++++++++-- apps/wiki/views.py | 6 ++++-- redakcja/static/js/wiki/base.js | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/wiki/forms.py b/apps/wiki/forms.py index 1d4d8549..394b823b 100644 --- a/apps/wiki/forms.py +++ b/apps/wiki/forms.py @@ -34,13 +34,13 @@ class DocumentTextSaveForm(forms.Form): text = forms.CharField(widget=forms.HiddenInput) author_name = forms.CharField( - required=False, + required=True, label=_(u"Author"), help_text=_(u"Your name"), ) author_email = forms.EmailField( - required=False, + required=True, label=_(u"Author's email"), help_text=_(u"Your email address, so we can show a gravatar :)"), ) @@ -59,6 +59,14 @@ class DocumentTextSaveForm(forms.Form): help_text=_(u"If you completed a life cycle stage, select it."), ) + def __init__(self, *args, **kwargs): + user = kwargs.pop('user') + r = super(DocumentTextSaveForm, self).__init__(*args, **kwargs) + if user and user.is_authenticated(): + self.fields['author_name'].required = False + self.fields['author_email'].required = False + return r + class DocumentTextRevertForm(forms.Form): """ diff --git a/apps/wiki/views.py b/apps/wiki/views.py index 15fc4621..b137a541 100644 --- a/apps/wiki/views.py +++ b/apps/wiki/views.py @@ -62,7 +62,7 @@ def editor(request, slug, chunk=None, template_name='wiki/document_details.html' return direct_to_template(request, template_name, extra_context={ 'chunk': chunk, 'forms': { - "text_save": forms.DocumentTextSaveForm(prefix="textsave"), + "text_save": forms.DocumentTextSaveForm(user=request.user, prefix="textsave"), "text_revert": forms.DocumentTextRevertForm(prefix="textrevert"), "pubmark": forms.DocumentPubmarkForm(prefix="pubmark"), }, @@ -104,7 +104,7 @@ def text(request, chunk_id): doc = get_object_or_404(Chunk, pk=chunk_id) if request.method == 'POST': - form = forms.DocumentTextSaveForm(request.POST, prefix="textsave") + form = forms.DocumentTextSaveForm(request.POST, user=request.user, prefix="textsave") if form.is_valid(): if request.user.is_authenticated(): author = request.user @@ -123,6 +123,8 @@ def text(request, chunk_id): parent=parent, description=form.cleaned_data['comment'], tags=tags, + author_name=form.cleaned_data['author_name'], + author_email=form.cleaned_data['author_email'], ) revision = doc.revision() return JSONResponse({ diff --git a/redakcja/static/js/wiki/base.js b/redakcja/static/js/wiki/base.js index de1d8e5d..8625b112 100644 --- a/redakcja/static/js/wiki/base.js +++ b/redakcja/static/js/wiki/base.js @@ -299,6 +299,7 @@ var global = $("*[data-ui-error-for='__all__']", this.$elem); var unassigned = []; + $("*[data-ui-error-for]", this.$elem).text(''); for (var field_name in errors) { var span = $("*[data-ui-error-for='"+field_name+"']", this.$elem); -- 2.20.1