home
·
contact
·
privacy
projects
/
plomtask
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Refactor request handler delete or retrieving items on POST.
[plomtask]
/
plomtask
/
db.py
diff --git
a/plomtask/db.py
b/plomtask/db.py
index b3f1db00986b1142f5f31be34060864840ab5bdc..71c59d50d8b0013dcf3bd9e6c811080563606830 100644
(file)
--- a/
plomtask/db.py
+++ b/
plomtask/db.py
@@
-235,6
+235,7
@@
class BaseModel(Generic[BaseModelId]):
to_save: list[str] = []
to_save_versioned: list[str] = []
to_save_relations: list[tuple[str, str, str, int]] = []
to_save: list[str] = []
to_save_versioned: list[str] = []
to_save_relations: list[tuple[str, str, str, int]] = []
+ add_to_dict: list[str] = []
id_: None | BaseModelId
cache_: dict[BaseModelId, Self]
to_search: list[str] = []
id_: None | BaseModelId
cache_: dict[BaseModelId, Self]
to_search: list[str] = []
@@
-295,6
+296,9
@@
class BaseModel(Generic[BaseModelId]):
for rel in getattr(self, attr_name):
l += [rel.as_dict_into_reference(library)]
d[attr_name] = l
for rel in getattr(self, attr_name):
l += [rel.as_dict_into_reference(library)]
d[attr_name] = l
+ for k in self.add_to_dict:
+ d[k] = [x.as_dict_into_reference(library)
+ for x in getattr(self, k)]
return d
def as_dict_into_reference(self,
return d
def as_dict_into_reference(self,
@@
-326,6
+330,11
@@
class BaseModel(Generic[BaseModelId]):
assert isinstance(as_dict['id'], (int, str))
return as_dict['id']
assert isinstance(as_dict['id'], (int, str))
return as_dict['id']
+ @classmethod
+ def name_lowercase(cls) -> str:
+ """Convenience method to return cls' name in lowercase."""
+ return cls.__name__.lower()
+
# cache management
# (we primarily use the cache to ensure we work on the same object in
# memory no matter where and how we retrieve it, e.g. we don't want
# cache management
# (we primarily use the cache to ensure we work on the same object in
# memory no matter where and how we retrieve it, e.g. we don't want