• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.user_grant_permission函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.user_grant_permission函数的典型用法代码示例。如果您正苦于以下问题:Python user_grant_permission函数的具体用法?Python user_grant_permission怎么用?Python user_grant_permission使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_permission_needed

def test_permission_needed(app, admin, demomodels, action):
    permission_mapping = {'export_as_csv': 'adminactions_export',
                          'export_as_fixture': 'adminactions_export',
                          'export_as_xls': 'adminactions_export',
                          'export_delete_tree': 'adminactions_export',
                          'mass_update': 'adminactions_massupdate',
                          'merge': 'adminactions_merge',
                          'graph_queryset': 'adminactions_chart',
                          }
    perm = "demo.{}_demomodel".format(permission_mapping[action])
    url = reverse('admin:demo_demomodel_changelist')
    pks = [demomodels[0].pk, demomodels[1].pk]
    with user_grant_permission(admin, ['demo.change_demomodel']):
        res = app.post(url, [('action', action),
                             ('_selected_action', pks)],
                       extra_environ={'wsgi.url_scheme': 'https'},
                       user=admin.username,
                       expect_errors=True)
        assert res.status_code == 302
        res = res.follow()
        assert 'Sorry you do not have rights to execute this action' in [str(m) for m in res.context['messages']]

        with user_grant_permission(admin, [perm]):
            res = app.post(url, [('action', action),
                                 ('_selected_action', pks)],
                           extra_environ={'wsgi.url_scheme': 'https'},
                           user=admin.username,
                           expect_errors=True)
            assert res.status_code == 200
开发者ID:PetrDlouhy,项目名称:django-adminactions,代码行数:29,代码来源:test_permissions.py


示例2: _run_action

    def _run_action(self, steps=3, page_start=None):
        with user_grant_permission(self.user,
                                   ['demo.change_demomodel',
                                    'demo.adminactions_merge_demomodel']):
            if isinstance(steps, int):
                steps = list(range(1, steps + 1))
                res = self.app.get('/', user='user')
                res = res.click('Demo models')
            else:
                res = page_start

            if 1 in steps:
                form = res.forms['changelist-form']
                form['action'] = 'merge'
                self._select_rows(form)
                res = form.submit()
                assert not hasattr(res.form, 'errors')

            if 2 in steps:
                res.form['image'] = res.form['form-1-image'].value
                res = res.form.submit('preview')
                assert not hasattr(res.form, 'errors')

            if 3 in steps:
                res = res.form.submit('apply')
            return res
开发者ID:saxix,项目名称:django-adminactions,代码行数:26,代码来源:test_merge.py


示例3: test_issue_93

    def test_issue_93(self):
        # default date(time) format in XLS export doesn't import well on excel
        with user_grant_permission(self.user, ['demo.change_demomodel',
                                               'demo.adminactions_export_demomodel']):
            res = self.app.get('/', user='user')
            res = res.click('Demo models')
            form = res.forms['changelist-form']
            form['action'] = self.action_name
            self._select_rows(form)
            res = form.submit()
            res.form['header'] = 1
            res.form['columns'] = ['date', ]
            res = res.form.submit('apply')
            io = six.BytesIO(res.body)

            io.seek(0)
            w = xlrd.open_workbook(file_contents=io.read(), formatting_info=True)
            sheet = w.sheet_by_index(0)

            cell = sheet.cell(1, 1)
            fmt = w.xf_list[cell.xf_index]
            format_key = fmt.format_key
            format = w.format_map[format_key]  # gets a Format object

            self.assertEqual(cell.value, 41303.0)
            self.assertEqual(cell.ctype, 3)
            self.assertEqual(format.format_str, u'd/m/Y')
开发者ID:saxix,项目名称:django-adminactions,代码行数:27,代码来源:test_exports.py


示例4: test_use_display_ko

    def test_use_display_ko(self):
        with user_grant_permission(self.user, ['demo.change_demomodel',
                                               'demo.adminactions_export_demomodel']):
            res = self.app.get('/', user='user')
            res = res.click('Demo models')
            form = res.forms['changelist-form']
            form['action'] = self.action_name
            self._select_rows(form)
            res = form.submit()
            res.form['header'] = 1
            res.form['columns'] = ['char', 'text', 'bigint', 'choices'
                                                             '']
            res = res.form.submit('apply')
            io = six.BytesIO(res.body)

            io.seek(0)
            w = xlrd.open_workbook(file_contents=io.read())
            sheet = w.sheet_by_index(0)
            self.assertEquals(sheet.cell_value(0, 1), u'Chäř')
            self.assertEquals(sheet.cell_value(0, 2), u'bigint')
            self.assertEquals(sheet.cell_value(0, 3), u'text')
            self.assertEquals(sheet.cell_value(0, 4), u'choices')
            self.assertEquals(sheet.cell_value(1, 1), u'Pizzä ïs Gööd')
            self.assertEquals(sheet.cell_value(1, 2), 333333333.0)
            self.assertEquals(sheet.cell_value(1, 3), u'lorem ipsum')
            self.assertEquals(sheet.cell_value(1, 4), 2.0)
开发者ID:PetrDlouhy,项目名称:django-adminactions,代码行数:26,代码来源:test_exports.py


示例5: test_swap

    def test_swap(self):
        with user_grant_permission(self.user, ['auth.change_user', 'auth.adminactions_merge_user']):
            # removed = User.objects.get(pk=self._selected_rows[0])
            # preserved = User.objects.get(pk=self._selected_rows[1])

            res = self.app.get('/', user='user')
            res = res.click('Users')
            form = res.forms['changelist-form']
            form['action'] = 'merge'
            self._select_rows(form, [1, 2])
            res = form.submit()
            removed = User.objects.get(pk=self._selected_values[0])
            preserved = User.objects.get(pk=self._selected_values[1])

            # steps = 2 (swap):
            res.form['master_pk'] = self._selected_values[1]
            res.form['other_pk'] = self._selected_values[0]

            res.form['username'] = res.form['form-0-username'].value
            res.form['email'] = res.form['form-0-email'].value
            res.form['last_login'] = res.form['form-1-last_login'].value
            res.form['date_joined'] = res.form['form-1-date_joined'].value

            # res.form['field_names'] = 'username,email'

            res = res.form.submit('preview')
            # steps = 3:
            res = res.form.submit('apply')

            preserved_after = User.objects.get(pk=self._selected_values[1])
            self.assertFalse(User.objects.filter(pk=removed.pk).exists())
            self.assertTrue(User.objects.filter(pk=preserved.pk).exists())

            self.assertEqual(preserved_after.email, removed.email)
            self.assertFalse(LogEntry.objects.filter(pk=removed.pk).exists())
开发者ID:saxix,项目名称:django-adminactions,代码行数:35,代码来源:test_merge.py


示例6: test_success

    def test_success(self):
        with user_grant_permission(self.user, ['auth.change_user',
                                               'auth.adminactions_export_user']):
            res = self.app.get('/', user='user')
            res = res.click('Users')
            form = res.forms['changelist-form']
            form['action'] = self.action_name
            # form.set('_selected_action', True, 0)
            # form.set('_selected_action', True, 1)
            # form.set('_selected_action', True, 2)
            self._select_rows(form)
            res = form.submit()
            res.form['header'] = 1
            res.form['columns'] = ['id', 'username', 'first_name'
                                                     '']
            res = res.form.submit('apply')
            io = six.BytesIO(res.body)

            io.seek(0)
            w = xlrd.open_workbook(file_contents=io.read())
            sheet = w.sheet_by_index(0)
            self.assertEquals(sheet.cell_value(0, 0), u'#')
            self.assertEquals(sheet.cell_value(0, 1), u'ID')
            self.assertEquals(sheet.cell_value(0, 2), u'username')
            self.assertEquals(sheet.cell_value(0, 3), u'first name')
            self.assertEquals(sheet.cell_value(1, 1), 1.0)
            self.assertEquals(sheet.cell_value(1, 2), u'sax')
            self.assertEquals(sheet.cell_value(2, 2), u'user')
开发者ID:PetrDlouhy,项目名称:django-adminactions,代码行数:28,代码来源:test_exports.py


示例7: test_merge_delete_detail

    def test_merge_delete_detail(self):
        from adminactions.merge import MergeForm

        with user_grant_permission(self.user, ['auth.change_user', 'auth.adminactions_merge_user']):
            # removed = User.objects.get(pk=self._selected_rows[0])
            # preserved = User.objects.get(pk=self._selected_rows[1])

            res = self.app.get('/', user='user')
            res = res.click('Users')
            form = res.forms['changelist-form']
            form['action'] = 'merge'
            self._select_rows(form, [1, 2])
            res = form.submit()
            removed = User.objects.get(pk=self._selected_values[0])
            preserved = User.objects.get(pk=self._selected_values[1])

            removed.userdetail_set.create(note='1')
            preserved.userdetail_set.create(note='2')

            # steps = 2:
            res.form['master_pk'] = self._selected_values[1]
            res.form['other_pk'] = self._selected_values[0]

            res.form['username'] = res.form['form-0-username'].value
            res.form['email'] = res.form['form-0-email'].value
            res.form['last_login'] = res.form['form-1-last_login'].value
            res.form['date_joined'] = res.form['form-1-date_joined'].value
            res.form['dependencies'] = MergeForm.DEP_DELETE
            res = res.form.submit('preview')
            # steps = 3:
            res = res.form.submit('apply')

            preserved_after = User.objects.get(pk=self._selected_values[1])
            self.assertEqual(preserved_after.userdetail_set.count(), 1)
            self.assertFalse(User.objects.filter(pk=removed.pk).exists())
开发者ID:saxix,项目名称:django-adminactions,代码行数:35,代码来源:test_merge.py


示例8: test_faster_export

    def test_faster_export(self):
        # generate 3k users
        start = time.time()
        user_count = User.objects.count()
        User.objects.bulk_create([User(
            username='bulk_user_%s' % i) for i in range(3000)])
        # print('created 3k users in %.1f seconds' % (time.time() - start))
        self.assertEqual(User.objects.count(), 3000 + user_count)

        start = time.time()
        with user_grant_permission(self.user, [
                'auth.change_user', 'auth.adminactions_export_user']):
            res = self.app.get('/', user='user')
            res = res.click('Users')
            form = res.forms['changelist-form']
            form['action'] = self.action_name
            form['select_across'] = 1
            self._select_rows(form)
            res = form.submit()
            res.form['header'] = 1
            res = res.form.submit('apply')

        res_time = (time.time() - start)
        # print('Response returned in %.1f seconds' % res_time)

        io = six.BytesIO(res.body)

        io.seek(0)
        w = xlrd.open_workbook(file_contents=io.read())
        sheet = w.sheet_by_index(0)

        self.assertEqual(sheet.nrows, 3000 + user_count + 1)
        self.assertLessEqual(res_time, 6.5, "Response should return under 6.5 "
                             "seconds, was %.2f" % res_time)
开发者ID:PetrDlouhy,项目名称:django-adminactions,代码行数:34,代码来源:test_exports.py


示例9: test_no_permission

 def test_no_permission(self):
     with user_grant_permission(self.user, ['demo.change_demomodel']):
         res = self.app.get('/', user='user')
         res = res.click('Demo models')
         form = res.forms['changelist-form']
         form['action'] = 'mass_update'
         form.set('_selected_action', True, 0)
         res = form.submit().follow()
         assert six.b('Sorry you do not have rights to execute this action') in res.body
开发者ID:PetrDlouhy,项目名称:django-adminactions,代码行数:9,代码来源:test_mass_update.py


示例10: test_no_permission

    def test_no_permission(self):
        with user_grant_permission(self.user, ['demo.change_demomodel']):
            res = self._get_changelist_form_response()

            form = res.forms['changelist-form']
            form['action'] = 'byrows_update'
            self._select_rows(form, selected_rows=self._selected_rows)
            res = form.submit().follow()
            assert six.b('Sorry you do not have rights to execute this action') in res.body
开发者ID:PetrDlouhy,项目名称:django-adminactions,代码行数:9,代码来源:test_byrows_update.py


示例11: test_error_if_too_many_records

 def test_error_if_too_many_records(self):
     with user_grant_permission(self.user, ['auth.change_user', 'auth.adminactions_merge_user']):
         res = self.app.get('/', user='user')
         res = res.click('Users')
         form = res.forms['changelist-form']
         form['action'] = 'merge'
         self._select_rows(form, [1, 2, 3])
         res = form.submit().follow()
         self.assertContains(res, 'Please select exactly 2 records')
开发者ID:saxix,项目名称:django-adminactions,代码行数:9,代码来源:test_merge.py


示例12: test_no_permission

 def test_no_permission(self):
     with user_grant_permission(self.user, ['auth.change_user']):
         res = self.app.get('/', user='user')
         res = res.click('Users')
         form = res.forms['changelist-form']
         form['action'] = 'merge'
         self._select_rows(form)
         res = form.submit().follow()
         assert 'Sorry you do not have rights to execute this action' in str(res.body)
开发者ID:saxix,项目名称:django-adminactions,代码行数:9,代码来源:test_merge.py


示例13: test_no_permission

 def test_no_permission(self):
     with user_grant_permission(self.user, ['auth.change_user']):
         res = self.app.get('/', user='user')
         res = res.click('Users')
         form = res.forms['changelist-form']
         form['action'] = 'export_as_csv'
         form.set('_selected_action', True, 0)
         res = form.submit().follow()
         assert six.b(
             'Sorry you do not have rights to execute this action') in res.body
开发者ID:PetrDlouhy,项目名称:django-adminactions,代码行数:10,代码来源:test_exports.py


示例14: test_messages

    def test_messages(self):
        with user_grant_permission(self.user, ['demo.change_demomodel', 'demo.adminactions_massupdate_demomodel']):
            res = self._run_action(**{'_clean': 1}).follow()
            messages = [m.message for m in list(res.context['messages'])]
            self.assertTrue(messages)
            self.assertEqual('Updated 2 records', messages[0])

            res = self._run_action(selected_rows=[1]).follow()
            messages = [m.message for m in list(res.context['messages'])]
            self.assertTrue(messages)
            self.assertEqual('Updated 1 records', messages[0])
开发者ID:PetrDlouhy,项目名称:django-adminactions,代码行数:11,代码来源:test_mass_update.py


示例15: test_form_rows_count

    def test_form_rows_count(self):
        """
            Count the selected items appear in the action form
        """
        with user_grant_permission(self.user, ['demo.change_demomodel', 'demo.adminactions_byrowsupdate_demomodel']):
            res = self._get_changelist_form_response()

            form = res.forms['changelist-form']
            self._select_rows(form, selected_rows=self._selected_rows)
            res = self._get_action_form_response(change_list_response=res)
            self.assertEqual(len(res.html.find(id="formset").find_all(class_="row")), len(self._selected_rows))
开发者ID:PetrDlouhy,项目名称:django-adminactions,代码行数:11,代码来源:test_byrows_update.py


示例16: _run_action

 def _run_action(self, steps=2):
     with user_grant_permission(self.user, ['auth.change_user',
                                            'auth.adminactions_export_user']):
         res = self.app.get('/', user='user')
         res = res.click('Users')
         if steps >= 1:
             form = res.forms['changelist-form']
             form['action'] = self.action_name
             self._select_rows(form)
             res = form.submit()
         if steps >= 2:
             res = res.form.submit('apply')
     return res
开发者ID:PetrDlouhy,项目名称:django-adminactions,代码行数:13,代码来源:test_exports.py


示例17: test_form_rows_fields_exists

    def test_form_rows_fields_exists(self):
        """
            Check model fields appear in action form for each selected models
        """
        with user_grant_permission(self.user, ['demo.change_demomodel', 'demo.adminactions_byrowsupdate_demomodel']):
            res = self._get_changelist_form_response()

            form = res.forms['changelist-form']
            self._select_rows(form, selected_rows=self._selected_rows)
            res = self._get_action_form_response(change_list_response=res)
            byrows_update_get_fields(ModelAdmin(DemoModel, self.site))
            for r, value in enumerate(self._selected_values):
                for fname in byrows_update_get_fields(ModelAdmin(DemoModel, self.site)):
                    assert res.form["form-%d-%s" % (r, fname)]
开发者ID:PetrDlouhy,项目名称:django-adminactions,代码行数:14,代码来源:test_byrows_update.py


示例18: test_add_foreign_keys

 def test_add_foreign_keys(self):
     with user_grant_permission(self.user, ['auth.change_user',
                                            'auth.adminactions_export_user']):
         res = self.app.get('/', user='user')
         res = res.click('Users')
         form = res.forms['changelist-form']
         form['action'] = self.action_name
         form.set('_selected_action', True, 0)
         form.set('_selected_action', True, 1)
         res = form.submit()
         res.form['use_natural_key'] = True
         res.form['add_foreign_keys'] = True
         res = res.form.submit('apply')
         assert res.json[0]['pk'] == 1
开发者ID:PetrDlouhy,项目名称:django-adminactions,代码行数:14,代码来源:test_exports.py


示例19: _run_action

    def _run_action(self, steps=2):
        # with user_grant_permission(self.user, ['demo.change_demomodel', 'demo.adminactions_massupdate_demomodel']):

        with user_grant_permission(self.user, ['auth.change_user', 'auth.adminactions_chart_user']):
            res = self.app.get('/', user='user')
            res = res.click('Users')
            if steps >= 1:
                form = res.forms['changelist-form']
                form['action'] = 'graph_queryset'
                self._select_rows(form)
                # form.set('_selected_action', True, 0)
                # form.set('_selected_action', True, 1)
                res = form.submit()
            if steps >= 2:
                res.form['axes_x'] = 'username'
                res = res.form.submit('apply')

            return res
开发者ID:PetrDlouhy,项目名称:django-adminactions,代码行数:18,代码来源:test_graph.py


示例20: _run_action

 def _run_action(self, steps=2, **kwargs):
     selected_rows = kwargs.pop('selected_rows', self._selected_rows)
     with user_grant_permission(self.user, ['demo.change_demomodel', 'demo.adminactions_massupdate_demomodel']):
         res = self.app.get('/', user='user')
         res = res.click('Demo models')
         if steps >= 1:
             form = res.forms['changelist-form']
             form['action'] = 'mass_update'
             self._select_rows(form, selected_rows)
             res = form.submit()
         if steps >= 2:
             for k, v in kwargs.items():
                 res.form[k] = v
             res.form['chk_id_char'].checked = True
             res.form['func_id_char'] = 'upper'
             res.form['chk_id_choices'].checked = True
             res.form['func_id_choices'] = 'set'
             res.form['choices'] = '1'
             res = res.form.submit('apply')
     return res
开发者ID:PetrDlouhy,项目名称:django-adminactions,代码行数:20,代码来源:test_mass_update.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.utf8函数代码示例发布时间:2022-05-26
下一篇:
Python utils.urljoin函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap