Esempio n. 1
0
def category_edit(request, category_id=None):
    """Edit an existing category or create a new one."""

    category = None
    if category_id is not None:
        category = Category.query.get(category_id)
        if category is None:
            raise NotFound()
    form = CategoryForm(category)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect(cat_endpoints['list'])
        elif 'delete' in request.form and category:
            return redirect_to(cat_endpoints['delete'], category_id=category_id)
        elif form.validate(request.form):
            if category is None:
                category = form.create_category()
                msg = _('Category %s was created successfully.')
                icon = 'add'
            else:
                form.save_changes(category)
                msg = _('Category %s was updated successfully.')
                icon = 'info'

            admin_flash(msg % ('<a href="%s">%s</a>' % (url_for(cat_endpoints['edit'], category_id=category.id),
                               escape(category.name))), icon)

            if 'save_and_continue' in request.form:
                return redirect_to(cat_endpoints['edit'], category_id=category_id)
            elif 'save_and_new' in request.form:
                return redirect_to(cat_endpoints['edit'])
            return redirect_to(cat_endpoints['list'])
    return render_admin_response('admin/board_base_edit.html', 'board.categories',
                                 form=form.as_widget(), itemname=_('Category'))
Esempio n. 2
0
def forum_edit(request, forum_id=None):
    """Edit an existing forum or create a new one."""

    forum = None
    if forum_id is not None:
        forum = Forum.query.get(forum_id)
        if forum is None:
            raise NotFound()
    form = ForumForm(forum)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect(forum_endpoints['list'])
        elif 'delete' in request.form and forum:
            return redirect_to(forum_endpoints['delete'], forum_id=forum_id)
        elif form.validate(request.form):
            if forum is None:
                forum = form.create_forum()
                msg = _('The forum %s was created successfully.')
                icon = 'add'
            else:
                form.save_changes(forum)
                msg = _('The forum %s was updated successfully.')
                icon = 'info'

            admin_flash(msg % ('<a href="%s">%s</a>' % (url_for(forum_endpoints['edit'], forum_id=forum.id),
                               escape(forum.name))), icon)

            if 'save_and_continue' in request.form:
                return redirect_to(forum_endpoints['edit'], forum_id=forum_id)
            elif 'save_and_new' in request.form:
                return redirect_to(forum_endpoints['edit'])
            return redirect_to(forum_endpoints['list'])
    return render_admin_response('admin/board_base_edit.html', 'board.forums',
                                 form=form.as_widget(), itemname=_('Forum'))
Esempio n. 3
0
def add_admin_links(sender, **kwds):
    """Add our views to the admin interface"""

    priv_check = kwds['request'].user.has_privilege

    entries = [('list', url_for('admin/news'), _(u'Overview'))]

    if priv_check(NEWS_CREATE) or priv_check(NEWS_EDIT):
        entries.append(('edit', url_for('admin/news/new'), _(u'Write')))

    kwds['navbar'].insert(1,(('news', url_for('admin/news'), _(u'News'), entries)))
Esempio n. 4
0
def add_admin_links(sender, **kwds):
    """Add our views to the admin interface"""

    priv_check = kwds['request'].user.has_privilege

    if not priv_check(WAR_MANAGE):
        return

    entries = [('wars', url_for('admin/wars'), _(u'Wars')),
               ('maps', url_for('admin/warmaps'), _(u'Maps')),
               ('modes', url_for('admin/warmodes'), _(u'Modes'))]

    kwds['navbar'].insert(1, ('war', url_for('admin/wars'), _(u'War Management'), entries))
Esempio n. 5
0
def add_admin_links(sender, **kwds):
    """Add our views to the admin interface"""

    priv_check = kwds['request'].user.has_privilege

    entries = [('squads', url_for('admin/squads'), _(u'Squads'))]

    if priv_check(GAME_MANAGE):
        entries.insert(0,('games', url_for('admin/games'), _(u'Games')))

    if priv_check(LEVEL_MANAGE):
        entries.append(('levels', url_for('admin/levels'), _(u'Levels')))

    kwds['navbar'].insert(1, ('gamesquad', url_for('admin/squads'), _(u'Games and Squads'), entries))
Esempio n. 6
0
def forum_delete(request, forum_id=None):
    forum = Forum.query.get(forum_id)
    if forum is None:
        raise NotFound()
    form = DeleteForumForm(forum)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return redirect_to(forum_endpoints['edit'], forum_id=forum_id)
        if form.validate(request.form) and 'confirm' in request.form:
            msg = _('The forum %s was deleted successfully.')  % \
                  escape(forum.name)
            icon = 'remove'
            form.delete_forum()
            admin_flash(msg, icon)
            return redirect_to(forum_endpoints['list'])

    return render_admin_response('admin/board_base_delete.html', 'board.forums',
                                 form=form.as_widget(), itemname=_('Forum'),
                                 childitemnames=_('Topics'), entryname=forum.name)
Esempio n. 7
0
def category_delete(request, category_id=None):
    category = Category.query.get(category_id)
    if category is None:
        raise NotFound()
    form = DeleteCategoryForm(category)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return redirect_to(cat_endpoints['edit'], category_id=category_id)
        if form.validate(request.form) and 'confirm' in request.form:
            msg = _('The category %s was deleted successfully.')  % \
                  escape(category.name)
            icon = 'remove'
            form.delete_category()
            admin_flash(msg, icon)
            return redirect_to(cat_endpoints['list'])

    return render_admin_response('admin/board_base_delete.html', 'board.categories',
                                 form=form.as_widget(), itemname=_('Category'),
                                 childitemnames=_('Forums'), entryname=category.name)
Esempio n. 8
0
def get_recaptcha_html(error=None, theme=None):
    """Returns the recaptcha input HTML."""

    app = get_application()
    theme_settings = get_application().theme.settings
    cfg = app.cfg

    if theme == None or theme not in AVAILABLE_THEMES:
        theme = theme_settings['recaptcha.theme']
        if theme == None or theme not in AVAILABLE_THEMES:
            theme = cfg['recaptcha_default_theme']

    server = cfg['recaptcha_use_ssl'] and SSL_API_SERVER or API_SERVER
    options = dict(k=cfg['recaptcha_public_key'])
    if error is not None:
        options['error'] = unicode(error)
    query = url_encode(options)
    return u'''
    <script type="text/javascript">var RecaptchaOptions = %(options)s;</script>
    <script type="text/javascript" src="%(script_url)s"></script>
    <noscript>
      <div><iframe src="%(frame_url)s" height="300" width="500"></iframe></div>
      <div><textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
      <input type="hidden" name="recaptcha_response_field" value="manual_challenge"></div>
    </noscript>
    ''' % dict(
        script_url='%schallenge?%s' % (server, query),
        frame_url='%snoscript?%s' % (server, query),
        options=dumps({
            'theme':    theme,
            'custom_translations': {
                'visual_challenge': _("Get a visual challenge"),
                'audio_challenge': _("Get an audio challenge"),
                'refresh_btn': _("Get a new challenge"),
                'instructions_visual': _("Type the two words:"),
                'instructions_audio': _("Type what you hear:"),
                'help_btn': _("Help"),
                'play_again': _("Play sound again"),
                'cant_hear_this': _("Download sound as MP3"),
                'incorrect_try_again': _("Incorrect. Try again.")
            }
        })
    )
Esempio n. 9
0
def configure(request):
    """This callback is called from the admin panel if the theme configuration
    page is opened.  Because only the active theme can be configured it's
    perfectly okay to ship the template for the configuration page as part of
    the theme template folder.  No need to register a separate template folder
    just for the admin panel template.
    """
    cfg = request.app.cfg
    form = ConfigurationForm(initial=dict(variation=cfg["vessel_theme/variation"]))

    if request.method == "POST":
        if "cancel" in request.form:
            return form.redirect("admin/theme")
        elif form.validate(request.form):
            flash(_("Color variation changed successfully."), "configure")
            cfg.change_single("vessel_theme/variation", form["variation"])
            return form.redirect("admin/theme")

    return render_admin_response("admin/configure_vessel_theme.html", "options.theme", form=form.as_widget())
Esempio n. 10
0
from pyClanSphere.api import db, _
from pyClanSphere.models import User
from pyClanSphere.utils.pagination import Pagination
from pyClanSphere.schema import users

from pyClanSphere.plugins.gamesquad.models import Game, Squad
from pyClanSphere.plugins.war.database import wars, war_maps, warmembers, \
     warmodes, warmaps, warresults, warmap_results

try:
    import cPickle as Pickle
except:
    import Pickle

warstates = {
    0:_('Fightus Request'),
    1:_('Incomplete'),
    2:_('Planned'),
    3:_('Running'),
    4:_('Finished'),
    5:_('Aborted'),
    6:_('Cancelled')
}

memberstates = {
    1:_('No'),
    2:_('Maybe'),
    3:_('Yes')
}

def _create_warmember(member, status):
Esempio n. 11
0
def add_account_links(sender, **kwds):
    """Add our views to the account interface"""

    kwds['navbar'].insert(2, ('gameaccounts', url_for('account/gameaccounts'), _(u'Gameaccounts'),[]))
Esempio n. 12
0
    :copyright: (c) 2009 by the Zine Team, pyClanSphere modifications (c) 2009 by the pyClanSphere Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
"""
from os.path import join, dirname
from pyClanSphere.api import url_for, _
from pyClanSphere.views.admin import render_admin_response
from pyClanSphere.utils.admin import flash
from pyClanSphere.utils import forms


TEMPLATE_FILES = join(dirname(__file__), "templates")
SHARED_FILES = join(dirname(__file__), "shared")


blue_variation = u"vessel_theme::blue.css"
variations = {blue_variation: _("Blue"), u"vessel_theme::gray.css": _("Gray"), u"vessel_theme::green.css": _("Green")}


class ConfigurationForm(forms.Form):
    """Very simple form for the variation selection."""

    variation = forms.ChoiceField(_("Color variation"))

    def __init__(self, initial=None):
        forms.Form.__init__(self, initial)
        choices = sorted(variations.items(), key=lambda x: x[1].lower())
        self.fields["variation"].choices = choices


def add_variation(spec, title):
    """Registers a new variation."""