* In the add influence view, preselect the first character if it is the user's only...
authorMatthijs Kooijman <matthijs@stdin.nl>
Wed, 23 Jan 2008 20:11:44 +0000 (21:11 +0100)
committerMatthijs Kooijman <matthijs@stdin.nl>
Wed, 23 Jan 2008 20:11:44 +0000 (21:11 +0100)
influences/views.py

index 3b26dac9d3f2b0b9d8959141adc3129d07223fef..41a1ecbe08cbd3db595a3e9b69344a47f80136ab 100644 (file)
@@ -20,18 +20,23 @@ def add(request, character_id):
     message = None
 
     initial = {}
+    # Get the current user's characters
+    chars = request.user.character_set.all()
+
     if (character_id):
         initial['character'] = character_id
+    elif (chars.count() == 1):
+        initial['character'] = chars[0].id
 
     f = InfluenceForm(request=request, initial=initial)
     if (f.is_valid()):
         f.save()
         message = _("Influence added.")
         f = None
-
+     
+    # Only allow characters of the current user
     if f:
-        # Only allow characters of the current user
-        f.fields['character']._set_queryset(request.user.character_set.all())
+        f.fields['character']._set_queryset(chars)
 
     return render_to_response('influences/add.html', {'message' : message, 'form' : f})