From: hernani Date: Wed, 7 Jul 2010 11:09:05 +0000 (+0000) Subject: Fixes OSQA 393, cannot send feedback when user is authenticated. X-Git-Tag: live~638 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/c8c6b98a7b2a365878871131e0f42c40d6b499fc Fixes OSQA 393, cannot send feedback when user is authenticated. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@496 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/forms/qanda.py b/forum/forms/qanda.py index a98ef38..ade6d5d 100644 --- a/forum/forms/qanda.py +++ b/forum/forms/qanda.py @@ -135,11 +135,17 @@ class SummaryField(forms.CharField): class FeedbackForm(forms.Form): - name = forms.CharField(label=_('Your name:'), required=False) - email = forms.EmailField(label=_('Email (not shared with anyone):'), required=True) message = forms.CharField(label=_('Your message:'), max_length=800,widget=forms.Textarea(attrs={'cols':60})) next = NextUrlField() + def __init__(self, user, *args, **kwargs): + super(FeedbackForm, self).__init__(*args, **kwargs) + if not user.is_authenticated(): + self.fields['name'] = forms.CharField(label=_('Your name:'), required=False) + self.fields['email'] = forms.EmailField(label=_('Email (not shared with anyone):'), required=True) + + + class AskForm(forms.Form): title = TitleField() text = QuestionEditorField() diff --git a/forum/skins/default/templates/notifications/feedback.html b/forum/skins/default/templates/notifications/feedback.html index ec4d211..6387049 100644 --- a/forum/skins/default/templates/notifications/feedback.html +++ b/forum/skins/default/templates/notifications/feedback.html @@ -13,13 +13,8 @@ {% htmlcontent notifications/base.html %}

- {% trans "Sender" %}: - {% if user.is_authenticated %} - {{ user.username }}
{% trans "email" %}:{{ user.email }} - {% else %} - {% if name %}{{ name }}{% else %}{% trans "anonymous" %}{% endif %} - {% if email %}{% trans "email" %}:{{ email }}{% endif %} - {% endif %} + {% trans "Sender" %}:{% if name %}{{ name }}{% else %}{% trans "anonymous" %}{% endif %}
+ {% trans "email" %}: {{ email }}
ip: {{ ip }}

@@ -31,13 +26,8 @@ {% endhtmlcontent %} {% textcontent notifications/base_text.html %} -{% if user.is_authenticated %} -{% trans "Sender" %}: {{ user.username }} -{% trans "email" %}: {{ user.email }} -{% else %} {% trans "Sender" %}: {% if name %}{{ name }}{% else %}{% trans "anonymous" %}{% endif %} -{% if email %}{% trans "email" %}: {{ email }}{% endif %} -{% endif %} +{% trans "email" %}: {{ email }} ip: {{ ip }} {% trans "Message body:" %} {{ message }} diff --git a/forum/views/meta.py b/forum/views/meta.py index 8195e44..3330a3b 100644 --- a/forum/views/meta.py +++ b/forum/views/meta.py @@ -44,15 +44,15 @@ def opensearch(request): def feedback(request): if request.method == "POST": - form = FeedbackForm(request.POST) + form = FeedbackForm(request.user, data=request.POST) if form.is_valid(): - context = {'user': request.user} - - if not request.user.is_authenticated: - context['email'] = form.cleaned_data.get('email', None) - context['message'] = form.cleaned_data['message'] - context['name'] = form.cleaned_data.get('name', None) - context['ip'] = request.META['REMOTE_ADDR'] + context = { + 'user': request.user, + 'email': request.user.is_authenticated() and request.user.email or form.cleaned_data.get('email', None), + 'message': form.cleaned_data['message'], + 'name': request.user.is_authenticated() and request.user.username or form.cleaned_data.get('name', None), + 'ip': request.META['REMOTE_ADDR'], + } recipients = User.objects.filter(is_superuser=True) send_template_email(recipients, "notifications/feedback.html", context) @@ -61,7 +61,7 @@ def feedback(request): request.user.message_set.create(message=msg) return HttpResponseRedirect(get_next_url(request)) else: - form = FeedbackForm(initial={'next':get_next_url(request)}) + form = FeedbackForm(request.user, initial={'next':get_next_url(request)}) return render_to_response('feedback.html', {'form': form}, context_instance=RequestContext(request))