admin charge page

This commit is contained in:
deflax 2017-06-04 18:22:59 +03:00
parent bf775e658e
commit 16f73f33c2
8 changed files with 72 additions and 15 deletions

13
app/admin/forms.py Normal file
View file

@ -0,0 +1,13 @@
import string
import random
from ..models import User, Role
from flask_wtf import FlaskForm, RecaptchaField
from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, DecimalField
from wtforms import validators, ValidationError
from wtforms.fields.html5 import EmailField
class ChargeForm(FlaskForm):
amount = DecimalField('Стойност:', [validators.DataRequired(), validators.NumberRange(min=0, max=6)])
submit = SubmitField('Зареди')

View file

@ -3,6 +3,8 @@ from flask_login import login_required, login_user, logout_user
from flask_sqlalchemy import get_debug_queries
from . import admin
from .forms import ChargeForm
from .. import db
from ..email import send_email
from ..models import User, Role, Deployment, Service, Region, Address, Domain, contact_proxmaster
@ -29,10 +31,23 @@ def after_request(response):
@admin.route("/", methods=['GET'])
@login_required
@admin_required
def index():
allusers = User.query.all()
def users():
allusers = User.query.order_by(User.pid.asc()).all()
return render_template('admin/users.html', users=allusers)
@admin.route("/charge/<int:user_pid>", methods=['GET', 'POST'])
@login_required
@admin_required
def charge(user_pid=0):
cuser = User.query.filter_by(pid=user_pid).first()
form = ChargeForm()
if form.validate_on_submit():
cuser.wallet += form.amount.data
db.session.add(cuser)
db.session.commit()
return redirect(url_for('admin.users'))
return render_template('admin/charge.html', form=form, usr=cuser)
@admin.route("/dashboard/<int:user_pid>", methods=['GET', 'POST'])
@login_required
@admin_required

View file

@ -3,10 +3,6 @@
{% block title %}Зареждане на сметка{% endblock %}
{% block page_content %}
<div class="page-header">
<h1>Фактуриране</h1>
</div>
<div class="container-fluid">
<br />
<div class="row">
@ -19,10 +15,10 @@
<div class="panel panel-info">
<div class="panel-heading">Зареждане на сметка</div>
<div class="panel-body">
<form method="POST" action="{{ url_for('uinvoice.charge') }}">
<form method="POST" action="{{ url_for('admin.charge', user_pid=usr.pid) }}">
<p>
{{ form.invoice_amount.label }} {{ form.invoice_amount }}<br />
{% for error in form.invoice_amount.errors %}
{{ form.charge_amount.label }} {{ form.charge_amount }}<br />
{% for error in form.charge_amount.errors %}
{{ error }}<br />
{% endfor %}
</p>

View file

@ -119,6 +119,8 @@ addEventListener("DOMContentLoaded", function() {
<br />
<div class="row">
<a href="{{ url_for('admin.users') }}">Return to user list</a><br />
<div class="col-md-12">
<div class="panel panel-danger" id="deployments">
<div class="panel-heading">Deployments</div>
@ -244,6 +246,8 @@ addEventListener("DOMContentLoaded", function() {
</div>
</div>
<a href="{{ url_for('admin.users') }}">Return to user list</a><br />
</div>

View file

@ -1,8 +1,40 @@
{% extends "base.html" %}
{% block page_content %}
<center>
<div class="row">
<div class="col-md-12">
<div class="panel panel-danger" id="users">
<div class="panel-heading">Users</div>
<div class="panel-body"><p>
<table class="table table-hover table-striped table-condensed cf">
<thead>
<tr>
<td>id</td>
<td>email</td>
<td>last seen</td>
<td>last ip</td>
<td>wallet</td>
<td>cntrl</td>
</tr>
</thead>
<tbody>
{% for usr in users %}
<tr>
<td>{{ usr.pid }}</td>
<td>{{ usr.email }}</td>
<td>{{ moment(usr.last_seen).fromNow()}}</td>
<td>{{ usr.last_ip }}</td>
<td><a href="{{ url_for('admin.charge', user_pid=usr.pid) }}">{{ usr.wallet }}</a></td>
<td><a href="{{ url_for('admin.dashboard', user_pid=usr.pid) }}">Inventory</a></td>
</td>
{% endfor %}
</tbody>
<table>
</div>
</div>
</div>
</div>
{% endblock %}

View file

@ -7,10 +7,6 @@ from wtforms import StringField, PasswordField, BooleanField, SubmitField, Selec
from wtforms import validators, ValidationError
from wtforms.fields.html5 import EmailField
class ChargeForm(FlaskForm):
invoice_amount = DecimalField('Стойност:', [validators.DataRequired(), validators.NumberRange(min=0, max=6)])
submit = SubmitField('Зареди')
class PaymentForm(FlaskForm):
plist = [('paypal', 'PayPal'), ('epay', 'ePay.bg'), ('bank', 'Bank Transfer')]
processor = SelectField('Финансов инструмент:', choices=plist)

View file

@ -3,7 +3,7 @@ from flask_login import login_required, login_user, logout_user, current_user
from sqlalchemy import desc
from . import uinvoice
from .forms import ChargeForm, PaymentForm
from .forms import PaymentForm
from ..email import send_email
from .. import db

View file

@ -122,6 +122,7 @@ def deploy(product_id=None):
@vmanager.route("/dashboard", methods=['GET', 'POST'])
@login_required
def dashboard():
cuser = current_user
deployments = cuser.inv_deployments.order_by(Deployment.date_created.desc()).all()
inv_deploycubeids = []
inv_deploynames = []