mirror of
https://github.com/django/django.git
synced 2024-11-30 07:06:18 +01:00
Added 'django-admin.py installperms' command
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1005 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
43ad69e24e
commit
c604de5a5d
@ -11,6 +11,7 @@ ACTION_MAPPING = {
|
||||
'init': management.init,
|
||||
'inspectdb': management.inspectdb,
|
||||
'install': management.install,
|
||||
'installperms': management.installperms,
|
||||
'runserver': management.runserver,
|
||||
'sql': management.get_sql_create,
|
||||
'sqlall': management.get_sql_all,
|
||||
@ -24,7 +25,7 @@ ACTION_MAPPING = {
|
||||
'validate': management.validate,
|
||||
}
|
||||
|
||||
NO_SQL_TRANSACTION = ('adminindex', 'createcachetable', 'dbcheck', 'install', 'sqlindexes')
|
||||
NO_SQL_TRANSACTION = ('adminindex', 'createcachetable', 'dbcheck', 'install', 'installperms', 'sqlindexes')
|
||||
|
||||
def get_usage():
|
||||
"""
|
||||
|
@ -345,6 +345,27 @@ The full error: %s\n""" % \
|
||||
install.help_doc = "Executes ``sqlall`` for the given model module name(s) in the current database."
|
||||
install.args = APP_ARGS
|
||||
|
||||
def installperms(mod):
|
||||
"Installs any permissions for the given model, if needed."
|
||||
from django.models.auth import permissions
|
||||
from django.models.core import packages
|
||||
num_added = 0
|
||||
package = packages.get_object(pk=mod._MODELS[0]._meta.app_label)
|
||||
for klass in mod._MODELS:
|
||||
opts = klass._meta
|
||||
for codename, name in _get_all_permissions(opts):
|
||||
try:
|
||||
permissions.get_object(name__exact=name, codename__exact=codename, package__label__exact=package.label)
|
||||
except permissions.PermissionDoesNotExist:
|
||||
p = permissions.Permission(name=name, package=package, codename=codename)
|
||||
p.save()
|
||||
print "Added permission '%r'." % p
|
||||
num_added += 1
|
||||
if not num_added:
|
||||
print "No permissions were added, because all necessary permissions were already installed."
|
||||
installperms.help_doc = "Installs any permissions for the given model module name(s), if needed."
|
||||
installperms.args = APP_ARGS
|
||||
|
||||
def _start_helper(app_or_project, name, directory, other_name=''):
|
||||
other = {'project': 'app', 'app': 'project'}[app_or_project]
|
||||
if not _is_valid_dir_name(name):
|
||||
|
Loading…
Reference in New Issue
Block a user