當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。