Add cache; bugfixing

This commit is contained in:
Xavier Bustamante Talavera 2019-01-29 16:29:08 +01:00
parent 74860be347
commit d2160b9db5
7 changed files with 40 additions and 13 deletions

View file

@ -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

View file

@ -20,9 +20,11 @@
<td>
{{ erasure.parent.serial_number.upper() }}
</td>
{% else %}
<td></td>
{% endif %}
<td>
{{ erasure.parent.tags }}
{{ erasure.parent.tags.__format__('') }}
</td>
<td>
{{ erasure.device.serial_number.upper() }}
@ -55,6 +57,7 @@
<dd>{{ erasure.parent.tags }}</dd>
<dt>Erasure:</dt>
<dd>{{ erasure.__format__('ts') }}</dd>
{% if erasure.steps %}
<dt>Erasure steps:</dt>
<dd>
<ol>
@ -63,6 +66,7 @@
{% endfor %}
</ol>
</dd>
{% endif %}
</dl>
</div>
{% endfor %}

View file

@ -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

View file

@ -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):

View file

@ -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.

View file

@ -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)

View file

@ -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()) \