Bump utils to 40.2.1

Brings in:
- re-usable `SerialisedModel`
- speed improvements to processing CSVs against email templates

I chose not to rename `JSONModel` or `ModelList` to keep the diff nice
and small.
This commit is contained in:
Chris Hill-Scott
2020-07-03 14:07:40 +01:00
parent 98eb3c61f6
commit c4458efa21
4 changed files with 19 additions and 29 deletions

View File

@@ -1,12 +1,13 @@
from abc import ABC, abstractmethod
from collections.abc import Sequence
from abc import abstractmethod
from flask import abort
from notifications_utils.serialised_model import (
SerialisedModel,
SerialisedModelCollection,
)
class JSONModel():
ALLOWED_PROPERTIES = set()
class JSONModel(SerialisedModel):
def __init__(self, _dict):
# in the case of a bad request _dict may be `None`
@@ -25,6 +26,8 @@ class JSONModel():
return self.id == other.id
def __getattribute__(self, attr):
# Eventually we should remove this custom implementation in
# favour of looping over self.ALLOWED_PROPERTIES in __init__
try:
return super().__getattribute__(attr)
@@ -54,29 +57,12 @@ class JSONModel():
abort(404)
class ModelList(ABC, Sequence):
class ModelList(SerialisedModelCollection):
@property
@abstractmethod
def client_method(self):
pass
@property
@abstractmethod
def model(self):
pass
def __init__(self, *args):
self.items = self.client_method(*args)
def __getitem__(self, index):
return self.model(self.items[index])
def __len__(self):
return len(self.items)
def __add__(self, other):
return list(self) + list(other)
def __radd__(self, other):
return list(other) + list(self)