コード例 #1
0
def serialize_category_atom(category, url, user, event_filter):
    """Export the events in a category to Atom.

    :param category: The category to export
    :param url: The URL of the feed
    :param user: The user who needs to be able to access the events
    :param event_filter: A SQLalchemy criterion to restrict which
                         events will be returned.  Usually something
                         involving the start/end date of the event.
    """
    query = (Event.query
             .filter(Event.category_chain_overlaps(category.id),
                     ~Event.is_deleted,
                     event_filter)
             .options(load_only('id', 'category_id', 'start_dt', 'title', 'description', 'protection_mode',
                                'access_key'),
                      subqueryload('acl_entries'))
             .order_by(Event.start_dt))
    events = [e for e in query if e.can_access(user)]

    feed = FeedGenerator()
    feed.id(url)
    feed.title(f'Indico Feed [{category.title}]')
    feed.link(href=url, rel='self')

    for event in events:
        entry = feed.add_entry(order='append')
        entry.id(event.external_url)
        entry.title(event.title)
        entry.summary(sanitize_html(str(event.description)) or None, type='html')
        entry.link(href=event.external_url)
        entry.updated(event.start_dt)
    return BytesIO(feed.atom_str(pretty=True))
コード例 #2
0
ファイル: string_test.py プロジェクト: javfg/indico
def test_sanitize_html_imagemaps():
    html = '''
        <img src="example.jpg" usemap="#image-map">
        <map name="image-map">
            <area alt="test" coords="1,2,3,4" href="//example.com" shape="rect" target="_blank" title="test">
        </map>
    '''
    assert sanitize_html(html) == html
コード例 #3
0
    def _process(self):
        tos_url = legal_settings.get('tos_url')
        tos_html = sanitize_html(legal_settings.get('tos')) or None
        privacy_policy_url = legal_settings.get('privacy_policy_url')
        privacy_policy_html = sanitize_html(legal_settings.get('privacy_policy')) or None
        if tos_url:
            tos_html = None
        if privacy_policy_url:
            privacy_policy_html = None

        return jsonify(help_url=config.HELP_URL,
                       contact_email=config.PUBLIC_SUPPORT_EMAIL,
                       has_tos=bool(tos_url or tos_html),
                       tos_html=tos_html,
                       tos_url=tos_url,
                       has_privacy_policy=bool(privacy_policy_url or privacy_policy_html),
                       privacy_policy_html=privacy_policy_html,
                       privacy_policy_url=privacy_policy_url)
コード例 #4
0
ファイル: misc.py プロジェクト: dwakna/indico-cbnu
 def _process(self):
     tos_url = legal_settings.get('tos_url')
     tos_html = sanitize_html(legal_settings.get('tos')) or None
     privacy_policy_url = legal_settings.get('privacy_policy_url')
     privacy_policy_html = sanitize_html(legal_settings.get('privacy_policy')) or None
     if tos_url:
         tos_html = None
     if privacy_policy_url:
         privacy_policy_html = None
     return jsonify(rooms_sprite_token=unicode(_cache.get('rooms-sprite-token', '')),
                    languages=get_all_locales(),
                    tileserver_url=rb_settings.get('tileserver_url'),
                    grace_period=rb_settings.get('grace_period'),
                    managers_edit_rooms=rb_settings.get('managers_edit_rooms'),
                    help_url=config.HELP_URL,
                    contact_email=config.PUBLIC_SUPPORT_EMAIL,
                    has_tos=bool(tos_url or tos_html),
                    tos_html=tos_html,
                    has_privacy_policy=bool(privacy_policy_url or privacy_policy_html),
                    privacy_policy_html=privacy_policy_html)
コード例 #5
0
    def _execute(self, fossils):
        results = fossils['results']
        if not isinstance(results, list):
            results = [results]

        feed = FeedGenerator()
        feed.id(fossils['url'])
        feed.title('Indico Feed')
        feed.link(href=fossils['url'], rel='self')

        for fossil in results:
            entry = feed.add_entry(order='append')
            entry.id(fossil['url'])
            entry.title(to_unicode(fossil['title']) or None)
            entry.summary(sanitize_html(to_unicode(fossil['description'])) or None, type='html')
            entry.link(href=fossil['url'])
            entry.updated(_deserialize_date(fossil['startDate']))
        return feed.atom_str(pretty=True)
コード例 #6
0
ファイル: app.py プロジェクト: zilehuda/indico
def setup_jinja(app):
    app.jinja_env.policies['ext.i18n.trimmed'] = True
    # Unicode hack
    app.jinja_env.add_extension(EnsureUnicodeExtension)
    app.add_template_filter(EnsureUnicodeExtension.ensure_unicode)
    # Useful (Python) builtins
    app.add_template_global(dict)
    # Global functions
    app.add_template_global(url_for)
    app.add_template_global(url_for_plugin)
    app.add_template_global(url_rule_to_js)
    app.add_template_global(IndicoConfig(exc=Exception), 'indico_config')
    app.add_template_global(call_template_hook, 'template_hook')
    app.add_template_global(is_single_line_field, '_is_single_line_field')
    app.add_template_global(render_field, '_render_field')
    app.add_template_global(iter_form_fields, '_iter_form_fields')
    app.add_template_global(format_currency)
    app.add_template_global(get_currency_name)
    app.add_template_global(url_for_index)
    app.add_template_global(url_for_login)
    app.add_template_global(url_for_logout)
    app.add_template_global(lambda: unicode(uuid.uuid4()), 'uuid')
    app.add_template_global(icon_from_mimetype)
    app.add_template_global(render_sidemenu)
    app.add_template_global(slugify)
    app.add_template_global(lambda: date_time_util.now_utc(False), 'now')
    app.add_template_global(render_session_bar)
    app.add_template_global(get_request_stats)
    # Global variables
    app.add_template_global(LocalProxy(get_current_locale), 'current_locale')
    app.add_template_global(
        LocalProxy(lambda: current_plugin.manifest
                   if current_plugin else None), 'plugin_webpack')
    # Useful constants
    app.add_template_global('^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$',
                            name='time_regex_hhmm')  # for input[type=time]
    # Filters (indico functions returning UTF8)
    app.add_template_filter(
        EnsureUnicodeExtension.wrap_func(date_time_util.format_date))
    app.add_template_filter(
        EnsureUnicodeExtension.wrap_func(date_time_util.format_time))
    app.add_template_filter(
        EnsureUnicodeExtension.wrap_func(date_time_util.format_datetime))
    app.add_template_filter(
        EnsureUnicodeExtension.wrap_func(date_time_util.format_human_date))
    app.add_template_filter(
        EnsureUnicodeExtension.wrap_func(date_time_util.format_timedelta))
    app.add_template_filter(
        EnsureUnicodeExtension.wrap_func(date_time_util.format_number))
    # Filters (new ones returning unicode)
    app.add_template_filter(date_time_util.format_human_timedelta)
    app.add_template_filter(date_time_util.format_pretty_date)
    app.add_template_filter(date_time_util.format_pretty_datetime)
    app.add_template_filter(lambda d: Markup(html_params(**d)), 'html_params')
    app.add_template_filter(underline)
    app.add_template_filter(markdown)
    app.add_template_filter(dedent)
    app.add_template_filter(html_to_plaintext)
    app.add_template_filter(natsort)
    app.add_template_filter(groupby)
    app.add_template_filter(any)
    app.add_template_filter(alpha_enum)
    app.add_template_filter(crc32)
    app.add_template_filter(bool)
    app.add_template_filter(lambda s: Markup(sanitize_html(s or '')),
                            'sanitize_html')
    app.add_template_filter(RichMarkup, 'rich_markup')
    # Tests
    app.add_template_test(
        instanceof)  # only use this test if you really have to!
    app.add_template_test(
        subclassof)  # only use this test if you really have to!
    # i18n
    app.jinja_env.add_extension('jinja2.ext.i18n')
    app.jinja_env.install_gettext_callables(gettext_context, ngettext_context,
                                            True)
コード例 #7
0
ファイル: controllers.py プロジェクト: innovexa/IDC-Events
 def _process(self):
     note = EventNote.get_for_linked_object(self.object, preload_event=False)
     if not note:
         raise NotFound
     return sanitize_html(note.html)
コード例 #8
0
ファイル: app.py プロジェクト: bkolobara/indico
def setup_jinja(app):
    app.jinja_env.policies['ext.i18n.trimmed'] = True
    # Unicode hack
    app.jinja_env.add_extension(EnsureUnicodeExtension)
    app.add_template_filter(EnsureUnicodeExtension.ensure_unicode)
    # Useful (Python) builtins
    app.add_template_global(dict)
    # Global functions
    app.add_template_global(url_for)
    app.add_template_global(url_for_plugin)
    app.add_template_global(url_rule_to_js)
    app.add_template_global(IndicoConfig(exc=Exception), 'indico_config')
    app.add_template_global(include_css_assets)
    app.add_template_global(include_js_assets)
    app.add_template_global(include_plugin_css_assets)
    app.add_template_global(include_plugin_js_assets)
    app.add_template_global(call_template_hook, 'template_hook')
    app.add_template_global(is_single_line_field, '_is_single_line_field')
    app.add_template_global(render_field, '_render_field')
    app.add_template_global(iter_form_fields, '_iter_form_fields')
    app.add_template_global(format_currency)
    app.add_template_global(get_currency_name)
    app.add_template_global(url_for_index)
    app.add_template_global(url_for_login)
    app.add_template_global(url_for_logout)
    app.add_template_global(lambda: unicode(uuid.uuid4()), 'uuid')
    app.add_template_global(icon_from_mimetype)
    app.add_template_global(render_sidemenu)
    app.add_template_global(slugify)
    app.add_template_global(lambda: date_time_util.now_utc(False), 'now')
    app.add_template_global(render_session_bar)
    app.add_template_global(lambda: 'custom_js' in core_env, 'has_custom_js')
    app.add_template_global(lambda: 'custom_sass' in core_env, 'has_custom_sass')
    app.add_template_global(get_request_stats)
    # Global variables
    app.add_template_global(LocalProxy(get_current_locale), 'current_locale')
    # Useful constants
    app.add_template_global('^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$', name='time_regex_hhmm')  # for input[type=time]
    # Filters (indico functions returning UTF8)
    app.add_template_filter(EnsureUnicodeExtension.wrap_func(date_time_util.format_date))
    app.add_template_filter(EnsureUnicodeExtension.wrap_func(date_time_util.format_time))
    app.add_template_filter(EnsureUnicodeExtension.wrap_func(date_time_util.format_datetime))
    app.add_template_filter(EnsureUnicodeExtension.wrap_func(date_time_util.format_human_date))
    app.add_template_filter(EnsureUnicodeExtension.wrap_func(date_time_util.format_timedelta))
    app.add_template_filter(EnsureUnicodeExtension.wrap_func(date_time_util.format_number))
    # Filters (new ones returning unicode)
    app.add_template_filter(date_time_util.format_human_timedelta)
    app.add_template_filter(date_time_util.format_pretty_date)
    app.add_template_filter(date_time_util.format_pretty_datetime)
    app.add_template_filter(lambda d: Markup(html_params(**d)), 'html_params')
    app.add_template_filter(underline)
    app.add_template_filter(markdown)
    app.add_template_filter(dedent)
    app.add_template_filter(html_to_plaintext)
    app.add_template_filter(natsort)
    app.add_template_filter(groupby)
    app.add_template_filter(any)
    app.add_template_filter(alpha_enum)
    app.add_template_filter(crc32)
    app.add_template_filter(bool)
    app.add_template_filter(lambda s: Markup(sanitize_html(s or '')), 'sanitize_html')
    app.add_template_filter(RichMarkup, 'rich_markup')
    # Tests
    app.add_template_test(instanceof)  # only use this test if you really have to!
    app.add_template_test(subclassof)  # only use this test if you really have to!
    # i18n
    app.jinja_env.add_extension('jinja2.ext.i18n')
    app.jinja_env.install_gettext_callables(gettext_context, ngettext_context, True)
    # webassets
    app.jinja_env.add_extension('webassets.ext.jinja2.AssetsExtension')
    app.jinja_env.assets_environment = core_env