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


Python models.Group方法代码示例

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


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

示例1: edit_group

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import Group [as 别名]
def edit_group(request, pk=None):
    title = _(u'Edit Group')
    object_list = Group.objects.all()

    if pk is None:
        group = Group()
        form = GroupForm(instance=group)
    else:
        group = Group.objects.get(pk=pk)
        title = group.name
        form = GroupForm(instance=group)

    if request.method == 'POST':
        form = GroupForm(request.POST, instance=group)
        if form.is_valid():
            form.save()
            messages.success(request, _(u'Group saved'))
            return redirect(list_groups)

    return render(request, 'admin/users/group_form.html', locals()) 
开发者ID:fpsw,项目名称:Servo,代码行数:22,代码来源:admin.py

示例2: settings

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import Group [as 别名]
def settings(self):
        if self.cached_settings:
            return self.cached_settings
        else:
            from django.conf import settings
            allowed_configurations = {
                'CONTENT_TYPE_CLASS': ContentType,
                'USER_CLASS': settings.AUTH_USER_MODEL,
                'PERMISSION_CLASS': Permission,
                'GROUP_CLASS': Group,
                'INJECT_MODEL_ADMIN': False
            }
            river_settings = {}
            for key, default in allowed_configurations.items():
                river_settings[key] = getattr(settings, self.get_with_prefix(key), default)

            river_settings['IS_MSSQL'] = connection.vendor == 'microsoft'
            self.cached_settings = river_settings

            return self.cached_settings 
开发者ID:javrasya,项目名称:django-river,代码行数:22,代码来源:config.py

示例3: _group_groups

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import Group [as 别名]
def _group_groups(perm_list):
    """Group permissions by group.

    Input is list of tuples of length 3, where each tuple is in
    following format::

        (<group_id>, <group_name>, <single_permission>)

    Permissions are regrouped and returned in such way that there is
    only one tuple for each group::

        (<group_id>, <group_name>, [<first_permission>, <second_permission>,...])

    :param list perm_list: list of touples of length 3
    :return: list tuples with grouped permissions
    :rtype: list

    """
    perm_list = sorted(perm_list, key=lambda tup: tup[0])

    grouped_perms = []
    for key, group in groupby(perm_list, lambda tup: (tup[0], tup[1])):
        grouped_perms.append((key[0], key[1], [g[2] for g in group]))

    return grouped_perms 
开发者ID:genialis,项目名称:resolwe,代码行数:27,代码来源:shortcuts.py

示例4: add_proj_manager

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import Group [as 别名]
def add_proj_manager(request, pk):
    obj = get_object_or_404(
        Project, pk=pk, is_active=True)
    group = Group.objects.get(name__exact="Project Manager")
    role_obj = UserRole(project=obj, group=group)
    scenario = 'Assign'
    if request.method == 'POST':
        form = SetProjectManagerForm(data=request.POST, instance=role_obj, request=request)
        if form.is_valid():
            role_obj = form.save(commit=False)
            user_id = request.POST.get('user')
            role_obj.user_id = int(user_id)
            role_obj.save()
        messages.add_message(request, messages.INFO, 'Project Manager Added')
        return HttpResponseRedirect(reverse("fieldsight:project-dashboard", kwargs={'pk': obj.pk}))
    else:
        form = SetProjectManagerForm(instance=role_obj, request=request)
    return render(request, "fieldsight/add_project_manager.html", {'obj':obj,'form':form, 'scenario':scenario}) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:20,代码来源:views.py

示例5: add_supervisor

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import Group [as 别名]
def add_supervisor(request, pk):
    obj = get_object_or_404(
        Site, pk=int(pk), is_active=True)
    group = Group.objects.get(name__exact="Site Supervisor")
    role_obj = UserRole(site=obj, group=group)
    if request.method == 'POST':
        form = SetSupervisorForm(data=request.POST, instance=role_obj, request=request)
        if form.is_valid():
            role_obj = form.save(commit=False)
            user_id = request.POST.get('user')
            role_obj.user_id = int(user_id)
            role_obj.save()
        messages.add_message(request, messages.INFO, 'Site Supervisor Added')
        return HttpResponseRedirect(reverse("fieldsight:site-dashboard", kwargs={'pk': obj.pk}))
    else:
        form = SetSupervisorForm(instance=role_obj, request=request)
    return render(request, "fieldsight/add_supervisor.html", {'obj':obj,'form':form}) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:19,代码来源:views.py

示例6: add_central_engineer

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import Group [as 别名]
def add_central_engineer(request, pk):
    obj = get_object_or_404(
        Project, pk=pk, is_active=True)
    group = Group.objects.get(name__exact="Reivewer")
    role_obj = UserRole(project=obj, group=group)
    scenario = 'Assign'
    if request.method == 'POST':
        form = SetProjectRoleForm(data=request.POST, instance=role_obj, request=request)
        if form.is_valid():
            role_obj = form.save(commit=False)
            user_id = request.POST.get('user')
            role_obj.user_id = int(user_id)
            role_obj.save()
        messages.add_message(request, messages.INFO, 'Reviewer Added')
        return HttpResponseRedirect(reverse("fieldsight:project-dashboard", kwargs={'pk': obj.pk}))
    else:
        form = SetProjectRoleForm(instance=role_obj, request=request,)
    return render(request, "fieldsight/add_central_engineer.html", {'obj':obj,'form':form, 'scenario':scenario}) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:20,代码来源:views.py

示例7: setUp

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

        self.group = Group.objects.create(name='test_group')
        self.group__permissions = list(Permission.objects.all()[:3])
        self.group.permissions.add(*self.group__permissions)
        self.user = User.objects.create_user('user')
        self.user__permissions = list(Permission.objects.all()[3:6])
        self.user.groups.add(self.group)
        self.user.user_permissions.add(*self.user__permissions)
        self.admin = User.objects.create_superuser('admin', 'admin@test.me',
                                                   'password')
        self.t1__permission = (Permission.objects.order_by('?')
                               .select_related('content_type')[0])
        self.t1 = Test.objects.create(
            name='test1', owner=self.user,
            date='1789-07-14', datetime='1789-07-14T16:43:27',
            permission=self.t1__permission)
        self.t2 = Test.objects.create(
            name='test2', owner=self.admin, public=True,
            date='1944-06-06', datetime='1944-06-06T06:35:00') 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:23,代码来源:read.py

示例8: get_initial

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import Group [as 别名]
def get_initial(self):
        """
        Returns the initial data to use for forms on this view.

        :returns: Dictionary with the following keys:

                  `type`: ``str``: Type of the target to be created

                  `groups`: ``QuerySet<Group>`` Groups available to the current user

        :rtype: dict
        """
        return {
            'type': self.get_target_type(),
            'groups': self.request.user.groups.all(),
            **dict(self.request.GET.items())
        } 
开发者ID:TOMToolkit,项目名称:tom_base,代码行数:19,代码来源:views.py

示例9: test_valid_user

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import Group [as 别名]
def test_valid_user(self):
        user = factories.UserFactory()
        script = factories.TranslateScriptFactory()
        d = utils.valid_user(script, user)
        self.assertTrue(d['valid'])
        from .. import settings as djangui_settings
        self.assertEqual('disabled', d['display'])
        djangui_settings.DJANGUI_SHOW_LOCKED_SCRIPTS = False
        d = utils.valid_user(script, user)
        self.assertEqual('hide', d['display'])
        from django.contrib.auth.models import Group
        test_group = Group(name='test')
        test_group.save()
        script.user_groups.add(test_group)
        d = utils.valid_user(script, user)
        self.assertFalse(d['valid'])
        user.groups.add(test_group)
        d = utils.valid_user(script, user)
        self.assertTrue(d['valid']) 
开发者ID:Chris7,项目名称:django-djangui,代码行数:21,代码来源:test_utils.py

示例10: config_entity_groups

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import Group [as 别名]
def config_entity_groups(self):
        """
            Get ConfigEntity-specific groups of the given ConfigEntity.
        :return: Group objects of the ConfigEntity
        """
        from footprint.client.configuration.fixture import ConfigEntityFixture

        # Each ConfigEntity class has its own groups according to the configuration
        # global groups listed in its configuration
        # Iterate through the configured global groups and create ConfigEntity-specific versions
        client_fixture = ConfigEntityFixture.resolve_config_entity_fixture(self)

        # Map the fixture to its ConfigEntity Group
        # GlobalConfig returns nothing here since the SuperAdmin Group is both its Global Group
        # and ConfigEntity Group
        return compact(map(
            lambda global_group_name: self.config_entity_group(global_group_name),
            client_fixture.default_config_entity_groups()
        )) 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:21,代码来源:config_entity.py

示例11: _update_or_create_config_entity_groups

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import Group [as 别名]
def _update_or_create_config_entity_groups(config_entity):
    """
        Updates/Creates all the ConfigEntity-specific groups of the given ConfigEntity.
    :param config_entity:
    :return:
    """
    from footprint.client.configuration.fixture import ConfigEntityFixture

    # Each ConfigEntity class has its own groups according to the configuration
    # global groups listed in its configuration
    # Iterate through the configured global groups and create ConfigEntity-specific versions
    # The exception is GlobalConfig, whose ConfigEntity Group is the SuperAdmin Group
    # It returns nothing here since SuperAdmin is a global Group as well, it doesn't need to be
    # treated as a ConfigEntity Group
    client_fixture = ConfigEntityFixture.resolve_config_entity_fixture(config_entity)
    return map(
        lambda global_group_name: _update_or_create_config_entity_group(config_entity, global_group_name),
        client_fixture.default_config_entity_groups()) 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:20,代码来源:user_publishing.py

示例12: get_allowed_groups

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import Group [as 别名]
def get_allowed_groups(user, config_entity):
    """
    Returns a list of groups associates with the config entity
    that the user has permission to access according to ROLE_CHOICES_MAP.
    """

    user_role_key = get_role_key_for_user(user)

    allowed_groups = []

    if user_has_permission_for_config_entity(user, config_entity):
        if config_entity.key == Keys.GLOBAL_CONFIG_KEY:
            for allowed_role in ROLE_CHOICES_MAP[user_role_key]:
                allowed_groups.append(Group.objects.get(name=allowed_role))
        else:
            for gh in config_entity.group_hierarchies.all():
                if gh.group:
                    group_role_key = get_role_key_for_group(gh.group)
                    if group_role_key in ROLE_CHOICES_MAP[user_role_key]:
                        allowed_groups.append(gh.group)

    return allowed_groups 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:24,代码来源:views.py

示例13: get_config_entities_for_user

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import Group [as 别名]
def get_config_entities_for_user(user):
    """Returns the ConfigEntity objects corresponding to the group a user belongs to."""

    global_config_group_names = [UserGroupKey.SUPERADMIN, UserGroupKey.ADMIN, UserGroupKey.MANAGER, UserGroupKey.USER]

    user_config_entities = []

    for group in user.groups.all():
        if group.group_hierarchy:

            if group.group_hierarchy.config_entity:
                user_config_entities.append(group.group_hierarchy.config_entity)

            elif group.id in Group.objects.filter(name__in=global_config_group_names).values_list('id', flat=True):
                user_config_entities.append(GlobalConfig.objects.get())

    return user_config_entities 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:19,代码来源:views.py

示例14: test_nonadmin_at_root

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import Group [as 别名]
def test_nonadmin_at_root(self):
        # Assign siteeditor permission over no_site_page, so that the deepest-common-ancestor
        # logic allows them to explore root
        GroupPagePermission.objects.create(
            group=Group.objects.get(name="Site-wide editors"),
            page=self.no_site_page, permission_type='add'
        )
        self.assertTrue(self.client.login(username='siteeditor', password='password'))
        response = self.client.get(reverse('wagtailadmin_explore_root'))

        self.assertEqual(response.status_code, 200)
        # Non-admin should get a simple "create pages as children of the homepage" prompt
        self.assertContains(
            response,
            "Pages created here will not be accessible at any URL. "
            "To add pages to an existing site, create them as children of the homepage."
        ) 
开发者ID:wagtail,项目名称:wagtail,代码行数:19,代码来源:test_explorer_view.py

示例15: test_nonadmin_at_non_site_page

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import Group [as 别名]
def test_nonadmin_at_non_site_page(self):
        # Assign siteeditor permission over no_site_page
        GroupPagePermission.objects.create(
            group=Group.objects.get(name="Site-wide editors"),
            page=self.no_site_page, permission_type='add'
        )
        self.assertTrue(self.client.login(username='siteeditor', password='password'))
        response = self.client.get(reverse('wagtailadmin_explore', args=(self.no_site_page.id, )))

        self.assertEqual(response.status_code, 200)
        # Non-admin should get a warning about unroutable pages
        self.assertContains(
            response,
            (
                "There is no site record for this location. "
                "Pages created here will not be accessible at any URL."
            )
        ) 
开发者ID:wagtail,项目名称:wagtail,代码行数:20,代码来源:test_explorer_view.py


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