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 flask_sqlalchemy import get_debug_queries
from . import admin from . import admin
from .forms import ChargeForm
from .. import db from .. import db
from ..email import send_email from ..email import send_email
from ..models import User, Role, Deployment, Service, Region, Address, Domain, contact_proxmaster from ..models import User, Role, Deployment, Service, Region, Address, Domain, contact_proxmaster
@ -29,10 +31,23 @@ def after_request(response):
@admin.route("/", methods=['GET']) @admin.route("/", methods=['GET'])
@login_required @login_required
@admin_required @admin_required
def index(): def users():
allusers = User.query.all() allusers = User.query.order_by(User.pid.asc()).all()
return render_template('admin/users.html', users=allusers) 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']) @admin.route("/dashboard/<int:user_pid>", methods=['GET', 'POST'])
@login_required @login_required
@admin_required @admin_required

View file

@ -3,10 +3,6 @@
{% block title %}Зареждане на сметка{% endblock %} {% block title %}Зареждане на сметка{% endblock %}
{% block page_content %} {% block page_content %}
<div class="page-header">
<h1>Фактуриране</h1>
</div>
<div class="container-fluid"> <div class="container-fluid">
<br /> <br />
<div class="row"> <div class="row">
@ -19,10 +15,10 @@
<div class="panel panel-info"> <div class="panel panel-info">
<div class="panel-heading">Зареждане на сметка</div> <div class="panel-heading">Зареждане на сметка</div>
<div class="panel-body"> <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> <p>
{{ form.invoice_amount.label }} {{ form.invoice_amount }}<br /> {{ form.charge_amount.label }} {{ form.charge_amount }}<br />
{% for error in form.invoice_amount.errors %} {% for error in form.charge_amount.errors %}
{{ error }}<br /> {{ error }}<br />
{% endfor %} {% endfor %}
</p> </p>

View file

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

View file

@ -1,8 +1,40 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block page_content %} {% block page_content %}
<center>
<div class="row"> <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> </div>
{% endblock %} {% endblock %}

View file

@ -7,10 +7,6 @@ from wtforms import StringField, PasswordField, BooleanField, SubmitField, Selec
from wtforms import validators, ValidationError from wtforms import validators, ValidationError
from wtforms.fields.html5 import EmailField 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): class PaymentForm(FlaskForm):
plist = [('paypal', 'PayPal'), ('epay', 'ePay.bg'), ('bank', 'Bank Transfer')] plist = [('paypal', 'PayPal'), ('epay', 'ePay.bg'), ('bank', 'Bank Transfer')]
processor = SelectField('Финансов инструмент:', choices=plist) 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 sqlalchemy import desc
from . import uinvoice from . import uinvoice
from .forms import ChargeForm, PaymentForm from .forms import PaymentForm
from ..email import send_email from ..email import send_email
from .. import db from .. import db

View file

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