def delete(self, reason, user=None): from fossir.modules.events import logger, EventLogRealm, EventLogKind self.is_deleted = True signals.event.deleted.send(self, user=user) db.session.flush() logger.info('Event %r deleted [%s]', self, reason) self.log(EventLogRealm.event, EventLogKind.negative, 'Event', 'Event deleted', user, data={'Reason': reason})
def create_event(category, event_type, data, add_creator_as_manager=True, features=None): """Create a new event. :param category: The category in which to create the event :param event_type: An `EventType` value :param data: A dict containing data used to populate the event :param add_creator_as_manager: Whether the creator (current user) should be added as a manager :param features: A list of features that will be enabled for the event. If set, only those features will be used and the default feature set for the event type will be ignored. """ event = Event(category=category, type_=event_type) data.setdefault('creator', session.user) theme = data.pop('theme', None) person_link_data = data.pop('person_link_data', {}) event.populate_from_dict(data) db.session.flush() event.person_link_data = person_link_data if theme is not None: layout_settings.set(event, 'timetable_theme', theme) if add_creator_as_manager: with event.logging_disabled: event.update_principal(event.creator, full_access=True) if features is not None: features_event_settings.set(event, 'enabled', features) db.session.flush() signals.event.created.send(event) logger.info('Event %r created in %r by %r ', event, category, session.user) event.log(EventLogRealm.event, EventLogKind.positive, 'Event', 'Event created', session.user) db.session.flush() return event
def create_reference_type(data): reference_type = ReferenceType() reference_type.populate_from_dict(data) db.session.add(reference_type) db.session.flush() logger.info('Reference type "%s" created by %s', reference_type, session.user) return reference_type
def update_event_protection(event, data): assert set(data.viewkeys()) <= {'protection_mode', 'own_no_access_contact', 'access_key', 'visibility'} changes = event.populate_from_dict(data) db.session.flush() signals.event.updated.send(event, changes=changes) logger.info('Protection of event %r updated with %r by %r', event, data, session.user) if changes: log_fields = {'protection_mode': 'Protection mode', 'own_no_access_contact': 'No access contact', 'access_key': {'title': 'Access key', 'type': 'string'}, 'visibility': {'title': 'Visibility', 'type': 'string', 'convert': lambda changes: [_format_visibility(event, x) for x in changes]}} event.log(EventLogRealm.management, EventLogKind.change, 'Event', 'Protection updated', session.user, data={'Changes': make_diff_log(changes, log_fields)})
def update_event(event, update_timetable=False, **data): assert set(data.viewkeys()) <= {'title', 'description', 'url_shortcut', 'location_data', 'keywords', 'person_link_data', 'start_dt', 'end_dt', 'timezone', 'keywords', 'references', 'organizer_info', 'additional_info', 'contact_title', 'contact_emails', 'contact_phones', 'start_dt_override', 'end_dt_override'} old_person_links = event.person_links[:] if (update_timetable or event.type == EventType.lecture) and 'start_dt' in data: # Lectures have no exposed timetable so if we have any timetable entries # (e.g. because the event had a different type before) we always update them # silently. event.move_start_dt(data.pop('start_dt')) changes = event.populate_from_dict(data) # Person links are partially updated when the WTForms field is processed, # we we don't have proper change tracking there in some cases changes.pop('person_link_data', None) visible_person_link_changes = event.person_links != old_person_links if visible_person_link_changes or 'person_link_data' in data: changes['person_links'] = (old_person_links, event.person_links) db.session.flush() signals.event.updated.send(event, changes=changes) logger.info('Event %r updated with %r by %r', event, data, session.user) _log_event_update(event, changes, visible_person_link_changes=visible_person_link_changes)
def create_event_references(event, data): event.references = data['references'] db.session.flush() for reference in event.references: logger.info('Reference "%s" created by %s', reference, session.user)
def delete_reference_type(reference_type): db.session.delete(reference_type) db.session.flush() logger.info('Reference type "%s" deleted by %s', reference_type, session.user)
def update_reference_type(reference_type, data): reference_type.populate_from_dict(data) db.session.flush() logger.info('Reference type "%s" updated by %s', reference_type, session.user)
def unlock_event(event): event.is_locked = False db.session.flush() logger.info('Event %r unlocked by %r', event, session.user) event.log(EventLogRealm.event, EventLogKind.change, 'Event', 'Event unlocked', session.user)
def update_event_type(event, type_): if event.type_ == type_: return event.type_ = type_ logger.info('Event %r type changed to %s by %r', event, type_.name, session.user) event.log(EventLogRealm.event, EventLogKind.change, 'Event', 'Type changed to {}'.format(type_.title), session.user)