Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added 'django-admin.py installperms' command

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1005 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c604de5a5db2cff33ad78ad8565fcb9b05e405f6 1 parent 43ad69e
@adrianholovaty adrianholovaty authored
Showing with 23 additions and 1 deletion.
  1. +2 −1  django/bin/django-admin.py
  2. +21 −0 django/core/management.py
View
3  django/bin/django-admin.py
@@ -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,
@@ -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():
"""
View
21 django/core/management.py
@@ -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):
Please sign in to comment.
Something went wrong with that request. Please try again.