Example #1
0
def gameaccount_edit(request, account_id=None):
    """Edit an existing game account or create a new one."""

    gameaccount = None
    if account_id is not None:
        gameaccount = GameAccount.query.get(account_id)
        if gameaccount is None:
            raise NotFound()
    form = EditGameAccountForm(request.user, gameaccount)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('account/gameaccounts')
        elif request.form.get('delete') and gameaccount:
            return redirect_to('account/gameaccounts/delete', account_id=account_id)
        elif form.validate(request.form):
            if gameaccount is None:
                gameaccount = form.make_gameaccount()
                msg = _('The game account %s was registered successfully.')
                icon = 'add'
            else:
                form.save_changes()
                msg = _('The game account %s was updated successfully.')
                icon = 'info'
            account_flash(msg % (escape(gameaccount.account)), icon)

            db.commit()
            if 'save_and_continue' in request.form:
                return redirect_to('account/gameaccounts/edit', account_id=gameaccount.id)
            return redirect_to('account/gameaccounts')
    return render_account_response('account/gameaccount_edit.html', 'gameaccounts',
                                    form=form.as_widget())
Example #2
0
def gameaccount_list(request, page):
    """List all registered gameaccounts"""
    gameaccounts = GameAccount.query.filter_by(user=request.user).limit(PER_PAGE).offset(PER_PAGE * (page - 1)).all()
    pagination = AdminPagination('account/gameaccounts', page, PER_PAGE,
                                 GameAccount.query.filter_by(user=request.user).count())
    if not gameaccounts and page != 1:
        raise NotFound()

    return render_account_response('account/gameaccount_list.html', 'gameaccounts',
                                   gameaccounts=gameaccounts, pagination=pagination)
Example #3
0
def acc_delete_gameaccount(request, account_id):
    """Delete an InGame Account from user-account panel"""

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

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

    return render_account_response('account/gameaccount_delete.html', 'gameaccounts',
                                   form=form.as_widget())