Skip to content

Commit

Permalink
different the forms by form name send in submit button
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Aug 9, 2012
1 parent 5dc3abe commit 2436d67
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions djangobb_forum/forms.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -55,7 +55,7 @@ <h2><span>{% if forum %}{% trans "New topic" %}{% else %}{% trans "New reply" %}
</fieldset>
</div>
{% endif %}
<p><input type="submit" value="{% trans "Submit" %}" /><a href="{{ back_url|default_if_none:"javascript:history.go(-1)" }}">{% trans "Go back" %}</a></p>
<p><input type="submit" name="{{ form.FORM_NAME }}" value="{% trans "Submit" %}" /><a href="{{ back_url|default_if_none:"javascript:history.go(-1)" }}">{% trans "Go back" %}</a></p>
</form>
</div>
</div>
2 changes: 1 addition & 1 deletion djangobb_forum/templates/djangobb_forum/topic.html
Expand Up @@ -32,7 +32,7 @@ <h2><span>{% trans "Poll" %}</span></h2>
{% blocktrans with count=poll.choice_count %}({{ count }} answers allows.){% endblocktrans %}
</p>
{% endif %}
<input type="submit" value="Vote" />
<input type="submit" name="{{ poll_form.FORM_NAME }}" value="{% trans "Vote" %}" />
</form>
{% else %}
<ul>
Expand Down
5 changes: 3 additions & 2 deletions djangobb_forum/views.py
Expand Up @@ -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()
Expand All @@ -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:
Expand Down

0 comments on commit 2436d67

Please sign in to comment.