* Use the Influence summary, where appropriate.
authorMatthijs Kooijman <matthijs@stdin.nl>
Sun, 27 Jan 2008 15:43:50 +0000 (16:43 +0100)
committerMatthijs Kooijman <matthijs@stdin.nl>
Sun, 27 Jan 2008 15:43:50 +0000 (16:43 +0100)
 * Add a detail view for Influence.
 * Let both add forms redirect to the detail view for the added item after adding it.

influences/views.py
templates/influences/character_detail.html
templates/influences/index.html
urls.py

index 22f2a3b03005fc4810c354bdedb00e7b7a5c7bb9..184a3a3957271a7a988efac2f56cbedb1c76dcd4 100644 (file)
@@ -3,14 +3,18 @@ from django.shortcuts import get_object_or_404
 from django.template import RequestContext
 from django.utils.translation import ugettext as _
 from django.contrib.auth.models import User
+from django.core.urlresolvers import reverse
+from django.http import HttpResponseRedirect
 from ee.influences.models import Character
 from ee.influences.models import Influence
 from ee.tools.forms import ContextModelForm
 
+
+
 class InfluenceForm(ContextModelForm):
     class Meta:
         model = Influence
-        fields = ('character', 'contact', 'description')
+        fields = ('character', 'contact', 'summary', 'description')
 
 class CharacterForm(ContextModelForm):
     class Meta:
@@ -18,8 +22,6 @@ class CharacterForm(ContextModelForm):
         fields = ('name')
 
 def add(request, character_id):
-    message = None
-
     initial = {}
     # Get the current user's characters
     chars = request.user.character_set.all()
@@ -31,27 +33,23 @@ def add(request, character_id):
 
     f = InfluenceForm(request=request, initial=initial)
     if (f.is_valid()):
-        f.save()
-        message = _("Influence added.")
-        f = None
+        influence = f.save()
+        return HttpResponseRedirect(reverse('influences_influence_detail', args=[influence.id]))
      
     # Only allow characters of the current user
-    if f:
-        f.fields['character']._set_queryset(chars)
+    f.fields['character']._set_queryset(chars)
 
-    return render_to_response('influences/add.html', {'message' : message, 'form' : f}, RequestContext(request))
+    return render_to_response('influences/add.html', {'form' : f}, RequestContext(request))
 
 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
+        character = f.save(commit=False)
+        character.player = request.user
+        character.save()
+        return HttpResponseRedirect(reverse('influences_character_detail', args=[character.id]))
 
-    return render_to_response('influences/add_character.html', {'message' : message, 'form' : f})
+    return render_to_response('influences/add_character.html', {'form' : f})
 
 def index(request):
     characters = request.user.character_set.all()
index d418529f812fecc6e30a67ee9b8ba687666656e1..b95a884eb2a1daabb32e6d3b35a22b3286bdd566 100644 (file)
@@ -11,6 +11,6 @@
 {% endfor %}
 </ul>
 
-<a href="{% url influences_add_influence_to_character object.id %}">{% trans "Submit influence" %}</a>
+<a href="{% url influences_add_influence_for_character object.id %}">{% trans "Submit influence" %}</a>
 
 {% endblock %}
index 888aee834ae4f4c370d171433829daa04887bcde..109901e9a7aff73811c8a2740be09cb9094d9c10 100644 (file)
@@ -20,7 +20,7 @@
 {% if influences %}
        <ul>
        {% for influence in influences %}
-        <li>{{ influence.character }} -- {{ influence.contact }} -- {{ influence.description }}</li>
+        <li>{{influence.contact }} -- {{ influence.summary }} </li>
        {% endfor %}
        </ul>
 {% else %}
diff --git a/urls.py b/urls.py
index a26fa4aac7220db95666327660f725bde33b6255..0483644b193f55511fe3dd60c2c8b81ab331f824 100644 (file)
--- a/urls.py
+++ b/urls.py
@@ -1,21 +1,30 @@
 from django.conf import settings
 from django.conf.urls.defaults import *
 from ee.influences.models import Character
+from ee.influences.models import Influence
 
 chars_dict = {
     'queryset': Character.objects.all(),
 }
  
+influences_dict = {
+    'queryset': Influence.objects.all(),
+}
 urlpatterns = patterns('',
     url(r'^admin/', include('django.contrib.admin.urls')),
     url(r'^events/event/(?P<event_id>\d+)/$', 'ee.events.views.event.detail'),
     url(r'^events/event/(?P<event_id>\d+)/regs$', 'ee.events.views.event.regs'),
-    url(r'^influences/add/(\d+)/$', 'ee.influences.views.add', name='influences_add_influence_for_character'),
-    url(r'^influences/add/$', 'ee.influences.views.add', name='influences_add_influence'),
+
     url(r'^influences/$', 'ee.influences.views.index', name='influences_index'),
+    url(r'^influences/influence/add/(\d+)/$', 'ee.influences.views.add', name='influences_add_influence_for_character'),
+    url(r'^influences/influence/add/$', 'ee.influences.views.add', name='influences_add_influence'),
+    url(r'^influences/influence/(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', influences_dict, name='influences_influence_detail'),
+    
     url(r'^influences/character/$', 'django.views.generic.list_detail.object_list', chars_dict, name='influences_character_list'),
     url(r'^influences/character/(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', chars_dict, name='influences_character_detail'),
     url(r'^influences/character/add/$', 'ee.influences.views.addCharacter', name='influences_add_character'),
+
     url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'base/login.html'}),
     url(r'^accounts/logout/$', 'django.contrib.auth.views.logout_then_login'),
 )