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.