From f30fd71c5ee6af832cdb9e01f9fdb915fef421ea Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Mon, 13 Dec 2010 13:42:01 -0800 Subject: [PATCH] Refactor: put the delete rule constants into the queryset module, too. --- mongoengine/document.py | 13 +++---------- mongoengine/queryset.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/mongoengine/document.py b/mongoengine/document.py index d1a031ab..504e14eb 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -1,21 +1,14 @@ from base import (DocumentMetaclass, TopLevelDocumentMetaclass, BaseDocument, ValidationError) -from queryset import OperationError +from queryset import OperationError, DO_NOTHING from connection import _get_db import pymongo -__all__ = ['Document', 'EmbeddedDocument', 'ValidationError', 'OperationError', - 'DO_NOTHING', 'NULLIFY', 'CASCADE', 'DENY'] +__all__ = ['Document', 'EmbeddedDocument', 'ValidationError', 'OperationError'] -# Delete rules -DO_NOTHING = 0 -NULLIFY = 1 -CASCADE = 2 -DENY = 3 - class EmbeddedDocument(BaseDocument): """A :class:`~mongoengine.Document` that isn't stored in its own collection. :class:`~mongoengine.EmbeddedDocument`\ s should be used as @@ -110,7 +103,7 @@ class Document(BaseDocument): @classmethod def register_delete_rule(cls, document_cls, field_name, rule): """This method registers the delete rules to apply when removing this - object. This could go into the Document class. + object. """ if rule == DO_NOTHING: return diff --git a/mongoengine/queryset.py b/mongoengine/queryset.py index 82efd4f7..c400a614 100644 --- a/mongoengine/queryset.py +++ b/mongoengine/queryset.py @@ -10,11 +10,18 @@ import copy import itertools __all__ = ['queryset_manager', 'Q', 'InvalidQueryError', - 'InvalidCollectionError'] + 'InvalidCollectionError', 'DO_NOTHING', 'NULLIFY', 'CASCADE', 'DENY'] + # The maximum number of items to display in a QuerySet.__repr__ REPR_OUTPUT_SIZE = 20 +# Delete rules +DO_NOTHING = 0 +NULLIFY = 1 +CASCADE = 2 +DENY = 3 + class DoesNotExist(Exception): pass @@ -882,8 +889,6 @@ class QuerySet(object): :param safe: check if the operation succeeded before returning """ - from document import CASCADE, DENY, NULLIFY - doc = self._document # Check for DENY rules before actually deleting/nullifying any other