from django.shortcuts import render_to_response
from django.shortcuts import get_object_or_404
-from django import newforms as forms
from django.utils.translation import ugettext as _
from ee.influences.models import Character
from ee.influences.models import Influence
+from ee.tools.forms import ContextModelForm
-class InfluenceForm(forms.ModelForm):
+class InfluenceForm(ContextModelForm):
class Meta:
model = Influence
fields = ('character', 'contact', 'description')
+class CharacterForm(ContextModelForm):
+ class Meta:
+ model = Character
+ fields = ('name')
+
def add(request, character_id):
message = None
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
+ f = CharacterForm(request=request)
+ if (f.is_valid()):
+ c = f.save(commit=False)
+ c.player = request.user
+ c.save()
+ message = _("Character added.")
+ f = None
+
+ return render_to_response('influences/add_character.html', {'message' : message, 'form' : f})
(r'^influences/add/(\d+)?/?$', 'ee.influences.views.add'),
(r'^influences/$', 'django.views.generic.list_detail.object_list', chars_dict),
(r'^influences/character/(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', chars_dict),
+ (r'^influences/character/add/$', 'ee.influences.views.addCharacter'),
(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'base/login.html'}),
(r'^accounts/logout/$', 'django.contrib.auth.views.logout_then_login'),
)