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


Python models.Permission类代码示例

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


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

示例1: pre_register

 def pre_register(self, model, **kwargs):
     content_type = ContentType.objects.get_for_model(model)
     codename = 'can_receive_notification_%s' % content_type.model
     if not Permission.objects.filter(content_type=content_type, codename=codename):
     
         permission = Permission(name = 'Can receive notification', content_type = content_type, codename = codename)
         permission.save()
开发者ID:pombredanne,项目名称:django-simple-utilities,代码行数:7,代码来源:signals.py

示例2: test_user_permission_not_allowed

 def test_user_permission_not_allowed(self):
     permission = Permission(content_type_id=1, name='Can something',
         codename='can_something')
     permission.save()
     response, json = self.do_get(self.perm % (self.user.pk, 'auth.can_something'))
     self.assertEquals(response.status_code, 200)
     self.assertEquals(json['is-allowed'], False, json)
开发者ID:pombredanne,项目名称:django-slumber,代码行数:7,代码来源:views.py

示例3: test_usuarios_render_form_change_pas

    def test_usuarios_render_form_change_pas(self):
        """
        Testa renderização do formulário de troca de senha
        """
        contentItem = ContentType.objects.get(app_label='acesso',model='usuario')
        permission = Permission(name='Can Change Pass',content_type=contentItem,codename='change_pass_usuario')
        permission.save()

        permissions = Permission.objects.all().filter(content_type=contentItem.id)
        
        for permission in permissions:
            self.user.user_permissions.add(permission)

        # Faz chamada da pagina
        response = self.client.get('/acesso/usuarios/password/')
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, 'name="new_password1"', status_code=200)

        """
        Testa renderização do formulário de troca de senha
        """
        dataPost = {
            'new_password1'  : 'testpass2',
            'new_password2'  : 'testpass2',
        }

        response = self.client.post('/acesso/usuarios/password/', dataPost)
        self.assertEquals(response.status_code, 200)
开发者ID:jairvercosa,项目名称:tsm,代码行数:28,代码来源:test_usuarios.py

示例4: test_current_user_permission_not_allowed

 def test_current_user_permission_not_allowed(self):
     permission = Permission(content_type=self.content_type,
         name='Can something', codename='can_something')
     permission.save()
     response, json = self.do_get(self.user_perm % 'auth.can_something',
             username=self.user.username)
     self.assertEquals(response.status_code, 200)
     self.assertEquals(json['permissions']['auth.can_something'], False, json)
开发者ID:nuimk-proteus,项目名称:django-slumber,代码行数:8,代码来源:views.py

示例5: _get_permission

 def _get_permission(self, obj, code, create = False):
     ct = ContentType.objects.get_for_model(obj)
     pe = Permission.objects.filter(codename = code, content_type = ct)
     if pe:
         pe = pe[0]
     elif create:
         pe = Permission(codename = code, content_type = ct, name = 'Can view %s' % force_str(obj._meta.verbose_name))
         pe.save()
     return pe
开发者ID:strogo,项目名称:djpcms,代码行数:9,代码来源:djmanagers.py

示例6: createProjectPermission

def createProjectPermission(pDesc, pCodeName, groups):
        projectContenType = ContentType.objects.get(app_label=APPLICATION_LABEL, model='project')
        permission = Permission(name=pDesc, codename=pCodeName, content_type=projectContenType)
        permission.save()
        print 'Created permission=%s...' % permission.codename
        for group in groups:
            group.permissions.add(permission)
            group.save()
            print '...and associated to group=%s' % group.name
        return permission
开发者ID:EarthSystemCoG,项目名称:COG,代码行数:10,代码来源:auth.py

示例7: edit_all_permission

 def edit_all_permission(self, log=None):
     ct = ContentType.objects.get_for_model(self)
     try:
         p = Permission.objects.get(content_type=ct, codename=self.edit_all_permission_name())
     except Permission.DoesNotExist:
         p = Permission(content_type=ct, codename=self.edit_all_permission_name(),
                         name="Edit all data for widget %s" % self.name)
         p.save()
         if log is not None:
             print >> log, "Created edit all permission for widget %s" % self.name
     return p
开发者ID:LegoStormtroopr,项目名称:openboard,代码行数:11,代码来源:widget_family.py

示例8: get_permission

 def get_permission(self, permission_prefix, create_permission=False):
     permission_codename = u"%s_%s" % (permission_prefix, self.name)
     permission_description = u"%s %s instances" % (permission_prefix, self.name)
     try:
         permission = Permission.objects.get(codename=permission_codename)
     except Permission.DoesNotExist:
         content_type = ContentType.objects.get(app_label=APP_LABEL, model='qproject')
         permission = Permission(codename=permission_codename, name=permission_description, content_type=content_type)
         if create_permission:
             permission.save()
     return permission
开发者ID:allynt,项目名称:new-questionnaire,代码行数:11,代码来源:models_projects.py

示例9: test_user_is_checked_for_global_db_permission

 def test_user_is_checked_for_global_db_permission(self):
     user = User(is_active=True)
     user.save()
     content_type = ContentType(app_label='test_app')
     content_type.save()
     permission = Permission(content_type=content_type,
                             codename='test_permission')
     permission.save()
     user.user_permissions.add(permission)
     backend = PermissionBackend()
     self.assertTrue(backend.has_perm(user, 'test_app.test_permission'))
开发者ID:TwigWorld,项目名称:django-rottweiler,代码行数:11,代码来源:test_backends.py

示例10: permission

 def permission(self, log=None):
     ct = ContentType.objects.get_for_model(self)
     try:
         p = Permission.objects.get(content_type=ct, 
                         codename=self.permission_name())
     except Permission.DoesNotExist:
         p = Permission(content_type=ct, codename=self.permission_name(),
                 name="upload data files for %s" % self.app)
         p.save()
         if log:
                 print >> log, "Created uploader permission for %s" % self.app
     return p
开发者ID:LegoStormtroopr,项目名称:openboard,代码行数:12,代码来源:models.py

示例11: view_permisions

def view_permisions(apps=None):
    if not apps: apps = ['whs', 'lab', 'energy', 'it']
    for app in apps:
        for c in ContentType.objects.filter(app_label=app):
            if issubclass(c.model_class(),UrlMixin):
                p = Permission(codename='view_%s' % c.model, name=u'Можно просматривать %s' % c.name, content_type=c)
                try:
                    p.validate_unique()
                except ValidationError:
                    pass
                else:
                    p.save()
开发者ID:wd5,项目名称:1-bkz,代码行数:12,代码来源:utils.py

示例12: employe

def employe(request):
    logger.info('function_call employe(request) ->')
    
    if request.method == 'POST':
        employe = User.objects.get(id = int(request.POST.get('id_record')))
        profile = UserProfile.objects.get(user = employe)

        form = EmployeForm(initial={'username': employe.username, 'email': employe.email, 'firstname': employe.first_name, 'lastname': employe.last_name,
                                    'vacation_days': profile.vacation_days, 'min_hours': profile.min_hours, 'max_hours': profile.max_hours,
                                    'hourly_rate': profile.hourly_rate, 'management': employe.has_perm('auth.management'), 'api': employe.is_staff})

        if request.POST.get('action'):
            if request.POST.get('action') == "modifie":
                form = EmployeForm(request.POST)
                
                if form.is_valid():
                    employe.username = form.cleaned_data['username']
                    employe.email = form.cleaned_data['email']
                    employe.first_name = form.cleaned_data['firstname']
                    employe.last_name = form.cleaned_data['lastname']
                    employe.save()

                    profile.vacation_days = form.cleaned_data['vacation_days']
                    profile.min_hours = form.cleaned_data['min_hours']
                    profile.max_hours = form.cleaned_data['max_hours']
                    profile.hourly_rate = form.cleaned_data['hourly_rate']
                    profile.save()

                    try:
                        permission = Permission.objects.get(codename='management')
                    except Exception:
                        permissionNew = Permission(name = "management", content_type = ContentType.objects.get(model='permission'), codename = "management")
                        permissionNew.save()

                    permission = Permission.objects.get(codename='management')
                    if form.cleaned_data['management'] == True:
                        employe.user_permissions.add(permission)
                    else:
                        employe.user_permissions.remove(permission)

                    if form.cleaned_data['api'] == True:
                        employe.is_staff = 1
                        employe.save()
                    else:
                        employe.is_staff = 0
                        employe.save()

                    return HttpResponseRedirect(reverse('staff'))

    
    c = {'user':request.user, 'employe':employe, 'form':form, 'SITENAME':settings.SITENAME, 'management':request.user.has_perm('auth.management')}
    c.update(csrf(request))
    return render_to_response('employe.html', c, context_instance=RequestContext(request))
开发者ID:akashagarwal,项目名称:qPaaS,代码行数:53,代码来源:views.py

示例13: test_render_configuracoes

    def test_render_configuracoes(self):
        # Faz chamada da pagina
        contentItem = ContentType.objects.get(app_label='core',model='parametro')
        permission = Permission(name='Can Access Configurations',content_type=contentItem,codename='core_configurations')
        permission.save()

        permissions = Permission.objects.all().filter(content_type=contentItem.id)
        
        for permission in permissions:
            self.user.user_permissions.add(permission)        

        response = self.client.get('/core/configuracoes/')
        self.assertEquals(response.status_code, 200)
开发者ID:jairvercosa,项目名称:onyxlog,代码行数:13,代码来源:test_core.py

示例14: add_permissions

    def add_permissions(self):
        #busca tabela de models
        contentItem = ContentType.objects.get(app_label='oportunidade',model='oportunidade')
        #busca permissoes do model
        if not contentItem:
            self.assertTrue(False)

        customPermission = Permission(name='Dashboard',content_type=contentItem,codename='index_dashboard')
        customPermission.save()

        permissions = Permission.objects.filter(content_type=contentItem.id)
    
        for permission in permissions:
            self.user.user_permissions.add(permission)
开发者ID:jairvercosa,项目名称:tsm,代码行数:14,代码来源:test_dashboard.py

示例15: edit_all_permission

 def edit_all_permission(self, log=None):
     """
         Returns the actual :model:`auth.Permission` permission object required to manually edit 
         all data for this widget family, creating it if it does not already exist.
     """
     ct = ContentType.objects.get_for_model(self)
     try:
         p = Permission.objects.get(content_type=ct, codename=self.edit_all_permission_name())
     except Permission.DoesNotExist:
         p = Permission(content_type=ct, codename=self.edit_all_permission_name(),
                         name="Edit all data for widget %s" % self.name)
         p.save()
         if log is not None:
             print >> log, "Created edit all permission for widget %s" % self.name
     return p
开发者ID:NICTA,项目名称:openboard,代码行数:15,代码来源:widget_family.py


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