コード例 #1
0
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
コード例 #2
0
 def _create_event(id_=None, **kwargs):
     # we specify `acl_entries` so SA doesn't load it when accessing it for
     # the first time, which would require no_autoflush blocks in some cases
     now = now_utc(exact=False)
     kwargs.setdefault('type_', EventType.meeting)
     kwargs.setdefault(
         'title', u'dummy#{}'.format(id_) if id_ is not None else u'dummy')
     kwargs.setdefault('start_dt', now)
     kwargs.setdefault('end_dt', now + timedelta(hours=1))
     kwargs.setdefault('timezone', 'UTC')
     kwargs.setdefault('category', dummy_category)
     event = Event(id=id_, creator=dummy_user, acl_entries=set(), **kwargs)
     db.session.flush()
     return event