Wrap a model around list of all organisations

This commit is contained in:
Chris Hill-Scott
2019-06-12 13:40:57 +01:00
parent 0aea038d51
commit 913095fe60
6 changed files with 43 additions and 22 deletions

View File

@@ -1,3 +1,6 @@
from abc import ABC, abstractmethod
from collections.abc import Sequence
from flask import abort
@@ -33,5 +36,30 @@ class JSONModel():
abort(404)
class ModelList(ABC, Sequence):
@property
@abstractmethod
def client():
pass
@property
@abstractmethod
def model():
pass
def __init__(self):
self.items = self.client()
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)
class InviteTokenError(Exception):
pass