From b66464dc46e749af194ed9db759ba68fc772a6d4 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 20 Sep 2020 11:31:51 -0700 Subject: [PATCH] Add exceptions.DeletedObject and ObjectBase.assert_not_deleted. --- etiquette/exceptions.py | 6 ++++++ etiquette/objects.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/etiquette/exceptions.py b/etiquette/exceptions.py index dbe28e2..4ce9034 100644 --- a/etiquette/exceptions.py +++ b/etiquette/exceptions.py @@ -181,6 +181,12 @@ class DatabaseOutOfDate(EtiquetteException): ''' error_message = OUTOFDATE +class DeletedObject(EtiquetteException): + ''' + For when thing.deleted == True. + ''' + error_message = '{} has already been deleted by another caller.' + class FeatureDisabled(EtiquetteException): ''' For when features of the system have been disabled by the configuration. diff --git a/etiquette/objects.py b/etiquette/objects.py index b23e050..0a2775e 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -68,6 +68,10 @@ class ObjectBase: return author_id + def assert_not_deleted(self): + if self.deleted: + raise exceptions.DeletedObject(self) + def get_author(self): ''' Return the User who created this object, or None if it is unassigned.