Remove unused code (part 2)
This commit is contained in:
parent
28bcf17083
commit
cdc3417c74
|
@ -97,62 +97,6 @@ class FilterForm(FlaskForm):
|
||||||
return ['Desktop', 'Laptop', 'Server']
|
return ['Desktop', 'Laptop', 'Server']
|
||||||
|
|
||||||
|
|
||||||
class LotDeviceForm(FlaskForm):
|
|
||||||
lot = StringField('Lot', [validators.UUID()])
|
|
||||||
devices = StringField('Devices', [validators.length(min=1)])
|
|
||||||
|
|
||||||
def validate(self, extra_validators=None):
|
|
||||||
is_valid = super().validate(extra_validators)
|
|
||||||
|
|
||||||
if not is_valid:
|
|
||||||
return False
|
|
||||||
|
|
||||||
self._lot = (
|
|
||||||
Lot.query.outerjoin(Trade)
|
|
||||||
.filter(Lot.id == self.lot.data)
|
|
||||||
.filter(
|
|
||||||
or_(
|
|
||||||
Trade.user_from == g.user,
|
|
||||||
Trade.user_to == g.user,
|
|
||||||
Lot.owner_id == g.user.id,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.one()
|
|
||||||
)
|
|
||||||
|
|
||||||
devices = set(self.devices.data.split(","))
|
|
||||||
self._devices = (
|
|
||||||
Device.query.filter(Device.id.in_(devices))
|
|
||||||
.filter(Device.owner_id == g.user.id)
|
|
||||||
.distinct()
|
|
||||||
.all()
|
|
||||||
)
|
|
||||||
|
|
||||||
return bool(self._devices)
|
|
||||||
|
|
||||||
def save(self, commit=True):
|
|
||||||
trade = self._lot.trade
|
|
||||||
if trade:
|
|
||||||
for dev in self._devices:
|
|
||||||
if trade not in dev.actions:
|
|
||||||
trade.devices.add(dev)
|
|
||||||
|
|
||||||
if self._devices:
|
|
||||||
self._lot.devices.update(self._devices)
|
|
||||||
db.session.add(self._lot)
|
|
||||||
|
|
||||||
if commit:
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
def remove(self, commit=True):
|
|
||||||
if self._devices:
|
|
||||||
self._lot.devices.difference_update(self._devices)
|
|
||||||
db.session.add(self._lot)
|
|
||||||
|
|
||||||
if commit:
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
|
|
||||||
class LotForm(FlaskForm):
|
class LotForm(FlaskForm):
|
||||||
name = StringField('Name', [validators.length(min=1)])
|
name = StringField('Name', [validators.length(min=1)])
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ from ereuse_devicehub.inventory.forms import (
|
||||||
AllocateForm,
|
AllocateForm,
|
||||||
DataWipeForm,
|
DataWipeForm,
|
||||||
FilterForm,
|
FilterForm,
|
||||||
LotDeviceForm,
|
|
||||||
LotForm,
|
LotForm,
|
||||||
NewActionForm,
|
NewActionForm,
|
||||||
NewDeviceForm,
|
NewDeviceForm,
|
||||||
|
@ -109,7 +108,6 @@ class DeviceListMix(GenericMixView):
|
||||||
self.context = {
|
self.context = {
|
||||||
'devices': devices,
|
'devices': devices,
|
||||||
'lots': lots,
|
'lots': lots,
|
||||||
'form_lot_device': LotDeviceForm(),
|
|
||||||
'form_tag_device': TagDeviceForm(),
|
'form_tag_device': TagDeviceForm(),
|
||||||
'form_new_action': form_new_action,
|
'form_new_action': form_new_action,
|
||||||
'form_new_allocate': form_new_allocate,
|
'form_new_allocate': form_new_allocate,
|
||||||
|
@ -153,46 +151,6 @@ class DeviceDetailView(GenericMixView):
|
||||||
return flask.render_template(self.template_name, **context)
|
return flask.render_template(self.template_name, **context)
|
||||||
|
|
||||||
|
|
||||||
class LotDeviceAddView(View):
|
|
||||||
methods = ['POST']
|
|
||||||
decorators = [login_required]
|
|
||||||
template_name = 'inventory/device_list.html'
|
|
||||||
|
|
||||||
def dispatch_request(self):
|
|
||||||
form = LotDeviceForm()
|
|
||||||
if form.validate_on_submit():
|
|
||||||
form.save(commit=False)
|
|
||||||
messages.success(
|
|
||||||
'Add devices to lot "{}" successfully!'.format(form._lot.name)
|
|
||||||
)
|
|
||||||
db.session.commit()
|
|
||||||
else:
|
|
||||||
messages.error('Error adding devices to lot!')
|
|
||||||
|
|
||||||
next_url = request.referrer or url_for('inventory.devicelist')
|
|
||||||
return flask.redirect(next_url)
|
|
||||||
|
|
||||||
|
|
||||||
class LotDeviceDeleteView(View):
|
|
||||||
methods = ['POST']
|
|
||||||
decorators = [login_required]
|
|
||||||
template_name = 'inventory/device_list.html'
|
|
||||||
|
|
||||||
def dispatch_request(self):
|
|
||||||
form = LotDeviceForm()
|
|
||||||
if form.validate_on_submit():
|
|
||||||
form.remove(commit=False)
|
|
||||||
messages.success(
|
|
||||||
'Remove devices from lot "{}" successfully!'.format(form._lot.name)
|
|
||||||
)
|
|
||||||
db.session.commit()
|
|
||||||
else:
|
|
||||||
messages.error('Error removing devices from lot!')
|
|
||||||
|
|
||||||
next_url = request.referrer or url_for('inventory.devicelist')
|
|
||||||
return flask.redirect(next_url)
|
|
||||||
|
|
||||||
|
|
||||||
class LotCreateView(GenericMixView):
|
class LotCreateView(GenericMixView):
|
||||||
methods = ['GET', 'POST']
|
methods = ['GET', 'POST']
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
|
@ -607,12 +565,6 @@ devices.add_url_rule(
|
||||||
devices.add_url_rule(
|
devices.add_url_rule(
|
||||||
'/lot/<string:lot_id>/device/', view_func=DeviceListView.as_view('lotdevicelist')
|
'/lot/<string:lot_id>/device/', view_func=DeviceListView.as_view('lotdevicelist')
|
||||||
)
|
)
|
||||||
devices.add_url_rule(
|
|
||||||
'/lot/devices/add/', view_func=LotDeviceAddView.as_view('lot_devices_add')
|
|
||||||
)
|
|
||||||
devices.add_url_rule(
|
|
||||||
'/lot/devices/del/', view_func=LotDeviceDeleteView.as_view('lot_devices_del')
|
|
||||||
)
|
|
||||||
devices.add_url_rule('/lot/add/', view_func=LotCreateView.as_view('lot_add'))
|
devices.add_url_rule('/lot/add/', view_func=LotCreateView.as_view('lot_add'))
|
||||||
devices.add_url_rule(
|
devices.add_url_rule(
|
||||||
'/lot/<string:id>/del/', view_func=LotDeleteView.as_view('lot_del')
|
'/lot/<string:id>/del/', view_func=LotDeleteView.as_view('lot_del')
|
||||||
|
|
Reference in New Issue