X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=influences%2Fmodels.py;h=2c626266fde1312aa9b6445bd66ac647c6e4b112;hb=eb2b5fc938fcc2fdc290da0b4a94ddbd9ed5cc76;hp=aa64f269fbca96db6bf6d5479775fed9d0465a11;hpb=d2c32e093a5f0bee8f4188cb7921de62051951be;p=matthijs%2Fprojects%2Fxerxes.git diff --git a/influences/models.py b/influences/models.py index aa64f26..2c62626 100644 --- a/influences/models.py +++ b/influences/models.py @@ -5,6 +5,7 @@ from django.utils.text import normalize_newlines from django.utils.translation import ugettext_lazy as _ from threadedcomments.models import ThreadedComment from xerxes.tools.text import rewrap +from string import strip # Create your models here. class Character(models.Model): @@ -93,6 +94,31 @@ class Influence(models.Model): prefix=prefix) return comments + @property + def involved(self): + """ Returns the Characters and contacts (strings) involved """ + chars = list(self.other_characters.all()) + if (self.other_contacts): + chars.extend(map(strip,self.other_contacts.split(','))) + return chars + + @property + def related_players(self): + """ Returns all players to this Influence (ie, the players of the + initiator or involved characters). Returns a dict where the + players (User objects) are keys and a list of Character objects + for which this player is related is the value. + """ + players = {self.initiator.player : [self.initiator]} + for char in self.other_characters.all(): + # Add this character to the player's list of characters for + # this Influence, creating a new list if this is the first + # character. + chars = players.get(char.player, []) + chars.append(char) + players[char.player] = chars + return players + class Meta: verbose_name = _("Influence") verbose_name_plural = _("Influences")