diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 701e73a7..c94342ed 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -5,6 +5,7 @@ from flask import g from ereuse_devicehub.db import db from ereuse_devicehub.resources.device.models import Device from ereuse_devicehub.resources.lot.models import Lot +from ereuse_devicehub.resources.tag.model import Tag class LotDeviceForm(FlaskForm): @@ -77,6 +78,22 @@ class LotForm(FlaskForm): return self.instance +class TagForm(FlaskForm): + code = StringField(u'Code', [validators.length(min=1)]) + + def save(self): + self.instance = Tag(id=self.code.data) + db.session.add(self.instance) + db.session.commit() + return self.instance + + def remove(self): + if not self.instance.device and not self.instance.provider: + self.instance.delete() + db.session.commit() + return self.instance + + class NewActionForm(FlaskForm): name = StringField(u'Name') date = StringField(u'Date') diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 1a7acc3d..60ca57e8 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -6,7 +6,7 @@ from flask_login import login_required, current_user from ereuse_devicehub.resources.lot.models import Lot from ereuse_devicehub.resources.tag.model import Tag from ereuse_devicehub.resources.device.models import Device -from ereuse_devicehub.inventory.forms import LotDeviceForm, LotForm +from ereuse_devicehub.inventory.forms import LotDeviceForm, LotForm, TagForm devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory') @@ -109,6 +109,21 @@ class TagListView(View): return flask.render_template(self.template_name, **context) +class TagAddView(View): + methods = ['GET', 'POST'] + decorators = [login_required] + template_name = 'inventory/tag.html' + + def dispatch_request(self): + form = TagForm() + 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) + + devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist')) devices.add_url_rule('/lot//device/', view_func=DeviceListView.as_view('lotdevicelist')) devices.add_url_rule('/lot/devices/add/', view_func=LotDeviceAddView.as_view('lot_devices_add')) @@ -117,3 +132,4 @@ devices.add_url_rule('/lot/add/', view_func=LotView.as_view('lot_add')) devices.add_url_rule('/lot//del/', view_func=LotDeleteView.as_view('lot_del')) devices.add_url_rule('/lot//', view_func=LotView.as_view('lot_edit')) devices.add_url_rule('/tag/', view_func=TagListView.as_view('taglist')) +devices.add_url_rule('/tag/add/', view_func=TagAddView.as_view('tag_add')) diff --git a/ereuse_devicehub/templates/inventory/tag.html b/ereuse_devicehub/templates/inventory/tag.html new file mode 100644 index 00000000..b92135e0 --- /dev/null +++ b/ereuse_devicehub/templates/inventory/tag.html @@ -0,0 +1,60 @@ +{% extends "ereuse_devicehub/base_site.html" %} +{% block main %} + +
+

{{ title }}

+ +
+ +
+
+
+ +
+
+ +
+
Add a new Tag
+

Please enter a code for the tag.

+ {% if form.form_errors %} +

+ {% for error in form.form_errors %} + {{ error }}
+ {% endfor %} +

+ {% endif %} +
+ +
+ {{ form.csrf_token }} + +
+ +
+ +
Please enter a code of the tag.
+
+
+ +
+ Cancel + +
+
+ +
+ +
+ +
+ +
+
+
+
+{% endblock main %} diff --git a/ereuse_devicehub/templates/inventory/tag_list.html b/ereuse_devicehub/templates/inventory/tag_list.html index fdc96973..a12c850f 100644 --- a/ereuse_devicehub/templates/inventory/tag_list.html +++ b/ereuse_devicehub/templates/inventory/tag_list.html @@ -22,7 +22,7 @@