diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index 8dbcec33..a1822515 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -107,6 +107,7 @@ class DeviceView(View): return self.schema.jsonify(device) @auth.Auth.requires_auth + @cache(datetime.timedelta(minutes=1)) def find(self, args: dict): """Gets many devices.""" # Compute query diff --git a/ereuse_devicehub/resources/documents/templates/documents/erasure.html b/ereuse_devicehub/resources/documents/templates/documents/erasure.html index 29e1d138..518358df 100644 --- a/ereuse_devicehub/resources/documents/templates/documents/erasure.html +++ b/ereuse_devicehub/resources/documents/templates/documents/erasure.html @@ -20,9 +20,11 @@ {{ erasure.parent.serial_number.upper() }} + {% else %} + {% endif %} - {{ erasure.parent.tags }} + {{ erasure.parent.tags.__format__('') }} {{ erasure.device.serial_number.upper() }} @@ -55,14 +57,16 @@
{{ erasure.parent.tags }}
Erasure:
{{ erasure.__format__('ts') }}
-
Erasure steps:
-
-
    - {% for step in erasure.steps %} -
  1. {{ step.__format__('') }}
  2. - {% endfor %} -
-
+ {% if erasure.steps %} +
Erasure steps:
+
+
    + {% for step in erasure.steps %} +
  1. {{ step.__format__('') }}
  2. + {% endfor %} +
+
+ {% endif %} {% endfor %} diff --git a/ereuse_devicehub/resources/event/models.py b/ereuse_devicehub/resources/event/models.py index f15ed1b2..6069ca2e 100644 --- a/ereuse_devicehub/resources/event/models.py +++ b/ereuse_devicehub/resources/event/models.py @@ -350,7 +350,10 @@ class EraseBasic(JoinedWithOneDeviceMixin, EventWithOneDevice): else: std = 'no standard' v += 'Method used: {}, {}. '.format(self.method, std) - v += '{} elapsed, on {}'.format(self.elapsed, self.date_str) + if self.end_time and self.start_time: + v += '{} elapsed. '.format(self.elapsed) + + v += 'On {}'.format(self.date_str) return v diff --git a/ereuse_devicehub/resources/event/models.pyi b/ereuse_devicehub/resources/event/models.pyi index 69971700..c6340b8c 100644 --- a/ereuse_devicehub/resources/event/models.pyi +++ b/ereuse_devicehub/resources/event/models.pyi @@ -61,6 +61,18 @@ class Event(Thing): def url(self) -> urlutils.URL: pass + @property + def elapsed(self) -> timedelta: + pass + + @property + def certificate(self) -> Optional[urlutils.URL]: + return None + + @property + def date_str(self): + return '{:%c}'.format(self.end_time or self.created) + class EventWithOneDevice(Event): diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index fb502da6..96c8c824 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -1,9 +1,11 @@ +import datetime import uuid from collections import deque from enum import Enum from typing import Dict, List, Set, Union import marshmallow as ma +import teal.cache from flask import Response, jsonify, request from marshmallow import Schema as MarshmallowSchema, fields as f from teal.marshmallow import EnumField @@ -50,6 +52,7 @@ class LotView(View): lot = Lot.query.filter_by(id=id).one() # type: Lot return self.schema.jsonify(lot) + @teal.cache.cache(datetime.timedelta(minutes=5)) def find(self, args: dict): """ Gets lots. diff --git a/ereuse_devicehub/resources/tag/model.py b/ereuse_devicehub/resources/tag/model.py index 49e2a2f4..367db2f1 100644 --- a/ereuse_devicehub/resources/tag/model.py +++ b/ereuse_devicehub/resources/tag/model.py @@ -2,10 +2,10 @@ from contextlib import suppress from typing import Set from boltons import urlutils -from sqlalchemy import BigInteger, Column, ForeignKey, Unicode, UniqueConstraint +from sqlalchemy import BigInteger, Column, ForeignKey, UniqueConstraint from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.orm import backref, relationship, validates -from teal.db import DB_CASCADE_SET_NULL, Query, URL, check_lower +from teal.db import DB_CASCADE_SET_NULL, Query, URL from teal.marshmallow import ValidationError from teal.resource import url_for_resource @@ -123,4 +123,4 @@ class Tag(Thing): return '{0.id} org: {0.org.name} device: {0.device}'.format(self) def __format__(self, format_spec: str) -> str: - return '{0.org.name} {0.id}' + return '{0.org.name} {0.id}'.format(self) diff --git a/ereuse_devicehub/resources/tag/view.py b/ereuse_devicehub/resources/tag/view.py index f337c8de..c4678873 100644 --- a/ereuse_devicehub/resources/tag/view.py +++ b/ereuse_devicehub/resources/tag/view.py @@ -1,3 +1,6 @@ +import datetime + +import teal.cache from flask import Response, current_app as app, g, redirect, request from flask_sqlalchemy import Pagination from teal.marshmallow import ValidationError @@ -19,6 +22,7 @@ class TagView(View): res = self._post_one() return res + @teal.cache.cache(datetime.timedelta(minutes=1)) def find(self, args: dict): tags = Tag.query.filter(Tag.is_printable_q()) \ .order_by(Tag.created.desc()) \