From 77573f8252f3f1daa8901ec3f446f8149dd200b0 Mon Sep 17 00:00:00 2001 From: Johnson Chetty Date: Wed, 2 Jan 2013 19:06:39 +0100 Subject: [PATCH] related_scripts(), related_people, worked_with_people model methods added --- itf/itfprofiles/models.py | 27 +++++++++++++++++++++++++++ itf/scriptbank/models.py | 12 ++++++++++++ 2 files changed, 39 insertions(+) diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index b4b5a76..3257687 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -104,6 +104,13 @@ class Person(ItfModel): 'resources': self.resources.all() } + def related_scripts(self): + prod_scripts = [ p.script for p in self.productions.all() ] + prod_scripts.extend( [ p.script for p in self.productions_authored.all() ] ) + prod_scripts.extend( [ p.script for p in self.productions_directed.all() ] ) + #auth_scripts = Script.objects.filter(author__iexact=) + return prod_scripts + OCCUPATION_TYPES = ( @@ -349,6 +356,15 @@ class TheatreGroup(ItfModel): 'people' : [obj for obj in self.persongroup_set.all() ], } + def worked_with_people(self): + people = [] + for p in self.production_set.all(): + if p.get_people(): + people.extend(p.get_people()) + + #script_auths = [ {"person":s.author, "role":"author","assoc_type":'script', "assoc_name":s.title } for s in self.script_set.all() ] + return people + def get_title(self): return self.__unicode__() @@ -395,6 +411,17 @@ class Production(ItfModel): def __unicode__(self): return self.name + def get_people(self): + persons = [{"person":self.director, "role":"director", "assoc_type":'production', "assoc_name":self.name }, + {"person":self.playwright, "role":"playwright", "assoc_type":'production', "assoc_name":self.name } + ] + cast_list=[] + for p in self.personproduction_set.all(): + cast_list.append({"person":p.person, "role":p.role, "assoc_type":'production', "assoc_name":self.name}) + if cast_list: + persons.extend(cast_list) + return persons + def get_dict(self): rel_level1 = [obj for obj in Production.objects.filter(script=self.script)] rel_level2 = list(set(obj.production_set.all() for obj in self.script.related_scripts.all())) diff --git a/itf/scriptbank/models.py b/itf/scriptbank/models.py index 6190a25..5cdad3e 100755 --- a/itf/scriptbank/models.py +++ b/itf/scriptbank/models.py @@ -89,6 +89,18 @@ class Script(ItfModel): 'productions': self.production_set.all(), 'related_scripts': self.related_scripts } + + def related_people(self): + people = [] + for p in self.production_set.all(): + if p.get_people(): + people.extend(p.get_people()) + + script_auths = [ {"person":s.author, "role":"author", "assoc_type":"related_script", "assoc_name":s.title } for s in self.related_scripts.all() ] + if script_auths: + people.extend(script_auths) + return people + SCRIPT_RELATIONS = ( ('adaptation', 'Adaptation Of'),