* Add a detail view for Influence.
* Let both add forms redirect to the detail view for the added item after adding it.
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:
fields = ('name')
def add(request, character_id):
- message = None
-
initial = {}
# Get the current user's characters
chars = request.user.character_set.all()
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()
{% 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 %}
{% if influences %}
<ul>
{% for influence in influences %}
- <li>{{ influence.character }} -- {{ influence.contact }} -- {{ influence.description }}</li>
+ <li>{{influence.contact }} -- {{ influence.summary }} </li>
{% endfor %}
</ul>
{% else %}
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'),
)