From: Matthijs Kooijman Date: Wed, 23 Jan 2008 19:00:48 +0000 (+0100) Subject: * Make the add view pass a request to ContextModelForm. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=11de77a786e3ffd82481076a7780adbb3455945a;p=matthijs%2Fprojects%2Fxerxes.git * 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. --- 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