Exemple #1
0
def archive(req, year=None, month=None, day=None, page=1):
    """Render the monthly archives.

    Available template variables:

        `posts`:
            a list of post objects we want to display

        `pagination`:
            a pagination object to render a pagination

        `year` / `month` / `day`:
            integers or None, useful to entitle the page.

    :Template name: ``news_archive.html``
    :URL endpoint: ``news/archive``
    """

    if not year:
        return render_response('news_archive.html', month_list=True,
                               **News.query.published() \
                                     .get_archive_summary())

    url_args = dict(year=year, month=month, day=day)
    per_page = 20
    data = News.query.published().date_filter(year, month, day) \
               .get_list(page=page, endpoint='news/archive',
                         url_args=url_args, per_page=per_page)

    return render_response('news_archive.html', year=year, month=month, day=day,
                           date=date(year, month or 1, day or 1),
                           month_list=False, **data)
Exemple #2
0
def delete_shoutbox_entry(request, entry_id):
    """Render form to delete a shoutbox entry.

    Available template variables:

        `form`:
            form object with all required fields

    :Template name: ``shoutbox_post.html``
    :URL endpoint: ``shoutbox/post``
    """

    entry = ShoutboxEntry.query.get(entry_id)
    if entry is None:
        raise NotFound()

    form = DeleteShoutboxEntryForm(entry)
    assert_privilege(SHOUTBOX_MANAGE)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('core/index')
        if form.validate(request.form):
            form.add_invalid_redirect_target('shoutbox/delete', entry_id=entry.id)
            form.delete_entry()
            db.commit()
            # as this affects pretty much all visible pages, we flush cache here
            request.app.cache.clear()
            return form.redirect('core/index')

    return render_response('shoutbox_delete.html', form=form.as_widget())
Exemple #3
0
def make_shoutbox_entry(request):
    """Render form to make a shoutbox entry.

    Available template variables:

        `form`:
            form object with all required fields

        `widgetoptions`:
            redirected widgetoptions to hide post button below entries

    :Template name: ``shoutbox_post.html``
    :URL endpoint: ``shoutbox/post``
    """

    form = ShoutboxEntryForm()

    if request.method == 'POST':
        if request.user.is_somebody:
            form.disable_author()
        if form.validate(request.form):
            entry = form.make_entry()
            db.commit()
            # as this affects pretty much all visible pages, we flush cache here
            request.app.cache.clear()
            target = get_redirect_target()
            return form.redirect(target if target is not None else 'core/index')

    return render_response('shoutbox_post.html', form=form.as_widget(),
                           widgetoptions=['hide_shoutbox_note'])
Exemple #4
0
def squad_detail(req, squad_id=None):
    """Show a game in detail.

    Available template variables:

        `squad`:
            selected squad object

    :Template name: ``squad_detail.html``
    :URL endpoint: ``squad/detail``
    """

    data = Squad.query.get(squad_id)
    if data is None:
        raise NotFound()

    return render_response('squad_detail.html', squad=data)
Exemple #5
0
def game_detail(req, game_id=None):
    """Show a game in detail.

    Available template variables:

        `game`:
            selected game

    :Template name: ``game_detail.html``
    :URL endpoint: ``game/detail``
    """

    data = Game.query.get(game_id)
    if data is None:
        raise NotFound()

    return render_response('game_detail.html', game=data)
Exemple #6
0
def detail(req, news_id):
    """Render the given post.

    Available template variables:

        `newsitem`:
            the item we want to display

    :Template name: ``news_detail.html``
    :URL endpoint: ``news/detail``
    """

    entry = News.query.get(news_id)
    if not entry or (entry and not entry.is_public and not req.user.is_somebody):
        raise NotFound()

    return render_response('news_detail.html', newsitem=entry)
Exemple #7
0
def game_index(req, page):
    """Render the most recent posts.

    Available template variables:

        `games`:
            list of known games

        `pagination`:
            a pagination object to render a pagination

    :Template name: ``game_index.html``
    :URL endpoint: ``game/index``
    """

    data = Game.query.get_list('game/index', page,
              req.per_page)

    return render_response('game_index.html', **data)
Exemple #8
0
def index(req, page=1):
    """Render the most recent posts.

    Available template variables:

        `newsitems`:
            a list of post objects we want to display

        `pagination`:
            a pagination object to render a pagination

    :Template name: ``index.html``
    :URL endpoint: ``news/index``
    """

    data = News.query.published() \
               .get_list(endpoint='news/index', page=page)

    return render_response('news_index.html', **data)
Exemple #9
0
def render_admin_response(template_name, _active_menu_item=None, **values):
    """Works pretty much like the normal `render_response` function but
    it emits some events to collect navigation items and injects that
    into the template context. This also gets the flashes messages from
    the user session and injects them into the template context after the
    plugins have provided theirs in the `before-admin-response-rendered`
    event.

    The second parameter can be the active menu item if wanted. For example
    ``'options.overview'`` would show the overview button in the options
    submenu. If the menu is a standalone menu like the dashboard (no
    child items) you can also just use ``'dashboard'`` to highlight that.
    """
    request = get_request()

    # set up the core navigation bar
    navigation_bar = [
        ('dashboard', url_for('admin/index'), _(u'Dashboard'), [])
    ]

    Access_items = []

    # set up the administration menu bar
    if request.user.has_privilege(CLAN_ADMIN):
        navigation_bar.extend([
            ('users_groups', url_for('admin/manage_users'), _(u'Users and Groups'), [
                ('users', url_for('admin/manage_users'), _(u'Users')),
                ('groups', url_for('admin/manage_groups'), _(u'Groups'))
            ])
        ])
        navigation_bar.extend([
            ('options', url_for('admin/options'), _(u'Options'), [
                ('basic', url_for('admin/basic_options'), _(u'Basic')),
                ('urls', url_for('admin/urls'), _(u'URLs')),
                ('theme', url_for('admin/theme'), _(u'Theme')),
                ('recaptcha', url_for('admin/recaptcha'), _(u'reCAPTCHA')),
                ('cache', url_for('admin/cache'), _(u'Cache')),
                ('configuration', url_for('admin/configuration'),
                 _(u'Configuration Editor'))
            ])
        ])

    # add the help item to the navigation bar
    system_items = [('help', url_for('admin/help'), _(u'Help'))]

    if request.user.has_privilege(CLAN_ADMIN):
        system_items[0:0] = [
            ('information', url_for('admin/information'),
             _(u'Information')),
            ('maintenance', url_for('admin/maintenance'),
             _(u'Maintenance')),
            ('plugins', url_for('admin/plugins'), _(u'Plugins')),
            ('log', url_for('admin/log'), _('Log'))
        ]

    navigation_bar.append(('system', system_items[0][1], _(u'System'),
                           system_items))

    signals.modify_admin_navigation_bar.send(request=request, navbar=navigation_bar)

    # find out which is the correct menu and submenu bar
    active_menu = active_submenu = None
    if _active_menu_item is not None:
        p = _active_menu_item.split('.')
        if len(p) == 1:
            active_menu = p[0]
        else:
            active_menu, active_submenu = p
    for id, url, title, subnavigation_bar in navigation_bar:
        if id == active_menu:
            break
    else:
        subnavigation_bar = []

    # if we are in maintenance_mode the user should know that, no matter
    # on which page he is.
    if request.app.cfg['maintenance_mode'] and \
                                        request.user.has_privilege(CLAN_ADMIN):
        flash(_(u'pyClanSphere is in maintenance mode. Don\'t forget to '
                u'<a href="%s">turn it off again</a> once you finish your '
                u'changes.') % url_for('admin/maintenance'))

    # check for broken plugins if we have the plugin guard enabled
    if request.app.cfg['plugin_guard']:
        plugins_to_deactivate = []
        for plugin in request.app.plugins.itervalues():
            if plugin.active and plugin.setup_error is not None:
                flash(_(u'Could not activate plugin “%(name)s”: %(error)s') % {
                    'name':     plugin.html_display_name,
                    'error':    plugin.setup_error
                })
                plugins_to_deactivate.append(plugin.name)

        if plugins_to_deactivate:
            #TODO: it's quite tricky – it needs at least two reloads to
            #      deactivate the plugin (which is in fact a application reload)
            cfg = request.app.cfg.edit()
            cfg['plugins'] = u', '.join(sorted(set(request.app.cfg['plugins']) - \
                                               set(plugins_to_deactivate)))
            cfg.commit()
            # we change the plugins inline so that the user get somewhat more
            # information
            request.app.cfg.touch()

    signals.before_admin_response_rendered.send(request=request, values=values)

    # the admin variables is pushed into the context after the event was
    # sent so that plugins can flash their messages. If we would emit the
    # event afterwards all flashes messages would appear in the request
    # after the current request.
    values['admin'] = {
        'navbar': [{
            'id':       id,
            'url':      url,
            'title':    title,
            'active':   active_menu == id
        } for id, url, title, children in navigation_bar],
        'ctxnavbar': [{
            'id':       id,
            'url':      url,
            'title':    title,
            'active':   active_submenu == id
        } for id, url, title in subnavigation_bar],
        'messages': [{
            'type':     type,
            'msg':      msg
        } for type, msg in request.session.pop('admin/flashed_messages', [])],
        'active_pane': _active_menu_item
    }
    return render_response(template_name, **values)