mirror of
https://github.com/django/django.git
synced 2025-09-15 05:29:11 +00:00
magic-removal: syncdb now installs permissions (if necessary)
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2481 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
242e652fe7
commit
809f9e9925
@ -391,6 +391,7 @@ def syncdb():
|
|||||||
seen_models = set([m for m in all_models if m._meta.db_table in table_list])
|
seen_models = set([m for m in all_models if m._meta.db_table in table_list])
|
||||||
created_models = set()
|
created_models = set()
|
||||||
pending_references = {}
|
pending_references = {}
|
||||||
|
install_permissions = True
|
||||||
|
|
||||||
for app in models.get_apps():
|
for app in models.get_apps():
|
||||||
model_list = models.get_models(app)
|
model_list = models.get_models(app)
|
||||||
@ -416,6 +417,20 @@ def syncdb():
|
|||||||
cursor.execute(statement)
|
cursor.execute(statement)
|
||||||
|
|
||||||
transaction.commit_unless_managed()
|
transaction.commit_unless_managed()
|
||||||
|
|
||||||
|
# Install permissions (first checking that they're installed)
|
||||||
|
if install_permissions:
|
||||||
|
try:
|
||||||
|
installperms(app)
|
||||||
|
except Exception, e:
|
||||||
|
sys.stderr.write("Permissions will not be installed because it "\
|
||||||
|
"appears that you are not using Django's auth framework. "\
|
||||||
|
"If you want to install them in the future, re-run syncdb."\
|
||||||
|
"\n(The full error was: %s)" % (app_name, app_name, e))
|
||||||
|
transaction.rollback_unless_managed()
|
||||||
|
else:
|
||||||
|
transaction.commit_unless_managed()
|
||||||
|
|
||||||
syncdb.args = ''
|
syncdb.args = ''
|
||||||
|
|
||||||
def get_admin_index(app):
|
def get_admin_index(app):
|
||||||
@ -445,6 +460,7 @@ get_admin_index.args = APP_ARGS
|
|||||||
def install(app):
|
def install(app):
|
||||||
"Executes the equivalent of 'get_sql_all' in the current database."
|
"Executes the equivalent of 'get_sql_all' in the current database."
|
||||||
from django.db import connection, transaction
|
from django.db import connection, transaction
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
app_name = app.__name__.split('.')[-2]
|
app_name = app.__name__.split('.')[-2]
|
||||||
|
|
||||||
@ -523,10 +539,8 @@ def installperms(app):
|
|||||||
except Permission.DoesNotExist:
|
except Permission.DoesNotExist:
|
||||||
p = Permission(name=name, codename=codename, content_type=ctype)
|
p = Permission(name=name, codename=codename, content_type=ctype)
|
||||||
p.save()
|
p.save()
|
||||||
print "Added permission '%r'." % p
|
print "Adding permission '%r'." % p
|
||||||
num_added += 1
|
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.help_doc = "Installs any permissions for the given model module name(s), if needed."
|
||||||
installperms.args = APP_ARGS
|
installperms.args = APP_ARGS
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user