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:
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