Skip to content

Commit

Permalink
New validation for model
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Nov 12, 2019
1 parent 3012e28 commit 1b71be5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/appier/legacy.py
Expand Up @@ -108,6 +108,11 @@ def ctx_absolute():
interpreter support the async/await syntax responsible
for the easy to use async methods """

PYTHON_ASYNC_GEN = sys.version_info[0] >= 3 and sys.version_info[1] >= 6
""" Global variable that defines if the current Python
interpreter support the async/await generator syntax
responsible for the async generator methods """

PYTHON_V = int("".join([str(v) for v in sys.version_info[:3]]))
""" The Python version integer describing the version of
a the interpreter as a set of three integer digits """
Expand Down
2 changes: 1 addition & 1 deletion src/appier/model.py
Expand Up @@ -241,7 +241,7 @@
""" The sequence that will contain the complete set of extra classes
(mixins) to add base functionality to the Model instances """

if legacy.PYTHON_ASYNC:
if legacy.PYTHON_ASYNC_GEN:
from . import model_a
EXTRA_CLS.append(model_a.ModelAsync)

Expand Down
22 changes: 22 additions & 0 deletions src/appier/model_a.py
Expand Up @@ -228,6 +228,28 @@ async def save_a(
# operation, this may be used for chaining operations
return self

async def delete_a(self, verify = True, pre_delete = True, post_delete = True):
# ensures that the current instance is associated with
# a concrete model, ready to be persisted in database
if verify: self.assert_is_concrete()

# calls the complete set of event handlers for the current
# delete operation, this should trigger changes in the model
pre_delete and self.pre_delete()

# retrieves the reference to the store object to be able to
# execute the removal command for the current model
store = self._get_store_a()
await store.remove({"_id" : self._id})

# calls the underlying delete handler that may be used to extend
# the default delete functionality
self._delete()

# calls the complete set of event handlers for the current
# delete operation, this should trigger changes in the model
post_delete and self.post_delete()

async def _filter_a(
self,
increment_a = True,
Expand Down

0 comments on commit 1b71be5

Please sign in to comment.