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


Python Permission.name方法代码示例

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


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

示例1: save_model

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
    def save_model (self, request, obj, form, change):
        """ Hey Hey Hey...let me see your id...or your boobs-your choice...i prefer the BOOBS unless you're OVER 18...EEEWWWWWWW """

        if not request.user.is_superuser:
            if not request.user.has_perm ("condor."+ Student.objects.get (pk = request.POST["student"]).class_room.grade.grade +"_"+ Student.objects.get (pk = request.POST["student"]).class_room.section +"_"+ Subject.objects.get (pk = request.POST ["subject"]).name):
                messages.add_message (request, messages.ERROR, "Denied, the request you've made has content you are not authorized to add/edit. Your request has not been saved")
                return None

            elif request.user.has_perm ("condor."+ Student.objects.get (pk = request.POST["student"]).class_room.grade.grade +"_"+ Student.objects.get (pk = request.POST["student"]).class_room.section +"_"+ Subject.objects.get (pk = request.POST ["subject"]).name):
                if not Permission.objects.filter (codename = "generate_report_card").exists():
                    NEW_P = Permission ()
                    NEW_P.codename = "generate_report_card"
                    NEW_P.name = "Can Generate Report Card"
                    NEW_P.content_type = ContentType.objects.get (app_label="condor", model="gradereport")
                    NEW_P.save()

                obj.save()

        elif request.user.is_superuser:
            if not Permission.objects.filter (codename = "generate_report_card").exists():
                NEW_P = Permission ()
                NEW_P.codename = "generate_report_card"
                NEW_P.name = "Can Generate Report Card"
                NEW_P.content_type = ContentType.objects.get (app_label="condor", model="gradereport")
                NEW_P.save()

            """ we are going have to check whether or not the super user has made the right choices...i feel OLD...which takes like two lines """
            if obj.subject not in obj.student.class_room.grade.subject.all():
                messages.add_message (request, messages.ERROR, "Error: the subject you have selected is not given in the specified grade level, No changes have been made.")
                return None

            obj.save()
开发者ID:jixtes,项目名称:TheCondor,代码行数:34,代码来源:admin.py

示例2: save

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
    def save (self, *args, **kwargs):
        if self.id == None: # object is bein created for the first time
            super (ClassRoom, self).save(*args, **kwargs) # saving object

            LEVEL = self.grade.grade
            SECTION = self.section
            for S in self.grade.subject.all():
                if not Permission.objects.filter (codename = (u""+ LEVEL +"_"+ SECTION +"_"+ S.__unicode__())).exists(): # creating...
                    # Permission Structure
                    # codename: {Level.grade}_{ClassRoom.section}_{Subject.name}
                    # name:     {Level.grade}-{ClassRoom.section}: {Subject.name}
                    NEW_P = Permission ()
                    NEW_P.name = u""+ LEVEL +"-"+ SECTION +": "+ S.__unicode__()
                    NEW_P.content_type = ContentType.objects.get (app_label="condor", model="classroom")
                    NEW_P.codename = u""+ LEVEL +"_"+ SECTION +"_"+ S.__unicode__()
                    NEW_P.save()

            NEW_P = Permission ()
            NEW_P.name = u"Head Teacher of "+ self.grade.grade +"-"+ self.section
            NEW_P.content_type = ContentType.objects.get (app_label="condor", model="classroom")
            NEW_P.codename = u"H_"+ self.grade.grade +"_"+ self.section
            NEW_P.save()

        else: # object is being edited...
            PREVIOUS_CLASSROOM = ClassRoom.objects.get (pk = self.id) # we know this exists!
            PREVIOUS_GRADE = PREVIOUS_CLASSROOM.grade

            super (ClassRoom, self).save(*args, **kwargs)

            if self.__unicode__() != PREVIOUS_CLASSROOM.__unicode__(): # There has been change in the object, Permissions update is necessary
                """
                NOTE:
                    - On permission, when a class is changed say from 1A to 1B or 2A: we will assume (for permission sake) 1B is a different class!
                    - i.e. all permissions associated with 1A will be removed, and new Permissions for 1B will be created
                """

                Permission.objects.filter (codename__istartswith = PREVIOUS_GRADE.grade +"_"+ PREVIOUS_CLASSROOM.section +"_").delete() # Deleting all associated permissions with the previous class room object
                Permission.objects.filter (codename = u"H_" + PREVIOUS_GRADE.grade +"_"+ PREVIOUS_CLASSROOM.section).delete()

                for S in self.grade.subject.all(): # Creating permissions for the NEW class room
                    NEW_P = Permission()
                    NEW_P.codename = self.grade.grade +"_"+ self.section +"_"+ S.name
                    NEW_P.name = self.grade.grade +"-"+ self.section +": "+ S.name
                    NEW_P.content_type = ContentType.objects.get (app_label="condor", model="classroom")
                    NEW_P.save()

                NEW_P = Permission ()
                NEW_P.name = u"Head Teacher of "+ self.grade.grade +"-"+ self.section
                NEW_P.content_type = ContentType.objects.get (app_label="condor", model="classroom")
                NEW_P.codename = u"H_"+ self.grade.grade +"_"+ self.section
                NEW_P.save()

        if not Permission.objects.filter (codename = "generate_report_card").exists():
            NEW_P = Permission ()
            NEW_P.codename = "generate_report_card"
            NEW_P.name = "Can Generate Report Card"
            NEW_P.content_type = ContentType.objects.get (app_label="condor", model="classroom")
            NEW_P.save()
开发者ID:jixtes,项目名称:TheCondor,代码行数:60,代码来源:models.py

示例3: save_related

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
    def save_related (self, request, form, formsets, change):
        if change:
            # If any grade change occurred; the save override will take care of the removal of previous permissions associated with the previous grade
            # All we have to care aboot here is saving the related objects i.e. subject with the appropriate permissions

            # codename: {Level.grade}_{ClassRoom.section}_{Subject.name}
            # name:     {Level.grade}-{ClassRoom.section}: {Subject.name}

            LEVEL = Level.objects.get (pk = request.META['HTTP_REFERER'][request.META['HTTP_REFERER'].rfind('/', 0, -1) + 1: -1]) # level object: related fields UNSAVED untill form save
            if LEVEL.classroom_set.count(): # we will have to create/edit permission if a level is associated with a class room
                NEW_SUBJECT_LIST = []
                for SID in request.POST.getlist ("subject"): # Looping through the subject id's
                    NEW_SUBJECT_LIST.append (Subject.objects.get(pk = SID).name)

                for CR in LEVEL.classroom_set.all(): # After finishing this loop we would have deleted any permission that shouldn't exist anymore due to the change in the level object 
                    for S in LEVEL.subject.all():
                        if S.name not in NEW_SUBJECT_LIST:
                            Permission.objects.filter (codename = LEVEL.grade +"_"+ CR.section +"_"+ S.name).delete()

                for CR in LEVEL.classroom_set.all(): # After finishing this loop we would have created any new permission that should be created due to the change in the level object 
                    for S in NEW_SUBJECT_LIST:
                        if not Permission.objects.filter (codename = LEVEL.grade +"_"+ CR.section +"_"+ S).exists():
                            # Permission Structure
                            # codename: {Level.grade}_{ClassRoom.section}_{Subject.name}
                            # name:     {Level.grade}-{ClassRoom.section}: {Subject.name}
                            NEW_P = Permission ()
                            NEW_P.codename = LEVEL.grade +"_"+ CR.section +"_"+ S
                            NEW_P.name = LEVEL.grade +"-"+ CR.section +": "+ S
                            NEW_P.content_type = ContentType.objects.get (app_label="condor", model="classroom")
                            NEW_P.save()

        form.save()
开发者ID:jixtes,项目名称:TheCondor,代码行数:34,代码来源:admin.py

示例4: save

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
 def save(self, *args, **kwargs):
     if not self.id and hasattr(self, "instance_permissions"):
         for perm in self.instance_permissions:
             p = Permission()
             p.codename = "%s%s" % (perm[0], self.slug)
             p.name = "%s%s" % (perm[1], self.name)
             p.content_type = ContentType.objects.get_for_model(self)
             p.save()
     return super(PermissionMixIn, self).save(*args, **kwargs)
开发者ID:nonni,项目名称:fruss,代码行数:11,代码来源:models.py

示例5: setUp

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
    def setUp(self):
        self.factory = RequestFactory()
        self.test_user = UserModel.objects.create_user("test_user", "[email protected]", "123456")
        self.test_noscope_user = UserModel.objects.create_user("test_no_scope_user", "[email protected]", "123456")
        from django.contrib.auth.models import Permission
        p = Permission()
        p.name = "test_user_scope"
        p.content_type_id = 7
        p.save()

        self.test_user.user_permissions.add(p)

        self.application = Application(
            name="Test Application",
            user=self.test_user,
            client_type=Application.CLIENT_CONFIDENTIAL,
            client_id="test_client_id",
            authorization_grant_type=Application.GRANT_PASSWORD,
            client_secret="test_client_secret",
            scopes="test_app_scope1 test_app_scope2"
        )
        self.application.save()

        oauth2_settings._SCOPES = ['read', 'write']
开发者ID:plivo,项目名称:django-oauth-toolkit,代码行数:26,代码来源:test_scopes.py

示例6: Permission

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'test_dmp.settings'
import django; django.setup()
from django.contrib.auth import models as conmod
import homepage.models as hmod
from django.contrib.auth.models import Group, Permission, ContentType

# Create Super Group, Permissions, and User
permission = Permission()
permission.codename = 'super'
permission.content_type = ContentType.objects.get(id=7)
permission.name = 'Super Privileges'
permission.save()

group = Group()
group.name = "super"
group.save()
group.permissions.add(permission)
permission = Permission.objects.get(id=28)
group.permissions.add(permission)

user = hmod.User()
user.is_staff = 'True'
user.is_active = 'True'
user.is_superuser = 'True'
user.username = 'super'
user.set_password('asdf')
user.first_name = 'Super'
user.last_name = 'User'
user.email = '[email protected]'
user.address1 = '4387 South 1400 East'
开发者ID:benwillard17,项目名称:groupproject3,代码行数:33,代码来源:doit.py

示例7: Permission

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
    user = hmod.User()
    user.username = data[0]
    user.set_password(data[1])
    user.is_superuser = data[2]
    user.is_staff = data[3]
    user.first_name = data[4]
    user.last_name = data[5]
    user.email = data[6]
    user.is_active = data[7]
    user.date_joined = data[8]
    user.save()

    permission = Permission()
    permission.codename = data[9]
    permission.content_type = ContentType.objects.get(id=data[10])
    permission.name = data[11]
    permission.save()

    group = Group()
    group.name = data[12]
    group.save()
    group.permissions.add(permission)
    permission = Permission.objects.get(id=data[13])
    group.permissions.add(permission)

    group.user_set.add(user)  # assign the user to the group



# create permissions and groups
'''
开发者ID:jeremyrhoads,项目名称:colheritage,代码行数:33,代码来源:init_db.py

示例8: Permission

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'colheritage.settings'
import django; django.setup()
import homepage.models as hmod
import datetime

from django.contrib.auth.models import Group, Permission, ContentType

permission = Permission()
permission.codename = 'Admin'
permission.content_type = ContentType.objects.get(id=7)
permission.name = 'Super Privileges'
permission.save()

group = Group()
group.name = "Admin"
group.save()
group.permissions.add(permission)
permission = Permission.objects.get(id=94)
group.permissions.add(permission)

user = hmod.User()
user.username = 'AdminUser'
user.set_password('asdf')
user.is_superuser = True
user.is_staff = True
user.first_name = ''
user.last_name = ''
user.email = ''
user.is_active = True
开发者ID:jeremyrhoads,项目名称:colheritage,代码行数:32,代码来源:create_template.py

示例9: create_permission

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
def create_permission():
    permission = Permission()
    permission.name = 'Do stuff'
    permission.codename = 'Can do stuff'
    permission.content_type = {}
    return permission
开发者ID:crs4,项目名称:ACTIVE,代码行数:8,代码来源:tests.py

示例10: print

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
cursor = connection.cursor()
cursor.execute("DROP SCHEMA PUBLIC CASCADE")
cursor.execute("CREATE SCHEMA PUBLIC")
subprocess.call([sys.executable, "manage.py", "migrate"])

print('Database Migrated')

# #### CREATE PERMISSIONS/GROUPS #####################
Permission.objects.all().delete()
Group.objects.all().delete()

permissionU = Permission()
permissionU.codename = 'User'
permissionU.content_type = ContentType.objects.get(id=9)
permissionU.name = 'user'
permissionU.save()
User = Group()
User.name = "User"
User.save()
User.permissions.add(permissionU)

permissionM = Permission()
permissionM.codename = 'Manager'
permissionM.content_type = ContentType.objects.get(id=8)
permissionM.name = 'manager'
permissionM.save()
Manager = Group()
Manager.name = "Manager"
Manager.save()
Manager.permissions.add(permissionM, permissionU)
开发者ID:dbwyatt,项目名称:ColonialHeritageFoundation,代码行数:32,代码来源:DB_Init.py

示例11: on_add_module

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
def on_add_module(request,module_type,parent_id):
	context = {}
	try:
		parent = Module.objects.get(id=parent_id)
		context.update({'parent_name':parent.name})
		context.update({'app_name':parent.app.name})
		# title
		title = ""
		if module_type=="G":
			title = _(u"THÊM NHÓM MODULE")
		elif module_type=="M":
			title = _(u"THÊM MODULE")
		elif module_type=="P":
			title = _(u"THÊM QUYỀN")
		context.update({'title':title})
		if request.POST:
			#auto commit
			transaction.set_autocommit(False)
			#parameter
			code = request.POST["txtCode"]
			name = request.POST["txtName"]
			action = request.POST["txtAction"]
			url = request.POST["txtUrl"]
			icon = request.POST["txtIcon"]
			ord_num = request.POST["txtOrd"]
			#new Module
			module = Module()
			module.code = code
			module.name = name
			module.action = action
			module.url = url
			module.type = module_type
			module.icon_class = icon
			module.ord = ord_num
			if request.POST.get('ckStatus'):
				module.status = "1"
			else:
				module.status = "0"
			module.parent = parent
			module.app = parent.app
			module.user_name = request.user.username
			if module_type=="M":
				#Insert content type
				content_type = ContentType()
				content_type.app_label = parent.app.code
				content_type.model = code
				content_type.name = name
				content_type.save()
				module.content_type = content_type
			elif module_type=="P":
				#Insert permission
				permission = Permission()
				permission.content_type = parent.content_type
				permission.name = name
				permission.codename = code
				permission.save()
				module.permission = permission
			#save module
			module.save()
			#commit
			transaction.commit()
			return HttpResponseRedirect(str("%s?app_id="+str(parent.app.id)) % resolve_url("module"))
	except Exception as ex:
		transaction.rollback()
		context.update({'has_error':str(ex)})
	finally:
		context.update(csrf(request))
	return render_to_response("admin/module/add-module.html", context, RequestContext(request))
开发者ID:ngotuan12,项目名称:AssetManagement,代码行数:70,代码来源:UserPermission.py

示例12: Permission

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
#empty or drop the tables
cursor = connection.cursor()
cursor.execute("DROP SCHEMA PUBLIC CASCADE")
cursor.execute("CREATE SCHEMA PUBLIC")
subprocess.call([sys.executable, "manage.py", "migrate"])

#### Create permissions/groups ######
Permission.objects.all().delete()
Group.objects.all().delete()


##Admin
permission = Permission()
permission.codename = 'admin_rights'
permission.content_type = ContentType.objects.get(id=7)
permission.name = 'AdminRights'
permission.save()

agroup = Group()
agroup.name = "Admin"
agroup.save()
agroup.permissions.add(permission)
subprocess.call([sys.executable, "manage.py", "migrate"])

###Manager
permission = Permission()
permission.codename = 'manager_rights'
permission.content_type = ContentType.objects.get(id=5)
permission.name = 'ManagerRights'
permission.save()
开发者ID:cjpwrs,项目名称:Colheritage,代码行数:32,代码来源:init.db.py

示例13: handle

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
	def handle(self, *args, **options):
		usuario = ContentType.objects.filter(name='usuario')[0]
		sucursal = ContentType.objects.filter(name='sucursal')[0]
		menu = ContentType.objects.filter(name='menu')[0]
		producto = ContentType.objects.filter(name='producto')[0]
		producto_de_sucursal = ContentType.objects.filter(name='producto_de_sucursal')[0]
		ticket = ContentType.objects.filter(name='ticket')[0]
		productos_del_ticket = ContentType.objects.filter(name='productos_del_ticket')[0]
		corte = ContentType.objects.filter(name='corte')[0]
		corte_productos = ContentType.objects.filter(name='corte_productos')[0]
		codigo = ContentType.objects.filter(name='codigo')[0]

		Permission.objects.filter(content_type__app_label = 'app').delete()

		permiso = Permission()
		permiso.name = 'Agregar codigos'
		permiso.content_type = codigo
		permiso.codename = 'add_codigo'
		permiso.save()

		permiso = Permission()
		permiso.name = 'Cambiar codigos'
		permiso.content_type = codigo
		permiso.codename = 'change_codigo'
		permiso.save()

		permiso = Permission()
		permiso.name = 'Borrar codigos'
		permiso.content_type = codigo
		permiso.codename = 'delete_codigo'
		permiso.save()

		permiso = Permission()
		permiso.name = 'Borrar cortes'
		permiso.content_type = corte
		permiso.codename = 'delete_corte'
		permiso.save()

		permiso = Permission()
		permiso.name = 'Ver cortes'
		permiso.content_type = corte
		permiso.codename = 'change_corte'
		permiso.save()

		permiso = Permission()
		permiso.name = 'Agregar menus'
		permiso.content_type = menu
		permiso.codename = 'add_menu'
		permiso.save()

		permiso = Permission()
		permiso.name = 'Cambiar menus'
		permiso.content_type = menu
		permiso.codename = 'change_menu'
		permiso.save()

		permiso = Permission()
		permiso.name = 'Eliminar menus'
		permiso.content_type = menu
		permiso.codename = 'delete_menu'
		permiso.save()

		permiso = Permission()
		permiso.name = 'Agregar productos'
		permiso.content_type = producto
		permiso.codename = 'add_producto'
		permiso.save()

		permiso = Permission()
		permiso.name = 'Cambiar productos'
		permiso.content_type = producto
		permiso.codename = 'change_producto'
		permiso.save()

		permiso = Permission()
		permiso.name = 'Eliminar productos'
		permiso.content_type = producto
		permiso.codename = 'delete_producto'
		permiso.save()

		permiso = Permission()
		permiso.name = 'Modificar datos productos'
		permiso.content_type = producto_de_sucursal
		permiso.codename = 'change_producto_de_sucursal'
		permiso.save()

		permiso = Permission()
		permiso.name = 'Eliminar productos de sucursales'
		permiso.content_type = producto_de_sucursal
		permiso.codename = 'delete_producto_de_sucursal'
		permiso.save()

		permiso = Permission()
		permiso.name = 'Agregar sucursales'
		permiso.content_type = sucursal
		permiso.codename = 'add_sucursal'
		permiso.save()

		permiso = Permission()
		permiso.name = 'Cambiar sucursales'
#.........这里部分代码省略.........
开发者ID:flipjack,项目名称:donvenancio,代码行数:103,代码来源:actualizar_permisos.py

示例14: Permission

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
##### DROP DATABASE, RECREATE IT, THEN MIGRATE IT #################

cursor = connection.cursor()
cursor.execute("DROP SCHEMA PUBLIC CASCADE")
cursor.execute("CREATE SCHEMA PUBLIC")
subprocess.call([sys.executable, "manage.py", "migrate"])

##### CREATE PERMISSIONS/GROUPS #####################

Permission.objects.all().delete()
Group.objects.all().delete()

AdminPermission = Permission()
AdminPermission.codename = 'admin_rights'
AdminPermission.content_type = ContentType.objects.get(id=7)
AdminPermission.name = 'Has Admin Rights'
AdminPermission.save()

ManagerPermission = Permission()
ManagerPermission.codename = 'manager_rights'
ManagerPermission.content_type = ContentType.objects.get(id=7)
ManagerPermission.name = 'Has Manager Rights'
ManagerPermission.save()

AdminGroup = Group()
AdminGroup.name = "AdminGroup"
AdminGroup.save()
AdminGroup.permissions.add(AdminPermission)
AdminGroup.permissions.add(ManagerPermission)

ManagerGroup = Group()
开发者ID:brocktj,项目名称:CHF_case,代码行数:33,代码来源:init_db.py

示例15: Permission

# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import name [as 别名]
from django.contrib.auth.models import Group, Permission, ContentType
from django.contrib.auth.decorators import permission_required





permission = Permission()
permission.codename = 'jedi_level'
permission.content_type = ContentType.objects.get(id=7)
permission.name = 'Has Jedi Privileges'
permission.save()

group = Group()
group.name = "Jedis"
group.save()
group.permissions.add(permission)
group.user_set.add(UserObjectHere)
开发者ID:ProjectUno,项目名称:colonialhf,代码行数:20,代码来源:permissions.py


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