Exemple #1
0
    def get_user(self, username):
        User = get_user_model()

        try:
            user = User.objects.get(username=username)
        except (User.DoesNotExist, User.MultipleObjectsReturned):
            return False

        return user
Exemple #2
0
 def handle(self, *args, **kwargs):
     try:
         user, _ = get_user_model().objects.update_create(
             **{self.username_key: self.username})
         user.set_password(self.password)
         user.save()
         self.stdout.write(self.style.SUCCESS('Success created user'))
     except Exception as e:
         self.stdout.write(self.style.ERROR(str(e)))
Exemple #3
0
def authenticate_credentials(userid, password, request=None):
    """
    Authenticate the userid and password against username and password
    with optional request for context.
    """
    credentials = {
        get_user_model().USERNAME_FIELD: userid,
        'password': password
    }
    user = authenticate(request=request, **credentials)

    if user is None:
        return False

    if not user.is_active:
        return False
    return True
Exemple #4
0
"""Database models used by django-reversion."""

import warnings
from functools import partial

try:
    from django.contrib.auth.models import get_user_model
    User = get_user_model()
except ImportError:
    from django.contrib.auth.models import User  # NOQA
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.core import serializers
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
from django.db import models, IntegrityError
from django.db.models.signals import pre_save, post_save
from django.dispatch.dispatcher import Signal, _make_id
from django.utils.translation import ugettext_lazy as _


def deprecated(original, replacement):
    """Decorator that defines a deprecated method."""
    def decorator(func):
        if not settings.DEBUG:
            return func
        def do_pending_deprication(*args, **kwargs):
            warnings.warn(
                "%s is deprecated, and will be removed in django-reversion 1.7. Use %s instead" % (original, replacement),
                PendingDeprecationWarning,
            )
Exemple #5
0
from django.core.management.base import NoArgsCommand
from django.template.loader import render_to_string
from django.contrib.sites.models import Site
from django.contrib.auth.models import get_user_model

from mailer import send_html_mail

import datetime

from dinette.models import Ftopics, Reply, DinetteUserProfile


User = get_user_model()

class Command(NoArgsCommand):
    help = """
           Cron job to send daily updates to subscribed users
           Sample cron usage:
           python manage.py daily_updates
           """
    
    def handle_noargs(self, **options):
        site = Site.objects.get_current()
        subject = "Daily Digest: %s" %( site.name)
        from_address = '%s notifications <admin@%s>' %(site.name, site.domain)
        to_address = User.objects.filter(dinetteuserprofile__is_subscribed_to_digest=True).values_list('email', flat=True)
        
        yesterday = datetime.datetime.now() - datetime.timedelta(1)
        topics = Ftopics.objects.filter(created_on__gt=yesterday)
        replies = Reply.objects.filter(updated_on__gt=yesterday)
        users = DinetteUserProfile.objects.filter(user__date_joined__gt=yesterday)
Exemple #6
0
from django.core.management.base import BaseCommand
from django.contrib.auth.models import get_user_model
from django.conf import settings

#settings check
assert settings.PAYCOM_SETTINGS.get('SECRET_KEY') != None

user_model = get_user_model()


class Command(BaseCommand):
    help = 'Create User for a PaycomUz'
    username = '******'
    password = settings.PAYCOM_SETTINGS.get['SECRET_KEY']
    username_key = user_model.USERNAME_FIELD

    def handle(self, *args, **kwargs):
        try:
            user, _ = get_user_model().objects.update_create(
                **{self.username_key: self.username})
            user.set_password(self.password)
            user.save()
            self.stdout.write(self.style.SUCCESS('Success created user'))
        except Exception as e:
            self.stdout.write(self.style.ERROR(str(e)))
Exemple #7
0
 def test_patron_user_cmp(self):
     User = get_user_model()
     user = User.objects.get(username="******")
     self.assertTrue(isinstance(user, User))
     self.assertTrue(isinstance(self.user1, Patron))
     self.assertTrue(user == self.user1)
Exemple #8
0
 class Meta:
     model = get_user_model()
     fields = '__all__'