Refactor: create method get_next_url()
This commit is contained in:
parent
f1a78e23f6
commit
e15e457481
|
@ -295,34 +295,37 @@ class NewActionView(View):
|
||||||
def dispatch_request(self):
|
def dispatch_request(self):
|
||||||
self.form = self._form()
|
self.form = self._form()
|
||||||
|
|
||||||
next_url = url_for('inventory.devices.devicelist')
|
|
||||||
lot_id = self.form.lot.data
|
|
||||||
if lot_id:
|
|
||||||
next_url = url_for('inventory.devices.lotdevicelist', lot_id=lot_id)
|
|
||||||
|
|
||||||
if self.form.validate_on_submit():
|
if self.form.validate_on_submit():
|
||||||
instance = self.form.save()
|
instance = self.form.save()
|
||||||
messages.success('Action "{}" created successfully!'.format(instance.type))
|
messages.success('Action "{}" created successfully!'.format(instance.type))
|
||||||
|
|
||||||
|
next_url = self.get_next_url()
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
def get_next_url(self):
|
||||||
|
lot_id = self.form.lot.data
|
||||||
|
|
||||||
|
if lot_id:
|
||||||
|
return url_for('inventory.devices.lotdevicelist', lot_id=lot_id)
|
||||||
|
|
||||||
|
return url_for('inventory.devices.devicelist')
|
||||||
|
|
||||||
|
|
||||||
class NewAllocateView(NewActionView, DeviceListMix):
|
class NewAllocateView(NewActionView, DeviceListMix):
|
||||||
methods = ['POST']
|
methods = ['POST']
|
||||||
_form = AllocateForm
|
_form = AllocateForm
|
||||||
|
|
||||||
def dispatch_request(self, lot_id=None):
|
def dispatch_request(self):
|
||||||
self.form = self._form()
|
self.form = self._form()
|
||||||
|
|
||||||
next_url = url_for('inventory.devices.devicelist')
|
|
||||||
lot_id = self.form.lot.data
|
|
||||||
if lot_id:
|
|
||||||
next_url = url_for('inventory.devices.lotdevicelist', lot_id=lot_id)
|
|
||||||
|
|
||||||
if self.form.validate_on_submit():
|
if self.form.validate_on_submit():
|
||||||
instance = self.form.save()
|
instance = self.form.save()
|
||||||
messages.success('Action "{}" created successfully!'.format(instance.type))
|
messages.success('Action "{}" created successfully!'.format(instance.type))
|
||||||
|
|
||||||
|
next_url = self.get_next_url()
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
lot_id = self.form.lot.data
|
||||||
self.get_context(lot_id)
|
self.get_context(lot_id)
|
||||||
self.context['form_new_allocate'] = self.form
|
self.context['form_new_allocate'] = self.form
|
||||||
return flask.render_template(self.template_name, **self.context)
|
return flask.render_template(self.template_name, **self.context)
|
||||||
|
|
Reference in a new issue