diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 1226dcbf..aad6b980 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -82,6 +82,26 @@ MONITORS = ["ComputerMonitor", "Monitor", "TelevisionSet", "Projector"] MOBILE = ["Mobile", "Tablet", "Smartphone", "Cellphone"] +class AdvancedSearchForm(FlaskForm): + q = StringField('Search', [validators.length(min=1)]) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + dhids = [x.strip() for x in self.q.data.split(' ')] + if ',' in self.q.data: + dhids = [x.strip() for x in self.q.data.split(',')] + if ';' in self.q.data: + dhids = [x.strip() for x in self.q.data.split(';')] + + self.devices = [] + if dhids: + self.search(dhids) + + def search(self, dhids): + self.devices = Device.query.filter(Device.devicehub_id.in_(dhids)) + + class FilterForm(FlaskForm): filter = SelectField( '', choices=DEVICES, default="All Computers", render_kw={'class': "form-select"} diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 5ed4247a..cf6621cf 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -13,6 +13,7 @@ from werkzeug.exceptions import NotFound from ereuse_devicehub import messages from ereuse_devicehub.db import db from ereuse_devicehub.inventory.forms import ( + AdvancedSearchForm, AllocateForm, DataWipeForm, FilterForm, @@ -102,6 +103,19 @@ class DeviceListView(DeviceListMix): return flask.render_template(self.template_name, **self.context) +class AdvancedSearchView(DeviceListMix): + methods = ['GET', 'POST'] + template_name = 'inventory/search.html' + title = "Advanced Search" + + def dispatch_request(self): + query = request.args.get('q', '') + self.get_context(None) + form = AdvancedSearchForm(q=query) + self.context.update({'devices': form.devices, 'advanced_form': form}) + return flask.render_template(self.template_name, **self.context) + + class DeviceDetailView(GenericMixView): decorators = [login_required] template_name = 'inventory/device_detail.html' @@ -524,6 +538,9 @@ devices.add_url_rule( view_func=NewTradeDocumentView.as_view('trade_document_add'), ) devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist')) +devices.add_url_rule( + '/search/', view_func=AdvancedSearchView.as_view('advanced_search') +) devices.add_url_rule( '/device//', view_func=DeviceDetailView.as_view('device_details') ) diff --git a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html index acf6efa2..bae54955 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html @@ -26,6 +26,11 @@ style="float: right;">DHID + diff --git a/ereuse_devicehub/templates/inventory/search.html b/ereuse_devicehub/templates/inventory/search.html new file mode 100644 index 00000000..d996a1f3 --- /dev/null +++ b/ereuse_devicehub/templates/inventory/search.html @@ -0,0 +1,412 @@ +{% extends "ereuse_devicehub/base_site.html" %} +{% block main %} + +
+

Inventory

+ +
+ +
+
+ +
+ +
+
+
+
+ {% for f in advanced_form %} + {{ f }} + {% endfor %} + +
+
+
+
+ {% if devices %} +
+
+ +
+
+ + + + + + + + + + + + + {% if lot and not lot.is_temporary %} + + {% endif %} + + + +
+ + + + + + + + + + + + + + + + + {% for dev in devices %} + + + + + + + + + + + + + {% endfor %} + +
SelectTitleDHIDUnique IdentifiersLifecycle StatusAllocated StatusPhysical StatusUpdated inRegistered in
+ + + + {% if dev.get_type_logo() %} + + {% endif %} + {{ dev.verbose_name }} + + {% if dev.lots | length > 0 %} +
+ {% for lot in dev.lots %} + {{ lot.name }} + {% endfor %} +
+ {% endif %} +
+ + {{ dev.devicehub_id }} + + + {% for t in dev.tags | sort(attribute="id") %} + {{ t.id }} + {% if not loop.last %},{% endif %} + {% endfor %} + {% if dev.status %}{{ dev.status.type }}{% endif %}{% if dev.allocated_status %}{{ dev.allocated_status.type }}{% endif %}{% if dev.physical_status %}{{ dev.physical_status.type }}{% endif %}{{ dev.updated.strftime('%Y-%m-%d %H:%M:%S')}}{{ dev.created.strftime('%Y-%m-%d %H:%M:%S')}} + + + +
+ +
+
+ {% if lot and not lot.is_temporary %} +
+
Documents
+ + + + + + + + + {% for doc in lot.trade.documents %} + + + + + {% endfor %} + +
FileUploaded on
+ {% if doc.url %} + {{ doc.file_name}} + {% else %} + {{ doc.file_name}} + {% endif %} + + {{ doc.created.strftime('%H:%M %d-%m-%Y')}} +
+
+ {% endif %} + +
+ {% endif %} +
+
+
+ +
+ +
+ +
+{% include "inventory/addDevicestag.html" %} +{% include "inventory/lot_delete_modal.html" %} +{% include "inventory/actions.html" %} +{% include "inventory/allocate.html" %} +{% include "inventory/data_wipe.html" %} +{% include "inventory/trade.html" %} +{% include "inventory/alert_export_error.html" %} +{% include "inventory/alert_unlink_tag_error.html" %} +{% include "inventory/alert_lots_changes.html" %} + + + + +{% endblock main %} diff --git a/tests/test_basic.py b/tests/test_basic.py index f9960219..c7b53c7b 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -42,6 +42,7 @@ def test_api_docs(client: Client): '/documents/erasures/', '/documents/internalstats/', '/documents/lots/', + '/inventory/search/', '/documents/stamps/', '/documents/static/{filename}', '/documents/stock/',