mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-16 20:49:00 -04:00
Get info about organisations from database table
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.
This commit is contained in:
27
app/models/__init__.py
Normal file
27
app/models/__init__.py
Normal file
@@ -0,0 +1,27 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user