From 4e43076c04f9944d49cad5772ac1bfecd215d134 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 11 Jan 2022 13:13:57 +0100 Subject: [PATCH 01/20] add tag list --- ereuse_devicehub/inventory/views.py | 14 +++ ereuse_devicehub/resources/tag/model.py | 4 + .../templates/inventory/tag_list.html | 87 +++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 ereuse_devicehub/templates/inventory/tag_list.html diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 63a5a336..1a7acc3d 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -4,6 +4,7 @@ from flask import Blueprint, url_for 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 @@ -95,6 +96,18 @@ class LotDeleteView(View): return flask.redirect(next_url) +class TagListView(View): + methods = ['GET'] + decorators = [login_required] + template_name = 'inventory/tag_list.html' + + def dispatch_request(self): + tags = Tag.query.filter( + Tag.owner_id == current_user.id) + context = {'tags': tags, + 'lots': []} + return flask.render_template(self.template_name, **context) + devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist')) devices.add_url_rule('/lot//device/', view_func=DeviceListView.as_view('lotdevicelist')) @@ -103,3 +116,4 @@ devices.add_url_rule('/lot/devices/del/', view_func=LotDeviceDeleteView.as_view( 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')) diff --git a/ereuse_devicehub/resources/tag/model.py b/ereuse_devicehub/resources/tag/model.py index 92c8d5d4..9c672f8c 100644 --- a/ereuse_devicehub/resources/tag/model.py +++ b/ereuse_devicehub/resources/tag/model.py @@ -136,6 +136,10 @@ class Tag(Thing): def code(self) -> str: return hashcode.encode(self.internal_id) + @property + def get_provider(self) -> str: + return self.provider.to_text() if self.provider else '' + def delete(self): """Deletes the tag. diff --git a/ereuse_devicehub/templates/inventory/tag_list.html b/ereuse_devicehub/templates/inventory/tag_list.html new file mode 100644 index 00000000..fdc96973 --- /dev/null +++ b/ereuse_devicehub/templates/inventory/tag_list.html @@ -0,0 +1,87 @@ +{% extends "ereuse_devicehub/base_site.html" %} +{% block main %} + + +
+

Inventory

+ +
+ +
+
+ +
+ +
+
+ + + + + + +
+ +
+ +
Computers
+ + + + + + + + + + + + {% for tag in tags %} + + + + + + + + {% endfor %} + +
Select allCodeTypeProviderDevice
{{ tag.code }}{% if tag.provider %}Unnamed tag {% else %}Named tag{% endif %}{{ tag.get_provider }}{% if tag.device %}{{ tag.device.type }} {{ tag.device.manufacturer }} {{ tag.device.model }}{% endif %}
+ +
+ +
+
+ +
+
+
+ + + + + + + +{% endblock main %} From 849e482d62d6c4d5eb43bf19d48874e31be35842 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 11 Jan 2022 13:42:01 +0100 Subject: [PATCH 02/20] add named tags --- ereuse_devicehub/inventory/forms.py | 17 ++++++ ereuse_devicehub/inventory/views.py | 18 +++++- ereuse_devicehub/templates/inventory/tag.html | 60 +++++++++++++++++++ .../templates/inventory/tag_list.html | 6 +- 4 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 ereuse_devicehub/templates/inventory/tag.html 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 @@