]> git.openstreetmap.org Git - osqa.git/commitdiff
Fixes OSQA 393, cannot send feedback when user is authenticated.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 7 Jul 2010 11:09:05 +0000 (11:09 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 7 Jul 2010 11:09:05 +0000 (11:09 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@496 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/forms/qanda.py
forum/skins/default/templates/notifications/feedback.html
forum/views/meta.py

index a98ef38ad6b5e54a24c79d1bb7f641cff28126ff..ade6d5d4dea91d4c6a3812e6ca73c2fd4c2acb83 100644 (file)
@@ -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()
index ec4d2116fbe2a0ab1463eeb30a832e9d85205781..6387049fe65a241a01251d59197214b9bd9ee784 100644 (file)
 
     {% htmlcontent notifications/base.html %}
         <p style="{{ p_style }}}">
-            {% trans "Sender" %}:
-            {% if user.is_authenticated %}
-                {{ user.username }} <br /> {% 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 %}<br />
+            {% trans "email" %}: {{ email }}
             <br/>
                 ip: {{ ip }}
         </p>
     {% 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 }}
index 8195e44f896b1478c4d8a5585c3048c9b93448a2..3330a3b641120295baa5387724e1343ca3cf3e47 100644 (file)
@@ -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))