Ejemplo 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)
Ejemplo n.º 2
0
    def test_invoice_upcoming(self, mock_stripe):
        """ Parse out the data correctly from a Stripe invoice payload. """
        parsed_payload = Invoice.upcoming('cus_000')

        next_bill_on = datetime.datetime(2015, 5, 30, 20, 46, 10)

        assert parsed_payload['plan'] == 'Gold'
        assert parsed_payload['description'] == 'GOLD MONTHLY'
        assert parsed_payload['next_bill_on'] == next_bill_on
        assert parsed_payload['amount_due'] == 500
        assert parsed_payload['interval'] == 'month'
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def billing_details(page):
    paginated_invoices = Invoice.query.filter(
      Invoice.user_id == current_user.id) \
        .order_by(Invoice.created_on.desc()).paginate(page, 12, True)

    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',
                           paginated_invoices=paginated_invoices,
                           upcoming=upcoming,
                           coupon=coupon)