From: Matthijs Kooijman Date: Wed, 23 Jan 2008 20:11:44 +0000 (+0100) Subject: * In the add influence view, preselect the first character if it is the user's only... X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=fdc7a4ff73dbee6b9bb721bb7e36597a12ae418b;hp=f24d3802458e7dea784f9b706e58419a5cbbc3a5;p=matthijs%2Fprojects%2Fxerxes.git * In the add influence view, preselect the first character if it is the user's only character. --- diff --git a/influences/views.py b/influences/views.py index 3b26dac..41a1ecb 100644 --- a/influences/views.py +++ b/influences/views.py @@ -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})