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 django.http import HttpResponseRedirect, HttpResponseForbidden
from django.views.generic.list_detail import object_detail, object_list
from ee.influences.models import Character
from ee.influences.models import Influence
f = InfluenceForm(request=request, initial=initial)
if (f.is_valid()):
- influence = f.save()
- return HttpResponseRedirect(reverse('influences_influence_detail', args=[influence.id]))
+ influence = f.save(commit=False)
+ if (influence.character.player == request.user):
+ influence.save()
+ return HttpResponseRedirect(reverse('influences_influence_detail', args=[influence.id]))
+ else:
+ # TODO: Make this a bit more pretty. Perhaps throw an exception here and add some middleware to catch it?
+ return HttpResponseForbidden("Forbidden -- Trying to submit influence for somebody else's character")
# Only allow characters of the current user
f.fields['character']._set_queryset(chars)