From 089b685a37fa8ecaecba20e10fa6bdcdfe449886 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Sun, 27 Jan 2008 16:43:50 +0100 Subject: [PATCH] * Use the Influence summary, where appropriate. * 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 | 30 ++++++++++------------ templates/influences/character_detail.html | 2 +- templates/influences/index.html | 2 +- urls.py | 13 ++++++++-- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/influences/views.py b/influences/views.py index 22f2a3b..184a3a3 100644 --- a/influences/views.py +++ b/influences/views.py @@ -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() diff --git a/templates/influences/character_detail.html b/templates/influences/character_detail.html index d418529..b95a884 100644 --- a/templates/influences/character_detail.html +++ b/templates/influences/character_detail.html @@ -11,6 +11,6 @@ {% endfor %} -{% trans "Submit influence" %} +{% trans "Submit influence" %} {% endblock %} diff --git a/templates/influences/index.html b/templates/influences/index.html index 888aee8..109901e 100644 --- a/templates/influences/index.html +++ b/templates/influences/index.html @@ -20,7 +20,7 @@ {% if influences %} {% else %} diff --git a/urls.py b/urls.py index a26fa4a..0483644 100644 --- 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\d+)/$', 'ee.events.views.event.detail'), url(r'^events/event/(?P\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\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\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'), ) -- 2.30.2