diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e26265b1..63a0458c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,6 @@ repos: rev: 5.9.3 hooks: - id: isort - # args: ["--profile", "black", "--filter-files"] - repo: https://github.com/PyCQA/flake8 rev: 4.0.1 hooks: diff --git a/CHANGELOG.md b/CHANGELOG.md index 96d64604..4e7d9b0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,34 +5,39 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.ht ml). +## master -## [2.0.0-alpha] -- [changes] #209 adding a new device in a lot if it is created from a lot -- [addend] #208 render from backend filter for type of devices in the general list -- [bugfix] #206 fix 2 bugs about visibility devices when you are not the owner -- [addend] #205 ux improvements -- [addend] #204 render from backend export files -- [addend] #203 render from backend Trade action -- [addend] #201 render from backend Data Wipe action -- [addend] #196 render from backend action system -- [addend] #195 render from backend tags system -- [addend] #193 render from backend devices and lots -- [changes] #191 pass to drop teal and use the pure flask and use render from flask +## testing + +## [2.0.0] - 2022-03-15 +First server render HTML version. Completely rewrites views of angular JS client on flask. +- [added] #193 render on backend devices and lots +- [added] #195 render on backend tags system +- [added] #196 render on backend action system +- [added] #201 render on backend Data Wipe action +- [added] #203 render on backend Trade action +- [added] #204 render on backend export files +- [added] #205 UX improvements +- [added] #208 render on backend filter for type of devices in the general list +- [changed] #191 pass to drop teal and use the pure flask and use render from flask +- [changed] #207 Create automatic tag only for Computers. +- [changed] #209 adding a new device in a lot if it is created from a lot +- [fixed] #206 fix 2 bugs about visibility devices when you are not the owner ## [1.0.12-beta] -- [changes] #187 now is possible duplicate slots of RAM. -- [changes] #188 Excel report devices allow to see device to old owners. +- [changed] #187 now is possible duplicate slots of RAM. +- [changed] #188 Excel report devices allow to see device to old owners. ## [1.0.11-beta] -- [addend] #186 adding property power_on_hours. +- [added] #186 adding property power_on_hours. ## [1.0.10-beta] -- [addend] #170 can delete/deactivate devices. -- [bugfix] #168 can to do a trade without devices. +- [added] #170 can delete/deactivate devices. - [added] #167 new actions of status devices: use, recycling, refurbish and management. -- [changes] #177 new structure of trade. -- [bugfix] #184 clean nested of schemas of lot - [added] #182 adding power on hours +- [changed] #177 new structure of trade. +- [fixed] #168 can to do a trade without devices. +- [fixed] #184 clean nested of schemas of lot ## [1.0.9-beta] - [added] #159 external document as proof of erase of disk @@ -40,7 +45,7 @@ ml). ## [1.0.8-beta] -- [bugfix] #161 fixing DataStorage with bigInteger +- [fixed] #161 fixing DataStorage with bigInteger ## [1.0.7-beta] - [added] #158 support for encrypted snapshots data @@ -48,26 +53,26 @@ ml). - [added] #140 adding endpoint for download the settings for usb workbench ## [1.0.6-beta] -- [bugfix] #143 biginteger instead of integer in TestDataStorage +- [fixed] #143 biginteger instead of integer in TestDataStorage ## [1.0.5-beta] - [added] #124 adding endpoint for extract the internal stats of use - [added] #122 system for verify all documents that it's produced from devicehub - [added] #127 add one code for every named tag - [added] #131 add one code for every device -- [bugfix] #138 search device with devicehubId +- [fixed] #138 search device with devicehubId ## [1.0.4-beta] - [added] #95 adding endpoint for check the hash of one report - [added] #98 adding endpoint for insert a new live - [added] #98 adding endpoint for get all licences in one query - [added] #102 adding endpoint for download metrics -- [bugfix] #100 fixing bug of scheme live -- [bugfix] #101 fixing bug when 2 users have one device and launch one live -- [changes] #114 clean blockchain of all models -- [changes] #118 deactivate manual merge -- [changes] #118 clean datas of public information of devices -- [remove] #114 remove proof system +- [changed] #114 clean blockchain of all models +- [changed] #118 deactivate manual merge +- [changed] #118 clean datas of public information of devices +- [fixed] #100 fixing bug of scheme live +- [fixed] #101 fixing bug when 2 users have one device and launch one live +- [removed] #114 remove proof system ## [1.0.3-beta] - [added] #85 add mac of network adapter to device hid @@ -75,6 +80,6 @@ ml). ## [1.0.2-beta] - [added] #87 allocate, deallocate and live actions -- [fixed] #89 save json on disk only for shapshots - [added] #83 add owner_id in all kind of device +- [fixed] #89 save json on disk only for shapshots - [fixed] #91 The most old time allow is 1970-01-01 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 16e3dfea..c34d93c5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,3 @@ -; SHARED on https://pad.cas.cat/usody-devicehub-contributing - # Contributing to devicehub ## Writing code diff --git a/ereuse_devicehub/__init__.py b/ereuse_devicehub/__init__.py index c69e4574..4bf535c4 100644 --- a/ereuse_devicehub/__init__.py +++ b/ereuse_devicehub/__init__.py @@ -1 +1 @@ -__version__ = "1.0.12-beta" +__version__ = "2.1.0.dev" diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 27069e56..5eab3236 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -51,6 +51,51 @@ from ereuse_devicehub.resources.tradedocument.models import TradeDocument from ereuse_devicehub.resources.user.exceptions import InsufficientPermission from ereuse_devicehub.resources.user.models import User +DEVICES = { + "All": ["All"], + "Computer": [ + "Desktop", + "Laptop", + "Server", + ], + "Monitor": ["ComputerMonitor", "Monitor", "TelevisionSet", "Projector"], + "Mobile, tablet & smartphone": ["Mobile", "Tablet", "Smartphone", "Cellphone"], + "DataStorage": ["HardDrive", "SolidStateDrive"], + "Accessories & Peripherals": [ + "GraphicCard", + "Motherboard", + "NetworkAdapter", + "Processor", + "RamModule", + "SoundCard", + "Battery", + "Keyboard", + "Mouse", + "MemoryCardReader", + ], +} + + +class FilterForm(FlaskForm): + filter = SelectField( + '', choices=DEVICES, default="Computer", render_kw={'class': "form-select"} + ) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + types_of_devices = [item for sublist in DEVICES.values() for item in sublist] + dev = request.args.get('filter') + self.device = dev if dev in types_of_devices else None + if self.device: + self.filter.data = self.device + + def search(self): + + if self.device: + return [self.device] + + return ['Desktop', 'Laptop', 'Server'] + class LotDeviceForm(FlaskForm): lot = StringField('Lot', [validators.UUID()]) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index e3ce18a4..4e827be4 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -11,11 +11,12 @@ from requests.exceptions import ConnectionError from sqlalchemy import or_ from werkzeug.exceptions import NotFound -from ereuse_devicehub import messages +from ereuse_devicehub import __version__, messages from ereuse_devicehub.db import db from ereuse_devicehub.inventory.forms import ( AllocateForm, DataWipeForm, + FilterForm, LotDeviceForm, LotForm, NewActionForm, @@ -34,8 +35,7 @@ from ereuse_devicehub.resources.hash_reports import insert_hash from ereuse_devicehub.resources.lot.models import Lot from ereuse_devicehub.resources.tag.model import Tag -# TODO(@slamora): rename base 'inventory.devices' --> 'inventory' -devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory') +devices = Blueprint('inventory', __name__, url_prefix='/inventory') logger = logging.getLogger(__name__) @@ -60,9 +60,8 @@ class DeviceListMix(GenericMixView): template_name = 'inventory/device_list.html' def get_context(self, lot_id): - # TODO @cayop adding filter - # https://github.com/eReuse/devicehub-teal/blob/testing/ereuse_devicehub/resources/device/views.py#L56 - filter_types = ['Desktop', 'Laptop', 'Server'] + form_filter = FilterForm() + filter_types = form_filter.search() lots = self.get_lots() lot = None tags = ( @@ -72,9 +71,10 @@ class DeviceListMix(GenericMixView): ) if lot_id: - # import pdb; pdb.set_trace() lot = lots.filter(Lot.id == lot_id).one() - devices = [dev for dev in lot.devices if dev.type in filter_types] + devices = lot.devices + if "All" not in filter_types: + devices = [dev for dev in lot.devices if dev.type in filter_types] devices = sorted(devices, key=lambda x: x.updated, reverse=True) form_new_action = NewActionForm(lot=lot.id) form_new_allocate = AllocateForm(lot=lot.id) @@ -85,12 +85,20 @@ class DeviceListMix(GenericMixView): user_from=g.user.email, ) else: - devices = ( - Device.query.filter(Device.owner_id == current_user.id) - .filter(Device.type.in_(filter_types)) - .filter_by(lots=None) - .order_by(Device.updated.desc()) - ) + if "All" in filter_types: + devices = ( + Device.query.filter(Device.owner_id == current_user.id) + .filter_by(lots=None) + .order_by(Device.updated.desc()) + ) + else: + devices = ( + Device.query.filter(Device.owner_id == current_user.id) + .filter_by(lots=None) + .filter(Device.type.in_(filter_types)) + .order_by(Device.updated.desc()) + ) + form_new_action = NewActionForm() form_new_allocate = AllocateForm() form_new_datawipe = DataWipeForm() @@ -109,9 +117,11 @@ class DeviceListMix(GenericMixView): 'form_new_allocate': form_new_allocate, 'form_new_datawipe': form_new_datawipe, 'form_new_trade': form_new_trade, + 'form_filter': form_filter, 'lot': lot, 'tags': tags, 'list_devices': list_devices, + 'version': __version__, } return self.context @@ -139,6 +149,7 @@ class DeviceDetailView(GenericMixView): 'device': device, 'lots': lots, 'page_title': 'Device {}'.format(device.devicehub_id), + 'version': __version__, } return flask.render_template(self.template_name, **context) @@ -159,7 +170,7 @@ class LotDeviceAddView(View): else: messages.error('Error adding devices to lot!') - next_url = request.referrer or url_for('inventory.devices.devicelist') + next_url = request.referrer or url_for('inventory.devicelist') return flask.redirect(next_url) @@ -179,7 +190,7 @@ class LotDeviceDeleteView(View): else: messages.error('Error removing devices from lot!') - next_url = request.referrer or url_for('inventory.devices.devicelist') + next_url = request.referrer or url_for('inventory.devicelist') return flask.redirect(next_url) @@ -193,11 +204,16 @@ class LotCreateView(GenericMixView): form = LotForm() if form.validate_on_submit(): form.save() - next_url = url_for('inventory.devices.lotdevicelist', lot_id=form.id) + next_url = url_for('inventory.lotdevicelist', lot_id=form.id) return flask.redirect(next_url) lots = self.get_lots() - context = {'form': form, 'title': self.title, 'lots': lots} + context = { + 'form': form, + 'title': self.title, + 'lots': lots, + 'version': __version__, + } return flask.render_template(self.template_name, **context) @@ -211,11 +227,16 @@ class LotUpdateView(View): form = LotForm(id=id) if form.validate_on_submit(): form.save() - next_url = url_for('inventory.devices.lotdevicelist', lot_id=id) + next_url = url_for('inventory.lotdevicelist', lot_id=id) return flask.redirect(next_url) lots = Lot.query.filter(Lot.owner_id == current_user.id) - context = {'form': form, 'title': self.title, 'lots': lots} + context = { + 'form': form, + 'title': self.title, + 'lots': lots, + 'version': __version__, + } return flask.render_template(self.template_name, **context) @@ -229,11 +250,11 @@ class LotDeleteView(View): if form.instance.trade: msg = "Sorry, the lot cannot be deleted because have a trade action " messages.error(msg) - next_url = url_for('inventory.devices.lotdevicelist', lot_id=id) + next_url = url_for('inventory.lotdevicelist', lot_id=id) return flask.redirect(next_url) form.remove() - next_url = url_for('inventory.devices.devicelist') + next_url = url_for('inventory.devicelist') return flask.redirect(next_url) @@ -250,6 +271,7 @@ class UploadSnapshotView(GenericMixView): 'lots': lots, 'form': form, 'lot_id': lot_id, + 'version': __version__, } if form.validate_on_submit(): snapshot = form.save(commit=False) @@ -275,12 +297,13 @@ class DeviceCreateView(GenericMixView): 'lots': lots, 'form': form, 'lot_id': lot_id, + 'version': __version__, } if form.validate_on_submit(): snapshot = form.save(commit=False) - next_url = url_for('inventory.devices.devicelist') + next_url = url_for('inventory.devicelist') if lot_id: - next_url = url_for('inventory.devices.lotdevicelist', lot_id=lot_id) + next_url = url_for('inventory.lotdevicelist', lot_id=lot_id) lot = lots.filter(Lot.id == lot_id).one() lot.devices.add(snapshot.device) db.session.add(lot) @@ -304,6 +327,7 @@ class TagListView(View): 'lots': lots, 'tags': tags, 'page_title': 'Tags Management', + 'version': __version__, } return flask.render_template(self.template_name, **context) @@ -315,11 +339,11 @@ class TagAddView(View): def dispatch_request(self): lots = Lot.query.filter(Lot.owner_id == current_user.id) - context = {'page_title': 'New Tag', 'lots': lots} + context = {'page_title': 'New Tag', 'lots': lots, 'version': __version__} form = TagForm() if form.validate_on_submit(): form.save() - next_url = url_for('inventory.devices.taglist') + next_url = url_for('inventory.taglist') return flask.redirect(next_url) return flask.render_template(self.template_name, form=form, **context) @@ -332,7 +356,11 @@ class TagAddUnnamedView(View): def dispatch_request(self): lots = Lot.query.filter(Lot.owner_id == current_user.id) - context = {'page_title': 'New Unnamed Tag', 'lots': lots} + context = { + 'page_title': 'New Unnamed Tag', + 'lots': lots, + 'version': __version__, + } form = TagUnnamedForm() if form.validate_on_submit(): try: @@ -347,7 +375,7 @@ class TagAddUnnamedView(View): ) messages.error(msg) - next_url = url_for('inventory.devices.taglist') + next_url = url_for('inventory.taglist') return flask.redirect(next_url) return flask.render_template(self.template_name, form=form, **context) @@ -367,6 +395,7 @@ class TagDetailView(View): 'lots': lots, 'tag': tag, 'page_title': '{} Tag'.format(tag.code), + 'version': __version__, } return flask.render_template(self.template_name, **context) @@ -395,11 +424,15 @@ class TagUnlinkDeviceView(View): if form.validate_on_submit(): form.remove() - next_url = url_for('inventory.devices.devicelist') + next_url = url_for('inventory.devicelist') return flask.redirect(next_url) return flask.render_template( - self.template_name, form=form, lots=lots, referrer=request.referrer + self.template_name, + form=form, + lots=lots, + referrer=request.referrer, + version=__version__, ) @@ -424,9 +457,9 @@ class NewActionView(View): lot_id = self.form.lot.data if lot_id: - return url_for('inventory.devices.lotdevicelist', lot_id=lot_id) + return url_for('inventory.lotdevicelist', lot_id=lot_id) - return url_for('inventory.devices.devicelist') + return url_for('inventory.devicelist') class NewAllocateView(NewActionView, DeviceListMix): @@ -508,11 +541,11 @@ class NewTradeDocumentView(View): if self.form.validate_on_submit(): self.form.save() messages.success('Document created successfully!') - next_url = url_for('inventory.devices.lotdevicelist', lot_id=lot_id) + next_url = url_for('inventory.lotdevicelist', lot_id=lot_id) return flask.redirect(next_url) return flask.render_template( - self.template_name, form=self.form, title=self.title + self.template_name, form=self.form, title=self.title, version=__version__ ) diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 107be562..f9c7a4b0 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1736,7 +1736,7 @@ class MoveOnDocument(JoinedTableMixin, ActionWithMultipleTradeDocuments): """Action than certify one movement of some indescriptible material of one container to an other.""" - weight = db.Column(db.Float(nullable=True)) + weight = db.Column(db.Float()) weight.comment = """Weight than go to recycling""" container_from_id = db.Column( db.BigInteger, diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 89ddc846..98227c4c 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -1217,8 +1217,9 @@ def create_code_tag(mapper, connection, device): this tag is the same of devicehub_id. """ from ereuse_devicehub.resources.tag.model import Tag - tag = Tag(device_id=device.id, id=device.devicehub_id) - db.session.add(tag) + if isinstance(device, Computer): + tag = Tag(device_id=device.id, id=device.devicehub_id) + db.session.add(tag) event.listen(Device, 'after_insert', create_code_tag, propagate=True) diff --git a/ereuse_devicehub/resources/tradedocument/models.py b/ereuse_devicehub/resources/tradedocument/models.py index 177b2bd3..59d8a8c4 100644 --- a/ereuse_devicehub/resources/tradedocument/models.py +++ b/ereuse_devicehub/resources/tradedocument/models.py @@ -72,7 +72,7 @@ class TradeDocument(Thing): file_hash.comment = """This is the hash of the file produced from frontend.""" url = db.Column(URL()) url.comment = """This is the url where resides the document.""" - weight = db.Column(db.Float(nullable=True)) + weight = db.Column(db.Float()) weight.comment = """This is the weight of one container than this document express.""" __table_args__ = ( @@ -150,10 +150,10 @@ class TradeDocument(Thing): with suppress(StopIteration, ValueError): actions = copy.copy(self.actions) actions.sort(key=lambda x: x.created) - t_trades = ['Trade', - 'Confirm', - 'ConfirmRevokeDocument', - 'RevokeDocument', + t_trades = ['Trade', + 'Confirm', + 'ConfirmRevokeDocument', + 'RevokeDocument', 'ConfirmDocument'] return next(e for e in reversed(actions) if e.t in t_trades) diff --git a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html index f9c1e075..5d87be53 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html @@ -5,7 +5,7 @@