本文整理汇总了Python中mezzanine.utils.models.get_user_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_user_model函数的具体用法?Python get_user_model怎么用?Python get_user_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_user_model函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: urls
def urls(self):
from django.conf import settings
urls = patterns("", ("", super(LazyAdminSite, self).urls),)
# Filebrowser admin media library.
fb_name = getattr(settings, "PACKAGE_NAME_FILEBROWSER", "")
if fb_name in settings.INSTALLED_APPS:
try:
fb_urls = import_dotted_path("%s.sites.site" % fb_name).urls
except ImportError:
fb_urls = "%s.urls" % fb_name
urls = patterns("", ("^media-library/", include(fb_urls)),) + urls
# Give the urlpatterm for the user password change view an
# actual name, so that it can be reversed with multiple
# languages are supported in the admin.
User = get_user_model()
for admin in self._registry.values():
user_change_password = getattr(admin, "user_change_password", None)
if user_change_password:
bits = (User._meta.app_label, User._meta.object_name.lower())
urls = patterns("",
url("^%s/%s/(\d+)/password/$" % bits,
self.admin_view(user_change_password),
name="user_change_password"),
) + urls
break
return urls
示例2: create_user
def create_user(self):
User = get_user_model()
if not settings.DEBUG or User.objects.count() > 0:
return
if self.verbosity >= 1:
print("\nCreating default account (username: %s / password: %s) "
"...\n" % (DEFAULT_USERNAME, DEFAULT_PASSWORD))
args = (DEFAULT_USERNAME, DEFAULT_EMAIL, DEFAULT_PASSWORD)
User.objects.create_superuser(*args)
示例3: decorator
def decorator(request, *args, **kwargs):
try:
engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
except:
import django.contrib.sessions.backends.db
engine = django.contrib.sessions.backends.db
session_data = engine.SessionStore(request.POST.get('session_key'))
user_id = session_data['_auth_user_id']
# will return 404 if the session ID does not resolve to a valid user
request.user = get_object_or_404(get_user_model(), pk=user_id)
return function(request, *args, **kwargs)
示例4: process_verified_phone
def process_verified_phone(self, phone, request):
user = get_user_model().objects.get(
pk=self.storage.extra_data.get('_user_id'))
token = default_token_generator.make_token(user)
user = authenticate(uidb36=int_to_base36(user.id),
token=token, is_active=True)
auth_login(request, user)
return redirect("profile_update")
示例5: get_profile_user_fieldname
def get_profile_user_fieldname(profile_model=None, user_model=None):
"""
Returns the name of the first field on the profile model that
points to the ``auth.User`` model.
"""
Profile = profile_model or get_profile_model()
User = user_model or get_user_model()
for field in Profile._meta.fields:
if field.rel and field.rel.to == User:
return field.name
raise ImproperlyConfigured("Value for AUTH_PROFILE_MODULE does not "
"contain a ForeignKey field for auth.User: %s"
% Profile.__name__)
示例6: get_user_model
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from calendar import month_name
from future.builtins import str
from future.builtins import int
from django.http import Http404
from django.shortcuts import get_object_or_404
from mezzanine.blog.models import BlogCategory, BlogPost
from mezzanine.conf import settings
from mezzanine.generic.models import Keyword
from mezzanine.utils.views import render, paginate
from mezzanine.utils.models import get_user_model
User = get_user_model()
def blog_post_list(request, tag=None, year=None, month=None, username=None,
category=None, template="blog/blog_post_list.html"):
"""
Display a list of blog posts that are filtered by tag, year, month,
author or category. Custom templates are checked for using the name
``blog/blog_post_list_XXX.html`` where ``XXX`` is either the
category slug or author's username if given.
"""
settings.use_editable()
templates = []
blog_posts = BlogPost.objects.published(for_user=request.user)