drop lot in actions in views and forms
This commit is contained in:
parent
11df33060f
commit
fedc85668a
|
@ -375,7 +375,6 @@ class NewActionForm(FlaskForm):
|
||||||
date = DateField(u'Date', validators=(validators.Optional(),))
|
date = DateField(u'Date', validators=(validators.Optional(),))
|
||||||
severity = SelectField(u'Severity', choices=[(v.name, v.name) for v in Severity])
|
severity = SelectField(u'Severity', choices=[(v.name, v.name) for v in Severity])
|
||||||
description = TextAreaField(u'Description')
|
description = TextAreaField(u'Description')
|
||||||
lot = HiddenField()
|
|
||||||
type = HiddenField()
|
type = HiddenField()
|
||||||
|
|
||||||
def validate(self, extra_validators=None):
|
def validate(self, extra_validators=None):
|
||||||
|
@ -384,10 +383,6 @@ class NewActionForm(FlaskForm):
|
||||||
if not is_valid:
|
if not is_valid:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.lot.data:
|
|
||||||
self._lot = Lot.query.filter(Lot.id == self.lot.data).filter(
|
|
||||||
Lot.owner_id == g.user.id).one()
|
|
||||||
|
|
||||||
devices = set(self.devices.data.split(","))
|
devices = set(self.devices.data.split(","))
|
||||||
self._devices = OrderedSet(Device.query.filter(Device.id.in_(devices)).filter(
|
self._devices = OrderedSet(Device.query.filter(Device.id.in_(devices)).filter(
|
||||||
Device.owner_id == g.user.id).all())
|
Device.owner_id == g.user.id).all())
|
||||||
|
@ -400,10 +395,16 @@ class NewActionForm(FlaskForm):
|
||||||
def save(self):
|
def save(self):
|
||||||
Model = db.Model._decl_class_registry.data[self.type.data]()
|
Model = db.Model._decl_class_registry.data[self.type.data]()
|
||||||
self.instance = Model()
|
self.instance = Model()
|
||||||
|
devices = self.devices.data
|
||||||
|
severity = self.severity.data
|
||||||
self.devices.data = self._devices
|
self.devices.data = self._devices
|
||||||
self.severity.data = Severity[self.severity.data]
|
self.severity.data = Severity[self.severity.data]
|
||||||
|
|
||||||
self.populate_obj(self.instance)
|
self.populate_obj(self.instance)
|
||||||
|
|
||||||
|
self.devices.data = devices
|
||||||
|
self.severity.data = severity
|
||||||
|
|
||||||
db.session.add(self.instance)
|
db.session.add(self.instance)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return self.instance
|
return self.instance
|
||||||
|
@ -427,4 +428,8 @@ class AllocateForm(NewActionForm):
|
||||||
self.end_time.errors = error
|
self.end_time.errors = error
|
||||||
is_valid = False
|
is_valid = False
|
||||||
|
|
||||||
|
if not self.end_users.data:
|
||||||
|
self.end_users.errors = ["You need to specify a number of users"]
|
||||||
|
is_valid = False
|
||||||
|
|
||||||
return is_valid
|
return is_valid
|
||||||
|
|
|
@ -27,14 +27,15 @@ class DeviceListMix(View):
|
||||||
devices = [dev for dev in lot.devices if dev.type in filter_types]
|
devices = [dev for dev in lot.devices if dev.type in filter_types]
|
||||||
devices = sorted(devices, key=lambda x: x.updated, reverse=True)
|
devices = sorted(devices, key=lambda x: x.updated, reverse=True)
|
||||||
form_new_action = NewActionForm(lot=lot.id)
|
form_new_action = NewActionForm(lot=lot.id)
|
||||||
|
form_new_allocate = AllocateForm(lot=lot.id)
|
||||||
else:
|
else:
|
||||||
devices = Device.query.filter(
|
devices = Device.query.filter(
|
||||||
Device.owner_id == current_user.id).filter(
|
Device.owner_id == current_user.id).filter(
|
||||||
Device.type.in_(filter_types)).filter(Device.lots == None).order_by(
|
Device.type.in_(filter_types)).filter(Device.lots == None).order_by(
|
||||||
Device.updated.desc())
|
Device.updated.desc())
|
||||||
form_new_action = NewActionForm()
|
form_new_action = NewActionForm()
|
||||||
|
form_new_allocate = AllocateForm()
|
||||||
|
|
||||||
form_new_allocate = AllocateForm()
|
|
||||||
|
|
||||||
self.context = {'devices': devices,
|
self.context = {'devices': devices,
|
||||||
'lots': lots,
|
'lots': lots,
|
||||||
|
@ -179,10 +180,7 @@ class NewActionView(View):
|
||||||
self.form = self._form()
|
self.form = self._form()
|
||||||
if self.form.validate_on_submit():
|
if self.form.validate_on_submit():
|
||||||
self.form.save()
|
self.form.save()
|
||||||
if self.form.lot.data:
|
next_url = request.referrer or url_for('inventory.devices.devicelist')
|
||||||
next_url = url_for('inventory.devices.lotdevicelist', id=self.form.lot.data)
|
|
||||||
|
|
||||||
next_url = url_for('inventory.devices.devicelist')
|
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
|
||||||
|
@ -197,9 +195,9 @@ class NewAllocateView(NewActionView, DeviceListMix):
|
||||||
if self.form.validate_on_submit():
|
if self.form.validate_on_submit():
|
||||||
return dispatch
|
return dispatch
|
||||||
|
|
||||||
lot_id = self.form.lot.data
|
# lot_id = self.form.lot.data
|
||||||
self.get_context(lot_id)
|
# FIXME
|
||||||
self.context['form_new_allocate'] = self.form
|
self.get_context(None)
|
||||||
return flask.render_template(self.template_name, **self.context)
|
return flask.render_template(self.template_name, **self.context)
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue