mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 19:03:30 -05:00
This is the first step of replacing the `domains.yml` file. In order to replicate the same functionality we get from the `domains.yml` file and its associated code this commit adds a `Organisation` model. This model copies a lot of methods from the `AgreementInfo` class which wrapped the `domains.yml` file. It factors out some stuff that would otherwise be duplicated between the `Organisation` and `Service` model, in such a way that could be reused for making other models in the future. This commit doesn’t change other parts of the code to make use of this new model yet – that will come in subsequent commits.
28 lines
694 B
Python
28 lines
694 B
Python
from flask import abort
|
|
|
|
|
|
class JSONModel():
|
|
|
|
ALLOWED_PROPERTIES = set()
|
|
|
|
def __init__(self, _dict):
|
|
# in the case of a bad request _dict may be `None`
|
|
self._dict = _dict or {}
|
|
|
|
def __bool__(self):
|
|
return self._dict != {}
|
|
|
|
def __getattr__(self, attr):
|
|
if attr in self.ALLOWED_PROPERTIES:
|
|
return self._dict[attr]
|
|
raise AttributeError('`{}` is not a {} attribute'.format(
|
|
attr,
|
|
self.__class__.__name__.lower(),
|
|
))
|
|
|
|
def _get_by_id(self, things, id):
|
|
try:
|
|
return next(thing for thing in things if thing['id'] == str(id))
|
|
except StopIteration:
|
|
abort(404)
|