setup kangaroo server
This commit is contained in:
parent
14a4e2f868
commit
6b173de5a8
|
@ -296,6 +296,8 @@ class BindingView(GenericMixin):
|
||||||
self.real_phid = self.new_placeholder.phid
|
self.real_phid = self.new_placeholder.phid
|
||||||
self.abstract_dhid = self.old_device.devicehub_id
|
self.abstract_dhid = self.old_device.devicehub_id
|
||||||
self.abstract_phid = self.old_placeholder.phid
|
self.abstract_phid = self.old_placeholder.phid
|
||||||
|
if self.old_placeholder.kangaroo:
|
||||||
|
self.new_placeholder.kangaroo = True
|
||||||
|
|
||||||
# to do a backup of abstract_dhid and abstract_phid in
|
# to do a backup of abstract_dhid and abstract_phid in
|
||||||
# workbench device
|
# workbench device
|
||||||
|
@ -383,6 +385,9 @@ class UnBindingView(GenericMixin):
|
||||||
if device.binding.is_abstract:
|
if device.binding.is_abstract:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
kangaroo = device.binding.kangaroo
|
||||||
|
device.binding.kangaroo = False
|
||||||
|
|
||||||
dict_device = copy.copy(device.__dict__)
|
dict_device = copy.copy(device.__dict__)
|
||||||
dict_device.pop('_sa_instance_state')
|
dict_device.pop('_sa_instance_state')
|
||||||
dict_device.pop('id', None)
|
dict_device.pop('id', None)
|
||||||
|
@ -402,7 +407,10 @@ class UnBindingView(GenericMixin):
|
||||||
if c.binding:
|
if c.binding:
|
||||||
c.binding.device.parent = new_device
|
c.binding.device.parent = new_device
|
||||||
|
|
||||||
placeholder = Placeholder(device=new_device, binding=device, is_abstract=True)
|
placeholder = Placeholder(
|
||||||
|
device=new_device, binding=device, is_abstract=True, kangaroo=kangaroo
|
||||||
|
)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
device.dhid_bk
|
device.dhid_bk
|
||||||
and not Device.query.filter_by(devicehub_id=device.dhid_bk).first()
|
and not Device.query.filter_by(devicehub_id=device.dhid_bk).first()
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
"""add kangaroo in placeholder
|
||||||
|
|
||||||
|
Revision ID: a13ed6ad0e3e
|
||||||
|
Revises: 626c17026ca7
|
||||||
|
Create Date: 2022-10-13 11:56:15.303218
|
||||||
|
|
||||||
|
"""
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from alembic import context, op
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'a13ed6ad0e3e'
|
||||||
|
down_revision = '626c17026ca7'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def get_inv():
|
||||||
|
INV = context.get_x_argument(as_dictionary=True).get('inventory')
|
||||||
|
if not INV:
|
||||||
|
raise ValueError("Inventory value is not specified")
|
||||||
|
return INV
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.add_column(
|
||||||
|
'placeholder',
|
||||||
|
sa.Column('kangaroo', sa.Boolean(), nullable=True),
|
||||||
|
schema=f'{get_inv()}',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_column('placeholder', 'kangaroo', schema=f'{get_inv()}')
|
|
@ -932,6 +932,7 @@ class Placeholder(Thing):
|
||||||
)
|
)
|
||||||
id_device_internal = db.Column(CIText())
|
id_device_internal = db.Column(CIText())
|
||||||
id_device_internal.comment = "Identification used internaly for the user"
|
id_device_internal.comment = "Identification used internaly for the user"
|
||||||
|
kangaroo = db.Column(Boolean, default=False, nullable=True)
|
||||||
|
|
||||||
device_id = db.Column(
|
device_id = db.Column(
|
||||||
BigInteger,
|
BigInteger,
|
||||||
|
|
|
@ -11,6 +11,62 @@
|
||||||
</div><!-- End Page Title -->
|
</div><!-- End Page Title -->
|
||||||
|
|
||||||
<section class="section profile">
|
<section class="section profile">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-6">
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
|
||||||
|
<div class="pt-6 pb-2">
|
||||||
|
<div class="row pt-3">
|
||||||
|
<div class="col">
|
||||||
|
<form method="post">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">PHID</th>
|
||||||
|
<th scope="col" class="text-center">Erasure Host</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for host in form.kangaroos %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ host.phid }}</td>
|
||||||
|
<td class="text-center">
|
||||||
|
<a href="{{ url_for('workbench.erasure_host', id=host.id) }}"><i class="bi bi-x-lg"></i></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
{% for f in form %}
|
||||||
|
{{ f }}
|
||||||
|
{% if f == form.phid and f.errors %}
|
||||||
|
<p class="text-danger">
|
||||||
|
{% for error in f.errors %}
|
||||||
|
{{ error }}<br/>
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
|
<td class="text-center">
|
||||||
|
<input type="submit" class="btn btn-primary" value="Add new host" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xl-6">
|
<div class="col-xl-6">
|
||||||
|
|
||||||
|
|
|
@ -3,34 +3,43 @@ import time
|
||||||
import flask
|
import flask
|
||||||
from flask import Blueprint
|
from flask import Blueprint
|
||||||
from flask import current_app as app
|
from flask import current_app as app
|
||||||
from flask import g, make_response, request
|
from flask import g, make_response, request, url_for
|
||||||
|
from flask.views import View
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
from ereuse_devicehub import auth
|
from ereuse_devicehub import auth
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
|
from ereuse_devicehub.resources.device.models import Placeholder
|
||||||
from ereuse_devicehub.resources.enums import SessionType
|
from ereuse_devicehub.resources.enums import SessionType
|
||||||
from ereuse_devicehub.resources.user.models import Session
|
from ereuse_devicehub.resources.user.models import Session
|
||||||
from ereuse_devicehub.views import GenericMixin
|
from ereuse_devicehub.views import GenericMixin
|
||||||
from ereuse_devicehub.workbench import isos
|
from ereuse_devicehub.workbench import isos
|
||||||
|
from ereuse_devicehub.workbench.forms import KangarooForm
|
||||||
|
|
||||||
workbench = Blueprint('workbench', __name__, url_prefix='/workbench')
|
workbench = Blueprint('workbench', __name__, url_prefix='/workbench')
|
||||||
|
|
||||||
|
|
||||||
class SettingsView(GenericMixin):
|
class SettingsView(GenericMixin):
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
|
methods = ['GET', 'POST']
|
||||||
template_name = 'workbench/settings.html'
|
template_name = 'workbench/settings.html'
|
||||||
page_title = "Workbench"
|
page_title = "Workbench"
|
||||||
|
|
||||||
def dispatch_request(self):
|
def dispatch_request(self):
|
||||||
self.get_context()
|
self.get_context()
|
||||||
|
form_kangaroo = KangarooForm()
|
||||||
self.context.update(
|
self.context.update(
|
||||||
{
|
{
|
||||||
'page_title': self.page_title,
|
'page_title': self.page_title,
|
||||||
'demo': g.user.email == app.config['EMAIL_DEMO'],
|
'demo': g.user.email == app.config['EMAIL_DEMO'],
|
||||||
'iso': isos,
|
'iso': isos,
|
||||||
|
'form': form_kangaroo,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if form_kangaroo.validate_on_submit():
|
||||||
|
form_kangaroo.save()
|
||||||
|
|
||||||
self.opt = request.values.get('opt')
|
self.opt = request.values.get('opt')
|
||||||
if self.opt in ['register', 'erease_basic', 'erease_sectors']:
|
if self.opt in ['register', 'erease_basic', 'erease_sectors']:
|
||||||
return self.download()
|
return self.download()
|
||||||
|
@ -86,4 +95,24 @@ class SettingsView(GenericMixin):
|
||||||
return token
|
return token
|
||||||
|
|
||||||
|
|
||||||
|
class ErasureHostView(View):
|
||||||
|
decorators = [login_required]
|
||||||
|
methods = ['GET']
|
||||||
|
|
||||||
|
def dispatch_request(self, id):
|
||||||
|
self.placeholder = (
|
||||||
|
Placeholder.query.filter(Placeholder.id == id)
|
||||||
|
.filter(Placeholder.kangaroo.is_(True))
|
||||||
|
.filter(Placeholder.owner_id == g.user.id)
|
||||||
|
.one()
|
||||||
|
)
|
||||||
|
self.placeholder.kangaroo = False
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return flask.redirect(url_for('workbench.settings'))
|
||||||
|
|
||||||
|
|
||||||
workbench.add_url_rule('/', view_func=SettingsView.as_view('settings'))
|
workbench.add_url_rule('/', view_func=SettingsView.as_view('settings'))
|
||||||
|
workbench.add_url_rule(
|
||||||
|
'/erasure_host/<int:id>/', view_func=ErasureHostView.as_view('erasure_host')
|
||||||
|
)
|
||||||
|
|
Reference in New Issue