change Mixin clases
This commit is contained in:
parent
37c43fe3d1
commit
b309cc4410
|
@ -15,7 +15,7 @@ from ereuse_devicehub.parser.models import SnapshotErrors
|
||||||
from ereuse_devicehub.parser.parser import ParseSnapshotLsHw
|
from ereuse_devicehub.parser.parser import ParseSnapshotLsHw
|
||||||
from ereuse_devicehub.parser.schemas import Snapshot_lite
|
from ereuse_devicehub.parser.schemas import Snapshot_lite
|
||||||
from ereuse_devicehub.resources.action.views.snapshot import (
|
from ereuse_devicehub.resources.action.views.snapshot import (
|
||||||
SnapshotMix,
|
SnapshotMixin,
|
||||||
move_json,
|
move_json,
|
||||||
save_json,
|
save_json,
|
||||||
)
|
)
|
||||||
|
@ -24,7 +24,7 @@ from ereuse_devicehub.resources.enums import Severity
|
||||||
api = Blueprint('api', __name__, url_prefix='/api')
|
api = Blueprint('api', __name__, url_prefix='/api')
|
||||||
|
|
||||||
|
|
||||||
class LoginMix(View):
|
class LoginMixin(View):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.authenticate()
|
self.authenticate()
|
||||||
|
@ -44,7 +44,7 @@ class LoginMix(View):
|
||||||
g.user = self.user
|
g.user = self.user
|
||||||
|
|
||||||
|
|
||||||
class InventoryView(LoginMix, SnapshotMix):
|
class InventoryView(LoginMixin, SnapshotMixin):
|
||||||
methods = ['POST']
|
methods = ['POST']
|
||||||
|
|
||||||
def dispatch_request(self):
|
def dispatch_request(self):
|
||||||
|
|
|
@ -33,7 +33,7 @@ from ereuse_devicehub.parser.schemas import Snapshot_lite
|
||||||
from ereuse_devicehub.resources.action.models import Snapshot, Trade
|
from ereuse_devicehub.resources.action.models import Snapshot, Trade
|
||||||
from ereuse_devicehub.resources.action.schemas import Snapshot as SnapshotSchema
|
from ereuse_devicehub.resources.action.schemas import Snapshot as SnapshotSchema
|
||||||
from ereuse_devicehub.resources.action.views.snapshot import (
|
from ereuse_devicehub.resources.action.views.snapshot import (
|
||||||
SnapshotMix,
|
SnapshotMixin,
|
||||||
move_json,
|
move_json,
|
||||||
save_json,
|
save_json,
|
||||||
)
|
)
|
||||||
|
@ -233,7 +233,7 @@ class LotForm(FlaskForm):
|
||||||
return self.instance
|
return self.instance
|
||||||
|
|
||||||
|
|
||||||
class UploadSnapshotForm(FlaskForm, SnapshotMix):
|
class UploadSnapshotForm(SnapshotMixin, FlaskForm):
|
||||||
snapshot = MultipleFileField('Select a Snapshot File', [validators.DataRequired()])
|
snapshot = MultipleFileField('Select a Snapshot File', [validators.DataRequired()])
|
||||||
|
|
||||||
def validate(self, extra_validators=None):
|
def validate(self, extra_validators=None):
|
||||||
|
@ -560,7 +560,7 @@ class TagDeviceForm(FlaskForm):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
class ActionFormMix(FlaskForm):
|
class ActionFormMixin(FlaskForm):
|
||||||
name = StringField(
|
name = StringField(
|
||||||
'Name',
|
'Name',
|
||||||
[validators.length(max=50)],
|
[validators.length(max=50)],
|
||||||
|
@ -641,7 +641,7 @@ class ActionFormMix(FlaskForm):
|
||||||
return self.type.data
|
return self.type.data
|
||||||
|
|
||||||
|
|
||||||
class NewActionForm(ActionFormMix):
|
class NewActionForm(ActionFormMixin):
|
||||||
def validate(self, extra_validators=None):
|
def validate(self, extra_validators=None):
|
||||||
is_valid = super().validate(extra_validators)
|
is_valid = super().validate(extra_validators)
|
||||||
|
|
||||||
|
@ -654,7 +654,7 @@ class NewActionForm(ActionFormMix):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class AllocateForm(ActionFormMix):
|
class AllocateForm(ActionFormMixin):
|
||||||
start_time = DateField('Start time')
|
start_time = DateField('Start time')
|
||||||
end_time = DateField('End time', [validators.Optional()])
|
end_time = DateField('End time', [validators.Optional()])
|
||||||
final_user_code = StringField(
|
final_user_code = StringField(
|
||||||
|
@ -773,7 +773,7 @@ class DataWipeDocumentForm(Form):
|
||||||
return self._obj
|
return self._obj
|
||||||
|
|
||||||
|
|
||||||
class DataWipeForm(ActionFormMix):
|
class DataWipeForm(ActionFormMixin):
|
||||||
document = FormField(DataWipeDocumentForm)
|
document = FormField(DataWipeDocumentForm)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
@ -800,7 +800,7 @@ class DataWipeForm(ActionFormMix):
|
||||||
return self.instance
|
return self.instance
|
||||||
|
|
||||||
|
|
||||||
class TradeForm(ActionFormMix):
|
class TradeForm(ActionFormMixin):
|
||||||
user_from = StringField(
|
user_from = StringField(
|
||||||
'Supplier',
|
'Supplier',
|
||||||
[validators.Optional()],
|
[validators.Optional()],
|
||||||
|
|
|
@ -30,14 +30,14 @@ from ereuse_devicehub.resources.documents.device_row import ActionRow, DeviceRow
|
||||||
from ereuse_devicehub.resources.hash_reports import insert_hash
|
from ereuse_devicehub.resources.hash_reports import insert_hash
|
||||||
from ereuse_devicehub.resources.lot.models import Lot
|
from ereuse_devicehub.resources.lot.models import Lot
|
||||||
from ereuse_devicehub.resources.tag.model import Tag
|
from ereuse_devicehub.resources.tag.model import Tag
|
||||||
from ereuse_devicehub.views import GenericMixView
|
from ereuse_devicehub.views import GenericMixin
|
||||||
|
|
||||||
devices = Blueprint('inventory', __name__, url_prefix='/inventory')
|
devices = Blueprint('inventory', __name__, url_prefix='/inventory')
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class DeviceListMix(GenericMixView):
|
class DeviceListMixin(GenericMixin):
|
||||||
template_name = 'inventory/device_list.html'
|
template_name = 'inventory/device_list.html'
|
||||||
|
|
||||||
def get_context(self, lot_id):
|
def get_context(self, lot_id):
|
||||||
|
@ -91,13 +91,13 @@ class DeviceListMix(GenericMixView):
|
||||||
return self.context
|
return self.context
|
||||||
|
|
||||||
|
|
||||||
class DeviceListView(DeviceListMix):
|
class DeviceListView(DeviceListMixin):
|
||||||
def dispatch_request(self, lot_id=None):
|
def dispatch_request(self, lot_id=None):
|
||||||
self.get_context(lot_id)
|
self.get_context(lot_id)
|
||||||
return flask.render_template(self.template_name, **self.context)
|
return flask.render_template(self.template_name, **self.context)
|
||||||
|
|
||||||
|
|
||||||
class DeviceDetailView(GenericMixView):
|
class DeviceDetailView(GenericMixin):
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
template_name = 'inventory/device_detail.html'
|
template_name = 'inventory/device_detail.html'
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ class DeviceDetailView(GenericMixView):
|
||||||
return flask.render_template(self.template_name, **self.context)
|
return flask.render_template(self.template_name, **self.context)
|
||||||
|
|
||||||
|
|
||||||
class LotCreateView(GenericMixView):
|
class LotCreateView(GenericMixin):
|
||||||
methods = ['GET', 'POST']
|
methods = ['GET', 'POST']
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
template_name = 'inventory/lot.html'
|
template_name = 'inventory/lot.html'
|
||||||
|
@ -141,7 +141,7 @@ class LotCreateView(GenericMixView):
|
||||||
return flask.render_template(self.template_name, **self.context)
|
return flask.render_template(self.template_name, **self.context)
|
||||||
|
|
||||||
|
|
||||||
class LotUpdateView(GenericMixView):
|
class LotUpdateView(GenericMixin):
|
||||||
methods = ['GET', 'POST']
|
methods = ['GET', 'POST']
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
template_name = 'inventory/lot.html'
|
template_name = 'inventory/lot.html'
|
||||||
|
@ -182,7 +182,7 @@ class LotDeleteView(View):
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
|
||||||
class UploadSnapshotView(GenericMixView):
|
class UploadSnapshotView(GenericMixin):
|
||||||
methods = ['GET', 'POST']
|
methods = ['GET', 'POST']
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
template_name = 'inventory/upload_snapshot.html'
|
template_name = 'inventory/upload_snapshot.html'
|
||||||
|
@ -210,7 +210,7 @@ class UploadSnapshotView(GenericMixView):
|
||||||
return flask.render_template(self.template_name, **self.context)
|
return flask.render_template(self.template_name, **self.context)
|
||||||
|
|
||||||
|
|
||||||
class DeviceCreateView(GenericMixView):
|
class DeviceCreateView(GenericMixin):
|
||||||
methods = ['GET', 'POST']
|
methods = ['GET', 'POST']
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
template_name = 'inventory/device_create.html'
|
template_name = 'inventory/device_create.html'
|
||||||
|
@ -255,7 +255,7 @@ class TagLinkDeviceView(View):
|
||||||
return flask.redirect(request.referrer)
|
return flask.redirect(request.referrer)
|
||||||
|
|
||||||
|
|
||||||
class TagUnlinkDeviceView(GenericMixView):
|
class TagUnlinkDeviceView(GenericMixin):
|
||||||
methods = ['POST', 'GET']
|
methods = ['POST', 'GET']
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
template_name = 'inventory/tag_unlink_device.html'
|
template_name = 'inventory/tag_unlink_device.html'
|
||||||
|
@ -308,7 +308,7 @@ class NewActionView(View):
|
||||||
return url_for('inventory.devicelist')
|
return url_for('inventory.devicelist')
|
||||||
|
|
||||||
|
|
||||||
class NewAllocateView(NewActionView, DeviceListMix):
|
class NewAllocateView(DeviceListMixin, NewActionView):
|
||||||
methods = ['POST']
|
methods = ['POST']
|
||||||
form_class = AllocateForm
|
form_class = AllocateForm
|
||||||
|
|
||||||
|
@ -332,7 +332,7 @@ class NewAllocateView(NewActionView, DeviceListMix):
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
|
||||||
class NewDataWipeView(NewActionView, DeviceListMix):
|
class NewDataWipeView(DeviceListMixin, NewActionView):
|
||||||
methods = ['POST']
|
methods = ['POST']
|
||||||
form_class = DataWipeForm
|
form_class = DataWipeForm
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ class NewDataWipeView(NewActionView, DeviceListMix):
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
|
||||||
class NewTradeView(NewActionView, DeviceListMix):
|
class NewTradeView(DeviceListMixin, NewActionView):
|
||||||
methods = ['POST']
|
methods = ['POST']
|
||||||
form_class = TradeForm
|
form_class = TradeForm
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ def move_json(tmp_snapshots, path_name, user, live=False):
|
||||||
os.remove(path_name)
|
os.remove(path_name)
|
||||||
|
|
||||||
|
|
||||||
class SnapshotMix:
|
class SnapshotMixin:
|
||||||
sync = Sync()
|
sync = Sync()
|
||||||
|
|
||||||
def build(self, snapshot_json=None): # noqa: C901
|
def build(self, snapshot_json=None): # noqa: C901
|
||||||
|
@ -119,7 +119,7 @@ class SnapshotMix:
|
||||||
return snapshot
|
return snapshot
|
||||||
|
|
||||||
|
|
||||||
class SnapshotView(SnapshotMix):
|
class SnapshotView(SnapshotMixin):
|
||||||
"""Performs a Snapshot.
|
"""Performs a Snapshot.
|
||||||
|
|
||||||
See `Snapshot` section in docs for more info.
|
See `Snapshot` section in docs for more info.
|
||||||
|
|
|
@ -49,7 +49,7 @@ class LogoutView(View):
|
||||||
return flask.redirect(flask.url_for('core.login'))
|
return flask.redirect(flask.url_for('core.login'))
|
||||||
|
|
||||||
|
|
||||||
class GenericMixView(View):
|
class GenericMixin(View):
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
|
|
||||||
def get_lots(self):
|
def get_lots(self):
|
||||||
|
@ -74,7 +74,7 @@ class GenericMixView(View):
|
||||||
return self.context
|
return self.context
|
||||||
|
|
||||||
|
|
||||||
class UserProfileView(GenericMixView):
|
class UserProfileView(GenericMixin):
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
template_name = 'ereuse_devicehub/user_profile.html'
|
template_name = 'ereuse_devicehub/user_profile.html'
|
||||||
|
|
||||||
|
|
Reference in New Issue