def create_society(sess: SQLASession, name: str, description: str, admins: Set[str], role_email: str = None) -> Result[Society]: """ Register or update a society in the database. """ try: soc = get_society(name, sess) except KeyError: soc = Society(society=name, description=description, admins=get_members(sess, *admins), role_email=role_email) sess.add(soc) state = State.success else: if admins != soc.admin_crsids: raise ValueError("Admins for {!r} are {}, expecting {}".format( name, soc.admin_crsids, admins)) soc.description = description soc.role_email = role_email state = State.success if sess.is_modified(soc) else State.unchanged return Result(state, soc)
def _update_society(sess: SQLASession, society: Society, description: str, role_email: Optional[str]) -> Result[Unset]: society.description = description society.role_email = role_email if not sess.is_modified(society): return Result(State.unchanged) LOG.debug("Updated society record: %r", society) return Result(State.success)