def process_vc_room_association(plugin, event, vc_room, form, event_vc_room=None, allow_same_room=False): # disable autoflush, so that the new event_vc_room does not influence the result with db.session.no_autoflush: if event_vc_room is None: event_vc_room = VCRoomEventAssociation() plugin.update_data_association(event, vc_room, event_vc_room, form.data) existing = set() if event_vc_room.link_object is not None: # check whether there is a room-event association already present # for the given event, room and plugin q = VCRoomEventAssociation.find( VCRoomEventAssociation.event_new == event, VCRoomEventAssociation.link_object == event_vc_room.link_object, _join=VCRoom ) if allow_same_room: q = q.filter(VCRoom.id != vc_room.id) existing = {x.vc_room for x in q} if event_vc_room.link_type != VCRoomLinkType.event and existing: transaction.abort() flash(_("There is already a VC room attached to '{link_object_title}'.").format( link_object_title=resolve_title(event_vc_room.link_object)), 'error') return None elif event_vc_room.link_type == VCRoomLinkType.event and vc_room in existing: transaction.abort() flash(_("This {plugin_name} room is already attached to the event.").format(plugin_name=plugin.friendly_name), 'error') return None else: return event_vc_room
def process_vc_room_association(plugin, event, vc_room, form, event_vc_room=None, allow_same_room=False): # disable autoflush, so that the new event_vc_room does not influence the result with db.session.no_autoflush: if event_vc_room is None: event_vc_room = VCRoomEventAssociation() plugin.update_data_association(event, vc_room, event_vc_room, form.data) # check whether there is a room-event association already present # for the given event, room and plugin q = VCRoomEventAssociation.find( VCRoomEventAssociation.event_id == event.id, VCRoomEventAssociation.link_type == event_vc_room.link_type, VCRoomEventAssociation.link_id == event_vc_room.link_id, _join=VCRoom ) if allow_same_room: q = q.filter(VCRoom.id != vc_room.id) existing = {x.vc_room for x in q} if event_vc_room.link_type != VCRoomLinkType.event and existing: transaction.abort() flash(_("There is already a VC room attached to '{link_object_title}'.").format( link_object_title=resolve_title(event_vc_room.link_object)), 'error') return None elif event_vc_room.link_type == VCRoomLinkType.event and vc_room in existing: transaction.abort() flash(_("This {plugin_name} room is already attached to the event.").format(plugin_name=plugin.friendly_name), 'error') return None else: return event_vc_room