From: Matthijs Kooijman Date: Wed, 23 Jan 2008 18:08:33 +0000 (+0100) Subject: * Add an addCharacter view to the influences app. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=69974d5dca02a99311dd5d97ae9907c31f500892;p=matthijs%2Fprojects%2Fxerxes.git * Add an addCharacter view to the influences app. * Let this view and the add view use the ContextModelForm class from the previous commit. --- diff --git a/influences/views.py b/influences/views.py index 1c7edb4..50ce600 100644 --- a/influences/views.py +++ b/influences/views.py @@ -1,15 +1,20 @@ 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 @@ -27,3 +32,15 @@ def add(request, character_id): 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}) diff --git a/templates/influences/character_list.html b/templates/influences/character_list.html index 85b1908..6673138 100644 --- a/templates/influences/character_list.html +++ b/templates/influences/character_list.html @@ -9,3 +9,5 @@ {% else %}

{% trans "No characters. Add a character first, so you can submit your influences." %}

{% endif %} + +

{% trans "Add character" %}

diff --git a/urls.py b/urls.py index cf577db..8890ef5 100644 --- a/urls.py +++ b/urls.py @@ -12,6 +12,7 @@ urlpatterns = patterns('', (r'^influences/add/(\d+)?/?$', 'ee.influences.views.add'), (r'^influences/$', 'django.views.generic.list_detail.object_list', chars_dict), (r'^influences/character/(?P\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'), )