From fdc7a4ff73dbee6b9bb721bb7e36597a12ae418b Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 23 Jan 2008 21:11:44 +0100 Subject: [PATCH 1/1] * In the add influence view, preselect the first character if it is the user's only character. --- influences/views.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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}) -- 2.30.2