mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-11 09:28:27 -04:00
Wrap a model around list of all organisations
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user