Skip to content

Commit

Permalink
Added 'django-admin.py installperms' command
Browse files Browse the repository at this point in the history
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1005 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Oct 23, 2005
1 parent 43ad69e commit c604de5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion django/bin/django-admin.py
Expand Up @@ -11,6 +11,7 @@
'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,
Expand All @@ -24,7 +25,7 @@
'validate': management.validate,
}

NO_SQL_TRANSACTION = ('adminindex', 'createcachetable', 'dbcheck', 'install', 'sqlindexes')
NO_SQL_TRANSACTION = ('adminindex', 'createcachetable', 'dbcheck', 'install', 'installperms', 'sqlindexes')

def get_usage():
"""
Expand Down
21 changes: 21 additions & 0 deletions django/core/management.py
Expand Up @@ -345,6 +345,27 @@ def install(mod):
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):
Expand Down

0 comments on commit c604de5

Please sign in to comment.