summaryrefslogtreecommitdiff
path: root/web-server/opendc/models/model.py
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-06-30 13:28:18 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:42:28 +0200
commit9f87ab4bbab048b527585929135cab80fafd9ef9 (patch)
tree835e41c1660ab12a2f3299049d2e15f8495d3b4b /web-server/opendc/models/model.py
parent5c673272747ed14e5668b2f4301f0f853b400ee1 (diff)
Address a number of pylint issues
Diffstat (limited to 'web-server/opendc/models/model.py')
-rw-r--r--web-server/opendc/models/model.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/web-server/opendc/models/model.py b/web-server/opendc/models/model.py
index b2fd1844..2b8eb4dc 100644
--- a/web-server/opendc/models/model.py
+++ b/web-server/opendc/models/model.py
@@ -4,31 +4,40 @@ from opendc.util.rest import Response
class Model:
+ """Base class for all models."""
+
collection_name = '<specified in subclasses>'
@classmethod
def from_id(cls, _id):
- return cls(DB.fetch_one({'_id': _id}, Model.collection_name))
+ """Fetches the document with given ID from the collection."""
+ return cls(DB.fetch_one({'_id': _id}, cls.collection_name))
@classmethod
def get_all(cls):
- return cls(DB.fetch_all({}, Model.collection_name))
+ """Fetches all documents from the collection."""
+ return cls(DB.fetch_all({}, cls.collection_name))
def __init__(self, obj):
self.obj = obj
def check_exists(self):
+ """Raises an error if the enclosed object does not exist."""
if self.obj is None:
raise ClientError(Response(404, 'Not found.'))
def set_property(self, key, value):
+ """Sets the given property on the enclosed object."""
self.obj[key] = value
def insert(self):
+ """Inserts the enclosed object and updates the internal reference to the newly inserted object."""
self.obj = DB.insert(self.obj, self.collection_name)
def update(self):
+ """Updates the enclosed object and updates the internal reference to the newly inserted object."""
self.obj = DB.update(self.obj['_id'], self.obj, self.collection_name)
def delete(self):
- self.obj = DB.delete_one({'_id': self.obj['_id']}, self.collection_name)
+ """Deletes the enclosed object in the database."""
+ DB.delete_one({'_id': self.obj['_id']}, self.collection_name)