def _process(self): form = RoleForm(event=self.event, color=self._get_color()) if form.validate_on_submit(): role = EventRole(event=self.event) form.populate_obj(role) db.session.flush() logger.info('Event role %r created by %r', role, session.user) self.event.log(EventLogRealm.management, EventLogKind.positive, 'Roles', 'Added role: "{}"'.format(role.name), session.user) return jsonify_data(html=_render_roles(self.event), role=serialize_role(role)) return jsonify_form(form)
def serialize_principal(principal): if principal.principal_type == PrincipalType.email: return serialize_email_principal(principal) elif principal.principal_type == PrincipalType.network: return serialize_ip_network_group(principal) elif principal.principal_type == PrincipalType.user: return serialize_user(principal) elif principal.principal_type == PrincipalType.event_role: return serialize_role(principal) elif principal.is_group: return serialize_group(principal) else: raise ValueError('Invalid principal: {} ({})'.format(principal, principal.principal_type))
def serialize_principal(principal): if principal.principal_type == PrincipalType.email: return serialize_email_principal(principal) elif principal.principal_type == PrincipalType.network: return serialize_ip_network_group(principal) elif principal.principal_type == PrincipalType.user: return serialize_user(principal) elif principal.principal_type == PrincipalType.event_role: return serialize_role(principal) elif principal.is_group: return serialize_group(principal) else: raise ValueError('Invalid principal: {} ({})'.format(principal, principal.principal_type))
def _process(self): form = RoleForm(event=self.event, color=self._get_color()) if form.validate_on_submit(): role = EventRole(event=self.event) form.populate_obj(role) db.session.flush() logger.info('Event role %r created by %r', role, session.user) self.event.log(EventLogRealm.management, EventLogKind.positive, 'Roles', 'Added role: "{}"'.format(role.name), session.user) return jsonify_data(html=_render_roles(self.event), role=serialize_role(role)) return jsonify_form(form)
def roles(self): return [serialize_role(role) for role in sorted(self.get_form().event.roles, key=attrgetter('code'))]
def roles(self): return [serialize_role(role) for role in sorted(self.event.roles, key=attrgetter('code'))]
def event_roles(self): return [ serialize_role(role, legacy=False) for role in sorted(self.event.roles, key=attrgetter('code')) ]