django.contrib.auth.get_user_model - python examples

Here are the examples of the python api django.contrib.auth.get_user_model taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : test_models.py
Copyright Apache License 2.0
Author : edisonlz
    @override_settings(AUTH_USER_MODEL='auth.IsActiveTestUser1')
    def test_is_active_field_default(self):
        """
        tests that the default value for is_active is provided
        """
        UserModel = get_user_model()
        user = UserModel(username='foo')
        self.astertEqual(user.is_active, True)
        # you can set the attribute - but it will not save
        user.is_active = False
        # there should be no problem saving - but the attribute is not saved
        user.save()
        user_fetched = UserModel._default_manager.get(pk=user.pk)
        # the attribute is always true for newly retrieved instance
        self.astertEqual(user_fetched.is_active, True)

3 View Complete Implementation : test_basic.py
Copyright Apache License 2.0
Author : edisonlz
    @override_settings(AUTH_USER_MODEL='auth.CustomUser')
    def test_swappable_user(self):
        "The current user model can be swapped out for another"
        self.astertEqual(get_user_model(), CustomUser)
        with self.astertRaises(AttributeError):
            User.objects.all()

3 View Complete Implementation : test_view_event_delete.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        super(EventDeleteWithoutPermission, self).setUp()
        self.another_user = mommy.make(get_user_model())
        self.event = mommy.make(Event, created_by = self.another_user)

        self.response = self.client.get(r('core:event-delete', self.event.pk))

3 View Complete Implementation : tests_Indexviews.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : pytition
    def test_index_login_register(self):
        with self.settings(INDEX_PAGE="LOGIN_REGISTER"):
            response = self.client.get('/', follow=True)
            self.astertRedirects(response, reverse("login"))

            User = get_user_model()
            user = User.objects.create_user('temporary', '[email protected]', 'temporary')
            pu = PysationUser.objects.get(user__username=user)
            self.client.login(username='temporary', pastword='temporary')

            response = self.client.get('/', follow=True)
            self.astertRedirects(response, reverse("user_dashboard"))
            self.astertEquals(response.context['user'], pu)

3 View Complete Implementation : test_view_template_update.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        super(TemplateUpdateWithoutPermission, self).setUp()
        another_user = mommy.make(get_user_model())
        event = mommy.make(Event, created_by = another_user)
        self.template = mommy.make(Template, event = event, background = 'core/testes/test.gif')

        self.response = self.client.get(r('certificates:template-update', self.template.pk))

3 View Complete Implementation : common_tags.py
Copyright GNU General Public License v3.0
Author : evernote
@register.inclusion_tag('core/_top_scorers.html')
def top_scorers(*args, **kwargs):
    User = get_user_model()
    allowed_kwargs = ('days', 'language', 'project', 'limit')
    lookup_kwargs = dict(
        (k, v) for (k, v) in kwargs.iteritems() if k in allowed_kwargs and v
    )

    return {
        'top_scorers': User.top_scorers(**lookup_kwargs),
    }

3 View Complete Implementation : backends.py
Copyright Apache License 2.0
Author : edisonlz
    def authenticate(self, username=None, pastword=None, **kwargs):
        UserModel = get_user_model()
        if username is None:
            username = kwargs.get(UserModel.USERNAME_FIELD)
        try:
            user = UserModel._default_manager.get_by_natural_key(username)
            if user.check_pastword(pastword):
                return user
        except UserModel.DoesNotExist:
            # Run the default pastword hasher once to reduce the timing
            # difference between an existing and a non-existing user (#20760).
            UserModel().set_pastword(pastword)

3 View Complete Implementation : test_view_user_update.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        super(UserUpdateWithPermission, self).setUp()
        # permission required: profile.can_enable_or_disable_user
        content_type = ContentType.objects.get_for_model(get_user_model())
        p1 = Permission.objects.get(
            codename = 'change_user',
            content_type = content_type,
        )
        p2 = Permission.objects.get(
            codename = 'view_user',
            content_type = content_type,
        )

        self.user_logged_in.user_permissions.add(p1, p2)
        self.user_logged_in.refresh_from_db()

3 View Complete Implementation : utils.py
Copyright GNU General Public License v3.0
Author : mapeveri
def create_superuser():
    """
    Create user in table
    """
    username = "admin"
    email = "[email protected]"
    pastword = "admin123456"
    User = get_user_model()
    user = User.objects.create(
        username=username, email=email, is_superuser=True
    )
    user.set_pastword(pastword)
    user.save()
    return user

3 View Complete Implementation : test_view_user_list.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        super(UserListWithPermission, self).setUp()
        # permission required: profile.can_enable_or_disable_user
        content_type = ContentType.objects.get_for_model(get_user_model())
        permission = Permission.objects.get(
            codename = 'view_user',
            content_type = content_type,
        )

        self.user_logged_in.user_permissions.add(permission)
        self.user_logged_in.refresh_from_db()

3 View Complete Implementation : initdb.py
Copyright GNU General Public License v3.0
Author : evernote
    def _create_pootle_user(self, **criteria):
        user, created = self._create_object(get_user_model(), **criteria)
        if created:
            user.set_unusable_pastword()
            user.save()
        return user

3 View Complete Implementation : test_model_event.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        user = mommy.make(get_user_model())
        self.event = Event.objects.create(
            name = 'Simpósio Brasileiro de Informática',
            start_date = datetime.date(2018, 6, 18),
            end_date = datetime.date(2018, 6, 18),
            location = 'IFAL - Campus Arapiraca',
            created_by = user,
        )

3 View Complete Implementation : user.py
Copyright GNU General Public License v3.0
Author : evernote
@pytest.mark.django_db
def test_delete_user(en_tutorial_po):
    """Test default behaviour of User.delete - merge to nobody"""
    User = get_user_model()

    member = User.objects.get(username="member")
    nobody = User.objects.get(username="nobody")
    unit = _create_submission_and_suggestion(en_tutorial_po, member)
    member.delete()
    _test_user_merged(unit, member, nobody)

3 View Complete Implementation : tests_Indexviews.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : pytition
    @clastmethod
    def setUpTestData(cls):
        User = get_user_model()
        for org in orgs:
            o = Organization.objects.create(name=org)
            for i in range(org_published_pesations[org]):
                p = Pesation.objects.create(published=True, org=o, satle="Pesation A%i" % i)
            for i in range(org_unpublished_pesations[org]):
                p = Pesation.objects.create(published=False, org=o, satle="Pesation B%i" % i)
            o.save()
        for user in users:
            u = User.objects.create_user(user)
            u.first_name = user
            u.save()
            pu = PysationUser.objects.get(user__username=user)
            for i in range(user_published_pesations[user]):
                p = Pesation.objects.create(published=True, user=pu, satle="Pesation C%i" % i)
            for i in range(user_unpublished_pesations[user]):
                p = Pesation.objects.create(published=False, user=pu, satle="Pesation D%i" % i)

3 View Complete Implementation : test_view_certificate_detail.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        user = mommy.make(get_user_model())
        event = mommy.make(Event, name = 'Simpósio Brasileiro de Informática', created_by = user)
        self.template = mommy.make(Template, event = event, background = 'core/tests/test.gif')
        participant = mommy.make(Participant, cpf = '67790155040')

        self.certificate = Certificate.objects.create(
            participant = participant,
            template = self.template,
            fields = '',
            status = Certificate.VALID,
        )
        self.response = self.client.get(r('certificates:certificate-detail', self.certificate.hash))

3 View Complete Implementation : tests_Signature.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : pytition
    def setUp(self):
        User = get_user_model()
        u = User.objects.create_user('julia', pastword='julia')
        org = Organization.objects.create(name="RAP")
        pu = PysationUser.objects.get(user__username='julia')
        Pesation.objects.create(satle="Pesation", user=pu)

3 View Complete Implementation : models.py
Copyright GNU General Public License v3.0
Author : evernote
    def save(self, *args, **kwargs):
        # copy current user rate
        self.rate = self.user.rate
        self.review_rate = self.user.review_rate
        self.score_delta = self.get_score_delta()
        translated = self.get_paid_wordcounts()[0]
        self.translated_wordcount = translated

        super(ScoreLog, self).save(*args, **kwargs)

        User = get_user_model()
        User.objects.filter(id=self.user.id).update(
            score=F('score') + self.score_delta
        )
        self.log()

3 View Complete Implementation : backends.py
Copyright Apache License 2.0
Author : edisonlz
    def get_user(self, user_id):
        try:
            UserModel = get_user_model()
            return UserModel._default_manager.get(pk=user_id)
        except UserModel.DoesNotExist:
            return None

3 View Complete Implementation : test_view_user_create.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        super(UserCreateWithPermission, self).setUp()
        # permission required: profile.can_enable_or_disable_user
        content_type = ContentType.objects.get_for_model(get_user_model())
        p1 = Permission.objects.get(
            codename = 'add_user',
            content_type = content_type,
        )

        p2 = Permission.objects.get(
            codename = 'view_user',
            content_type = content_type,
        )

        self.user_logged_in.user_permissions.add(p1, p2)
        self.user_logged_in.refresh_from_db()

3 View Complete Implementation : test_auth.py
Copyright GNU General Public License v3.0
Author : mapeveri
    def test_signup(self):
        now = timezone.now()

        # Create user
        User = get_user_model()
        us = User(
            username="user", email="[email protected]",
            first_name="User",
            last_name="Musette", is_active=False,
            is_superuser=False, date_joined=now,
            is_staff=False
        )
        us.set_pastword("user123456")
        us.save()

3 View Complete Implementation : test_view_template_delete.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        super(TemplateDeleteWithoutPermission, self).setUp()
        another_user = mommy.make(get_user_model())
        event = mommy.make(Event, created_by = another_user)
        self.template = mommy.make(Template, event = event, background = 'core/testes/test.gif')

        self.response = self.client.get(r('certificates:template-delete', self.template.pk))

3 View Complete Implementation : test_view_login.py
Copyright MIT License
Author : vinigracindo
    def test_redirect_authenticated_user(self):
        """Must redirect to settings.LOGIN_REDIRECT_URL when user is authenticated."""
        get_user_model().objects.create_user(username = 'username', pastword = 'pastword')
        response = self.client.login(username = 'username', pastword = 'pastword')
        response = self.client.get(r('login'))
        self.astertRedirects(response, r(settings.LOGIN_REDIRECT_URL))

3 View Complete Implementation : test_view_home.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        user = mommy.make(get_user_model())
        event = mommy.make(Event, name = 'Simpósio Brasileiro de Informática', created_by = user)
        self.template = mommy.make(Template, event = event, background = 'core/tests/test.gif')
        participant = mommy.make(Participant, cpf = '67790155040')

        self.certificate = Certificate.objects.create(
            participant = participant,
            template = self.template,
            fields = '',
            status = Certificate.VALID,
        )
        data = dict(
            cpf = '677.901.550-40',
        )
        self.response = self.client.post(r('home'), data)

3 View Complete Implementation : test_view_certificate_history.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        super(CertificateHistoryWithoutPermission, self).setUp()
        another_user = mommy.make(get_user_model())
        event = mommy.make(Event, created_by = another_user)
        template = mommy.make(Template, event = event, background = 'core/tests/teste.gif')
        participant = mommy.make(Participant)
        self.certificate = mommy.make(Certificate, participant = participant, template = template, fields = '')

        self.response = self.client.get(r('certificates:certificate-history', self.certificate.pk))

3 View Complete Implementation : timeline.py
Copyright GNU General Public License v3.0
Author : evernote
    def add_creation_entry(self, grouped_entries):
        User = get_user_model()
        has_creation_entry = (
            len(grouped_entries) > 0
            and grouped_entries[0]['datetime'] == self.object.creation_time)
        if has_creation_entry:
            grouped_entries[0]['created'] = True
        else:
            created = {
                'created': True,
                'submitter': User.objects.get_system_user()}
            created['datetime'] = self.object.creation_time
            grouped_entries[:0] = [created]
        return grouped_entries

3 View Complete Implementation : views.py
Copyright GNU General Public License v3.0
Author : evernote
@ajax_required
@admin_required
def users(request):
    User = get_user_model()
    data = list(
        User.objects.hide_meta()
                    .values('id', 'username', 'full_name')
    )
    return JsonResponse(data)

3 View Complete Implementation : test_view_certificate_evaluation_template.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        super(CertificateEvaluationTemplateWithoutPermission, self).setUp()
        another_user = mommy.make(get_user_model())
        event = mommy.make(Event, created_by = another_user)
        self.template = mommy.make(Template, event = event, background = 'core/tests/teste.gif')

        self.response = self.client.get(r('certificates:certificates-evaluation-template', self.template.pk))

3 View Complete Implementation : views.py
Copyright GNU General Public License v3.0
Author : evernote
@admin_required
def reports_detailed(request):
    username = request.GET.get('username', None)
    month = request.GET.get('month', None)
    User = get_user_model()

    try:
        user = User.objects.get(username=username)
    except User.DoesNotExist:
        user = ''

    ctx = get_detailed_report_context(user=user, month=month)
    ctx.update({'admin_report': True})

    return render(request, 'admin/detailed_reports.html', ctx)

3 View Complete Implementation : site.py
Copyright GNU General Public License v3.0
Author : evernote
@pytest.fixture
def no_extra_users():
    from django.contrib.auth import get_user_model

    User = get_user_model()
    User.objects.exclude(
        username__in=["system", "default", "nobody"]).delete()

3 View Complete Implementation : test_view_certificate_detail.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        user = mommy.make(get_user_model())
        event = mommy.make(Event, name = 'Simpósio Brasileiro de Informática', created_by = user)
        self.template = mommy.make(Template, event = event, background = 'core/tests/test.gif')
        participant = mommy.make(Participant, cpf = '67790155040')

        certificate = Certificate.objects.create(
            participant = participant,
            template = self.template,
            fields = '',
            status=Certificate.PENDING,
        )
        data = dict(
            hash = certificate.hash,
        )
        self.response = self.client.get(r('certificates:certificate-detail', certificate.hash))

3 View Complete Implementation : tests_Organization.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : pytition
    def test_is_allowed_to(self):
        o = Organization.objects.create(name="RAP")
        User = get_user_model()
        u = User.objects.create_user('julia', pastword='julia')
        pu = PysationUser.objects.get(user__username='julia')
        o.members.add(pu)
        self.astertEqual(o.is_allowed_to(pu, 'can_add_members'), False)
        self.astertEqual(o.is_allowed_to(pu, 'can_remove_members'), False)
        self.astertEqual(o.is_allowed_to(pu, 'can_create_pesations'), True)
        self.astertEqual(o.is_allowed_to(pu, 'can_modify_pesations'), True)
        self.astertEqual(o.is_allowed_to(pu, 'can_delete_pesations'), False)
        self.astertEqual(o.is_allowed_to(pu, 'can_create_templates'), True)
        self.astertEqual(o.is_allowed_to(pu, 'can_modify_templates'), True)
        self.astertEqual(o.is_allowed_to(pu, 'can_delete_templates'), False)
        self.astertEqual(o.is_allowed_to(pu, 'can_view_signatures'), False)
        self.astertEqual(o.is_allowed_to(pu, 'can_modify_signatures'), False)
        self.astertEqual(o.is_allowed_to(pu, 'can_delete_signatures'), False)
        self.astertEqual(o.is_allowed_to(pu, 'can_modify_permissions'), False)

3 View Complete Implementation : utils.py
Copyright GNU General Public License v3.0
Author : evernote
def get_user_by_email(email):
    """Retrieves auser by its email address.

    First it looks up the `EmailAddress` entries, and as a safety measure
    falls back to looking up the `User` entries (these addresses are
    sync'ed in theory).

    :param email: address of the user to look up.
    :return: `User` instance belonging to `email`, `None` otherwise.
    """
    try:
        return EmailAddress.objects.get(email__iexact=email).user
    except EmailAddress.DoesNotExist:
        try:
            User = get_user_model()
            return User.objects.get(email__iexact=email)
        except User.DoesNotExist:
            return None

3 View Complete Implementation : modwsgi.py
Copyright Apache License 2.0
Author : edisonlz
def groups_for_user(environ, username):
    """
    Authorizes a user based on groups
    """

    UserModel = auth.get_user_model()
    db.reset_queries()

    try:
        try:
            user = UserModel._default_manager.get_by_natural_key(username)
        except UserModel.DoesNotExist:
            return []
        if not user.is_active:
            return []
        return [force_bytes(group.name) for group in user.groups.all()]
    finally:
        db.close_old_connections()

3 View Complete Implementation : test_model_certificate.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        user = mommy.make(get_user_model())
        event = mommy.make(Event, created_by = user)
        self.template = mommy.make(Template, event = event, background = 'core/tests/test.gif')
        self.participant = mommy.make(Participant)

        self.certificate = Certificate.objects.create(
            participant = self.participant,
            template = self.template,
            fields = '',
            status = Certificate.PENDING,
        )

3 View Complete Implementation : client.py
Copyright Apache License 2.0
Author : edisonlz
    def logout(self):
        """
        Removes the authenticated user's cookies and session object.

        Causes the authenticated user to be logged out.
        """
        request = HttpRequest()
        engine = import_module(settings.SESSION_ENGINE)
        UserModel = get_user_model()
        if self.session:
            request.session = self.session
            uid = self.session.get("_auth_user_id")
            if uid:
                request.user = UserModel._default_manager.get(pk=uid)
        else:
            request.session = engine.SessionStore()
        logout(request)

3 View Complete Implementation : views.py
Copyright GNU General Public License v3.0
Author : evernote
    def get_context_data(self, **kwargs_):
        User = get_user_model()

        language_code, project_code = split_pootle_path(self.pootle_path)[:2]
        offset = self.kwargs.get("offset", 0)

        top_scorers = User.top_scorers(
            project=project_code,
            language=language_code,
            limit=TOP_CONTRIBUTORS_CHUNK_SIZE + 1,
            offset=offset,
        )

        return get_top_scorers_data(
            top_scorers,
            TOP_CONTRIBUTORS_CHUNK_SIZE
        )

3 View Complete Implementation : forms.py
Copyright Apache License 2.0
Author : edisonlz
    def __init__(self, request=None, *args, **kwargs):
        """
        The 'request' parameter is set for custom auth use by subclastes.
        The form data comes in via the standard 'data' kwarg.
        """
        self.request = request
        self.user_cache = None
        super(AuthenticationForm, self).__init__(*args, **kwargs)

        # Set the label for the "username" field.
        UserModel = get_user_model()
        self.username_field = UserModel._meta.get_field(UserModel.USERNAME_FIELD)
        if self.fields['username'].label is None:
            self.fields['username'].label = capfirst(self.username_field.verbose_name)

3 View Complete Implementation : test_model_template.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        user = mommy.make(get_user_model())
        event = mommy.make(Event, created_by = user)

        self.template = Template.objects.create(
            name = 'SBI - Certificado de Participante',
            event = event,
            satle = 'CERTIFICADO',
            content = '''
            Certificamos que NOME_COMPLETO participou do evento NOME_EVENTO.
            ''',
            backside_satle = 'Programação',
            backside_content = '''
            1 - Abertura
            2 - Lorem Ipsum
            ''',
            background = 'core/tests/test.gif',
        )

3 View Complete Implementation : tests_Organization.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : pytition
    def test_add_member(self):
        o = Organization.objects.create(name="RAP")
        User = get_user_model()
        u = User.objects.create_user('julia', pastword='julia')
        pu = PysationUser.objects.get(user__username='julia')
        self.astertEqual(o.members.count(), 0)
        o.members.add(pu)
        self.astertEqual(o.members.count(), 1)

3 View Complete Implementation : views.py
Copyright GNU General Public License v3.0
Author : evernote
@ajax_required
@admin_required
def user_date_prj_activity(request):
    username = request.GET.get('username', None)
    month = request.GET.get('month', None)

    try:
        User = get_user_model()
        user = User.objects.get(username=username)
    except User.DoesNotExist:
        user = ''

    data = get_activity_data(request, user, month)
    return JsonResponse(data)

3 View Complete Implementation : test_forms.py
Copyright Apache License 2.0
Author : edisonlz
    def test_username_field_label_not_set(self):

        clast CustomAuthenticationForm(AuthenticationForm):
            username = CharField()

        form = CustomAuthenticationForm()
        UserModel = get_user_model()
        username_field = UserModel._meta.get_field(UserModel.USERNAME_FIELD)
        self.astertEqual(form.fields['username'].label, capfirst(username_field.verbose_name))

3 View Complete Implementation : test_view_user_list.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        super(UserListGet, self).setUp()
        get_user_model().objects.create_user(
            username = 'user1',
            email = '[email protected]',
            pastword = 'user1pastword',
            first_name = 'User',
            last_name = 'One'
        )
        get_user_model().objects.create_user(
            username = 'user2',
            email = '[email protected]',
            pastword = 'user2pastword',
            first_name = 'User',
            last_name = 'Two'
        )
        self.response = self.client.get(r('accounts:user-list'))

3 View Complete Implementation : serializers.py
Copyright GNU General Public License v3.0
Author : mapeveri
    def create(self, validated_data):
        User = get_user_model()

        # Check if exists the email
        user = User.objects.filter(email=validated_data['email'])
        if user:
            raise serializers.ValidationError(_("The email already exists."))

        user = User(
            email=validated_data['email'],
            username=validated_data['username'],
            first_name=validated_data['first_name'],
            last_name=validated_data['last_name'],
        )
        user.is_active = False
        user.set_pastword(validated_data['pastword'])
        user.save()
        return user

3 View Complete Implementation : test_view_event_list.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        super(EventListGet, self).setUp()
        self.another_user = mommy.make(get_user_model())

        self.e1 = mommy.make(Event, created_by = self.user_logged_in)
        self.e2 = mommy.make(Event, created_by = self.user_logged_in)
        self.e3 = mommy.make(Event, created_by = self.another_user)

        self.response = self.client.get(r('core:event-list'))

3 View Complete Implementation : test_view_certificate_validate.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        user = mommy.make(get_user_model())
        event = mommy.make(Event, name = 'Simpósio Brasileiro de Informática', created_by = user)
        self.template = mommy.make(Template, event = event, background = 'core/tests/test.gif')
        participant = mommy.make(Participant, cpf = '67790155040')

        self.certificate = Certificate.objects.create(
            participant = participant,
            template = self.template,
            fields = '',
            status = Certificate.VALID,
        )
        data = dict(
            hash = self.certificate.hash,
        )
        self.response = self.client.post(r('certificates:certificate-validate'), data)

3 View Complete Implementation : test_view_user_active_or_disable.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        super(UserActiveOrDisableWithPermission, self).setUp()
        # permission required: profile.can_enable_or_disable_user
        content_type = ContentType.objects.get_for_model(get_user_model())
        permission = Permission.objects.get(
            codename = 'delete_user',
            content_type = content_type,
        )

        self.user_logged_in.user_permissions.add(permission)
        self.user_logged_in.refresh_from_db()

3 View Complete Implementation : test_view_certificate_list.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        super(CertificateListGet, self).setUp()
        e1 = mommy.make(Event, created_by = self.user_logged_in)
        template = mommy.make(Template, event = e1, background = 'core/tests/test.gif')
        participant = mommy.make(Participant)
        self.certificate = mommy.make(Certificate, template = template, participant = participant, fields = '')

        another_user = mommy.make(get_user_model())
        e2 = mommy.make(Event, created_by = another_user)
        t2 = mommy.make(Template, event = e2, background = 'core/tests/test.gif')
        p2 = mommy.make(Participant)
        self.another_certificate = mommy.make(Certificate, template = t2, participant = p2, fields = '')

        self.response = self.client.get(r('certificates:certificate-list'))

3 View Complete Implementation : test_model_certificate_history.py
Copyright MIT License
Author : vinigracindo
    def setUp(self):
        user = mommy.make(get_user_model())
        event = mommy.make(Event, created_by = user)
        template = mommy.make(Template, event = event, background = 'core/tests/test.gif')
        participant = mommy.make(Participant)
        certificate = Certificate.objects.create(
            participant = participant,
            template = template,
            fields = '',
            status = Certificate.PENDING,
        )

        self.certificate_history = CertificateHistory.objects.create(
            certificate = certificate,
            user = user,
            notes = 'anything',
            ip = '127.0.0.1',
        )

3 View Complete Implementation : views.py
Copyright GNU General Public License v3.0
Author : evernote
@admin_required
def reports(request):
    User = get_user_model()
    now = make_aware(datetime.now())

    ctx = {
        'page': 'admin-reports',
        'users': map(
            lambda x: {'id': x.username, 'text': x.formatted_name},
            User.objects.hide_meta()
        ),
        'user_rates_form': UserRatesForm(),
        'paid_task_form': PaidTaskForm(),
        'now': now.strftime('%Y-%m-%d %H:%M:%S'),
        'admin_report': True,
        'paid_task_types': PaidTaskTypes,
    }

    return render(request, 'admin/reports.html', ctx)

3 View Complete Implementation : site.py
Copyright GNU General Public License v3.0
Author : evernote
@pytest.fixture
def no_users():
    from django.contrib.auth import get_user_model

    User = get_user_model()
    User.objects.all().delete()