Exemple #1
0
def war_edit(request, war_id=None):
    """Edit an existing war or create a new one."""

    war = None
    if war_id is not None:
        war = War.query.get(war_id)
        if war is None:
            raise NotFound()
    form = forms.EditWarForm(war)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('admin/wars')
        elif 'result' in request.form:
            return form.redirect('admin/warresult_edit', war_id=war_id)
        elif request.form.get('delete') and war:
            return redirect_to('admin/wars/delete', war_id=war_id)
        elif form.validate(request.form):
            if war is None:
                war = form.make_war()
                msg = _('The war %s was added successfully.')
                icon = 'add'
            else:
                form.save_changes()
                msg = _('The war %s was updated successfully.')
                icon = 'info'
            admin_flash(msg % (war.clanname), icon)

            db.commit()
            if 'save_and_continue' in request.form:
                return redirect_to('admin/wars/edit', war_id=war.id)
            return redirect_to('admin/wars')

    return render_admin_response('admin/war_edit.html', 'war.wars',
                                 form=form.as_widget(), memberstates=memberstates, warstates=warstates)
Exemple #2
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'))
Exemple #3
0
def edit_level(request, level_id=None):
    """Edit an existing level or create a new one."""

    level = None
    if level_id is not None:
        level = Level.query.get(level_id)
        if level is None:
            raise NotFound()
    form = EditLevelForm(level)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('admin/levels')
        elif request.form.get('delete') and level:
            return redirect_to('admin/levels/delete', level_id=level_id)
        elif form.validate(request.form):
            if level is None:
                level = form.make_level()
                msg = _('The level %s was created successfully.')
                icon = 'add'
            else:
                form.save_changes()
                msg = _('The level %s was updated successfully.')
                icon = 'info'
            admin_flash(msg % (escape(level.name)), icon)

            db.commit()
            if 'save_and_continue' in request.form:
                return redirect_to('admin/levels/edit', level_id=level.id)
            return redirect_to('admin/levels')
    return render_admin_response('admin/level_edit.html', 'levelsquad.levels',
                                 form=form.as_widget())
Exemple #4
0
def edit_squad(request, squad_id=None):
    """Edit an existing squad or create a new one."""

    squad = None
    if squad_id is not None:
        squad = Squad.query.get(squad_id)
        if squad is None:
            raise NotFound()
    form = EditSquadForm(squad)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('admin/squads')
        elif request.form.get('delete') and squad:
            return redirect_to('admin/squads/delete', squad_id=squad.id)
        elif form.validate(request.form):
            if squad is None:
                squad = form.make_squad()
                msg = _('The squad %s was created successfully.')
                icon = 'add'
            else:
                form.save_changes()
                msg = _('The squad %s was updated successfully.')
                icon = 'info'
            admin_flash(msg % (escape(squad.name)), icon)

            db.commit()
            if 'save_and_continue' in request.form:
                return redirect_to('admin/squads/edit', squad_id=squad.id)
            return redirect_to('admin/squads')
    return render_admin_response('admin/squad_edit.html', 'gamesquad.squads',
                                 form=form.as_widget())
Exemple #5
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'))
Exemple #6
0
def edit_game(request, game_id=None):
    """Edit an existing game or create a new one."""

    game = None
    if game_id is not None:
        game = Game.query.get(game_id)
        if game is None:
            raise NotFound()
    form = EditGameForm(game)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('admin/games')
        elif request.form.get('delete') and game:
            return redirect_to('admin/games/delete', game_id=game.id)
        elif form.validate(request.form):
            if game is None:
                game = form.make_game()
                msg = _('The game %s was created successfully.')
                icon = 'add'
            else:
                form.save_changes()
                msg = _('The game %s was updated successfully.')
                icon = 'info'
            admin_flash(msg % (escape(game.name)), icon)

            db.commit()
            if 'save_and_continue' in request.form:
                return redirect_to('admin/game_edit', game_id=game.id)
            return redirect_to('admin/games')
    return render_admin_response('admin/game_edit.html', 'gamesquad.games',
                                 form=form.as_widget())
Exemple #7
0
def warmode_edit(request, warmode_id=None):
    """Edit an existing warmode or create a new one."""

    warmode = None
    if warmode_id is not None:
        warmode = WarMode.query.get(warmode_id)
        if warmode is None:
            raise NotFound()
    form = forms.EditWarModeForm(warmode)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('admin/warmodes')
        elif request.form.get('delete') and warmode:
            return redirect_to('admin/warmodes/delete', warmode_id=warmode_id)
        elif form.validate(request.form):
            if warmode is None:
                warmode = form.make_warmode()
                msg = _('Warmode %s was created successfully.')
                icon = 'add'
            else:
                form.save_changes()
                msg = _('Warmode %s was updated successfully.')
                icon = 'info'

            admin_flash(msg % (warmode.name), icon)

            db.commit()

            if 'save_and_continue' in request.form:
                return redirect_to('admin/warmodes/edit', warmode_id=warmode.id)
            return redirect_to('admin/warmodes')
    return render_admin_response('admin/warmode_edit.html', 'war.modes',
                                    form=form.as_widget())
Exemple #8
0
def delete_news(request, news_id=None):
    """Remove given news entry"""

    newsitem = News.query.get(news_id)
    if newsitem is None:
        raise NotFound()
    form = DeleteNewsForm(newsitem)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('admin/news/edit', news_id=news_id)
        elif 'confirm' in request.form and form.validate(request.form):
            title = str(newsitem.title)
            form.delete_news()
            db.commit()
            admin_flash(_('The entry %s was deleted successfully') % title, 'remove')
            return redirect_to('admin/news')

    return render_admin_response('admin/news_delete.html', 'news.edit',
                                 form=form.as_widget())
Exemple #9
0
def delete_level(request, level_id):
    """Deletes a level."""

    level = Level.query.get(level_id)
    if level is None:
        raise NotFound()
    form = DeleteLevelForm(level)

    if request.method == 'POST':
        if request.form.get('cancel'):
            return form.redirect('admin/levels/edit', level_id=level.id)
        elif request.form.get('confirm') and form.validate(request.form):
            levelname = str(level.name)
            form.delete_level()
            db.commit()
            admin_flash(_('The level %s was deleted successfully') % levelname, 'remove')
            return redirect_to('admin/levels')

    return render_admin_response('admin/level_delete.html', 'levelsquad.levels',
                                 form=form.as_widget())
Exemple #10
0
def delete_squad(request, squad_id):
    """Deletes a squad."""

    squad = Squad.query.get(squad_id)
    if squad is None:
        raise NotFound()
    form = DeleteSquadForm(squad)

    if request.method == 'POST':
        if request.form.get('cancel'):
            return form.redirect('admin/squads/edit', squad_id=squad.id)
        elif request.form.get('confirm') and form.validate(request.form):
            squadname = str(squad.name)
            form.delete_squad()
            db.commit()
            admin_flash(_('%s was deleted successfully') % squadname, 'remove')
            return redirect_to('admin/squads')

    return render_admin_response('admin/squad_delete.html', 'gamesquad.squads',
                                 form=form.as_widget())
Exemple #11
0
def delete_game(request, game_id):
    """Deletes a game."""

    game = Game.query.get(game_id)
    if game is None:
        raise NotFound()
    form = DeleteGameForm(game)

    if request.method == 'POST':
        if request.form.get('cancel'):
            return form.redirect('admin/games/edit', game_id=game.id)
        elif request.form.get('confirm') and form.validate(request.form):
            gamename = str(game.name)
            form.delete_game()
            db.commit()
            admin_flash(_('The game %s was deleted successfully') % gamename, 'remove')
            return redirect_to('admin/games')

    return render_admin_response('admin/game_delete.html', 'gamesquad.games',
                                 form=form.as_widget())
Exemple #12
0
def adm_delete_gameaccount(request, account_id):
    """Delete an InGame Account from admin panel"""

    gameaccount = GameAccount.query.get(account_id)
    if gameaccount is None:
        raise NotFound()
    form = DeleteGameAccountForm(gameaccount)

    if request.method == 'POST':
        if request.form.get('cancel'):
            return form.redirect('admin/edit_user', user_id=gameaccount.user.id)
        elif request.form.get('confirm') and form.validate(request.form):
            account = str(gameaccount.account)
            form.delete_account()
            db.commit()
            admin_flash(_('The game account %s was deleted successfully') % account, 'remove')
            return redirect_to('admin/edit_user', user_id=gameaccount.user.id)

    return render_admin_response('admin/gameaccount_delete.html', 'users_groups.users',
                                 form=form.as_widget())
Exemple #13
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)
Exemple #14
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)
Exemple #15
0
def warmode_delete(request, warmode_id=None):
    warmode = None
    if warmode_id is not None:
        warmode = WarMode.query.get(warmode_id)
        if warmode is None:
            raise NotFound()
    form = forms.DeleteWarModeForm(warmode)

    if request.method == 'POST':
        if request.form.get('cancel'):
            return form.redirect('admin/warmodes/edit', warmode_id=warmode_id)
        elif request.form.get('confirm') and form.validate(request.form):
            name = str(warmode.name)
            form.delete_warmode()
            db.commit()
            admin_flash(_('Warmode %s was deleted successfully') % name, 'remove')
            return redirect_to('admin/warmodes')

    return render_admin_response('admin/warmode_delete.html', 'war.modes',
                                 form=form.as_widget())
Exemple #16
0
def edit_squadmember(request, squad_id=None, user_id=None):
    """Edit Squadmemberships"""

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

    squadmember = None
    if user_id is not None:
        squadmember = SquadMember.query.get((user_id,squad_id))
        if squadmember is None:
            raise NotFound()
    form = EditSquadMemberForm(squad, squadmember)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('admin/squadmembers', squad_id=squad_id)
        elif request.form.get('delete') and user_id is not None:
            return redirect_to('admin/squadmembers/delete', squad_id=squad_id, user_id=user_id)
        elif form.validate(request.form):
            if squadmember is None:
                squadmember = form.make_squadmember()
                msg = _('The squadmember %s was created successfully.')
                icon = 'add'
            else:
                form.save_changes()
                msg = _('The squadmember %s was updated successfully.')
                icon = 'info'

            admin_flash(msg % (escape(squadmember.user.display_name)),icon)
            db.commit()
            if 'save_and_continue' in request.form:
                return redirect_to('admin/squadmembers/edit', squad_id=squad_id,
                                   user_id=squadmember.user.id)
            return redirect_to('admin/squadmembers', squad_id=squad_id)
    return render_admin_response('admin/squad_editmember.html', 'gamesquad.squads',
                                 form=form.as_widget(), squad=squad, squadmember=squadmember)
Exemple #17
0
def warmap_edit(request, warmap_id=None):
    """Edit an existing warmap or create a new one."""

    warmap = None
    if warmap_id is not None:
        warmap = WarMap.query.get(warmap_id)
        if warmap is None:
            raise NotFound()
    form = forms.EditWarMapForm(warmap)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('admin/warmaps')
        elif request.form.get('delete') and warmap:
            return redirect_to('admin/warmaps/delete', warmap_id=warmap_id)
        elif form.validate(request.form):
            if warmap is None:
                warmap = form.make_warmap()
                msg = _('Warmap %s was created successfully.')
                icon = 'add'
            else:
                form.save_changes()
                msg = _('Warmap %s was updated successfully.')
                icon = 'info'
            db.commit()

            mapfile = request.files.get('mapfile')
            if mapfile:
                warmap.place_file(mapfile)
                if form.overwrite_mapname and hasattr(warmap.metadata, 'name'):
                    warmap.name = unicode(warmap.metadata.name)
                    db.commit()
            admin_flash(msg % (warmap.name), icon)

            if 'save_and_continue' in request.form:
                return redirect_to('admin/warmaps/edit', warmap_id=warmap.id)
            return redirect_to('admin/warmaps')
    return render_admin_response('admin/warmap_edit.html', 'war.maps',
                                    form=form.as_widget())
Exemple #18
0
def warresult_edit(request, war_id=None):
    war = None
    if war_id is not None:
        war = War.query.get(war_id)
        if war is None:
            raise NotFound()
    else:
        raise NotFound()
    warresult = WarResult.query.get(war_id)
    form = forms.EditWarResultForm(war, warresult)

    if request.method == 'POST':
        if request.form.get('cancel'):
            return form.redirect('admin/wars/edit', war_id=war_id)
        elif request.form.get('delete'):
            if warresult is not None:
                db.delete(warresult)
                db.commit()
                admin_flash(_('The result for %s was deleted successfully') % war.clanname, 'remove')
            return form.redirect('admin/wars/edit', war_id=war_id)
        elif form.validate(request.form):
            if warresult is None:
                warresult = form.make_warresult()
                msg = _('The result for war %s was created successfully.')
                icon = 'add'
            else:
                form.save_changes()
                msg = _('The result for war %s was updated successfully.')
                icon = 'info'

            admin_flash(msg % (war.clanname), icon)

            db.commit()

            if 'save_and_continue' in request.form:
                return redirect_to('admin/warresult_edit', war_id=war_id)
            return redirect_to('admin/wars')
    return render_admin_response('admin/warresult_edit.html', 'war.wars',
                                    form=form.as_widget())
Exemple #19
0
def delete_squadmember(request, squad_id=None, user_id=None):
    """Remove Member from Squad"""

    if squad_id is None or user_id is None:
        raise NotFound()
    member = SquadMember.query.get((user_id, squad_id))
    if member is None:
        raise NotFound()
    form = DeleteSquadMemberForm(member)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('admin/squadmembers/edit', squad_id=squad_id, user_id=user_id)
        elif request.form.get('confirm') and form.validate(request.form):
            membername = str(member.user.display_name)
            squadname = str(member.squad.name)
            form.delete_member()
            db.commit()
            admin_flash(_('Member %s removed from %s') % (membername,  squadname), 'remove')
            return redirect_to('admin/squadmembers', squad_id=squad_id)

    return render_admin_response('admin/squad_deletemember.html', 'gamesquad.squads',
                                 form=form.as_widget())
Exemple #20
0
def edit_news(request, news_id=None):
    """Edit an existing entry or create a new one."""

    newsitem = None
    if news_id is not None:
        newsitem = News.query.get(news_id)
        if newsitem is None:
            raise NotFound()
    form = NewsForm(newsitem)

    if newsitem is None:
        assert_privilege(privileges.NEWS_CREATE)
    else:
        if not newsitem.can_edit(request.user):
            raise Forbidden()

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('admin/news')
        elif 'delete' in request.form:
            return redirect_to('admin/news/delete', news_id=news_id)
        elif form.validate(request.form):
            if newsitem is None:
                newsitem = form.make_news(request.user)
                msg = _('The entry %s was created successfully.')
            else:
                form.save_changes()
                msg = _('The entry %s was updated successfully.')

            admin_flash(msg % (escape(newsitem.title)))

            db.commit()
            if 'save_and_continue' in request.form:
                return redirect_to('admin/news_edit', news_id=newsitem.id)
            return redirect_to('admin/news')
    return render_admin_response('admin/news_edit.html', 'news.edit',
                                 form=form.as_widget())