* Add an addCharacter view to the influences app.
authorMatthijs Kooijman <matthijs@stdin.nl>
Wed, 23 Jan 2008 18:08:33 +0000 (19:08 +0100)
committerMatthijs Kooijman <matthijs@stdin.nl>
Wed, 23 Jan 2008 18:08:33 +0000 (19:08 +0100)
 * Let this view and the add view use the ContextModelForm class from the previous commit.

influences/views.py
templates/influences/character_list.html
urls.py

index 1c7edb44753aa0dec03275fc869373a3883930c5..50ce60001996f26b82db32c2f8372aab70db8f5a 100644 (file)
@@ -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})
index 85b190824d7c4c02347f5ababefdd376c9214077..6673138cc4f2416b18492b86080ca548f07fe2c7 100644 (file)
@@ -9,3 +9,5 @@
 {% else %}
        <p>{% trans "No characters. Add a character first, so you can submit your influences." %}</p>
 {% endif %}
+
+<p><a href="character/add">{% trans "Add character" %}</a></p>
diff --git a/urls.py b/urls.py
index cf577db4d6e00c62456786d5f910edb0f6d6082e..8890ef5a22951149a7502d2f8d2b7c521d1c6e36 100644 (file)
--- 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<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'),
 )