author | Lennard de Rijk <ljvderijk@gmail.com> |
Thu, 23 Jul 2009 14:36:45 +0200 | |
changeset 2664 | 06d4f4d06f64 |
parent 2663 | d270bd8b7417 |
child 2665 | 1f4acb80fd95 |
--- a/app/soc/logic/models/club_admin.py Sat Jul 18 15:04:44 2009 -0700 +++ b/app/soc/logic/models/club_admin.py Thu Jul 23 14:36:45 2009 +0200 @@ -36,12 +36,12 @@ def __init__(self, model=soc.models.club_admin.ClubAdmin, base_model=soc.models.role.Role, scope_logic=club_logic, - disallow_last_resign=True): + role_name='club_admin', disallow_last_resign=True): """Defines the name, key_name and model for this entity. """ - super(Logic, self).__init__(model=model, base_model=base_model, - scope_logic=scope_logic, + super(Logic, self).__init__(role_name=role_name, model=model, + base_model=base_model, scope_logic=scope_logic, disallow_last_resign=disallow_last_resign) def _onCreate(self, entity):
--- a/app/soc/logic/models/club_member.py Sat Jul 18 15:04:44 2009 -0700 +++ b/app/soc/logic/models/club_member.py Thu Jul 23 14:36:45 2009 +0200 @@ -35,12 +35,12 @@ def __init__(self, model=soc.models.club_member.ClubMember, base_model=soc.models.role.Role, scope_logic=club_logic, - disallow_last_resign=False): + role_name='club_member', disallow_last_resign=False): """Defines the name, key_name and model for this entity. """ - super(Logic, self).__init__(model=model, base_model=base_model, - scope_logic=scope_logic, + super(Logic, self).__init__(role_name=role_name, model=model, + base_model=base_model, scope_logic=scope_logic, disallow_last_resign=disallow_last_resign)
--- a/app/soc/logic/models/host.py Sat Jul 18 15:04:44 2009 -0700 +++ b/app/soc/logic/models/host.py Thu Jul 23 14:36:45 2009 +0200 @@ -34,14 +34,14 @@ """Logic methods for the Host model. """ - def __init__(self, model=soc.models.host.Host, + def __init__(self, model=soc.models.host.Host, base_model=soc.models.role.Role, scope_logic=sponsor_logic, - disallow_last_resign=True): + role_name='host', disallow_last_resign=True): """Defines the name, key_name and model for this entity. """ - super(Logic, self).__init__(model=model, base_model=base_model, - scope_logic=scope_logic, + super(Logic, self).__init__(role_name=role_name, model=model, + base_model=base_model, scope_logic=scope_logic, disallow_last_resign=disallow_last_resign)
--- a/app/soc/logic/models/mentor.py Sat Jul 18 15:04:44 2009 -0700 +++ b/app/soc/logic/models/mentor.py Thu Jul 23 14:36:45 2009 +0200 @@ -44,12 +44,12 @@ def __init__(self, model=soc.models.mentor.Mentor, base_model=soc.models.role.Role, scope_logic=org_logic, - disallow_last_resign=False): + role_name='mentor', disallow_last_resign=False): """Defines the name, key_name and model for this entity. """ - super(Logic, self).__init__(model=model, base_model=base_model, - scope_logic=scope_logic, + super(Logic, self).__init__(role_name=role_name, model=model, + base_model=base_model, scope_logic=scope_logic, disallow_last_resign=disallow_last_resign) def canResign(self, entity):
--- a/app/soc/logic/models/role.py Sat Jul 18 15:04:44 2009 -0700 +++ b/app/soc/logic/models/role.py Thu Jul 23 14:36:45 2009 +0200 @@ -33,24 +33,48 @@ "resigned, please make sure it's not the last %(name)s." +ROLE_LOGICS = {} + + +def registerRoleLogic(role_logic): + """Adds the specified Role Logic to the known ones. + + Args: + role_logic: Instance of or subclass from Role Logic + """ + + global ROLE_LOGICS + name = role_logic.role_name + ROLE_LOGICS[name] = role_logic + + class Logic(base.Logic): """Logic methods for the Role model. """ def __init__(self, model=soc.models.role.Role, - base_model=None, scope_logic=None, disallow_last_resign=False): + base_model=None, scope_logic=None, role_name=None, + disallow_last_resign=False): """Defines the name, key_name and model for this entity. + + Args: + role_name: The name of this role used for instance for Requests + dissallow_last_resign: Iff True and a given role entity is the last of + its kind in its scope then this role can not be resigned. """ super(Logic, self).__init__(model, base_model=base_model, scope_logic=scope_logic) + self.role_name = role_name + registerRoleLogic(self) + self.disallow_last_resign = disallow_last_resign def getGroupEntityFromScopePath(self, group_logic, scope_path): """Returns a group entity by using the given scope_path. - + Args: group_logic: logic for the group which should be retrieved scope_path : the scope path of the entity
--- a/app/soc/logic/models/student.py Sat Jul 18 15:04:44 2009 -0700 +++ b/app/soc/logic/models/student.py Thu Jul 23 14:36:45 2009 +0200 @@ -35,12 +35,12 @@ def __init__(self, model=soc.models.student.Student, base_model=soc.models.role.Role, scope_logic=program_logic, - disallow_last_resign=False): + role_name='student', disallow_last_resign=False): """Defines the name, key_name and model for this entity. """ - super(Logic, self).__init__(model=model, base_model=base_model, - scope_logic=scope_logic, + super(Logic, self).__init__(role_name=role_name, model=model, + base_model=base_model, scope_logic=scope_logic, disallow_last_resign=disallow_last_resign)