Compare commits

..

8 Commits

Author SHA1 Message Date
Stefan Wojcik
5e0b97e90c add a test with an invalid data type 2017-04-16 11:50:28 -04:00
Stefan Wojcik
a0a3805e2d Revert "switch from octal to hex for consistency" (because of pypy3)
This reverts commit 7d5caf8368.
2017-04-15 23:14:19 -04:00
Stefan Wojcik
7d5caf8368 switch from octal to hex for consistency 2017-04-15 22:20:19 -04:00
Stefan Wojcik
dee5465440 dont run the unicode email test on pypy3 2017-04-15 18:07:32 -04:00
Stefan Wojcik
33e50e48c1 use six.u 2017-04-15 16:46:36 -04:00
Stefan Wojcik
41371e5fc5 empty whitelist by default + allow_ip_domain option 2017-04-10 10:00:49 -04:00
Stefan Wojcik
ce86ea4c9a flake8 fixes 2017-04-10 08:18:56 -04:00
Stefan Wojcik
601b79865d support unicode in EmailField 2017-04-09 22:33:11 -04:00
6 changed files with 16 additions and 52 deletions

View File

@@ -6,11 +6,6 @@ Development
=========== ===========
- (Fill this out as you fix issues and develop your features). - (Fill this out as you fix issues and develop your features).
Changes in 0.13.0
=================
- POTENTIAL BREAKING CHANGE: Added Unicode support to the `EmailField`, see
docs/upgrade.rst for details.
Changes in 0.12.0 Changes in 0.12.0
================= =================
- POTENTIAL BREAKING CHANGE: Fixed limit/skip/hint/batch_size chaining #1476 - POTENTIAL BREAKING CHANGE: Fixed limit/skip/hint/batch_size chaining #1476

View File

@@ -6,17 +6,6 @@ Development
*********** ***********
(Fill this out whenever you introduce breaking changes to MongoEngine) (Fill this out whenever you introduce breaking changes to MongoEngine)
0.13.0
******
This release adds Unicode support to the `EmailField` and changes its
structure significantly. Previously, email addresses containing Unicode
characters didn't work at all. Starting with v0.13.0, domains with Unicode
characters are supported out of the box, meaning some emails that previously
didn't pass validation now do. Make sure the rest of your application can
accept such email addresses. Additionally, if you subclassed the `EmailField`
in your application and overrode `EmailField.EMAIL_REGEX`, you will have to
adjust your code to override `EmailField.USER_REGEX`, `EmailField.DOMAIN_REGEX`,
and potentially `EmailField.UTF8_USER_REGEX`.
0.12.0 0.12.0
****** ******

View File

@@ -23,7 +23,7 @@ __all__ = (list(document.__all__) + list(fields.__all__) +
list(signals.__all__) + list(errors.__all__)) list(signals.__all__) + list(errors.__all__))
VERSION = (0, 13, 0) VERSION = (0, 12, 0)
def get_version(): def get_version():

View File

@@ -272,6 +272,13 @@ class BaseDocument(object):
def __ne__(self, other): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)
def __hash__(self):
if getattr(self, 'pk', None) is None:
# For new object
return super(BaseDocument, self).__hash__()
else:
return hash(self.pk)
def clean(self): def clean(self):
""" """
Hook for doing document level data cleaning before validation is run. Hook for doing document level data cleaning before validation is run.

View File

@@ -60,12 +60,6 @@ class EmbeddedDocument(BaseDocument):
my_metaclass = DocumentMetaclass my_metaclass = DocumentMetaclass
__metaclass__ = DocumentMetaclass __metaclass__ = DocumentMetaclass
# A generic embedded document doesn't have any immutable properties
# that describe it uniquely, hence it shouldn't be hashable. You can
# define your own __hash__ method on a subclass if you need your
# embedded documents to be hashable.
__hash__ = None
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(EmbeddedDocument, self).__init__(*args, **kwargs) super(EmbeddedDocument, self).__init__(*args, **kwargs)
self._instance = None self._instance = None
@@ -166,15 +160,6 @@ class Document(BaseDocument):
"""Set the primary key.""" """Set the primary key."""
return setattr(self, self._meta['id_field'], value) return setattr(self, self._meta['id_field'], value)
def __hash__(self):
"""Return the hash based on the PK of this document. If it's new
and doesn't have a PK yet, return the default object hash instead.
"""
if self.pk is None:
return super(BaseDocument, self).__hash__()
else:
return hash(self.pk)
@classmethod @classmethod
def _get_db(cls): def _get_db(cls):
"""Some Model using other db_alias""" """Some Model using other db_alias"""

View File

@@ -2164,7 +2164,7 @@ class InstanceTest(unittest.TestCase):
class BlogPost(Document): class BlogPost(Document):
pass pass
# Clear old data # Clear old datas
User.drop_collection() User.drop_collection()
BlogPost.drop_collection() BlogPost.drop_collection()
@@ -2176,18 +2176,17 @@ class InstanceTest(unittest.TestCase):
b1 = BlogPost.objects.create() b1 = BlogPost.objects.create()
b2 = BlogPost.objects.create() b2 = BlogPost.objects.create()
# Make sure docs are properly identified in a list (__eq__ is used # in List
# for the comparison).
all_user_list = list(User.objects.all()) all_user_list = list(User.objects.all())
self.assertTrue(u1 in all_user_list) self.assertTrue(u1 in all_user_list)
self.assertTrue(u2 in all_user_list) self.assertTrue(u2 in all_user_list)
self.assertTrue(u3 in all_user_list) self.assertTrue(u3 in all_user_list)
self.assertTrue(u4 not in all_user_list) # New object self.assertFalse(u4 in all_user_list) # New object
self.assertTrue(b1 not in all_user_list) # Other object self.assertFalse(b1 in all_user_list) # Other object
self.assertTrue(b2 not in all_user_list) # Other object self.assertFalse(b2 in all_user_list) # Other object
# Make sure docs can be used as keys in a dict (__hash__ is used # in Dict
# for hashing the docs).
all_user_dic = {} all_user_dic = {}
for u in User.objects.all(): for u in User.objects.all():
all_user_dic[u] = "OK" all_user_dic[u] = "OK"
@@ -2199,20 +2198,9 @@ class InstanceTest(unittest.TestCase):
self.assertEqual(all_user_dic.get(b1, False), False) # Other object self.assertEqual(all_user_dic.get(b1, False), False) # Other object
self.assertEqual(all_user_dic.get(b2, False), False) # Other object self.assertEqual(all_user_dic.get(b2, False), False) # Other object
# Make sure docs are properly identified in a set (__hash__ is used # in Set
# for hashing the docs).
all_user_set = set(User.objects.all()) all_user_set = set(User.objects.all())
self.assertTrue(u1 in all_user_set) self.assertTrue(u1 in all_user_set)
self.assertTrue(u4 not in all_user_set)
self.assertTrue(b1 not in all_user_list)
self.assertTrue(b2 not in all_user_list)
# Make sure duplicate docs aren't accepted in the set
self.assertEqual(len(all_user_set), 3)
all_user_set.add(u1)
all_user_set.add(u2)
all_user_set.add(u3)
self.assertEqual(len(all_user_set), 3)
def test_picklable(self): def test_picklable(self):
pickle_doc = PickleTest(number=1, string="One", lists=['1', '2']) pickle_doc = PickleTest(number=1, string="One", lists=['1', '2'])