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()
{% 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 }}
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)
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))