Refactor: put the delete rule constants into the queryset module, too.

This commit is contained in:
Vincent Driessen 2010-12-13 13:42:01 -08:00
parent 3b55deb472
commit f30fd71c5e
2 changed files with 11 additions and 13 deletions

View File

@ -1,21 +1,14 @@
from base import (DocumentMetaclass, TopLevelDocumentMetaclass, BaseDocument, from base import (DocumentMetaclass, TopLevelDocumentMetaclass, BaseDocument,
ValidationError) ValidationError)
from queryset import OperationError from queryset import OperationError, DO_NOTHING
from connection import _get_db from connection import _get_db
import pymongo import pymongo
__all__ = ['Document', 'EmbeddedDocument', 'ValidationError', 'OperationError', __all__ = ['Document', 'EmbeddedDocument', 'ValidationError', 'OperationError']
'DO_NOTHING', 'NULLIFY', 'CASCADE', 'DENY']
# Delete rules
DO_NOTHING = 0
NULLIFY = 1
CASCADE = 2
DENY = 3
class EmbeddedDocument(BaseDocument): class EmbeddedDocument(BaseDocument):
"""A :class:`~mongoengine.Document` that isn't stored in its own """A :class:`~mongoengine.Document` that isn't stored in its own
collection. :class:`~mongoengine.EmbeddedDocument`\ s should be used as collection. :class:`~mongoengine.EmbeddedDocument`\ s should be used as
@ -110,7 +103,7 @@ class Document(BaseDocument):
@classmethod @classmethod
def register_delete_rule(cls, document_cls, field_name, rule): def register_delete_rule(cls, document_cls, field_name, rule):
"""This method registers the delete rules to apply when removing this """This method registers the delete rules to apply when removing this
object. This could go into the Document class. object.
""" """
if rule == DO_NOTHING: if rule == DO_NOTHING:
return return

View File

@ -10,11 +10,18 @@ import copy
import itertools import itertools
__all__ = ['queryset_manager', 'Q', 'InvalidQueryError', __all__ = ['queryset_manager', 'Q', 'InvalidQueryError',
'InvalidCollectionError'] 'InvalidCollectionError', 'DO_NOTHING', 'NULLIFY', 'CASCADE', 'DENY']
# The maximum number of items to display in a QuerySet.__repr__ # The maximum number of items to display in a QuerySet.__repr__
REPR_OUTPUT_SIZE = 20 REPR_OUTPUT_SIZE = 20
# Delete rules
DO_NOTHING = 0
NULLIFY = 1
CASCADE = 2
DENY = 3
class DoesNotExist(Exception): class DoesNotExist(Exception):
pass pass
@ -882,8 +889,6 @@ class QuerySet(object):
:param safe: check if the operation succeeded before returning :param safe: check if the operation succeeded before returning
""" """
from document import CASCADE, DENY, NULLIFY
doc = self._document doc = self._document
# Check for DENY rules before actually deleting/nullifying any other # Check for DENY rules before actually deleting/nullifying any other