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
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)
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)
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")
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__)
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')) # Check to see if the request has already set a user (probably from middleware above). If it has, # use the user from the request, as we trust it has been set for a reason if request.user: user_id = request.user.id else: 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)
from __future__ import unicode_literals from future.builtins import str from django.db import connection from django.template import Context, Template from mezzanine.conf import settings from mezzanine.core.models import CONTENT_STATUS_PUBLISHED from mezzanine.core.request import current_request from mezzanine.pages.models import Page, RichTextPage from mezzanine.urls import PAGES_SLUG from mezzanine.utils.tests import TestCase from mezzanine.utils.models import get_user_model from django.contrib.auth.models import AnonymousUser User = get_user_model() class PagesTests(TestCase): def test_page_ascendants(self): """ Test the methods for looking up ascendants efficiently behave as expected. """ # Create related pages. primary, created = RichTextPage.objects.get_or_create(title="Primary") secondary, created = primary.children.get_or_create(title="Secondary") tertiary, created = secondary.children.get_or_create(title="Tertiary") # Force a site ID to avoid the site query when measuring queries. setattr(current_request(), "site_id", settings.SITE_ID)
# -*- 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)
(url, instance.person.__str__())) person_link.allow_tags = True def my_groups(self, instance): grp_str = [] for group in instance.groups.all(): if group: grp_str.append(group.name) return ", ".join(grp_str) def null_filter(field, title_=None): """Helper to filter by null or not null any field in admin""" class NullListFieldFilter(NullListFilter): parameter_name = field title = title_ or parameter_name return NullListFieldFilter admin.site.register(LinkType) admin.site.unregister(BlogPost) admin.site.unregister(ThreadedComment) admin.site.register(Keyword, KeywordAdmin) if settings.DEBUG and settings.HIJACK_REGISTER_ADMIN: UserModel = get_user_model() admin.site.unregister(UserModel) admin.site.register(UserModel, UserAdminCustom)