Beispiel #1
0
 def theme(self):
     from fossir.modules.events.layout import layout_settings, theme_settings
     theme = layout_settings.get(self, 'timetable_theme')
     if theme and theme in theme_settings.get_themes_for(self.type):
         return theme
     else:
         return theme_settings.defaults[self.type]
    def run(self, new_event, cloners, shared_data):
        for col in ('logo_metadata', 'logo', 'stylesheet_metadata', 'stylesheet'):
            setattr(new_event, col, getattr(self.old_event, col))

        layout_settings.set_multi(new_event, layout_settings.get_all(self.old_event, no_defaults=True))
        if layout_settings.get(self.old_event, 'use_custom_menu'):
            for menu_entry in MenuEntry.get_for_event(self.old_event):
                self._copy_menu_entry(menu_entry, new_event)
        db.session.flush()
 def _process(self):
     custom_menu_enabled = layout_settings.get(self.event,
                                               'use_custom_menu')
     menu = menu_entries_for_event(
         self.event) if custom_menu_enabled else None
     return WPMenuEdit.render_template(
         'menu_edit.html',
         self.event,
         menu=menu,
         custom_menu_enabled=custom_menu_enabled)
 def _process(self):
     self.event.preload_all_acl_entries()
     if self.theme is None:
         event_info = serialize_event_info(self.event)
         timetable_data = TimetableSerializer(self.event).serialize_timetable(strip_empty_days=True)
         timetable_settings = layout_settings.get(self.event, 'timetable_theme_settings')
         return self.view_class.render_template('display.html', self.event, event_info=event_info,
                                                timetable_data=timetable_data, timetable_settings=timetable_settings,
                                                timetable_layout=self.timetable_layout)
     else:
         return self.view_class_simple(self, self.event, self.theme, self.theme_override).display()
def _render_now_happening_info(event, text_color_css, **kwargs):
    from fossir.modules.events.layout import layout_settings
    if layout_settings.get(event, 'show_banner'):
        current_dt = now_utc(exact=False)
        entries = event.timetable_entries.filter(TimetableEntry.start_dt <= current_dt,
                                                 TimetableEntry.end_dt > current_dt,
                                                 TimetableEntry.type != TimetableEntryType.SESSION_BLOCK).all()
        if not entries:
            return
        return render_template('events/display/now_happening.html', event=event, entries=entries,
                               text_color_css=text_color_css)
def get_css_url(event, force_theme=None, for_preview=False):
    """Builds the URL of a CSS resource.

    :param event: The `Event` to get the CSS url for
    :param force_theme: The ID of the theme to override the custom CSS resource
                        only if it exists
    :param for_preview: Whether the URL is used in the CSS preview page
    :return: The URL to the CSS resource
    """
    from fossir.modules.events.layout import layout_settings

    if force_theme and force_theme != '_custom':
        return _build_css_url(force_theme)
    elif for_preview and force_theme is None:
        return None
    elif force_theme == '_custom' or layout_settings.get(event, 'use_custom_css'):
        if not event.has_stylesheet:
            return None
        return url_for('event_layout.css_display', event, slug=event.stylesheet_metadata['hash'])
    elif layout_settings.get(event, 'theme'):
        return _build_css_url(layout_settings.get(event, 'theme'))
 def url(self):
     # explicit _external=False since offline site creation forces
     # _external=True if not specified and we want to be able to mangle
     # the generated urls into something suitable as filenames
     if self.is_user_link:
         return self.link_url
     elif (self.is_internal_link
           or self.is_plugin_link) and not self.default_data.endpoint:
         return None
     elif self.is_internal_link:
         data = self.default_data
         if data.static_site and isinstance(
                 data.static_site, basestring) and g.get('static_site'):
             return data.static_site
         kwargs = {}
         if self.name == 'timetable':
             from fossir.modules.events.layout import layout_settings
             if layout_settings.get(self.event_ref, 'timetable_by_room'):
                 kwargs['layout'] = 'room'
             if layout_settings.get(self.event_ref, 'timetable_detailed'):
                 start_date = self.event_ref.start_dt_local
                 kwargs['_anchor'] = start_date.strftime('%Y%m%d.detailed')
         return url_for(data.endpoint,
                        self.event_ref,
                        _external=False,
                        **kwargs)
     elif self.is_plugin_link:
         from fossir.core.plugins import url_for_plugin
         return url_for_plugin(self.default_data.endpoint,
                               self.event_ref,
                               _external=False)
     elif self.is_page:
         return url_for('event_pages.page_display',
                        self.event_ref,
                        page_id=self.page_id,
                        slug=slugify(self.title),
                        _external=False)
     else:
         return None
Beispiel #8
0
def _make_theme_settings_form(event, theme):
    try:
        settings = theme_settings.themes[theme]['user_settings']
    except KeyError:
        return None
    form_class = type(b'ThemeSettingsForm', (fossirForm,), {})
    for name, field_data in settings.iteritems():
        field_type = field_data['type']
        field_class = getattr(fossir_fields, field_type, None) or getattr(wtforms_fields, field_type, None)
        if not field_class:
            raise Exception('Invalid field type: {}'.format(field_type))
        label = field_data['caption']
        description = field_data.get('description')
        validators = [DataRequired()] if field_data.get('required') else []
        field = field_class(label, validators, description=description, **field_data.get('kwargs', {}))
        setattr(form_class, name, field)

    defaults = {name: field_data.get('defaults') for name, field_data in settings.iteritems()}
    if theme == event.theme:
        defaults.update(layout_settings.get(event, 'timetable_theme_settings'))

    return form_class(csrf_enabled=False, obj=FormDefaults(defaults), prefix='tt-theme-settings-')
Beispiel #9
0
def inject_week_timetable(event,
                          days,
                          tz_name,
                          tpl='events/timetable/display/_weeks.html'):
    first_week_day = layout_settings.get(
        event, 'timetable_theme_settings').get('start_day')
    sunday_first = (first_week_day == 'sunday')
    show_end_times = request.args.get('showEndTimes') == '1'

    tz = timezone(tz_name)

    day_dict = defaultdict(list, days)
    sorted_dates = [
        d.date() for d in iterdays(event.start_dt.astimezone(tz),
                                   event.end_dt.astimezone(tz))
    ]
    first_day, last_day = sorted_dates[0], sorted_dates[-1]
    has_weekends = any(d.weekday() in (5, 6) for d in sorted_dates)

    # Calculate the actual starting day, based on the selected first day of the week
    if first_week_day != 'event':
        week_start = 6 if sunday_first else 0
        if first_day.weekday() != week_start:
            first_day -= timedelta(days=first_day.weekday()) + timedelta(
                days=int(has_weekends and sunday_first))
    week_table_shallow = []
    skipped_days = 0
    for i, dt in enumerate(iterdays(first_day, last_day)):
        day = dt.date()
        if day > last_day:
            # the loop doesn't account for skipped days so we might have to break early
            break
        if not has_weekends and day.weekday() == 5:
            day += timedelta(days=2)
            skipped_days += 2
        if i % (7 if has_weekends else 5) == 0:
            week_table_shallow.append([])
        week_table_shallow[-1].append((day, day_dict[day]))

    # build a new week table that contains placeholders
    week_table = []
    for week in week_table_shallow:
        # Build list of time slots that are used this week
        time_slots = set()
        for day, entries in week:
            time_slots.update(_localized_time(x.start_dt, tz) for x in entries)

        # Build each day with its contributions and placeholders
        tmp = []
        for day, entries in week:
            day_tmp = defaultdict(list)
            for entry in entries:
                day_tmp[_localized_time(entry.start_dt, tz)].append(entry)

            for slot in sorted(time_slots):
                day_tmp.setdefault(slot, [])

            # We've got a dict with a {slot: [entry, entry, ...]} mapping (for a single day)
            # We'll run over it and make some additional calculations
            day_tmp_sorted = sorted(day_tmp.viewitems())
            day_entries = OrderedDict()
            for n, (slot, slot_entries) in enumerate(day_tmp_sorted):
                tmp_slot_entries = []
                for entry in slot_entries:
                    # Check how many empty slots which intersect this one exist
                    count = sum(1 for x in takewhile(
                        lambda x: not x[1], iter(day_tmp_sorted[n + 1:]))
                                if x[0] < _localized_time(entry.end_dt, tz))
                    tmp_slot_entries.append((entry, count))
                day_entries[slot] = tmp_slot_entries
            tmp.append((day, day_entries))
        week_table.append(tmp)

    timetable_settings = layout_settings.get(event, 'timetable_theme_settings')
    return render_template(tpl,
                           event=event,
                           week_table=week_table,
                           timetable_settings=timetable_settings,
                           has_weekends=has_weekends,
                           timezone=tz_name,
                           tz_object=tz,
                           show_end_times=show_end_times)
Beispiel #10
0
 def _require_custom_menu(self):
     if not layout_settings.get(self.event, 'use_custom_menu'):
         raise Forbidden(
             'The menu cannot be changed unless menu customization is enabled'
         )
Beispiel #11
0
def menu_entries_for_event(event):
    custom_menu_enabled = layout_settings.get(event, 'use_custom_menu')
    return _build_menu(event) if custom_menu_enabled else _build_transient_menu(event)