1 from django.shortcuts import render_to_response
2 from django.shortcuts import get_object_or_404
3 from django.template import RequestContext
4 from django.utils.translation import ugettext as _
5 from django.contrib.auth.models import User
6 from django.core.urlresolvers import reverse
7 from django.http import HttpResponseRedirect
8 from ee.influences.models import Character
9 from ee.influences.models import Influence
10 from ee.tools.forms import ContextModelForm
14 class InfluenceForm(ContextModelForm):
17 fields = ('character', 'contact', 'summary', 'description')
19 class CharacterForm(ContextModelForm):
24 def add(request, character_id=None):
26 # Get the current user's characters
27 chars = request.user.character_set.all()
30 initial['character'] = character_id
31 elif (chars.count() == 1):
32 initial['character'] = chars[0].id
34 f = InfluenceForm(request=request, initial=initial)
37 return HttpResponseRedirect(reverse('influences_influence_detail', args=[influence.id]))
39 # Only allow characters of the current user
40 f.fields['character']._set_queryset(chars)
42 return render_to_response('influences/add.html', {'form' : f}, RequestContext(request))
44 def addCharacter(request):
45 f = CharacterForm(request=request)
47 character = f.save(commit=False)
48 character.player = request.user
50 return HttpResponseRedirect(reverse('influences_character_detail', args=[character.id]))
52 return render_to_response('influences/add_character.html', {'form' : f}, RequestContext(request))
55 characters = request.user.character_set.all()
56 influences = Influence.objects.filter(character__in=characters)
57 return render_to_response('influences/index.html', {'characters' : characters, 'influences' : influences}, RequestContext(request))