本文整理汇总了Python中django.contrib.auth.models.Permission.codename方法的典型用法代码示例。如果您正苦于以下问题:Python Permission.codename方法的具体用法?Python Permission.codename怎么用?Python Permission.codename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.models.Permission
的用法示例。
在下文中一共展示了Permission.codename方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_model
# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import codename [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()
示例2: save
# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import codename [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()
示例3: save_related
# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import codename [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()
示例4: save
# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import codename [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)
示例5: Permission
# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import codename [as 别名]
['guestUser1', 'password', False, False, 'Baylor', 'Tarrowes', '[email protected]', True, datetime.datetime.now(), 'User', 7, 'Guest Privileges', 'User', 96],
]:
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
示例6: Permission
# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import codename [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'
示例7: create_permission
# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import codename [as 别名]
def create_permission():
permission = Permission()
permission.name = 'Do stuff'
permission.codename = 'Can do stuff'
permission.content_type = {}
return permission
示例8: Permission
# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import codename [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
示例9: print
# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import codename [as 别名]
import subprocess
# #### 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"])
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"
示例10: Permission
# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import codename [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)
示例11: handle
# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import codename [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'
#.........这里部分代码省略.........
示例12: on_add_module
# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import codename [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))
示例13: Permission
# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import codename [as 别名]
import subprocess
import homepage.models as hmod
##### 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)
示例14: print
# 需要导入模块: from django.contrib.auth.models import Permission [as 别名]
# 或者: from django.contrib.auth.models.Permission import codename [as 别名]
print(hmod)
#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'