Ejemplo n.º 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
Ejemplo n.º 2
0
 def _process_conference(self):
     form = ConferenceLayoutForm(obj=self._get_form_defaults(), event=self.event)
     css_form = CSSForm()
     logo_form = LogoForm()
     tt_theme_settings_form = _make_theme_settings_form(self.event, form.timetable_theme.data)
     tt_form_valid = tt_theme_settings_form.validate_on_submit() if tt_theme_settings_form else True
     if form.validate_on_submit() and tt_form_valid:
         if tt_theme_settings_form:
             layout_settings.set(self.event, 'timetable_theme_settings', tt_theme_settings_form.data)
         else:
             layout_settings.delete(self.event, 'timetable_theme_settings')
         data = {unicode(key): value for key, value in form.data.iteritems() if key in layout_settings.defaults}
         layout_settings.set_multi(self.event, data)
         if form.theme.data == '_custom':
             layout_settings.set(self.event, 'use_custom_css', True)
         flash(_('Settings saved'), 'success')
         return redirect(url_for('.index', self.event))
     else:
         if self.event.logo_metadata:
             logo_form.logo.data = self.event
         if self.event.has_stylesheet:
             css_form.css_file.data = self.event
     return WPLayoutEdit.render_template('layout_conference.html', self.event, form=form,
                                         logo_form=logo_form, css_form=css_form,
                                         timetable_theme_settings_form=tt_theme_settings_form)
Ejemplo n.º 3
0
    def migrate_layout_settings(self):
        print cformat('%{white!}migrating layout settings, event logos and custom stylesheets')

        default_styles = self.zodb_root['MaKaCInfo']['main']._styleMgr._defaultEventStylesheet
        for event, event_type, dmgr, logo, custom_css in committing_iterator(self._iter_event_layout_data()):
            if event_type != 'conference':
                theme = dmgr._defaultstyle
                if not theme or theme == default_styles[event_type]:
                    continue
                layout_settings.set(event, 'timetable_theme', theme)
                if not self.quiet:
                    self.print_success(cformat('- %{cyan}Default timetable theme: {}').format(theme), event_id=event.id)
                continue

            settings = self._get_event_settings(event, dmgr)
            layout_settings.set_multi(event, settings)
            if not self.quiet:
                self.print_success(cformat('- %{cyan}Layout settings'), event_id=event.id)
            if logo or custom_css:
                sa_event = Event.get(event.id)
                if not sa_event:
                    self.print_warning('Event does not exist (anymore)! Logo and/or CSS file not saved!',
                                       event_id=event.id)
                    continue
            if logo:
                self._process_logo(logo, sa_event)
            if custom_css:
                self._process_css(custom_css, sa_event)
Ejemplo n.º 4
0
 def _process(self):
     self.event.stylesheet = None
     self.event.stylesheet_metadata = None
     layout_settings.set(self.event, 'use_custom_css', False)
     flash(_('CSS file deleted'), 'success')
     logger.info("CSS file for %s deleted by %s", self.event, session.user)
     return jsonify_data(content=None)
Ejemplo n.º 5
0
    def _process_conference(self):
        form = ConferenceLayoutForm(obj=self._get_form_defaults(),
                                    event=self.event_new)
        css_form = CSSForm()
        logo_form = LogoForm()

        if form.validate_on_submit():
            data = {
                unicode(key): value
                for key, value in form.data.iteritems()
                if key in layout_settings.defaults
            }
            layout_settings.set_multi(self.event_new, data)
            if form.theme.data == '_custom':
                layout_settings.set(self.event_new, 'use_custom_css', True)
            flash(_('Settings saved'), 'success')
            return redirect(url_for('.index', self.event_new))
        else:
            if self.event_new.logo_metadata:
                logo_form.logo.data = self.event_new
            if self.event_new.has_stylesheet:
                css_form.css_file.data = self.event_new
        return WPLayoutEdit.render_template('layout_conference.html',
                                            self._conf,
                                            form=form,
                                            event=self.event_new,
                                            logo_form=logo_form,
                                            css_form=css_form)
Ejemplo n.º 6
0
    def migrate(self):
        dmgr = self.zodb_root['displayRegistery'][self.conf.id]

        style_mgr = getattr(
            dmgr, '_styleMngr',
            None) if self.event._type == EventType.conference else None
        custom_css = getattr(
            style_mgr, '_css',
            None) if self.event._type == EventType.conference else None

        if self.event._type == EventType.conference:
            logo = self.conf._logo
            settings = self._get_event_settings(dmgr)
            layout_settings.set_multi(self.event, settings)
            if not self.quiet:
                self.print_success('- %[cyan]Layout settings')
            if logo:
                self._process_logo(logo)
            if custom_css:
                self._process_css(custom_css)
        else:
            theme = dmgr._defaultstyle
            if not theme or theme == self.default_styles[
                    self.event._type.legacy_name]:
                return
            layout_settings.set(self.event, 'timetable_theme', theme)
            if not self.quiet:
                self.print_success(
                    '- %[cyan]Default timetable theme: {}'.format(theme))
Ejemplo n.º 7
0
 def _process_conference(self):
     form = ConferenceLayoutForm(obj=self._get_form_defaults(), event=self.event)
     css_form = CSSForm()
     logo_form = LogoForm()
     tt_theme_settings_form = _make_theme_settings_form(self.event, form.timetable_theme.data)
     tt_form_valid = tt_theme_settings_form.validate_on_submit() if tt_theme_settings_form else True
     if form.validate_on_submit() and tt_form_valid:
         if tt_theme_settings_form:
             layout_settings.set(self.event, 'timetable_theme_settings', tt_theme_settings_form.data)
         else:
             layout_settings.delete(self.event, 'timetable_theme_settings')
         data = {unicode(key): value for key, value in form.data.iteritems() if key in layout_settings.defaults}
         layout_settings.set_multi(self.event, data)
         if form.theme.data == '_custom':
             layout_settings.set(self.event, 'use_custom_css', True)
         flash(_('Settings saved'), 'success')
         return redirect(url_for('.index', self.event))
     else:
         if self.event.logo_metadata:
             logo_form.logo.data = self.event
         if self.event.has_stylesheet:
             css_form.css_file.data = self.event
     return WPLayoutEdit.render_template('layout_conference.html', self.event, form=form,
                                         logo_form=logo_form, css_form=css_form,
                                         timetable_theme_settings_form=tt_theme_settings_form)
Ejemplo n.º 8
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
Ejemplo n.º 9
0
    def _process(self):
        defaults = FormDefaults(**layout_settings.get_all(self._conf))
        form = LayoutForm(obj=defaults, event=self.event)
        css_form = CSSForm()
        logo_form = LogoForm()

        if form.validate_on_submit():
            data = {
                unicode(key): value
                for key, value in form.data.iteritems()
                if key in layout_settings.defaults
            }
            layout_settings.set_multi(self._conf, data)
            if form.theme.data == '_custom':
                layout_settings.set(self._conf, 'use_custom_css', True)
            flash(_('Settings saved'), 'success')
            return redirect(url_for('event_layout.index', self._conf))
        else:
            if self.event.logo_metadata:
                logo_form.logo.data = _logo_data(self.event)
            if self.event.has_stylesheet:
                css_form.css_file.data = _css_file_data(self.event)
        return WPLayoutEdit.render_template('layout.html',
                                            self._conf,
                                            form=form,
                                            event=self._conf,
                                            logo_form=logo_form,
                                            css_form=css_form)
Ejemplo n.º 10
0
 def _process(self):
     self.event.stylesheet = None
     self.event.stylesheet_metadata = None
     layout_settings.set(self.event, 'use_custom_css', False)
     flash(_('CSS file deleted'), 'success')
     logger.info("CSS file for %s deleted by %s", self.event, session.user)
     return jsonify_data(content=None)
Ejemplo n.º 11
0
    def migrate_layout_settings(self):
        print cformat('%{white!}migrating layout settings, event logos and custom stylesheets')

        default_styles = self.zodb_root['MaKaCInfo']['main']._styleMgr._defaultEventStylesheet
        for event, event_type, dmgr, logo, custom_css in committing_iterator(self._iter_event_layout_data()):
            if event_type != 'conference':
                theme = dmgr._defaultstyle
                if not theme or theme == default_styles[event_type]:
                    continue
                layout_settings.set(event, 'timetable_theme', theme)
                if not self.quiet:
                    self.print_success(cformat('- %{cyan}Default timetable theme: {}').format(theme), event_id=event.id)
                continue

            settings = self._get_event_settings(event, dmgr)
            layout_settings.set_multi(event, settings)
            if not self.quiet:
                self.print_success(cformat('- %{cyan}Layout settings'), event_id=event.id)
            if logo or custom_css:
                sa_event = Event.get(event.id)
                if not sa_event:
                    self.print_warning('Event does not exist (anymore)! Logo and/or CSS file not saved!',
                                       event_id=event.id)
                    continue
            if logo:
                self._process_logo(logo, sa_event)
            if custom_css:
                self._process_css(custom_css, sa_event)
Ejemplo n.º 12
0
 def _process(self):
     form = CSSSelectionForm(event=self.event)
     if form.validate_on_submit():
         layout_settings.set(self.event, 'use_custom_css', form.theme.data == '_custom')
         if form.theme.data != '_custom':
             layout_settings.set(self.event, 'theme', form.theme.data)
         flash(_('Settings saved'), 'success')
         return redirect(url_for('.index', self.event))
Ejemplo n.º 13
0
 def _process(self):
     form = CSSSelectionForm(event=self.event)
     if form.validate_on_submit():
         layout_settings.set(self.event, "use_custom_css", form.theme.data == "_custom")
         if form.theme.data != "_custom":
             layout_settings.set(self._conf, "theme", form.theme.data)
         flash(_("Settings saved"), "success")
         return redirect(url_for("event_layout.index", self.event))
Ejemplo n.º 14
0
 def migrate_event_menus(self):
     self.print_step("migrating conference menus")
     for event, display_mgr in committing_iterator(self._iter_events()):
         if _get_menu_structure(display_mgr) in DEFAULT_MENU_STRUCTURES:
             continue
         self.print_success("", event_id=event.id)
         db.session.add_all(self._migrate_menu(event, display_mgr._menu))
         layout_settings.set(event, "use_custom_menu", True)
Ejemplo n.º 15
0
 def _process(self):
     form = CSSSelectionForm(event=self.event)
     if form.validate_on_submit():
         layout_settings.set(self.event, 'use_custom_css', form.theme.data == '_custom')
         if form.theme.data != '_custom':
             layout_settings.set(self.event, 'theme', form.theme.data)
         flash(_('Settings saved'), 'success')
         return redirect(url_for('.index', self.event))
Ejemplo n.º 16
0
 def migrate_event_menus(self):
     self.print_step('migrating conference menus')
     for event, display_mgr in committing_iterator(self._iter_events()):
         if _get_menu_structure(display_mgr) in DEFAULT_MENU_STRUCTURES:
             continue
         self.print_success('', event_id=event.id)
         db.session.add_all(self._migrate_menu(event, display_mgr._menu))
         layout_settings.set(event, 'use_custom_menu', True)
Ejemplo n.º 17
0
def create_event(category, event_type, data):
    from MaKaC.conference import Conference
    conf = Conference.new(category, creator=session.user, title=data.pop('title'), start_dt=data.pop('start_dt'),
                          end_dt=data.pop('end_dt'), timezone=data.pop('timezone'), event_type=event_type)
    event = conf.as_event
    theme = data.pop('theme', None)
    if theme is not None:
        layout_settings.set(event, 'timetable_theme', theme)
    event.populate_from_dict(data)
    db.session.flush()
    logger.info('Event %r created in %r by %r ', event, category, session.user)
    event.log(EventLogRealm.event, EventLogKind.positive, 'Event', 'Event created', session.user)
    return event
Ejemplo n.º 18
0
 def _process(self):
     enabled = request.form['enabled'] == '1'
     if enabled:
         # nothing else to do here. menu items are added to the DB when retrieving the menu
         flash(_('Menu customization has been enabled.'), 'success')
     else:
         for entry in MenuEntry.find(event_id=int(self._conf.id)):
             db.session.delete(entry)
         flash(_('Menu customization has been disabled.'), 'success')
     layout_settings.set(self._conf, 'use_custom_menu', enabled)
     logger.info('Menu customization for {} {} by {}'.format(self._conf, 'enabled' if enabled else 'disabled',
                                                             session.user))
     return jsonify(enabled=enabled)
Ejemplo n.º 19
0
 def _process(self):
     enabled = request.form['enabled'] == '1'
     if enabled:
         # nothing else to do here. menu items are added to the DB when retrieving the menu
         flash(_('Menu customization has been enabled.'), 'success')
     else:
         for entry in MenuEntry.query.with_parent(self.event):
             db.session.delete(entry)
         flash(_('Menu customization has been disabled.'), 'success')
     layout_settings.set(self.event, 'use_custom_menu', enabled)
     logger.info('Menu customization for %s %s by %s', self.event,
                 'enabled' if enabled else 'disabled', session.user)
     return jsonify(enabled=enabled)
Ejemplo n.º 20
0
 def _process(self):
     enabled = request.form['enabled'] == '1'
     if enabled:
         # nothing else to do here. menu items are added to the DB when retrieving the menu
         flash(_('Menu customization has been enabled.'), 'success')
     else:
         for entry in MenuEntry.query.with_parent(self.event):
             db.session.delete(entry)
         flash(_('Menu customization has been disabled.'), 'success')
     layout_settings.set(self.event, 'use_custom_menu', enabled)
     logger.info('Menu customization for %s %s by %s', self.event, 'enabled' if enabled else 'disabled',
                 session.user)
     return jsonify(enabled=enabled)
Ejemplo n.º 21
0
 def _process_lecture_meeting(self):
     form = LectureMeetingLayoutForm(obj=self._get_form_defaults(), event=self.event)
     tt_theme_settings_form = _make_theme_settings_form(self.event, form.timetable_theme.data)
     tt_form_valid = tt_theme_settings_form.validate_on_submit() if tt_theme_settings_form else True
     if form.validate_on_submit() and tt_form_valid:
         if tt_theme_settings_form:
             layout_settings.set(self.event, 'timetable_theme_settings', tt_theme_settings_form.data)
         else:
             layout_settings.delete(self.event, 'timetable_theme_settings')
         layout_settings.set_multi(self.event, form.data)
         flash(_('Settings saved'), 'success')
         return redirect(url_for('.index', self.event))
     return WPLayoutEdit.render_template('layout_meeting_lecture.html', self.event, form=form,
                                         timetable_theme_settings_form=tt_theme_settings_form)
Ejemplo n.º 22
0
 def _process_lecture_meeting(self):
     form = LectureMeetingLayoutForm(obj=self._get_form_defaults(), event=self.event)
     tt_theme_settings_form = _make_theme_settings_form(self.event, form.timetable_theme.data)
     tt_form_valid = tt_theme_settings_form.validate_on_submit() if tt_theme_settings_form else True
     if form.validate_on_submit() and tt_form_valid:
         if tt_theme_settings_form:
             layout_settings.set(self.event, 'timetable_theme_settings', tt_theme_settings_form.data)
         else:
             layout_settings.delete(self.event, 'timetable_theme_settings')
         layout_settings.set_multi(self.event, form.data)
         flash(_('Settings saved'), 'success')
         return redirect(url_for('.index', self.event))
     return WPLayoutEdit.render_template('layout_meeting_lecture.html', self.event, form=form,
                                         timetable_theme_settings_form=tt_theme_settings_form)
Ejemplo n.º 23
0
def create_event(category, event_type, data, add_creator_as_manager=True, features=None):
    from indico.modules.rb_new.operations.bookings import create_booking_for_event
    """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)
    create_booking = data.pop('create_booking', False)
    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()
    if create_booking:
        room_id = data['location_data'].pop('room_id', None)
        if room_id:
            booking = create_booking_for_event(room_id, event)
            if booking:
                logger.info('Booking %r created for event %r', booking, event)
                log_data = {'Room': booking.room.full_name,
                            'Date': booking.start_dt.strftime('%d/%m/%Y'),
                            'Times': '%s - %s' % (booking.start_dt.strftime('%H:%M'), booking.end_dt.strftime('%H:%M'))}
                event.log(EventLogRealm.event, EventLogKind.positive, 'Event', 'Room booked for the event',
                          session.user, data=log_data)
                db.session.flush()
    return event
Ejemplo n.º 24
0
    def migrate(self):
        dmgr = self.zodb_root['displayRegistery'][self.conf.id]
        if _get_menu_structure(dmgr) not in DEFAULT_MENU_STRUCTURES:
            self.print_success('Custom menu')
            new_menu_data = list(self._migrate_menu(self.event, dmgr._menu))
            db.session.add_all(new_menu_data)
            layout_settings.set(self.event, 'use_custom_menu', True)

        # set on event context whether "participants" item is enabled
        # this is used later in the registration form migration
        entries = [
            entry for entry in new_menu_data if entry.name == 'participants'
        ]
        assert (len(entries) < 2)
        self.event_ns.misc_data['participant_list_disabled'] = False
        if entries:
            self.event_ns.misc_data['participant_list_disabled'] = entries[
                0].is_disabled
Ejemplo n.º 25
0
def create_event(category, event_type, data):
    from MaKaC.conference import Conference
    conf = Conference.new(category,
                          creator=session.user,
                          title=data.pop('title'),
                          start_dt=data.pop('start_dt'),
                          end_dt=data.pop('end_dt'),
                          timezone=data.pop('timezone'),
                          event_type=event_type)
    event = conf.as_event
    theme = data.pop('theme', None)
    if theme is not None:
        layout_settings.set(event, 'timetable_theme', theme)
    event.populate_from_dict(data)
    db.session.flush()
    logger.info('Event %r created in %r by %r ', event, category, session.user)
    event.log(EventLogRealm.event, EventLogKind.positive, 'Event',
              'Event created', session.user)
    return event
Ejemplo n.º 26
0
    def clone(self, new_event, options):
        if self.event.getType() != 'conference':
            # for meetings/lecture we want to keep the default timetable style in all cases
            theme = layout_settings.get(self.event, 'timetable_theme')
            if theme is not None:
                layout_settings.set(new_event, 'timetable_theme', theme)
            return

        if 'layout' not in options:
            return

        for col in ('logo_metadata', 'logo', 'stylesheet_metadata', 'stylesheet'):
            setattr(new_event.as_event, col, getattr(self.event.as_event, col))

        layout_settings.set_multi(new_event, layout_settings.get_all(self.event, no_defaults=True))
        if layout_settings.get(self.event, 'use_custom_menu'):
            for menu_entry in MenuEntry.get_for_event(self.event):
                self._copy_menu_entry(menu_entry, new_event, new_event.as_event.menu_entries)
        db.session.flush()
Ejemplo n.º 27
0
    def _process(self):
        defaults = FormDefaults(**layout_settings.get_all(self._conf))
        form = LayoutForm(obj=defaults, event=self.event_new)
        css_form = CSSForm()
        logo_form = LogoForm()

        if form.validate_on_submit():
            data = {unicode(key): value for key, value in form.data.iteritems() if key in layout_settings.defaults}
            layout_settings.set_multi(self._conf, data)
            if form.theme.data == '_custom':
                layout_settings.set(self._conf, 'use_custom_css', True)
            flash(_('Settings saved'), 'success')
            return redirect(url_for('event_layout.index', self._conf))
        else:
            if self.event_new.logo_metadata:
                logo_form.logo.data = self.event_new
            if self.event_new.has_stylesheet:
                css_form.css_file.data = self.event_new
        return WPLayoutEdit.render_template('layout.html', self._conf, form=form, event=self.event_new,
                                            logo_form=logo_form, css_form=css_form)
Ejemplo n.º 28
0
    def _process(self):
        defaults = FormDefaults(**layout_settings.get_all(self._conf))
        form = LayoutForm(obj=defaults, event=self.event)
        css_form = CSSForm()
        logo_form = LogoForm()

        if form.validate_on_submit():
            data = {unicode(key): value for key, value in form.data.iteritems() if key in layout_settings.defaults}
            layout_settings.set_multi(self._conf, data)
            if form.theme.data == "_custom":
                layout_settings.set(self._conf, "use_custom_css", True)
            flash(_("Settings saved"), "success")
            return redirect(url_for("event_layout.index", self._conf))
        else:
            if self.event.logo_metadata:
                logo_form.logo.data = _logo_data(self.event)
            if self.event.has_stylesheet:
                css_form.css_file.data = _css_file_data(self.event)
        return WPLayoutEdit.render_template(
            "layout.html", self._conf, form=form, event=self._conf, logo_form=logo_form, css_form=css_form
        )
Ejemplo n.º 29
0
    def clone(self, new_event, options):
        if self.event.getType() != 'conference':
            # for meetings/lecture we want to keep the default timetable style in all cases
            theme = layout_settings.get(self.event, 'timetable_theme')
            if theme is not None:
                layout_settings.set(new_event, 'timetable_theme', theme)
            return

        if 'layout' not in options:
            return

        for col in ('logo_metadata', 'logo', 'stylesheet_metadata',
                    'stylesheet'):
            setattr(new_event.as_event, col, getattr(self.event.as_event, col))

        layout_settings.set_multi(
            new_event, layout_settings.get_all(self.event, no_defaults=True))
        if layout_settings.get(self.event, 'use_custom_menu'):
            for menu_entry in MenuEntry.get_for_event(self.event):
                self._copy_menu_entry(menu_entry, new_event,
                                      new_event.as_event.menu_entries)
        db.session.flush()
Ejemplo n.º 30
0
        theme = confData.get('defaultStyle', '')
        curType = c.getType()
        newType = confData.get('eventType', '')
        if newType != "" and newType != curType:
            wr = webFactoryRegistry.WebFactoryRegistry()
            factory = wr.getFactoryById(newType)
            wr.registerFactory(c, factory)
            # type changed. always revert to the default theme
            layout_settings.delete(c, 'timetable_theme')
        elif not theme or theme == styleMgr.getDefaultStyleForEventType(
                newType):
            # if it's the default theme or nothing was set (does this ever happen?!), we don't store it
            layout_settings.delete(c, 'timetable_theme')
        else:
            # set the new theme
            layout_settings.set(c, 'timetable_theme', theme)

    @staticmethod
    def validateShortURL(tag, target):
        if tag.isdigit():
            raise ValueError(
                _("Short URL tag is a number: '%s'. Please add at least one non-digit."
                  ) % tag)
        if not re.match(r'^[a-zA-Z0-9/._-]+$', tag) or '//' in tag:
            raise ValueError(
                _("Short URL tag contains invalid chars: '%s'. Please select another one."
                  ) % tag)
        if tag[0] == '/' or tag[-1] == '/':
            raise ValueError(
                _("Short URL tag may not begin/end with a slash: '%s'. Please select another one."
                  ) % tag)
Ejemplo n.º 31
0
def create_event(category,
                 event_type,
                 data,
                 add_creator_as_manager=True,
                 features=None):
    from indico.modules.rb.operations.bookings import create_booking_for_event
    """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)
    create_booking = data.pop('create_booking', False)
    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()
    if create_booking:
        room_id = data['location_data'].pop('room_id', None)
        if room_id:
            booking = create_booking_for_event(room_id, event)
            if booking:
                logger.info('Booking %r created for event %r', booking, event)
                log_data = {
                    'Room':
                    booking.room.full_name,
                    'Date':
                    booking.start_dt.strftime('%d/%m/%Y'),
                    'Times':
                    '%s - %s' % (booking.start_dt.strftime('%H:%M'),
                                 booking.end_dt.strftime('%H:%M'))
                }
                event.log(EventLogRealm.event,
                          EventLogKind.positive,
                          'Event',
                          'Room booked for the event',
                          session.user,
                          data=log_data)
                db.session.flush()
    return event
Ejemplo n.º 32
0
 def _handleSet(self):
     if self._value == theme_settings.defaults[self._conf.getType()]:
         layout_settings.delete(self._conf, 'timetable_theme')
     else:
         layout_settings.set(self._conf, 'timetable_theme', self._value)
Ejemplo n.º 33
0
def create_event(category,
                 event_type,
                 data,
                 add_creator_as_manager=True,
                 features=None,
                 cloning=False):
    """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.
    :param cloning: Whether the event is created via cloning or not
    """
    from indico.modules.rb.operations.bookings import create_booking_for_event
    event = Event(category=category, type_=event_type)
    data.setdefault('creator', session.user)
    theme = data.pop('theme', None)
    create_booking = data.pop('create_booking', False)
    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, cloning=cloning)
    logger.info('Event %r created in %r by %r ', event, category, session.user)
    sep = ' \N{RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK} '
    event.log(EventLogRealm.event,
              LogKind.positive,
              'Event',
              'Event created',
              session.user,
              data={
                  'Category':
                  sep.join(category.chain_titles) if category else None
              })
    if category:
        category.log(CategoryLogRealm.events,
                     LogKind.positive,
                     'Content',
                     f'Event created: "{event.title}"',
                     session.user,
                     data={
                         'ID': event.id,
                         'Type': orig_string(event.type_.title)
                     })
    db.session.flush()
    if create_booking:
        room_id = data['location_data'].pop('room_id', None)
        if room_id:
            booking = create_booking_for_event(room_id, event)
            if booking:
                logger.info('Booking %r created for event %r', booking, event)
                log_data = {
                    'Room':
                    booking.room.full_name,
                    'Date':
                    booking.start_dt.strftime('%d/%m/%Y'),
                    'Times':
                    '{} - {}'.format(booking.start_dt.strftime('%H:%M'),
                                     booking.end_dt.strftime('%H:%M'))
                }
                event.log(EventLogRealm.event,
                          LogKind.positive,
                          'Event',
                          'Room booked for the event',
                          session.user,
                          data=log_data)
                db.session.flush()
    return event
Ejemplo n.º 34
0
        styleMgr = info.HelperMaKaCInfo.getMaKaCInfoInstance().getStyleManager()
        theme = confData.get('defaultStyle', '')
        curType = c.getType()
        newType = confData.get('eventType', '')
        if newType != "" and newType != curType:
            wr = webFactoryRegistry.WebFactoryRegistry()
            factory = wr.getFactoryById(newType)
            wr.registerFactory(c,factory)
            # type changed. always revert to the default theme
            layout_settings.delete(c, 'timetable_theme')
        elif not theme or theme == styleMgr.getDefaultStyleForEventType(newType):
            # if it's the default theme or nothing was set (does this ever happen?!), we don't store it
            layout_settings.delete(c, 'timetable_theme')
        else:
            # set the new theme
            layout_settings.set(c, 'timetable_theme', theme)

    @staticmethod
    def validateShortURL(tag, target):
        if tag.isdigit():
            raise ValueError(_("Short URL tag is a number: '%s'. Please add at least one non-digit.") % tag)
        if not re.match(r'^[a-zA-Z0-9/._-]+$', tag) or '//' in tag:
            raise ValueError(
                _("Short URL tag contains invalid chars: '%s'. Please select another one.") % tag)
        if tag[0] == '/' or tag[-1] == '/':
            raise ValueError(
                _("Short URL tag may not begin/end with a slash: '%s'. Please select another one.") % tag)
        mapper = ShortURLMapper()
        if mapper.hasKey(tag) and mapper.getById(tag) != target:
            raise ValueError(_("Short URL tag already used: '%s'. Please select another one.") % tag)
        if conference.ConferenceHolder().hasKey(tag):
Ejemplo n.º 35
0
 def _handleSet(self):
     styleMgr = HelperMaKaCInfo.getMaKaCInfoInstance().getStyleManager()
     if self._value == styleMgr.getDefaultStyleForEventType(self._conf.getType()):
         layout_settings.delete(self._conf, 'timetable_theme')
     else:
         layout_settings.set(self._conf, 'timetable_theme', self._value)
Ejemplo n.º 36
0
class UtilsConference:
    @staticmethod
    def get_start_dt(params):
        tz = params['Timezone']
        try:
            return timezone(tz).localize(
                datetime(int(params['sYear']), int(params['sMonth']),
                         int(params['sDay']), int(params['sHour']),
                         int(params['sMinute'])))
        except ValueError as e:
            raise FormValuesError(
                'The start date you have entered is not correct: {}'.format(e),
                'Event')

    @staticmethod
    def get_end_dt(params, start_dt):
        tz = params['Timezone']
        if params.get('duration'):
            end_dt = start_dt + timedelta(minutes=params['duration'])
        else:
            try:
                end_dt = timezone(tz).localize(
                    datetime(int(params['eYear']), int(params['eMonth']),
                             int(params['eDay']), int(params['eHour']),
                             int(params['eMinute'])))
            except ValueError as e:
                raise FormValuesError(
                    'The end date you have entered is not correct: {}'.format(
                        e), 'Event')
        return end_dt

    @staticmethod
    def get_location_data(params):
        location_data = json.loads(params['location_data'])
        if location_data.get('room_id'):
            location_data['room'] = Room.get_one(location_data['room_id'])
        if location_data.get('venue_id'):
            location_data['venue'] = Location.get_one(
                location_data['venue_id'])
        return location_data

    @classmethod
    def setValues(cls, c, confData, notify=False):
        c.setTitle(confData["title"])
        c.setDescription(confData["description"])
        c.setOrgText(confData.get("orgText", ""))
        c.setComments(confData.get("comments", ""))
        c.as_event.keywords = confData["keywords"]
        c.setChairmanText(confData.get("chairText", ""))
        if "shortURLTag" in confData.keys():
            tag = confData["shortURLTag"].strip()
            if tag:
                try:
                    UtilsConference.validateShortURL(tag, c)
                except ValueError, e:
                    raise FormValuesError(e.message)
            if c.getUrlTag() != tag:
                mapper = ShortURLMapper()
                mapper.remove(c)
                c.setUrlTag(tag)
                if tag:
                    mapper.add(tag, c)
        c.setContactInfo(confData.get("contactInfo", ""))
        #################################
        # Fermi timezone awareness      #
        #################################
        c.setTimezone(confData["Timezone"])
        sDate = cls.get_start_dt(confData)
        eDate = cls.get_end_dt(confData, sDate)
        moveEntries = int(confData.get("move", 0))
        with track_time_changes():
            c.setDates(sDate.astimezone(timezone('UTC')),
                       eDate.astimezone(timezone('UTC')),
                       moveEntries=moveEntries)

        #################################
        # Fermi timezone awareness(end) #
        #################################

        old_location_data = c.as_event.location_data
        location_data = cls.get_location_data(confData)
        update_event(c.as_event, {'location_data': location_data})

        if old_location_data != location_data:
            signals.event.data_changed.send(c,
                                            attr='location',
                                            old=old_location_data,
                                            new=location_data)

        emailstr = setValidEmailSeparators(confData.get("supportEmail", ""))

        if (emailstr != "") and not validMail(emailstr):
            raise FormValuesError(
                "One of the emails specified or one of the separators is invalid"
            )

        c.getSupportInfo().setEmail(emailstr)
        c.getSupportInfo().setCaption(confData.get("supportCaption",
                                                   "Support"))
        # TODO: remove TODO once visibility has been updated
        if c.getVisibility() != confData.get(
                "visibility", 999) and confData.get('visibility') != 'TODO':
            c.setVisibility(confData.get("visibility", 999))
        theme = confData.get('defaultStyle', '')
        new_type = EventType.legacy_map[confData[
            'eventType']] if 'eventType' in confData else c.as_event.type_
        if new_type != c.as_event.type_:
            c.as_event.type_ = new_type
        elif not theme or theme == theme_settings.defaults.get(
                new_type.legacy_name):
            # if it's the default theme or nothing was set (does this ever happen?!), we don't store it
            layout_settings.delete(c, 'timetable_theme')
        else:
            # set the new theme
            layout_settings.set(c, 'timetable_theme', theme)
Ejemplo n.º 37
0
 def _handleSet(self):
     if self._value == theme_settings.defaults[self._conf.getType()]:
         layout_settings.delete(self._conf, 'timetable_theme')
     else:
         layout_settings.set(self._conf, 'timetable_theme', self._value)