当前位置: 首页>>代码示例>>Python>>正文


Python models.AnonymousUser方法代码示例

本文整理汇总了Python中django.contrib.auth.models.AnonymousUser方法的典型用法代码示例。如果您正苦于以下问题:Python models.AnonymousUser方法的具体用法?Python models.AnonymousUser怎么用?Python models.AnonymousUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.auth.models的用法示例。


在下文中一共展示了models.AnonymousUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _create_view

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def _create_view(self):
        """
        Creates DjangoRestFramework view
        :return: view
        """
        view = self.callback()

        view.kwargs = getattr(view, 'kwargs', dict())
        if hasattr(self.introspector.pattern, 'default_args'):
            view.kwargs.update(self.introspector.pattern.default_args)

        view.request = HttpRequest()
        view.request.user = AnonymousUser()
        view.request.method = self.method

        return view 
开发者ID:Arello-Mobile,项目名称:py2swagger,代码行数:18,代码来源:method.py

示例2: user_boards_contributed

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def user_boards_contributed(user, include_removed=False, viewing_user=AnonymousUser):
    """Return list of boards contributed to by the user in reverse order (most recent contributions first).

    :param user: the user
    :param include_removed: True iff boards that have been removed should be included in the result
    :param viewing_user: user for calculating permissions
    """
    # basic approach: (1) merge, (2) sort, and (3) add making sure there's no duplicate boards
    def _boards(class_):
        models = (
            class_.objects.filter(creator=user)
            .order_by('-submit_date')
            .select_related('board', 'board__permissions')
        )
        return [(x.submit_date, x.board) for x in models if include_removed or not x.board.removed]
    contributions = sorted(itertools.chain(_boards(Evidence), _boards(Hypothesis)), key=lambda x: x[0], reverse=True)
    boards = [
        board
        for date, board in contributions
        if (include_removed or not board.removed) and board.can_read(viewing_user)
    ]
    return first_occurrences(boards) 
开发者ID:twschiller,项目名称:open-synthesis,代码行数:24,代码来源:metrics.py

示例3: test_collection_data_count

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def test_collection_data_count(self):
        data1 = self._create_data()
        data2 = self._create_data()

        entity = self._create_entity([data1, data2])

        collection1 = Collection.objects.create(contributor=self.contributor)
        assign_perm("view_collection", AnonymousUser(), collection1)

        collection2 = Collection.objects.create(contributor=self.contributor)
        assign_perm("view_collection", AnonymousUser(), collection2)
        collection2.entity_set.add(entity)
        collection2.data.add(data1, data2)

        response = self.client.get(self.detail_url(collection1.id))
        self.assertEqual(response.data["data_count"], 0)

        response = self.client.get(self.detail_url(collection2.id))
        self.assertEqual(response.data["data_count"], 2) 
开发者ID:genialis,项目名称:resolwe,代码行数:21,代码来源:test_api.py

示例4: setUp

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def setUp(self):
        super().setUp()

        user_model = get_user_model()
        user = user_model.objects.create(username="user")

        self.proc_1 = Process.objects.create(
            name="My process", contributor=user, version=1
        )
        self.proc_2 = Process.objects.create(
            name="My process", contributor=user, version=2
        )

        assign_perm("view_process", AnonymousUser(), self.proc_1)
        assign_perm("view_process", AnonymousUser(), self.proc_2)

        self.url = reverse("resolwe-api:process-list") 
开发者ID:genialis,项目名称:resolwe,代码行数:19,代码来源:test_ordering.py

示例5: test_get_ip_reverse_proxy

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def test_get_ip_reverse_proxy(self):
        """ Tests if can handle a long user agent
        """
        request_factory = RequestFactory()
        request = request_factory.get(ADMIN_LOGIN_URL)
        request.user = AnonymousUser()
        request.session = SessionStore()

        request.META["HTTP_X_FORWARDED_FOR"] = "192.168.24.24"
        self.assertEqual(utils.get_ip(request), "192.168.24.24")

        request_factory = RequestFactory()
        request = request_factory.get(ADMIN_LOGIN_URL)
        request.user = AnonymousUser()
        request.session = SessionStore()

        request.META["REMOTE_ADDR"] = "24.24.24.24"
        self.assertEqual(utils.get_ip(request), "24.24.24.24") 
开发者ID:jazzband,项目名称:django-defender,代码行数:20,代码来源:tests.py

示例6: test_login_non_blocked_for_non_standard_login_views_different_msg

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def test_login_non_blocked_for_non_standard_login_views_different_msg(self):
        """
        Check that a view wich returns the expected status code but not the
        expected message is not causing the IP to be locked out.
        """

        @watch_login(status_code=401, msg="Invalid credentials")
        def fake_api_401_login_view_without_msg(request):
            """ Fake the api login with 401 """
            return HttpResponse("Ups, wrong credentials", status=401)

        request_factory = RequestFactory()
        request = request_factory.post("api/login")
        request.user = AnonymousUser()
        request.session = SessionStore()

        request.META["HTTP_X_FORWARDED_FOR"] = "192.168.24.24"

        for _ in range(4):
            fake_api_401_login_view_without_msg(request)

            data_out = utils.get_blocked_ips()
            self.assertEqual(data_out, []) 
开发者ID:jazzband,项目名称:django-defender,代码行数:25,代码来源:tests.py

示例7: logout

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def logout(request):
    """
    Removes the authenticated user's ID from the request and flushes their
    session data.
    """
    # Dispatch the signal before the user is logged out so the receivers have a
    # chance to find out *who* logged out.
    user = getattr(request, 'user', None)
    if hasattr(user, 'is_authenticated') and not user.is_authenticated():
        user = None
    user_logged_out.send(sender=user.__class__, request=request, user=user)

    # remember language choice saved to session
    language = request.session.get(LANGUAGE_SESSION_KEY)

    request.session.flush()

    if language is not None:
        request.session[LANGUAGE_SESSION_KEY] = language

    if hasattr(request, 'user'):
        from django.contrib.auth.models import AnonymousUser
        request.user = AnonymousUser() 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:25,代码来源:__init__.py

示例8: auth

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def auth(request):
    """
    Returns context variables required by apps that use Django's authentication
    system.

    If there is no 'user' attribute in the request, uses AnonymousUser (from
    django.contrib.auth).
    """
    if hasattr(request, 'user'):
        user = request.user
    else:
        from django.contrib.auth.models import AnonymousUser
        user = AnonymousUser()

    return {
        'user': user,
        'perms': PermWrapper(user),
    } 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:20,代码来源:context_processors.py

示例9: test_get_statements_matching_principal_if_user_is_anonymous

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def test_get_statements_matching_principal_if_user_is_anonymous(self):
        user = AnonymousUser()

        statements = [
            {"principal": ["id:5"], "action": ["create"]},
            {"principal": ["*"], "action": ["list"]},
            {"principal": ["authenticated"], "action": ["authenticated_action"]},
            {"principal": ["anonymous"], "action": ["anonymous_action"]},
        ]

        policy = AccessPolicy()

        result = policy._get_statements_matching_principal(
            FakeRequest(user), statements
        )

        self.assertEqual(len(result), 2)
        self.assertEqual(result[0]["action"], ["list"])
        self.assertEqual(result[1]["action"], ["anonymous_action"]) 
开发者ID:rsinger86,项目名称:drf-access-policy,代码行数:21,代码来源:test_access_policy.py

示例10: test_public_with_link_to_share_toggle_on

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def test_public_with_link_to_share_toggle_on(self):
        # sharing behavior as of 09/13/2012:
        # it requires both data_share and form_share both turned on
        # in order to grant anon access to form uploading
        # TODO: findout 'for_user': 'all' and what it means
        response = self.client.post(self.perm_url, {'for_user': 'all',
                                    'perm_type': 'link'})
        self.assertEqual(response.status_code, 302)
        self.assertEqual(MetaData.public_link(self.xform), True)
        # toggle shared on
        self.xform.shared = True
        self.xform.shared_data = True
        self.xform.save()
        response = self.anon.get(self.show_url)
        self.assertEqual(response.status_code, 302)
        if not self._running_enketo():
            raise SkipTest
        with HTTMock(enketo_mock):
            factory = RequestFactory()
            request = factory.get('/')
            request.user = AnonymousUser()
            response = enter_data(
                request, self.user.username, self.xform.id_string)
            self.assertEqual(response.status_code, 302) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:26,代码来源:test_form_enter_data.py

示例11: logout

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def logout(request):
    """
    Remove the authenticated user's ID from the request and flush their session
    data.
    """
    # Dispatch the signal before the user is logged out so the receivers have a
    # chance to find out *who* logged out.
    user = getattr(request, 'user', None)
    if hasattr(user, 'is_authenticated') and not user.is_authenticated:
        user = None
    user_logged_out.send(sender=user.__class__, request=request, user=user)

    # remember language choice saved to session
    language = request.session.get(LANGUAGE_SESSION_KEY)

    request.session.flush()

    if language is not None:
        request.session[LANGUAGE_SESSION_KEY] = language

    if hasattr(request, 'user'):
        from django.contrib.auth.models import AnonymousUser
        request.user = AnonymousUser() 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:25,代码来源:__init__.py

示例12: auth

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def auth(request):
    """
    Return context variables required by apps that use Django's authentication
    system.

    If there is no 'user' attribute in the request, use AnonymousUser (from
    django.contrib.auth).
    """
    if hasattr(request, 'user'):
        user = request.user
    else:
        from django.contrib.auth.models import AnonymousUser
        user = AnonymousUser()

    return {
        'user': user,
        'perms': PermWrapper(user),
    } 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:20,代码来源:context_processors.py

示例13: get_users_for

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def get_users_for(cls, perms, slug):
        """
        return users with ``perms`` for the given ``slug``.

        ``perms`` could be the permission name or an iterable
         of permissions names
        """

        rules = cls.get_rules_for(perms, slug)
        if rules.filter(apply_to=ACLRule.TO_ANY).exists():
            return {AnonymousUser()} | set(get_user_model().objects.all())
        elif rules.filter(apply_to=ACLRule.TO_LOGGED).exists():
            return get_user_model().objects.all()

        allowed = []
        for rule in rules:
            if rule.apply_to == ACLRule.TO_STAFF:
                allowed += get_user_model().objects.filter(is_staff=True).values_list('id', flat=True)
            elif rule.apply_to == ACLRule.TO_SUPERUSERS:
                allowed += get_user_model().objects.filter(is_superuser=True).values_list('id', flat=True)
            else:
                allowed += get_user_model().objects.filter(Q(aclrule=rule) |
                                                           Q(groups__aclrule=rule)).values_list('id',
                                                                                                flat=True)
        return get_user_model().objects.filter(id__in=allowed).distinct() 
开发者ID:mgaitan,项目名称:waliki,代码行数:27,代码来源:models.py

示例14: get_user

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def get_user(self, request):
        session_key = request.cookies.get('sessionid', '')

        if session_key:
            try:
                session = Session.objects.get(session_key=session_key)
                uid = session.get_decoded().get('_auth_user_id')

                try:
                    return User.objects.get(pk=uid)

                except User.DoesNotExist:
                    pass

            except Session.DoesNotExist:
                pass

        return AnonymousUser() 
开发者ID:pengutronix,项目名称:aiohttp-json-rpc,代码行数:20,代码来源:django.py

示例15: authenticate

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AnonymousUser [as 别名]
def authenticate(self, request):
        """
        Authenticate the request for anyone!
        """
        return AnonymousUser(), None 
开发者ID:deis,项目名称:controller,代码行数:7,代码来源:authentication.py


注:本文中的django.contrib.auth.models.AnonymousUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。