Files
notifications-api/app/json_models.py
Chris Hill-Scott 415083cc3e Don’t store the underlying dict
This will give us smaller objects to cache, and forces us to be explicit
about which properties we’re using.
2020-06-17 15:58:52 +01:00

31 lines
628 B
Python

from abc import ABC, abstractmethod
class JSONModel(ABC):
@property
@abstractmethod
def ALLOWED_PROPERTIES(self):
pass
def __init__(self, _dict):
for property in self.ALLOWED_PROPERTIES:
setattr(self, property, _dict[property])
def __dir__(self):
return super().__dir__() + list(sorted(self.ALLOWED_PROPERTIES))
class TemplateJSONModel(JSONModel):
ALLOWED_PROPERTIES = {
'archived',
'content',
'id',
'postage',
'process_type',
'reply_to_text',
'subject',
'template_type',
'version',
}