Редактирование тарифного плана

This commit is contained in:
Vyacheslav Anzhiganov 2016-06-08 02:03:13 +03:00
parent 8176b078c9
commit 966d0c77d6
6 changed files with 122 additions and 25 deletions

View file

@ -73,28 +73,30 @@ def page_not_found(e):
@app.before_request
def before_request():
# app.logger.debug("db.connect")
g.errors = {'total': 0, 'items': []}
g.settings = dict()
try:
database.connect()
except Exception as e:
# TODO: code to email alert
# g.endpoint = request.endpoint.replace('.', '/')
return render_template('errors/500.html'), 500
# извлекаем настройки и определяем их в глобальную переменную
for setting in models.Settings.select(models.Settings.key, models.Settings.val).execute():
g.settings[setting.key] = setting.val
@app.before_first_request
def before_first_request():
try:
database.connect()
except Exception as e:
app.logger.error(e)
# TODO: code to email alert
# g.endpoint = request.endpoint.replace('.', '/')
return render_template('errors/500.html'), 500
@app.after_request
def after_request(response):
# app.logger.debug("db.close")
try:
database.close()
except Exception as e:
# try:
# database.close()
# except Exception as e:
# app.logger.error(e)
# TODO: code to email alert
pass
# pass
return response

View file

@ -3,17 +3,20 @@
{% block content %}
<div class="row">
<div class="large-12 columns">
{% if g.errors['total'] > 0 %}
{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="alert-box alert">
<ul>
{% for error in g.errors['items'] %}<li>{{ error }}</li>{% endfor %}
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endwith %}
<form action="{{ url_for('administrator.login') }}" method="post">
<label for="email">email</lable>
<input type="text" name="email" value="" id="email" />
<label for="password">password</label>
<input type="password" name="password" value="" id="password" />
<input type="submit" value="login" class="button" />

View file

@ -0,0 +1,51 @@
{% extends 'administrator/_layout.auth.html' %}
{% set title="Billing" %}
{% set subtitle="Edit Plan" %}
{% block content %}
<form action="{{ url_for('administrator.plan_edit', plan_id=plan_details.id) }}" method="POST">
<table class="table table-bordered" width="100%">
<tbody>
<tr>
<td>ID</td>
<td><input type="text" name="id" value="{{ plan_details.id }}" disabled /></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" name="name" value="{{ plan_details.name }}" /></td>
</tr>
<tr>
<td>Price</td>
<td><input type="text" name="price" value="{{ plan_details.price }}" /></td>
</tr>
<tr>
<td>Status</td>
<td>
<select name="status">
<option {% if plan_details.status == 'inactive' %}selected{% endif %} >inactive</option>
<option {% if plan_details.status == 'active' %}selected{% endif %} >active</option>
</select>
</td>
</tr>
<tr>
<td>Storage (Mb)</td>
<td><input type="text" name="storage" value="{{ plan_details.storage }}" /></td>
</tr>
<tr>
<td>SWAP (Mb)</td>
<td><input type="text" name="swap" value="{{ plan_details.swap }}" /></td>
</tr>
<tr>
<td>Memory (Mb)</td>
<td><input type="text" name="memory" value="{{ plan_details.memory }}" /></td>
</tr>
<tr>
<td><label for="cores">Cores (int)</label></td>
<td><input type="text" name="cores" id="cores" value="{{ plan_details.cores }}" /></td>
</tr>
</tbody>
</table>
<input type="submit" value="Update" class="button success" />
</form>
{% endblock %}

View file

@ -33,7 +33,7 @@
<td>{{ plan.storage }}</td>
<td>{{ plan.swap }}</td>
<td>{{ plan.memory }}</td>
<td><a href="">Edit</a></td>
<td><a href="{{ url_for('administrator.plan_edit', plan_id=plan.id) }}">Edit</a></td>
</tr>
{% endfor %}
{% endif %}

View file

@ -520,6 +520,10 @@ def json_datacenter_list():
@viewAdministrator.route('/tasks/', methods=['GET'])
def tasks_index():
# check session
if not ControllerAdministrators().check_session():
return redirect(url_for("administrator.logout"))
return render_template(
'administrator/tasks/index.html',
# tasks=ControllerManageTasks().get_by_server().get()
@ -529,6 +533,10 @@ def tasks_index():
@viewAdministrator.route('/plans/', methods=['GET'])
def plans_index():
# check session
if not ControllerAdministrators().check_session():
return redirect(url_for("administrator.logout"))
return render_template(
'administrator/plans/index.html',
plans=ControllerPlans().get()
@ -537,6 +545,10 @@ def plans_index():
@viewAdministrator.route('/plans/create.html', methods=['GET', 'POST'])
def plans_create():
# check session
if not ControllerAdministrators().check_session():
return redirect(url_for("administrator.logout"))
if request.method == "POST":
plan_id = str(uuid4())
models.PlansVMs.create(
@ -553,3 +565,32 @@ def plans_create():
flash('Plan has been created')
return redirect(url_for('administrator.plans_index'))
return render_template('administrator/plans/create.html')
@viewAdministrator.route('/plans/<uuid:plan_id>/edit.html', methods=['GET', 'POST'])
def plan_edit(plan_id):
# check session
if not ControllerAdministrators().check_session():
return redirect(url_for("administrator.logout"))
# check exists plan
if models.PlansVMs.select().where(models.PlansVMs.id == plan_id).count() == 0:
return redirect(url_for('administrator.plans_index'))
if request.method == 'POST':
x = models.PlansVMs.get(models.PlansVMs.id == plan_id)
x.name = request.form.get('name')
x.status = request.form.get('status')
x.price = request.form.get('price')
x.storage = request.form.get('storage')
x.swap = request.form.get('swap')
x.memory = request.form.get('memory')
x.cores = request.form.get('cores')
x.save()
return redirect(url_for('administrator.plans_index'))
return render_template(
'administrator/plans/edit.html',
plan_details=models.PlansVMs.select().where(models.PlansVMs.id == plan_id).get()
)

View file

@ -4,7 +4,7 @@ from setuptools import setup
setup(
name='SWSCloudCore',
version='2.4.10',
version='2.4.11',
author='Vyacheslav Anzhiganov',
author_email='hello@anzhiganov.com',
packages=[