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:
Adrian Holovaty 2005-10-23 22:43:24 +00:00
parent 43ad69e24e
commit c604de5a5d
2 changed files with 23 additions and 1 deletions

View File

@ -11,6 +11,7 @@ ACTION_MAPPING = {
'init': management.init, 'init': management.init,
'inspectdb': management.inspectdb, 'inspectdb': management.inspectdb,
'install': management.install, 'install': management.install,
'installperms': management.installperms,
'runserver': management.runserver, 'runserver': management.runserver,
'sql': management.get_sql_create, 'sql': management.get_sql_create,
'sqlall': management.get_sql_all, 'sqlall': management.get_sql_all,
@ -24,7 +25,7 @@ ACTION_MAPPING = {
'validate': management.validate, 'validate': management.validate,
} }
NO_SQL_TRANSACTION = ('adminindex', 'createcachetable', 'dbcheck', 'install', 'sqlindexes') NO_SQL_TRANSACTION = ('adminindex', 'createcachetable', 'dbcheck', 'install', 'installperms', 'sqlindexes')
def get_usage(): def get_usage():
""" """

View File

@ -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.help_doc = "Executes ``sqlall`` for the given model module name(s) in the current database."
install.args = APP_ARGS 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=''): def _start_helper(app_or_project, name, directory, other_name=''):
other = {'project': 'app', 'app': 'project'}[app_or_project] other = {'project': 'app', 'app': 'project'}[app_or_project]
if not _is_valid_dir_name(name): if not _is_valid_dir_name(name):