def new(self, session, message='', **params): if params.get('id'): raise HTTPRedirect('form?id={}', params['id']) department = session.department(params, bools=Department.all_bools, checkgroups=Department.all_checkgroups) if cherrypy.request.method == 'POST': message = check_dept_admin(session) if not message: message = check(department) if not message: attendee = session.admin_attendee() has_email = bool(attendee.email) department.memberships = [ DeptMembership(attendee=attendee, is_dept_head=True, is_poc=has_email, is_checklist_admin=has_email) ] session.add(department) raise HTTPRedirect('form?id={}', department.id) return {'department': department, 'message': message}
def set_inherent_role(self, session, department_id, attendee_id, role, value=None): assert role in ('dept_head', 'poc', 'checklist_admin'), \ 'Unknown role: "{}"'.format(role) admin_role = 'dept_head' if role == 'dept_head' else None message = check_dept_admin(session, department_id, admin_role) if message: return {'error': message} try: value = str(value).lower() not in ('false', 'none', '', '0') dept_membership = session.query(DeptMembership).filter_by( department_id=department_id, attendee_id=attendee_id).one() setattr(dept_membership, 'is_' + role, value) session.commit() except Exception: return {'error': 'Unexpected error setting role'} else: return { 'dept_membership_id': dept_membership.id, 'department_id': department_id, 'attendee_id': attendee_id, 'role': role, 'value': value }
def new(self, session, message='', **params): if params.get('id'): raise HTTPRedirect('form?id={}', params['id']) department = session.department( params, bools=Department.all_bools, checkgroups=Department.all_checkgroups) if cherrypy.request.method == 'POST': message = check_dept_admin(session) if not message: message = check(department) if not message: attendee = session.admin_attendee() has_email = bool(attendee.email) department.memberships = [DeptMembership( attendee=attendee, is_dept_head=True, is_poc=has_email, is_checklist_admin=has_email)] session.add(department) raise HTTPRedirect('form?id={}', department.id) return { 'department': department, 'message': message }
def set_inherent_role( self, session, department_id, attendee_id, role, value=None): assert role in ('dept_head', 'poc', 'checklist_admin'), \ 'Unknown role: "{}"'.format(role) admin_role = 'dept_head' if role == 'dept_head' else None message = check_dept_admin(session, department_id, admin_role) if message: return {'error': message} try: value = str(value).lower() not in ('false', 'none', '', '0') dept_membership = session.query(DeptMembership).filter_by( department_id=department_id, attendee_id=attendee_id).one() setattr(dept_membership, 'is_' + role, value) session.commit() except Exception: return {'error': 'Unexpected error setting role'} else: return { 'dept_membership_id': dept_membership.id, 'department_id': department_id, 'attendee_id': attendee_id, 'role': role, 'value': value }
def delete_role(self, session, id): dept_role = session.query(DeptRole).get(id) department_id = dept_role.department_id message = '' if cherrypy.request.method == 'POST': message = check_dept_admin(session, department_id) if not message: session.delete(dept_role) raise HTTPRedirect( 'form?id={}&message={}', department_id, 'The {} role was deleted'.format(dept_role.name)) if not message: raise HTTPRedirect('form?id={}', department_id) else: raise HTTPRedirect('form?id={}&message={}', department_id, message)
def role(self, session, department_id=None, message='', **params): if not department_id or department_id == 'None': department_id = None if not department_id \ and (not params.get('id') or params.get('id') == 'None'): raise HTTPRedirect('index') role = session.dept_role( params, bools=DeptRole.all_bools, checkgroups=DeptRole.all_checkgroups) department_id = role.department_id or department_id department = session.query(Department).filter_by(id=department_id).order_by(Department.id) \ .options( subqueryload(Department.memberships) .subqueryload(DeptMembership.attendee) .subqueryload(Attendee.dept_roles)) \ .one() if cherrypy.request.method == 'POST': message = check_dept_admin(session) if not message: if role.is_new: role.department = department message = check(role) if not message: session.add(role) raise HTTPRedirect( 'form?id={}&message={}', department_id, 'The {} role was successfully {}'.format( role.name, 'created' if role.is_new else 'updated')) session.rollback() return { 'department': department, 'role': role, 'message': message }
def role(self, session, department_id=None, message='', **params): if not department_id or department_id == 'None': department_id = None if not department_id \ and (not params.get('id') or params.get('id') == 'None'): raise HTTPRedirect('index') role = session.dept_role(params, bools=DeptRole.all_bools, checkgroups=DeptRole.all_checkgroups) department_id = role.department_id or department_id department = session.query(Department).filter_by(id=department_id).order_by(Department.id) \ .options( subqueryload(Department.memberships) .subqueryload(DeptMembership.attendee) .subqueryload(Attendee.dept_roles)) \ .one() if cherrypy.request.method == 'POST': message = check_dept_admin(session) if not message: if role.is_new: role.department = department message = check(role) if not message: session.add(role) raise HTTPRedirect( 'form?id={}&message={}', department_id, 'The {} role was successfully {}'.format( role.name, 'created' if role.is_new else 'updated')) session.rollback() return {'department': department, 'role': role, 'message': message}