adding new viewLotDeviceAddView
This commit is contained in:
parent
e1c46e4725
commit
ae4dd59f07
|
@ -1,10 +1,12 @@
|
||||||
import flask
|
import flask
|
||||||
from flask import Blueprint
|
|
||||||
from flask.views import View
|
from flask.views import View
|
||||||
|
from flask import Blueprint, url_for, g
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
|
|
||||||
from ereuse_devicehub.resources.device.models import Device
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.resources.lot.models import Lot
|
from ereuse_devicehub.resources.lot.models import Lot
|
||||||
|
from ereuse_devicehub.resources.device.models import Device
|
||||||
|
from ereuse_devicehub.inventory.forms import LotDeviceAddForm
|
||||||
|
|
||||||
devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory')
|
devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory')
|
||||||
|
|
||||||
|
@ -22,8 +24,29 @@ class DeviceListView(View):
|
||||||
|
|
||||||
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
||||||
|
|
||||||
context = {'devices': devices, 'lots': lots}
|
context = {'devices': devices, 'lots': lots, 'form_lot_device': LotDeviceAddForm()}
|
||||||
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 = LotDeviceAddForm()
|
||||||
|
if form.validate_on_submit():
|
||||||
|
lot = form.lot
|
||||||
|
devices = form.devices
|
||||||
|
lot.devices.update(devices)
|
||||||
|
g.user = current_user
|
||||||
|
db.session.add(lot)
|
||||||
|
db.session().final_flush()
|
||||||
|
|
||||||
|
next_url = url_for('inventory.devices.devicelist')
|
||||||
|
# next_url = url_for('inventory.devices.lot')
|
||||||
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
|
||||||
devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist'))
|
devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist'))
|
||||||
|
devices.add_url_rule('/lot/devices/add', view_func=LotDeviceAddView.as_view('lot_devices_add'))
|
||||||
|
|
Reference in a new issue