From 11de77a786e3ffd82481076a7780adbb3455945a Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 23 Jan 2008 20:00:48 +0100 Subject: [PATCH] * Make the add view pass a request to ContextModelForm. * Make the add view prefill the character dropdown when a character id is given in the url. * Replace some tabs with spaces. --- influences/views.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/influences/views.py b/influences/views.py index 50ce600..b13c83e 100644 --- a/influences/views.py +++ b/influences/views.py @@ -6,9 +6,9 @@ from ee.influences.models import Influence from ee.tools.forms import ContextModelForm class InfluenceForm(ContextModelForm): - class Meta: - model = Influence - fields = ('character', 'contact', 'description') + class Meta: + model = Influence + fields = ('character', 'contact', 'description') class CharacterForm(ContextModelForm): class Meta: @@ -16,22 +16,23 @@ class CharacterForm(ContextModelForm): fields = ('name') def add(request, character_id): - message = None - - if (request.method == "POST"): - f = InfluenceForm(request.POST) - if (f.is_valid()): - f.save() - message = _("Influence added.") - f = None - else: - f = InfluenceForm() - - if f: - # Only allow characters of the current user - f.fields['character']._set_queryset(request.user.character_set.all()) - - return render_to_response('influences/character_addinfluence.html', {'message' : message, 'form' : f}) + message = None + + initial = {} + if (character_id): + initial['character'] = character_id + + f = InfluenceForm(request=request, initial=initial) + if (f.is_valid()): + f.save() + message = _("Influence added.") + f = None + + if f: + # Only allow characters of the current user + f.fields['character']._set_queryset(request.user.character_set.all()) + + return render_to_response('influences/character_addinfluence.html', {'message' : message, 'form' : f}) def addCharacter(request): message = None -- 2.30.2