Esempio n. 1
0
def users_edit(id):
    user = User.query.get(id)
    form = UserForm(obj=user)

    invoices = Invoice.billing_history(current_user)
    if current_user.subscription:
        upcoming = Invoice.upcoming(current_user.payment_id)
        coupon = Coupon.query \
            .filter(Coupon.code == current_user.subscription.coupon).first()
    else:
        upcoming = None
        coupon = None

    if form.validate_on_submit():
        if User.is_last_admin(user, request.form.get('role'),
                              request.form.get('active')):
            flash('You are the last admin, you cannot do that.', 'error')
            return redirect(url_for('admin.users'))

        form.populate_obj(user)

        if not user.username:
            user.username = None

        user.save()

        flash('User has been saved successfully.', 'success')
        return redirect(url_for('admin.users'))

    return render_template('admin/user/edit.html',
                           form=form,
                           user=user,
                           invoices=invoices,
                           upcoming=upcoming,
                           coupon=coupon)
Esempio n. 2
0
def billing_details():
    invoices = Invoice.billing_history(current_user)

    if current_user.subscription:
        upcoming = Invoice.upcoming(current_user.payment_id)
        coupon = Coupon.query \
            .filter(Coupon.code == current_user.subscription.coupon).first()
    else:
        upcoming = None
        coupon = None

    return render_template('billing/billing_details.html',
                           invoices=invoices,
                           upcoming=upcoming,
                           coupon=coupon)