Code

Ticket #1436: management_error_messages.diff

File management_error_messages.diff, 2.7 KB (added by akaihola, 8 years ago)

fixed app_name and removed app_label for error messages

Line 
1Index: django/core/management.py
2===================================================================
3--- django/core/management.py   (revision 2458)
4+++ django/core/management.py   (working copy)
5@@ -501,8 +501,7 @@
6     "Executes the equivalent of 'get_sql_all' in the current database."
7     from django.db import connection, transaction
8     from cStringIO import StringIO
9-    app_name = app.__name__[app.__name__.rindex('.')+1:]
10-    app_label = app_name.split('.')[-1]
11+    app_name = app.__name__.split('.')[-2]
12 
13     # First, try validating the models.
14     s = StringIO()
15@@ -519,13 +518,13 @@
16         for sql in sql_list:
17             cursor.execute(sql)
18     except Exception, e:
19-        sys.stderr.write("""Error: %s couldn't be installed. Possible reasons:
20+        sys.stderr.write("""Error: %(app_name)s couldn't be installed. Possible reasons:
21   * The database isn't running or isn't configured correctly.
22   * At least one of the database tables already exists.
23   * The SQL was invalid.
24-Hint: Look at the output of 'django-admin.py sqlall %s'. That's the SQL this command wasn't able to run.
25-The full error: %s\n""" % \
26-            (app_name, app_label, e))
27+Hint: Look at the output of 'django-admin.py sqlall %(app_name)s'. That's the SQL this command wasn't able to run.
28+The full error: %(e)s\n""" % \
29+            locals())
30         transaction.rollback_unless_managed()
31         sys.exit(1)
32     transaction.commit_unless_managed()
33@@ -536,8 +535,7 @@
34     "Executes the equivalent of 'get_sql_reset' in the current database."
35     from django.db import connection, transaction
36     from cStringIO import StringIO
37-    app_name = app.__name__[app.__name__.rindex('.')+1:]
38-    app_label = app_name.split('.')[-1]
39+    app_name = app.__name__.split('.')[-2]
40 
41     # First, try validating the models.
42     s = StringIO()
43@@ -561,13 +559,13 @@
44             for sql in sql_list:
45                 cursor.execute(sql)
46         except Exception, e:
47-            sys.stderr.write("""Error: %s couldn't be installed. Possible reasons:
48+            sys.stderr.write("""Error: %(app_name)s couldn't be installed. Possible reasons:
49   * The database isn't running or isn't configured correctly.
50   * At least one of the database tables already exists.
51   * The SQL was invalid.
52-Hint: Look at the output of 'django-admin.py sqlreset %s'. That's the SQL this command wasn't able to run.
53-The full error: %s\n""" % \
54-                (app_name, app_label, e))
55+Hint: Look at the output of 'django-admin.py sqlreset %(app_name)s'. That's the SQL this command wasn't able to run.
56+The full error: %(e)s\n""" % \
57+                locals())
58             transaction.rollback_unless_managed()
59             sys.exit(1)
60         transaction.commit_unless_managed()