diff --git a/ereuse_devicehub/api/views.py b/ereuse_devicehub/api/views.py index ff5bd014..6af655b9 100644 --- a/ereuse_devicehub/api/views.py +++ b/ereuse_devicehub/api/views.py @@ -15,7 +15,7 @@ from ereuse_devicehub.parser.models import SnapshotErrors from ereuse_devicehub.parser.parser import ParseSnapshotLsHw from ereuse_devicehub.parser.schemas import Snapshot_lite from ereuse_devicehub.resources.action.views.snapshot import ( - SnapshotMix, + SnapshotMixin, move_json, save_json, ) @@ -24,7 +24,7 @@ from ereuse_devicehub.resources.enums import Severity api = Blueprint('api', __name__, url_prefix='/api') -class LoginMix(View): +class LoginMixin(View): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.authenticate() @@ -44,7 +44,7 @@ class LoginMix(View): g.user = self.user -class InventoryView(LoginMix, SnapshotMix): +class InventoryView(LoginMixin, SnapshotMixin): methods = ['POST'] def dispatch_request(self): diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index a4e7ae40..d1c1b13e 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -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.schemas import Snapshot as SnapshotSchema from ereuse_devicehub.resources.action.views.snapshot import ( - SnapshotMix, + SnapshotMixin, move_json, save_json, ) @@ -233,7 +233,7 @@ class LotForm(FlaskForm): return self.instance -class UploadSnapshotForm(FlaskForm, SnapshotMix): +class UploadSnapshotForm(SnapshotMixin, FlaskForm): snapshot = MultipleFileField('Select a Snapshot File', [validators.DataRequired()]) def validate(self, extra_validators=None): @@ -560,7 +560,7 @@ class TagDeviceForm(FlaskForm): db.session.commit() -class ActionFormMix(FlaskForm): +class ActionFormMixin(FlaskForm): name = StringField( 'Name', [validators.length(max=50)], @@ -641,7 +641,7 @@ class ActionFormMix(FlaskForm): return self.type.data -class NewActionForm(ActionFormMix): +class NewActionForm(ActionFormMixin): def validate(self, extra_validators=None): is_valid = super().validate(extra_validators) @@ -654,7 +654,7 @@ class NewActionForm(ActionFormMix): return True -class AllocateForm(ActionFormMix): +class AllocateForm(ActionFormMixin): start_time = DateField('Start time') end_time = DateField('End time', [validators.Optional()]) final_user_code = StringField( @@ -773,7 +773,7 @@ class DataWipeDocumentForm(Form): return self._obj -class DataWipeForm(ActionFormMix): +class DataWipeForm(ActionFormMixin): document = FormField(DataWipeDocumentForm) def save(self): @@ -800,7 +800,7 @@ class DataWipeForm(ActionFormMix): return self.instance -class TradeForm(ActionFormMix): +class TradeForm(ActionFormMixin): user_from = StringField( 'Supplier', [validators.Optional()], diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 7731d2ad..0c725448 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -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.lot.models import Lot 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') logger = logging.getLogger(__name__) -class DeviceListMix(GenericMixView): +class DeviceListMixin(GenericMixin): template_name = 'inventory/device_list.html' def get_context(self, lot_id): @@ -91,13 +91,13 @@ class DeviceListMix(GenericMixView): return self.context -class DeviceListView(DeviceListMix): +class DeviceListView(DeviceListMixin): def dispatch_request(self, lot_id=None): self.get_context(lot_id) return flask.render_template(self.template_name, **self.context) -class DeviceDetailView(GenericMixView): +class DeviceDetailView(GenericMixin): decorators = [login_required] template_name = 'inventory/device_detail.html' @@ -118,7 +118,7 @@ class DeviceDetailView(GenericMixView): return flask.render_template(self.template_name, **self.context) -class LotCreateView(GenericMixView): +class LotCreateView(GenericMixin): methods = ['GET', 'POST'] decorators = [login_required] template_name = 'inventory/lot.html' @@ -141,7 +141,7 @@ class LotCreateView(GenericMixView): return flask.render_template(self.template_name, **self.context) -class LotUpdateView(GenericMixView): +class LotUpdateView(GenericMixin): methods = ['GET', 'POST'] decorators = [login_required] template_name = 'inventory/lot.html' @@ -182,7 +182,7 @@ class LotDeleteView(View): return flask.redirect(next_url) -class UploadSnapshotView(GenericMixView): +class UploadSnapshotView(GenericMixin): methods = ['GET', 'POST'] decorators = [login_required] template_name = 'inventory/upload_snapshot.html' @@ -210,7 +210,7 @@ class UploadSnapshotView(GenericMixView): return flask.render_template(self.template_name, **self.context) -class DeviceCreateView(GenericMixView): +class DeviceCreateView(GenericMixin): methods = ['GET', 'POST'] decorators = [login_required] template_name = 'inventory/device_create.html' @@ -255,7 +255,7 @@ class TagLinkDeviceView(View): return flask.redirect(request.referrer) -class TagUnlinkDeviceView(GenericMixView): +class TagUnlinkDeviceView(GenericMixin): methods = ['POST', 'GET'] decorators = [login_required] template_name = 'inventory/tag_unlink_device.html' @@ -308,7 +308,7 @@ class NewActionView(View): return url_for('inventory.devicelist') -class NewAllocateView(NewActionView, DeviceListMix): +class NewAllocateView(DeviceListMixin, NewActionView): methods = ['POST'] form_class = AllocateForm @@ -332,7 +332,7 @@ class NewAllocateView(NewActionView, DeviceListMix): return flask.redirect(next_url) -class NewDataWipeView(NewActionView, DeviceListMix): +class NewDataWipeView(DeviceListMixin, NewActionView): methods = ['POST'] form_class = DataWipeForm @@ -353,7 +353,7 @@ class NewDataWipeView(NewActionView, DeviceListMix): return flask.redirect(next_url) -class NewTradeView(NewActionView, DeviceListMix): +class NewTradeView(DeviceListMixin, NewActionView): methods = ['POST'] form_class = TradeForm diff --git a/ereuse_devicehub/resources/action/views/snapshot.py b/ereuse_devicehub/resources/action/views/snapshot.py index 14c59e7f..569f6b0d 100644 --- a/ereuse_devicehub/resources/action/views/snapshot.py +++ b/ereuse_devicehub/resources/action/views/snapshot.py @@ -62,7 +62,7 @@ def move_json(tmp_snapshots, path_name, user, live=False): os.remove(path_name) -class SnapshotMix: +class SnapshotMixin: sync = Sync() def build(self, snapshot_json=None): # noqa: C901 @@ -119,7 +119,7 @@ class SnapshotMix: return snapshot -class SnapshotView(SnapshotMix): +class SnapshotView(SnapshotMixin): """Performs a Snapshot. See `Snapshot` section in docs for more info. diff --git a/ereuse_devicehub/views.py b/ereuse_devicehub/views.py index bee12ad0..018a85a9 100644 --- a/ereuse_devicehub/views.py +++ b/ereuse_devicehub/views.py @@ -49,7 +49,7 @@ class LogoutView(View): return flask.redirect(flask.url_for('core.login')) -class GenericMixView(View): +class GenericMixin(View): decorators = [login_required] def get_lots(self): @@ -74,7 +74,7 @@ class GenericMixView(View): return self.context -class UserProfileView(GenericMixView): +class UserProfileView(GenericMixin): decorators = [login_required] template_name = 'ereuse_devicehub/user_profile.html'