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


Python status.HTTP_200_OK属性代码示例

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


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

示例1: update

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def update(self, request, **kwargs):
        app = self.get_object()
        old_owner = app.owner

        if request.data.get('owner'):
            if self.request.user != app.owner and not self.request.user.is_superuser:
                raise PermissionDenied()
            new_owner = get_object_or_404(User, username=request.data['owner'])
            app.owner = new_owner
            # ensure all downstream objects that are owned by this user and are part of this app
            # is also updated
            for downstream_model in [models.AppSettings, models.Build, models.Config,
                                     models.Domain, models.Release, models.TLS]:
                downstream_model.objects.filter(owner=old_owner, app=app).update(owner=new_owner)
        app.save()
        return Response(status=status.HTTP_200_OK) 
开发者ID:deis,项目名称:controller,代码行数:18,代码来源:views.py

示例2: app

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def app(self, request, *args, **kwargs):
        app = get_object_or_404(models.App, id=kwargs['id'])

        perm_name = "api.use_app"
        usernames = [u.id for u in get_users_with_perms(app)
                     if u.has_perm(perm_name, app)]

        data = {}
        result = models.Key.objects \
                       .filter(owner__in=usernames) \
                       .values('owner__username', 'public', 'fingerprint') \
                       .order_by('created')
        for info in result:
            user = info['owner__username']
            if user not in data:
                data[user] = []

            data[user].append({
                'key': info['public'],
                'fingerprint': info['fingerprint']
            })

        return Response(data, status=status.HTTP_200_OK) 
开发者ID:deis,项目名称:controller,代码行数:25,代码来源:views.py

示例3: users

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def users(self, request, *args, **kwargs):
        app = get_object_or_404(models.App, id=kwargs['id'])
        request.user = get_object_or_404(User, username=kwargs['username'])
        # check the user is authorized for this app
        if not permissions.is_app_user(request, app):
            raise PermissionDenied()

        data = {request.user.username: []}
        keys = models.Key.objects \
                     .filter(owner__username=kwargs['username']) \
                     .values('public', 'fingerprint') \
                     .order_by('created')
        if not keys:
            raise NotFound("No Keys match the given query.")

        for info in keys:
            data[request.user.username].append({
                'key': info['public'],
                'fingerprint': info['fingerprint']
            })

        return Response(data, status=status.HTTP_200_OK) 
开发者ID:deis,项目名称:controller,代码行数:24,代码来源:views.py

示例4: test_list

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def test_list(self, monkeypatch, sm_test_data):
        monkeypatch.setattr(django.contrib.sites.shortcuts,
                            'get_current_site',
                            lambda req: site)
        site = sm_test_data['site']
        org = sm_test_data['organization']
        co = sm_test_data['course_overviews'][0]

        if organizations_support_sites():
            caller = UserFactory()
            UserOrganizationMappingFactory(user=caller,
                                           organization=org,
                                           is_amc_admin=True)
        else:
            caller = UserFactory(is_staff=True)

        request_path = self.request_path
        request = APIRequestFactory().get(request_path)
        request.META['HTTP_HOST'] = site.domain

        force_authenticate(request, user=caller)
        view = self.view_class.as_view({'get': 'list'})
        response = view(request)
        assert response.status_code == status.HTTP_200_OK
        # TODO: Assert data are correct 
开发者ID:appsembler,项目名称:figures,代码行数:27,代码来源:test_mau_views.py

示例5: add_users

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def add_users(self, request, *args, **kwargs):
        """
        Add users to project members.
        """
        self.check_admin_permission()

        project = self.get_object()

        users = request.data.get('users', None)
        logger.debug("Add users {} into project {}.".format(users,
            project.name))
        for user_id in users:
            user = MyUser.objects.get(id=user_id)
            project.members.add(user)

        return Response(status=status.HTTP_200_OK) 
开发者ID:wangtaoking1,项目名称:hummer,代码行数:18,代码来源:views.py

示例6: remove_users

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def remove_users(self, request, *args, **kwargs):
        """
        Remove users from project members.
        """
        self.check_admin_permission()

        project = self.get_object()

        users = request.data.get('users', None)
        logger.debug("Remove users {} from project {}.".format(users,
            project.name))
        for user_id in users:
            user = MyUser.objects.get(id=user_id)
            project.members.remove(user)

        return Response(status=status.HTTP_200_OK) 
开发者ID:wangtaoking1,项目名称:hummer,代码行数:18,代码来源:views.py

示例7: pod_lists

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def pod_lists(self, request, *args, **kwargs):
        """
        Return the pods list of the application with json.
        """
        application = self.get_object()

        if not application:
            raise ValidationError(detail="The application doesn't exist.")

        kubeclient = KubeClient("http://{}:{}{}".format(settings.MASTER_IP,
            settings.K8S_PORT, settings.K8S_API_PATH))
        pods = kubeclient.list_pods(namespace=application.image.project.name,
            label="app={}".format(get_application_instance_name(application)))
        logger.debug(pods)

        return Response(pods, status=status.HTTP_200_OK) 
开发者ID:wangtaoking1,项目名称:hummer,代码行数:18,代码来源:views.py

示例8: logs_pod

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def logs_pod(self, request, *args, **kwargs):
        """
        Return the tail n lines logs of pod.
        """
        user = request.user

        assert 'pid' in self.kwargs
        pid = self.kwargs['pid']
        project = Project.objects.get(id=pid)

        if not check_member_in_project(project, user):
            raise PermissionDenied(detail="User {} is not in project {}."
                .format(user.username, project.name))

        assert 'pod' in self.kwargs
        pod = self.kwargs['pod']
        tailLine = int(request.query_params['tail'])

        kubeclient = KubeClient("http://{}:{}{}".format(settings.MASTER_IP,
            settings.K8S_PORT, settings.K8S_API_PATH))
        logs = kubeclient.get_logs_of_pod(project.name, pod, tailLine)
        # print(logs)

        return Response(data=logs, status=status.HTTP_200_OK) 
开发者ID:wangtaoking1,项目名称:hummer,代码行数:26,代码来源:views.py

示例9: list_pods

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def list_pods(self, request, *args, **kwargs):
        """
        AdminUser search pods for application id.
        """
        user = self.request.user
        if not user.is_staff:
            raise PermissionDenied()

        app_id = request.GET.get('app', 0)
        try:
            application = Application.objects.get(id=app_id)
        except Exception:
            return Response(status=status.HTTP_200_OK)

        kubeclient = KubeClient("http://{}:{}{}".format(settings.MASTER_IP,
            settings.K8S_PORT, settings.K8S_API_PATH))
        pods = kubeclient.list_pods(
            namespace=application.image.project.name,
            label="app={}".format(get_application_instance_name(application)))
        logger.debug(pods)

        return Response(pods, status=status.HTTP_200_OK) 
开发者ID:wangtaoking1,项目名称:hummer,代码行数:24,代码来源:views.py

示例10: test_send_link_with_username_as_verification_id_ok

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def test_send_link_with_username_as_verification_id_ok(self):
        user = self.create_test_user(username='testusername')
        request = self.create_post_request({
            'login': user.username,
        })
        with self.assert_one_mail_sent() as sent_emails, self.timer() as timer:
            response = self.view_func(request)
            self.assert_valid_response(response, status.HTTP_200_OK)
        sent_email = sent_emails[0]
        verification_data = self._assert_valid_verification_email(
            sent_email, user)
        self.assertEqual(verification_data['user_id'], user.username)
        url_sig_timestamp = int(verification_data['timestamp'])
        self.assertGreaterEqual(url_sig_timestamp, timer.start_time)
        self.assertLessEqual(url_sig_timestamp, timer.end_time)
        signer = ResetPasswordSigner(verification_data)
        signer.verify() 
开发者ID:apragacz,项目名称:django-rest-registration,代码行数:19,代码来源:test_send_reset_password_link.py

示例11: test_object_viewset

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def test_object_viewset(self):
        """
        Tests the ObjectMutlipleModelAPIViewSet with the default settings
        """
        client = APIClient()
        response = client.get('/object/', format='api')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertEqual(len(response.data), 2)
        self.assertEqual(response.data, {
            'Play': [
                {'title': 'Romeo And Juliet', 'genre': 'Tragedy', 'year': 1597},
                {'title': "A Midsummer Night's Dream", 'genre': 'Comedy', 'year': 1600},
                {'title': 'Julius Caesar', 'genre': 'Tragedy', 'year': 1623},
                {'title': 'As You Like It', 'genre': 'Comedy', 'year': 1623},
            ],
            'Poem': [
                {'title': "Shall I compare thee to a summer's day?", 'style': 'Sonnet'},
                {'title': "As a decrepit father takes delight", 'style': 'Sonnet'}
            ]
        }) 
开发者ID:MattBroach,项目名称:DjangoRestMultipleModels,代码行数:23,代码来源:test_viewsets.py

示例12: test_flat_viewset

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def test_flat_viewset(self):
        """
        Tests the ObjectMutlipleModelAPIViewSet with the default settings
        """
        client = APIClient()
        response = client.get('/flat/', format='api')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertEqual(len(response.data), 6)
        self.assertEqual(response.data, [
            {'genre': 'Tragedy', 'title': 'Romeo And Juliet', 'year': 1597, 'type': 'Play'},
            {'genre': 'Comedy', 'title': 'A Midsummer Night\'s Dream', 'year': 1600, 'type': 'Play'},
            {'genre': 'Tragedy', 'title': 'Julius Caesar', 'year': 1623, 'type': 'Play'},
            {'genre': 'Comedy', 'title': 'As You Like It', 'year': 1623, 'type': 'Play'},
            {'title': "Shall I compare thee to a summer's day?", 'style': 'Sonnet', 'type': 'Poem'},
            {'title': "As a decrepit father takes delight", 'style': 'Sonnet', 'type': 'Poem'},
        ]) 
开发者ID:MattBroach,项目名称:DjangoRestMultipleModels,代码行数:19,代码来源:test_viewsets.py

示例13: test_html_renderer

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def test_html_renderer(self):
        """
        Testing bug in which results dict failed to be passed into template context
        """
        client = APIClient()
        response = client.get('/template', format='html')

        # test the data is formatted properly and shows up in the template
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertIn('data', response.data)
        self.assertContains(response, "Tragedy")
        self.assertContains(response, "<html>")
        self.assertContains(response, "decrepit")

        # test that the JSONRenderer does NOT add the dictionary wrapper to the data
        response = client.get('/template?format=json')

        # test the data is formatted properly and shows up in the template
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertNotIn('data', response.data)
        self.assertNotIn('<html>', response) 
开发者ID:MattBroach,项目名称:DjangoRestMultipleModels,代码行数:23,代码来源:test_html_renderer.py

示例14: test_dynamic_querylist

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def test_dynamic_querylist(self):
        """
        using get_querylist allows the construction of dynamic queryLists
        """
        view = DynamicQueryView.as_view()

        request = factory.get('/Julius-Caesar')
        with self.assertNumQueries(2):
            response = view(request, play="Julius-Caesar")

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertEqual(len(response.data), 2)
        self.assertEqual(response.data, {
            'Play': [
                {'title': 'Julius Caesar', 'genre': 'Tragedy', 'year': 1623},
            ],
            'Poem': [
                {'title': "Shall I compare thee to a summer's day?", 'style': 'Sonnet'},
                {'title': "As a decrepit father takes delight", 'style': 'Sonnet'}
            ]
        }) 
开发者ID:MattBroach,项目名称:DjangoRestMultipleModels,代码行数:24,代码来源:test_object_view.py

示例15: test_cached_querylist

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_200_OK [as 别名]
def test_cached_querylist(self):
        view = CachedQueryView.as_view()

        request = factory.get('/Julius-Caesar')
        with self.assertNumQueries(2):
            response = view(request)
        with self.assertNumQueries(0):
            response = view(request)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {
            'Play': [
                {'title': 'Romeo And Juliet', 'genre': 'Tragedy', 'year': 1597},
                {'title': "A Midsummer Night's Dream", 'genre': 'Comedy', 'year': 1600},
                {'title': 'Julius Caesar', 'genre': 'Tragedy', 'year': 1623},
                {'title': 'As You Like It', 'genre': 'Comedy', 'year': 1623},
            ],
            'Poem': [
                {'title': "Shall I compare thee to a summer's day?", 'style': 'Sonnet'},
                {'title': "As a decrepit father takes delight", 'style': 'Sonnet'}
            ]
        }) 
开发者ID:MattBroach,项目名称:DjangoRestMultipleModels,代码行数:24,代码来源:test_object_view.py


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