From b7e8108edd1e271dd4e552ccf3aedb1a9a24fb72 Mon Sep 17 00:00:00 2001 From: Harry Marr Date: Thu, 7 Jan 2010 22:48:39 +0000 Subject: [PATCH] Added docs about using MongoEngine with Django --- docs/changelog.rst | 8 ++++++++ docs/index.rst | 1 + mongoengine/django/auth.py | 14 ++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 96f7cbf9..e6f11571 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,6 +2,14 @@ Changelog ========= +Changes is v0.1.3 +================= +- Added Django authentication backend +- Added Document.meta support for indexes, which are ensured just before + querying takes place +- A few minor bugfixes + + Changes in v0.1.2 ================= - Query values may be processed before before being used in queries diff --git a/docs/index.rst b/docs/index.rst index 5a04de7a..40672f49 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -16,6 +16,7 @@ The source is available on `GitHub `_. tutorial userguide apireference + django changelog Indices and tables diff --git a/mongoengine/django/auth.py b/mongoengine/django/auth.py index cc88ed0a..5789d208 100644 --- a/mongoengine/django/auth.py +++ b/mongoengine/django/auth.py @@ -32,6 +32,8 @@ class User(Document): last_login = DateTimeField(default=datetime.datetime.now) def get_full_name(self): + """Returns the users first and last names, separated by a space. + """ full_name = u'%s %s' % (self.first_name or '', self.last_name or '') return full_name.strip() @@ -42,6 +44,10 @@ class User(Document): return True def set_password(self, raw_password): + """Sets the user's password - always use this rather than directly + assigning to :attr:`~mongoengine.django.auth.User.password` as the + password is hashed before storage. + """ from random import random algo = 'sha1' salt = get_hexdigest(algo, str(random()), str(random()))[:5] @@ -49,11 +55,19 @@ class User(Document): self.password = '%s$%s$%s' % (algo, salt, hash) def check_password(self, raw_password): + """Checks the user's password against a provided password - always use + this rather than directly comparing to + :attr:`~mongoengine.django.auth.User.password` as the password is + hashed before storage. + """ algo, salt, hash = self.password.split('$') return hash == get_hexdigest(algo, salt, raw_password) @classmethod def create_user(cls, username, password, email=None): + """Create (and save) a new user with the given username, password and + email address. + """ user = User(username=username, email=email) user.set_password(password) user.save()