* Make the add view pass a request to ContextModelForm.
authorMatthijs Kooijman <matthijs@stdin.nl>
Wed, 23 Jan 2008 19:00:48 +0000 (20:00 +0100)
committerMatthijs Kooijman <matthijs@stdin.nl>
Wed, 23 Jan 2008 19:00:48 +0000 (20:00 +0100)
 * 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

index 50ce60001996f26b82db32c2f8372aab70db8f5a..b13c83e6c3a9a5d1a99613c17196bf52303dc65a 100644 (file)
@@ -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