Permalink
Browse files

django 1.10 update

1 parent 4acff07 commit 7b2c0552d8645e4ffa558827f1c70c1ec26c009d @last-partizan last-partizan committed Sep 10, 2016
Showing with 30 additions and 23 deletions.
  1. +16 −12 django_mongoengine/mongo_auth/models.py
  2. +14 −11 example/tumblelog/tumblelog/settings.py
@@ -1,7 +1,10 @@
from django.utils.encoding import smart_str
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
-from django.contrib.auth.models import _user_has_perm, _user_get_all_permissions, _user_has_module_perms
+from django.contrib.auth.models import (
+ AbstractBaseUser,
+ _user_has_perm, _user_get_all_permissions, _user_has_module_perms,
+)
from django.db import models
from django.contrib.contenttypes.models import ContentTypeManager
from django.contrib import auth
@@ -39,6 +42,12 @@ def make_password(raw_password):
return '%s$%s$%s' % (algo, salt, hash)
+class BaseUser(object):
+
+ is_anonymous = AbstractBaseUser.is_anonymous
+ is_authenticated = AbstractBaseUser.is_authenticated
+
+
class ContentType(document.Document):
name = fields.StringField(max_length=100)
app_label = fields.StringField(max_length=100)
@@ -160,7 +169,7 @@ def __unicode__(self):
return self.name
-class User(document.Document):
+class User(BaseUser, document.Document):
"""A User document that aims to mirror most of the API specified by Django
at http://docs.djangoproject.com/en/dev/topics/auth/#users
"""
@@ -222,12 +231,6 @@ def get_full_name(self):
full_name = u'%s %s' % (self.first_name or '', self.last_name or '')
return full_name.strip()
- def is_anonymous(self):
- return False
-
- def is_authenticated(self):
- 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
@@ -344,8 +347,9 @@ def get_profile(self):
return self._profile_cache
-class MongoUser(models.Model):
- """"Dummy user model for Django.
+class MongoUser(BaseUser, models.Model):
+ """"
+ Dummy user model for Django.
MongoUser is used to replace Django's UserManager with MongoUserManager.
The actual user document class is django_mongoengine.auth.models.User or any
@@ -356,13 +360,13 @@ class MongoUser(models.Model):
"""
objects = MongoUserManager()
- is_anonymous = False
- is_authenticated = False
+
class Meta:
app_label = 'mongo_auth'
def set_password(self, password):
"""Doesn't do anything, but works around the issue with Django 1.6."""
make_password(password)
+
MongoUser._meta.pk.to_python = ObjectId
@@ -7,7 +7,6 @@
DEBUG = True
-TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
@@ -88,13 +87,6 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'd2h8yt+x2g0$+e#9$z5z$auy%v0axov(wt3o*bj1#h^1+x^n(!'
-# List of callables that know how to import templates from various sources.
-TEMPLATE_LOADERS = (
- 'django.template.loaders.filesystem.Loader',
- 'django.template.loaders.app_directories.Loader',
-# 'django.template.loaders.eggs.Loader',
-)
-
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
@@ -110,9 +102,20 @@
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'tumblelog.wsgi.application'
-TEMPLATE_DIRS = (
- os.path.join(os.path.realpath(os.path.dirname(__file__)), '../templates'),
-)
+
+TEMPLATES = [
+ {
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [os.path.join(os.path.realpath(os.path.dirname(__file__)), '../templates')],
+ 'OPTIONS': {
+ 'loaders': [
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+ ],
+ },
+ },
+]
+
INSTALLED_APPS = (
'django.contrib.auth',

0 comments on commit 7b2c055

Please sign in to comment.