add an unnamed tag
This commit is contained in:
parent
96a62e7072
commit
2327fa5a89
|
@ -401,6 +401,18 @@ class TagForm(FlaskForm):
|
||||||
return self.instance
|
return self.instance
|
||||||
|
|
||||||
|
|
||||||
|
class TagUnnamedForm(FlaskForm):
|
||||||
|
amount = IntegerField(u'amount')
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
num = self.amount.data
|
||||||
|
tags_id, _ = g.tag_provider.post('/', {}, query=[('num', num)])
|
||||||
|
tags = [Tag(id=tag_id, provider=g.inventory.tag_provider) for tag_id in tags_id]
|
||||||
|
db.session.add_all(tags)
|
||||||
|
db.session.commit()
|
||||||
|
return tags
|
||||||
|
|
||||||
|
|
||||||
class TagDeviceForm(FlaskForm):
|
class TagDeviceForm(FlaskForm):
|
||||||
tag = SelectField(u'Tag', choices=[])
|
tag = SelectField(u'Tag', choices=[])
|
||||||
device = StringField(u'Device', [validators.Optional()])
|
device = StringField(u'Device', [validators.Optional()])
|
||||||
|
|
|
@ -7,7 +7,7 @@ from ereuse_devicehub.resources.lot.models import Lot
|
||||||
from ereuse_devicehub.resources.tag.model import Tag
|
from ereuse_devicehub.resources.tag.model import Tag
|
||||||
from ereuse_devicehub.resources.device.models import Device
|
from ereuse_devicehub.resources.device.models import Device
|
||||||
from ereuse_devicehub.inventory.forms import LotDeviceForm, LotForm, UploadSnapshotForm, \
|
from ereuse_devicehub.inventory.forms import LotDeviceForm, LotForm, UploadSnapshotForm, \
|
||||||
NewDeviceForm, TagForm, TagDeviceForm
|
NewDeviceForm, TagForm, TagUnnamedForm, TagDeviceForm
|
||||||
|
|
||||||
devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory')
|
devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory')
|
||||||
|
|
||||||
|
@ -189,6 +189,21 @@ class TagAddView(View):
|
||||||
return flask.render_template(self.template_name, form=form)
|
return flask.render_template(self.template_name, form=form)
|
||||||
|
|
||||||
|
|
||||||
|
class TagAddUnnamedView(View):
|
||||||
|
methods = ['GET', 'POST']
|
||||||
|
decorators = [login_required]
|
||||||
|
template_name = 'inventory/tagUnnamed.html'
|
||||||
|
|
||||||
|
def dispatch_request(self):
|
||||||
|
form = TagUnnamedForm()
|
||||||
|
if form.validate_on_submit():
|
||||||
|
form.save()
|
||||||
|
next_url = url_for('inventory.devices.taglist')
|
||||||
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
return flask.render_template(self.template_name, form=form)
|
||||||
|
|
||||||
|
|
||||||
class TagDeviceAddView(View):
|
class TagDeviceAddView(View):
|
||||||
methods = ['POST']
|
methods = ['POST']
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
|
@ -230,5 +245,6 @@ devices.add_url_rule('/upload-snapshot/', view_func=UploadSnapshotView.as_view('
|
||||||
devices.add_url_rule('/device/add/', view_func=CreateDeviceView.as_view('device_add'))
|
devices.add_url_rule('/device/add/', view_func=CreateDeviceView.as_view('device_add'))
|
||||||
devices.add_url_rule('/tag/', view_func=TagListView.as_view('taglist'))
|
devices.add_url_rule('/tag/', view_func=TagListView.as_view('taglist'))
|
||||||
devices.add_url_rule('/tag/add/', view_func=TagAddView.as_view('tag_add'))
|
devices.add_url_rule('/tag/add/', view_func=TagAddView.as_view('tag_add'))
|
||||||
|
devices.add_url_rule('/tag//unnamed/add/', view_func=TagAddUnnamedView.as_view('tag_unnamed_add'))
|
||||||
devices.add_url_rule('/tag/devices/add/', view_func=TagDeviceAddView.as_view('tag_devices_add'))
|
devices.add_url_rule('/tag/devices/add/', view_func=TagDeviceAddView.as_view('tag_devices_add'))
|
||||||
devices.add_url_rule('/tag/devices/<int:id>/del/', view_func=TagDeviceDeleteView.as_view('tag_devices_del'))
|
devices.add_url_rule('/tag/devices/<int:id>/del/', view_func=TagDeviceDeleteView.as_view('tag_devices_del'))
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="btn-group dropdown ml-1" uib-dropdown="">
|
<div class="btn-group dropdown ml-1" uib-dropdown="">
|
||||||
<a href="{{ url_for('inventory.devices.devicelist')}}" type="button" class="btn btn-primary">
|
<a href="{{ url_for('inventory.devices.tag_unnamed_add')}}" type="button" class="btn btn-primary">
|
||||||
<i class="bi bi-plus"></i>
|
<i class="bi bi-plus"></i>
|
||||||
Create UnNamed Tag
|
Create UnNamed Tag
|
||||||
<span class="caret"></span>
|
<span class="caret"></span>
|
||||||
|
|
Reference in New Issue