From 2436d67edf0cbb68536d28c9867f2b41fc5f8a43 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Thu, 9 Aug 2012 16:27:21 +0200 Subject: [PATCH] different the forms by form name send in submit button --- djangobb_forum/forms.py | 4 ++++ .../templates/djangobb_forum/includes/post_form.html | 2 +- djangobb_forum/templates/djangobb_forum/topic.html | 2 +- djangobb_forum/views.py | 5 +++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/djangobb_forum/forms.py b/djangobb_forum/forms.py index 02d76b53..1d7a7aa3 100644 --- a/djangobb_forum/forms.py +++ b/djangobb_forum/forms.py @@ -46,6 +46,8 @@ class AddPostForm(forms.ModelForm): + FORM_NAME = "AddPostForm" # used in view and template submit button + name = forms.CharField(label=_('Subject'), max_length=255, widget=forms.TextInput(attrs={'size':'115'})) attachment = forms.FileField(label=_('Attachment'), required=False) @@ -409,6 +411,8 @@ class VotePollForm(forms.Form): """ Dynamic form for the poll. """ + FORM_NAME = "VotePollForm" # used in view and template submit button + choice = forms.MultipleChoiceField() def __init__(self, poll, *args, **kwargs): self.poll = poll diff --git a/djangobb_forum/templates/djangobb_forum/includes/post_form.html b/djangobb_forum/templates/djangobb_forum/includes/post_form.html index 07f86f29..13c7ab5b 100644 --- a/djangobb_forum/templates/djangobb_forum/includes/post_form.html +++ b/djangobb_forum/templates/djangobb_forum/includes/post_form.html @@ -55,7 +55,7 @@

{% if forum %}{% trans "New topic" %}{% else %}{% trans "New reply" %} {% endif %} -

{% trans "Go back" %}

+

{% trans "Go back" %}

\ No newline at end of file diff --git a/djangobb_forum/templates/djangobb_forum/topic.html b/djangobb_forum/templates/djangobb_forum/topic.html index 35ab9eb7..414f8eee 100644 --- a/djangobb_forum/templates/djangobb_forum/topic.html +++ b/djangobb_forum/templates/djangobb_forum/topic.html @@ -32,7 +32,7 @@

{% trans "Poll" %}

{% blocktrans with count=poll.choice_count %}({{ count }} answers allows.){% endblocktrans %}

{% endif %} - + {% else %}
    diff --git a/djangobb_forum/views.py b/djangobb_forum/views.py index b00b0a78..6c734ebd 100644 --- a/djangobb_forum/views.py +++ b/djangobb_forum/views.py @@ -353,7 +353,7 @@ def show_topic(request, topic_id, full=True): back_url = request.path ip = request.META.get('REMOTE_ADDR', None) post_form_kwargs = {"topic":topic, "user":request.user, "ip":ip} - if request.method == 'POST': + if post_request and AddPostForm.FORM_NAME in request.POST: reply_form = AddPostForm(request.POST, request.FILES, **post_form_kwargs) if reply_form.is_valid(): post = reply_form.save() @@ -377,7 +377,8 @@ def show_topic(request, topic_id, full=True): poll = polls[0] poll.auto_deactivate() has_voted = request.user in poll.users.all() - if not post_request: + if not post_request or not VotePollForm.FORM_NAME in request.POST: + # It's not a POST request or: The reply form was send and not a poll vote if poll.active and not has_voted: poll_form = VotePollForm(poll) else: