from xerxes.influences.models import Character
from xerxes.influences.models import Influence
from forms import get_influence_comment_form, InfluenceForm, CharacterForm
+from xerxes.tools.misc import make_choices
@login_required
def add_influence(request, character_id=None):
initial = {}
# Get the current user's characters
- chars = request.user.character_set.all()
+ my_chars = request.user.character_set.all().filter(type__in=[Character.PLAYER, Character.NPC])
+ # Get all chars
+ all_chars = Character.objects.all().filter(type__in=[Character.PLAYER, Character.NPC])
# If a character_id was specified in the url, or there is only one
# character, preselect it.
if (character_id):
- initial['character'] = character_id
- elif (chars.count() == 1):
- initial['character'] = chars[0].id
-
+ initial['initiator'] = character_id
+ elif (my_chars.count() == 1):
+ initial['initiator'] = my_chars[0].id
f = InfluenceForm(request=request, initial=initial)
# Only allow characters of the current user. Putting this here also
# ensures that a form will not validate when any other choice was
# selected (perhaps through URL crafting).
- f.fields['character']._set_queryset(chars)
+ f.fields['initiator']._set_queryset(my_chars)
+
+ # List the contacts of each of the current users characters, as well
+ # as all other (non-contact) characters as choices for the
+ # other_characters field.
+ char_choices = [
+ ("Contacts of %s" % c, make_choices(c.contacts.all()))
+ for c in my_chars
+ if c.contacts.all()
+ ]
+ char_choices.append(('All player characters', make_choices(all_chars)))
+ f.fields['other_characters'].choices = char_choices
if (f.is_valid()):
# The form was submitted, let's save it.
def index(request):
# Only show this player's characters and influences
characters = request.user.character_set.all()
- influences = Influence.objects.filter(character__player=request.user)
+ influences = Influence.objects.filter(initiator__player=request.user)
return render_to_response('influences/index.html', {'characters' : characters, 'influences' : influences}, RequestContext(request))
#
def character_detail(request, object_id):
o = Character.objects.get(pk=object_id)
# Don't show other player's characters
- if (o.player != request.user):
+ if (not request.user.is_staff and o.player != request.user):
return HttpResponseForbidden("Forbidden -- Trying to view somebody else's character")
return render_to_response('influences/character_detail.html', {'object' : o}, RequestContext(request))
@login_required
def influence_list(request):
- # Only show this player's influences
- os = Influence.objects.filter(character__player=request.user)
- return render_to_response('influences/influence_list.html', {'object_list' : os}, RequestContext(request))
+ # Only show the influences related to this player's characters
+ characters = request.user.character_set.all()
+ return render_to_response('influences/influence_list.html', {'characters' : characters}, RequestContext(request))
def influence_comment_preview(request, context_processors, extra_context, **kwargs):
# Use a custom template
o = Influence.objects.get(pk=object_id)
# Don't show other player's influences
- if (o.character.player != request.user):
- return HttpResponseForbidden("Forbidden -- Trying to view influences of somebody else's character")
+ if (not request.user.is_staff and not request.user in o.related_players):
+ return HttpResponseForbidden("Forbidden -- Trying to view influences you are not involved in.")
# Show all comments to staff, but only public comments to other
# users