fix recycle bin

This commit is contained in:
deflax 2017-09-24 20:24:11 +03:00
parent 379f7be272
commit ddd07804ee
4 changed files with 29 additions and 16 deletions

View file

@ -56,14 +56,14 @@ def list_domains():
alldomains = Domain.query.filter_by(cancelled=False).order_by(Domain.daysleft.asc()).all() alldomains = Domain.query.filter_by(cancelled=False).order_by(Domain.daysleft.asc()).all()
return render_template('admin/list_domains.html', domains=alldomains) return render_template('admin/list_domains.html', domains=alldomains)
@admin.route("/listcancelled", methods=['GET']) @admin.route("/listrecyclebin", methods=['GET'])
@login_required @login_required
@admin_required @admin_required
def list_cancelled(): def list_recyclebin():
expdeployments = Deployment.query.filter_by(cancelled=True).all() deployments = Deployment.query.filter_by(protected=False).order_by(Deployment.daysleft.asc()).all()
expservices = Service.query.filter_by(cancelled=True).all() services = Service.query.filter_by(cancelled=True).all()
expdomains = Domain.query.filter_by(cancelled=True).all() domains = Domain.query.filter_by(cancelled=True).all()
return render_template('admin/list_cancelled.html', deployments=expdeployments, services=expservices, domains=expdomains) return render_template('admin/list_recyclebin.html', deployments=deployments, services=services, domains=domains)
@admin.route("/listaddresses", methods=['GET']) @admin.route("/listaddresses", methods=['GET'])
@login_required @login_required

View file

@ -6,7 +6,7 @@
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_deployments') }}','_self')"><span class="glyphicon glyphicon-hdd" aria-hidden="true"></span> Deployments</button> <button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_deployments') }}','_self')"><span class="glyphicon glyphicon-hdd" aria-hidden="true"></span> Deployments</button>
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_services') }}','_self')"><span class="glyphicon glyphicon-star" aria-hidden="true"></span> Services</button> <button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_services') }}','_self')"><span class="glyphicon glyphicon-star" aria-hidden="true"></span> Services</button>
<button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_domains') }}','_self')"><span class="glyphicon glyphicon-home" aria-hidden="true"></span> Domains</button> <button class="btn btn-success btn-md" onclick="window.open('{{ url_for('admin.list_domains') }}','_self')"><span class="glyphicon glyphicon-home" aria-hidden="true"></span> Domains</button>
<button class="btn btn-danger btn-md" onclick="window.open('{{ url_for('admin.list_cancelled') }}', '_self')"><span class="glyphicon glyphicon-cd" aria-hidden="true"></span> Recycle Bin</button> <button class="btn btn-danger btn-md" onclick="window.open('{{ url_for('admin.list_recyclebin') }}', '_self')"><span class="glyphicon glyphicon-cd" aria-hidden="true"></span> Recycle Bin</button>
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_users') }}','_self')"><span class="glyphicon glyphicon-user" aria-hidden="true"></span> Users</button> <button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_users') }}','_self')"><span class="glyphicon glyphicon-user" aria-hidden="true"></span> Users</button>
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_transactions') }}','_self')"><span class="glyphicon glyphicon-usd" aria-hidden="true"></span> Transactions</button> <button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_transactions') }}','_self')"><span class="glyphicon glyphicon-usd" aria-hidden="true"></span> Transactions</button>
<button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_addresses') }}','_self')"><span class="glyphicon glyphicon-tag" aria-hidden="true"></span> Addresses</button> <button class="btn btn-primary btn-md" onclick="window.open('{{ url_for('admin.list_addresses') }}','_self')"><span class="glyphicon glyphicon-tag" aria-hidden="true"></span> Addresses</button>

View file

@ -74,6 +74,9 @@ addEventListener("DOMContentLoaded", function() {
</thead> </thead>
<tbody> <tbody>
{% for deploy in deployments %} {% for deploy in deployments %}
{% if deploy.cancelled == True %}
<tr class="active">
{% else %}
{% if deploy.enabled == False %} {% if deploy.enabled == False %}
<tr class="danger"> <tr class="danger">
{% else %} {% else %}
@ -83,15 +86,24 @@ addEventListener("DOMContentLoaded", function() {
<tr> <tr>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endif %}
<td><a href="{{ url_for('admin.dashboard', user_pid=deploy.user_id) }}">{{ deploy.owner.email }}</a></td> <td><a href="{{ url_for('admin.dashboard', user_pid=deploy.user_id) }}">{{ deploy.owner.email }}</a></td>
<td>{{ deploy.machine_id }}</td> <td>{{ deploy.machine_id }}</td>
<td>{{ deploy.machine_alias }}</font></td> <td>{{ deploy.machine_alias }}</font></td>
<td>{{ deploy.machine_cpu }}</td> <td>{{ deploy.machine_cpu }}</td>
<td>{{ deploy.machine_mem }} MB</td> <td>{{ deploy.machine_mem }} MB</td>
<td>{{ deploy.machine_hdd }} GB</td> <td>{{ deploy.machine_hdd }} GB</td>
{% if deploy.date_last_charge == None %}
<td>Never</td>
{% else %}
<td>{{ moment(deploy.date_last_charge).format('lll') }} ({{ moment(deploy.date_last_charge).fromNow() }})</td> <td>{{ moment(deploy.date_last_charge).format('lll') }} ({{ moment(deploy.date_last_charge).fromNow() }})</td>
{% endif %}
<td>{{ deploy.daysleft }}</td> <td>{{ deploy.daysleft }}</td>
<td><button class="btn btn-default btn-danger" onclick="window.open('/vmanager/vmremove/{{ deploy.machine_id }}');"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</button></td> {% if deploy.cancelled == True %}
<td>-deleted-</td>
{% else %}
<td><button class="btn btn-default btn-danger" onclick="location.reload();location.href='/vmanager/vmremove/{{ deploy.machine_id }}'"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</button></td>
{% endif %}
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>

View file

@ -76,15 +76,16 @@ def createvm():
@login_required @login_required
def remove(itemid=0): def remove(itemid=0):
data = {} data = {}
result = Deployment.query.filter_by(machine_id=int(itemid)).first() deploy = Deployment.query.filter_by(machine_id=int(itemid)).first()
if current_user.is_administrator(): if current_user.is_administrator():
try: try:
query = contact_proxmaster(data, 'vmremove', int(itemid)) query = contact_proxmaster(data, 'vmremove', int(itemid))
flash('Machine {} terminated'.format(itemid)) flash('Machine {} terminated'.format(itemid))
deploy.cancelled = True
db.session.commit()
except: except:
flash('Cannot delete machine {}'.format(itemid)) flash('Cannot delete machine {}'.format(itemid))
return redirect(url_for('admin.list_cancelled')) return redirect(url_for('admin.list_recyclebin'))
abort(404) abort(404)
@vmanager.route('/activate/<int:itemid>', methods=['GET', 'POST']) @vmanager.route('/activate/<int:itemid>', methods=['GET', 'POST'])