def capacityForRole(self,role):
if isinstance(role, DanceRole):<EOL><INDENT>role_id = role.id<EOL><DEDENT>else:<EOL><INDENT>role_id = role<EOL><DEDENT>eventRoles = self.eventrole_set.filter(capacity__gt=<NUM_LIT:0>)<EOL>if eventRoles.count() > <NUM_LIT:0> and role_id not in [x.role.id for x in eventRoles]:<EOL><INDENT>'''<STR_LIT>'''<EOL>return <NUM_LIT:0><EOL><DEDENT>elif eventRoles.count() > <NUM_LIT:0>:<EOL><INDENT>'''<STR_LIT>'''<EOL>return eventRoles.get(role=role).capacity<EOL><DEDENT>if isinstance(self,Series):<EOL><INDENT>try:<EOL><INDENT>availableRoles = self.classDescription.danceTypeLevel.danceType.roles.all()<EOL>if availableRoles.count() > <NUM_LIT:0> and role_id not in [x.id for x in availableRoles]:<EOL><INDENT>'''<STR_LIT>'''<EOL>return <NUM_LIT:0><EOL><DEDENT>elif availableRoles.count() > <NUM_LIT:0> and self.capacity:<EOL><INDENT>return ceil(self.capacity / availableRoles.count())<EOL><DEDENT><DEDENT>except ObjectDoesNotExist as e:<EOL><INDENT>logger.error('<STR_LIT>' % e)<EOL><DEDENT><DEDENT>return self.capacity<EOL>
Accepts a DanceRole object and determines the capacity for that role at this event.this
Since roles are not always custom specified for events, this looks for the set of
available roles in multiple places, and only returns the overall capacity of the event
if roles are not found elsewhere.