本文整理匯總了Python中swapper.get_model_name方法的典型用法代碼示例。如果您正苦於以下問題:Python swapper.get_model_name方法的具體用法?Python swapper.get_model_name怎麽用?Python swapper.get_model_name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類swapper
的用法示例。
在下文中一共展示了swapper.get_model_name方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: set_default_organization_uuid
# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import get_model_name [as 別名]
def set_default_organization_uuid(apps, schema_editor):
"""
Get or create a default organization then
set settings._OPENWISP_DEFAULT_ORG_UUID
"""
org_model = swapper.get_model_name('openwisp_users', 'organization')
model_app_label = swapper.split(org_model)[0]
organization = apps.get_model(model_app_label, 'organization')
default_organization = organization.objects.first()
if default_organization is None:
default_organization = organization(
name='default',
slug='default',
description='This is the default organization. '
'It was created automatically during installation. '
'You can simply rename it to your organization name.',
)
default_organization.full_clean()
default_organization.save()
# settings._OPENWISP_DEFAULT_ORG_UUID is used in
# openwisp-radius.migrations, it helps to enable
# users to migrate from freeradius 3
settings._OPENWISP_DEFAULT_ORG_UUID = default_organization.pk
示例2: update_admins_permissions
# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import get_model_name [as 別名]
def update_admins_permissions(apps, schema_editor):
org_model = swapper.get_model_name('openwisp_users', 'organization')
model_app_label = swapper.split(org_model)[0]
group = apps.get_model(model_app_label, 'group')
email_model = swapper.get_model_name('account', 'EmailAddress')
email_app_label = swapper.split(email_model)[0]
try:
admin = group.objects.get(name='Administrator')
permissions = [
Permission.objects.get(
content_type__app_label=email_app_label, codename='view_emailaddress'
).pk,
Permission.objects.get(
content_type__app_label=email_app_label, codename='delete_emailaddress'
).pk,
Permission.objects.get(
content_type__app_label=email_app_label, codename='change_emailaddress'
).pk,
Permission.objects.get(
content_type__app_label=model_app_label, codename='delete_user'
).pk,
]
admin.permissions.add(*permissions)
except ObjectDoesNotExist:
pass
示例3: add_default_menu_items
# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import get_model_name [as 別名]
def add_default_menu_items(self):
menu_setting = 'OPENWISP_DEFAULT_ADMIN_MENU_ITEMS'
items = [
{'model': settings.AUTH_USER_MODEL},
{'model': get_model_name('openwisp_users', 'Organization')},
]
if not hasattr(settings, menu_setting):
setattr(settings, menu_setting, items)
else:
current_menu = getattr(settings, menu_setting)
current_menu += items
示例4: get_swapped_model
# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import get_model_name [as 別名]
def get_swapped_model(apps, app_name, model_name):
model_path = swapper.get_model_name(app_name, model_name)
return get_model(apps, model_path)
示例5: add_default_menu_items
# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import get_model_name [as 別名]
def add_default_menu_items(self):
menu_setting = 'OPENWISP_DEFAULT_ADMIN_MENU_ITEMS'
items = [
{'model': get_model_name('config', 'Device')},
{'model': get_model_name('config', 'Template')},
{'model': get_model_name('config', 'Vpn')},
]
if not hasattr(settings, menu_setting):
setattr(settings, menu_setting, items)
else:
current_menu = getattr(settings, menu_setting)
current_menu += items
示例6: test_swap_setting
# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import get_model_name [as 別名]
def test_swap_setting(self):
self.assertTrue(swapper.is_swapped("default_app", "Type"))
self.assertEqual(
swapper.get_model_name("default_app", "Type"),
"alt_app.Type"
)
示例7: test_default_setting
# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import get_model_name [as 別名]
def test_default_setting(self):
self.assertFalse(swapper.is_swapped("default_app", "Type"))
self.assertEqual(
swapper.get_model_name("default_app", "Type"),
"default_app.Type"
)
示例8: add_default_menu_items
# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import get_model_name [as 別名]
def add_default_menu_items(self):
menu_setting = 'OPENWISP_DEFAULT_ADMIN_MENU_ITEMS'
items = [{'model': swapper.get_model_name('topology', 'Topology')}]
if not hasattr(settings, menu_setting):
setattr(settings, menu_setting, items)
else:
current_menu = getattr(settings, menu_setting)
current_menu += items
示例9: get_swapped_model
# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import get_model_name [as 別名]
def get_swapped_model(apps, app_name, model_name):
model_path = swapper.get_model_name(app_name, model_name)
app, model = swapper.split(model_path)
return apps.get_model(app, model)
示例10: create_default_groups
# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import get_model_name [as 別名]
def create_default_groups(apps, schema_editor):
org_model = swapper.get_model_name('openwisp_users', 'organization')
model_app_label = swapper.split(org_model)[0]
group = apps.get_model(model_app_label, 'group')
# To populate all the permissions
for app_config in apps.get_app_configs():
app_config.models_module = True
create_permissions(app_config, apps=apps, verbosity=0)
app_config.models_module = None
operator = group.objects.filter(name='Operator')
if operator.count() == 0:
operator = group.objects.create(name='Operator')
admin = group.objects.filter(name='Administrator')
if admin.count() == 0:
admin = group.objects.create(name='Administrator')
permissions = [
Permission.objects.get(
content_type__app_label=model_app_label, codename='add_user'
).pk,
Permission.objects.get(
content_type__app_label=model_app_label, codename='change_user'
).pk,
Permission.objects.get(
content_type__app_label=model_app_label,
codename='change_organizationuser',
).pk,
Permission.objects.get(
content_type__app_label=model_app_label,
codename='delete_organizationuser',
).pk,
Permission.objects.get(
content_type__app_label=model_app_label,
codename='add_organizationuser',
).pk,
]
try:
permissions += [
Permission.objects.get(
content_type__app_label=model_app_label, codename='view_user'
).pk,
Permission.objects.get(
content_type__app_label=model_app_label, codename='view_group'
).pk,
Permission.objects.get(
content_type__app_label=model_app_label,
codename='view_organizationuser',
).pk,
]
except Permission.DoesNotExist:
pass
admin.permissions.set(permissions)