deallocate
This commit is contained in:
parent
32a17decd7
commit
0415b7efb9
|
@ -38,7 +38,14 @@ def upgrade():
|
||||||
schema=f'{get_inv()}'
|
schema=f'{get_inv()}'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Deallocate action
|
||||||
op.drop_table('deallocate', schema=f'{get_inv()}')
|
op.drop_table('deallocate', schema=f'{get_inv()}')
|
||||||
|
op.create_table('deallocate',
|
||||||
|
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
schema=f'{get_inv()}'
|
||||||
|
)
|
||||||
|
|
||||||
# Add allocate as a column in device
|
# Add allocate as a column in device
|
||||||
op.add_column('device', sa.Column('allocated', sa.Boolean(), nullable=True), schema=f'{get_inv()}')
|
op.add_column('device', sa.Column('allocated', sa.Boolean(), nullable=True), schema=f'{get_inv()}')
|
||||||
|
|
|
@ -312,13 +312,18 @@ class Remove(ActionWithOneDevice):
|
||||||
|
|
||||||
|
|
||||||
class Allocate(JoinedTableMixin, ActionWithMultipleDevices):
|
class Allocate(JoinedTableMixin, ActionWithMultipleDevices):
|
||||||
"""The act of assigned one list of devices to one person of the system or not
|
"""The act of allocate one list of devices to one person
|
||||||
"""
|
"""
|
||||||
code = Column(CIText(), default='', nullable=True)
|
code = Column(CIText(), default='', nullable=True)
|
||||||
code.comment = """ This is a internal code for mainteing the secrets of the personal datas of the new holder """
|
code.comment = """ This is a internal code for mainteing the secrets of the personal datas of the new holder """
|
||||||
end_users = Column(Numeric(precision=4), check_range('end_users', 0), nullable=False)
|
end_users = Column(Numeric(precision=4), check_range('end_users', 0), nullable=False)
|
||||||
|
|
||||||
|
|
||||||
|
class Deallocate(JoinedTableMixin, ActionWithMultipleDevices):
|
||||||
|
"""The act of deallocate one list of devices to one person of the system or not
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
class EraseBasic(JoinedWithOneDeviceMixin, ActionWithOneDevice):
|
class EraseBasic(JoinedWithOneDeviceMixin, ActionWithOneDevice):
|
||||||
"""An erasure attempt to a ``DataStorage``. The action contains
|
"""An erasure attempt to a ``DataStorage``. The action contains
|
||||||
information about success and nature of the erasure.
|
information about success and nature of the erasure.
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
from typing import Callable, Iterable, Tuple
|
|
||||||
from ereuse_devicehub.resources.action import schemas
|
from ereuse_devicehub.resources.action import schemas
|
||||||
from teal.resource import Resource
|
from teal.resource import Resource
|
||||||
from ereuse_devicehub.resources.allocate.views import AllocateView
|
from ereuse_devicehub.resources.allocate.views import AllocateView, DeallocateView
|
||||||
|
|
||||||
|
|
||||||
class AssignedDef(Resource):
|
class AllocateDef(Resource):
|
||||||
VIEW = AllocateView
|
VIEW = AllocateView
|
||||||
SCHEMA = schemas.Allocate
|
SCHEMA = schemas.Allocate
|
||||||
|
AUTH = True
|
||||||
|
|
||||||
|
class DeallocateDef(Resource):
|
||||||
|
VIEW = DeallocateView
|
||||||
|
SCHEMA = schemas.Deallocate
|
||||||
|
AUTH = True
|
||||||
|
|
|
@ -1,43 +1,39 @@
|
||||||
import uuid
|
|
||||||
# from typing import Callable, Iterable, Tuple
|
|
||||||
from flask import g, request
|
from flask import g, request
|
||||||
# from flask.json import jsonify
|
|
||||||
from teal.resource import View
|
from teal.resource import View
|
||||||
|
|
||||||
from ereuse_devicehub import auth
|
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.query import things_response
|
from ereuse_devicehub.query import things_response
|
||||||
from ereuse_devicehub.resources.action.models import Allocate
|
from ereuse_devicehub.resources.action.models import Allocate, Deallocate
|
||||||
|
|
||||||
|
|
||||||
class AllocateView(View):
|
class AllocateMix():
|
||||||
@auth.Auth.requires_auth
|
model = None
|
||||||
def get(self, id: uuid.UUID) -> Allocate:
|
|
||||||
return super().get(id)
|
|
||||||
|
|
||||||
@auth.Auth.requires_auth
|
|
||||||
def post(self):
|
def post(self):
|
||||||
""" Create one allocate """
|
""" Create one res_obj """
|
||||||
res_json = request.get_json()
|
res_json = request.get_json()
|
||||||
allocate = Allocate(**res_json)
|
res_obj = model(**res_json)
|
||||||
db.session.add(allocate)
|
db.session.add(res_obj)
|
||||||
db.session().final_flush()
|
db.session().final_flush()
|
||||||
ret = self.schema.jsonify(allocate)
|
ret = self.schema.jsonify(res_obj)
|
||||||
ret.status_code = 201
|
ret.status_code = 201
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def find(self, args: dict):
|
def find(self, args: dict):
|
||||||
allocates = Allocate.query.filter_by(author=g.user) \
|
res_objs = model.query.filter_by(author=g.user) \
|
||||||
.order_by(Allocate.created.desc()) \
|
.order_by(model.created.desc()) \
|
||||||
.paginate(per_page=200)
|
.paginate(per_page=200)
|
||||||
return things_response(
|
return things_response(
|
||||||
self.schema.dump(allocates.items, many=True, nested=0),
|
self.schema.dump(res_objs.items, many=True, nested=0),
|
||||||
allocates.page, allocates.per_page, allocates.total,
|
res_objs.page, res_objs.per_page, res_objs.total,
|
||||||
allocates.prev_num, allocates.next_num
|
res_objs.prev_num, res_objs.next_num
|
||||||
)
|
)
|
||||||
|
|
||||||
def one(self, id: uuid.UUID):
|
|
||||||
"""Gets one action."""
|
class AllocateView(AllocateMix):
|
||||||
allocate = Allocate.query.filter_by(id=id, author=g.user).one()
|
model = Allocate
|
||||||
return self.schema.jsonify(allocate, nested=2)
|
|
||||||
|
|
||||||
|
class DeallocateView(AllocateMix):
|
||||||
|
model = Deallocate
|
||||||
|
|
Reference in New Issue