Ticket #1259: magic_removal-singular_normalization.diff
File magic_removal-singular_normalization.diff, 12.6 KB (added by , 19 years ago) |
---|
-
db/models/options.py
7 7 from bisect import bisect 8 8 import re 9 9 10 # Calculate the module_name using a poor-man's pluralization.11 get_module_name = lambda class_name: class_name.lower() + 's'10 # Calculate the module_name by converting to lowercase 11 get_module_name = lambda class_name: class_name.lower() 12 12 13 13 # Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces". 14 14 get_verbose_name = lambda class_name: re.sub('([A-Z])', ' \\1', class_name).lower().strip() -
core/management.py
29 29 def _get_packages_insert(app_label): 30 30 from django.db import backend 31 31 return "INSERT INTO %s (%s, %s) VALUES ('%s', '%s');" % \ 32 (backend.quote_name(' packages'), backend.quote_name('label'), backend.quote_name('name'),32 (backend.quote_name('django_package'), backend.quote_name('label'), backend.quote_name('name'), 33 33 app_label, app_label) 34 34 35 35 def _get_permission_codename(action, opts): … … 46 46 def _get_permission_insert(name, codename, opts): 47 47 from django.db import backend 48 48 return "INSERT INTO %s (%s, %s, %s) VALUES ('%s', '%s', '%s');" % \ 49 (backend.quote_name('auth_permission s'), backend.quote_name('name'), backend.quote_name('package'),49 (backend.quote_name('auth_permission'), backend.quote_name('name'), backend.quote_name('package'), 50 50 backend.quote_name('codename'), name.replace("'", "''"), opts.app_label, codename) 51 51 52 52 def _get_contenttype_insert(opts): 53 53 from django.db import backend 54 54 return "INSERT INTO %s (%s, %s, %s) VALUES ('%s', '%s', '%s');" % \ 55 (backend.quote_name(' content_types'), backend.quote_name('name'), backend.quote_name('package'),55 (backend.quote_name('django_content_type'), backend.quote_name('name'), backend.quote_name('package'), 56 56 backend.quote_name('python_module_name'), opts.verbose_name, opts.app_label, opts.module_name) 57 57 58 58 def _is_valid_dir_name(s): … … 249 249 250 250 app_label = app_models[0]._meta.app_label 251 251 252 # Delete from packages, auth_permissions, content_types.252 # Delete from django_package, auth_permission, django_content_type. 253 253 output.append("DELETE FROM %s WHERE %s = '%s';" % \ 254 (backend.quote_name(' packages'), backend.quote_name('label'), app_label))254 (backend.quote_name('django_package'), backend.quote_name('label'), app_label)) 255 255 output.append("DELETE FROM %s WHERE %s = '%s';" % \ 256 (backend.quote_name('auth_permission s'), backend.quote_name('package'), app_label))256 (backend.quote_name('auth_permission'), backend.quote_name('package'), app_label)) 257 257 output.append("DELETE FROM %s WHERE %s = '%s';" % \ 258 (backend.quote_name(' content_types'), backend.quote_name('package'), app_label))258 (backend.quote_name('django_content_type'), backend.quote_name('package'), app_label)) 259 259 260 260 # Delete from the admin log. 261 261 if cursor is not None: 262 262 cursor.execute("SELECT %s FROM %s WHERE %s = %%s" % \ 263 (backend.quote_name('id'), backend.quote_name(' content_types'),263 (backend.quote_name('id'), backend.quote_name('django_content_type'), 264 264 backend.quote_name('package')), [app_label]) 265 265 if admin_log_exists: 266 266 for row in cursor.fetchall(): … … 373 373 374 374 # Check that the package exists in the database. 375 375 cursor.execute("SELECT 1 FROM %s WHERE %s = %%s" % \ 376 (backend.quote_name(' packages'), backend.quote_name('label')), [app_label])376 (backend.quote_name('django_package'), backend.quote_name('label')), [app_label]) 377 377 if has_no_records(cursor): 378 378 # sys.stderr.write("The '%s' package isn't installed.\n" % app_label) 379 379 print _get_packages_insert(app_label) … … 388 388 contenttypes_seen[opts.module_name] = 1 389 389 for codename, name in perms: 390 390 cursor.execute("SELECT 1 FROM %s WHERE %s = %%s AND %s = %%s" % \ 391 (backend.quote_name('auth_permission s'), backend.quote_name('package'),391 (backend.quote_name('auth_permission'), backend.quote_name('package'), 392 392 backend.quote_name('codename')), (app_label, codename)) 393 393 if has_no_records(cursor): 394 394 # sys.stderr.write("The '%s.%s' permission doesn't exist.\n" % (app_label, codename)) 395 395 print _get_permission_insert(name, codename, opts) 396 396 cursor.execute("SELECT 1 FROM %s WHERE %s = %%s AND %s = %%s" % \ 397 (backend.quote_name(' content_types'), backend.quote_name('package'),397 (backend.quote_name('django_content_type'), backend.quote_name('package'), 398 398 backend.quote_name('python_module_name')), (app_label, opts.module_name)) 399 399 if has_no_records(cursor): 400 400 # sys.stderr.write("The '%s.%s' content type doesn't exist.\n" % (app_label, opts.module_name)) … … 403 403 # Check that there aren't any *extra* permissions in the DB that the model 404 404 # doesn't know about. 405 405 cursor.execute("SELECT %s FROM %s WHERE %s = %%s" % \ 406 (backend.quote_name('codename'), backend.quote_name('auth_permission s'),406 (backend.quote_name('codename'), backend.quote_name('auth_permission'), 407 407 backend.quote_name('package')), (app_label,)) 408 408 for row in cursor.fetchall(): 409 409 try: … … 411 411 except KeyError: 412 412 # sys.stderr.write("A permission called '%s.%s' was found in the database but not in the model.\n" % (app_label, row[0])) 413 413 print "DELETE FROM %s WHERE %s='%s' AND %s = '%s';" % \ 414 (backend.quote_name('auth_permission s'), backend.quote_name('package'),414 (backend.quote_name('auth_permission'), backend.quote_name('package'), 415 415 app_label, backend.quote_name('codename'), row[0]) 416 416 417 417 # Check that there aren't any *extra* content types in the DB that the 418 418 # model doesn't know about. 419 419 cursor.execute("SELECT %s FROM %s WHERE %s = %%s" % \ 420 (backend.quote_name('python_module_name'), backend.quote_name(' content_types'),420 (backend.quote_name('python_module_name'), backend.quote_name('django_content_type'), 421 421 backend.quote_name('package')), (app_label,)) 422 422 for row in cursor.fetchall(): 423 423 try: … … 425 425 except KeyError: 426 426 # sys.stderr.write("A content type called '%s.%s' was found in the database but not in the model.\n" % (app_label, row[0])) 427 427 print "DELETE FROM %s WHERE %s='%s' AND %s = '%s';" % \ 428 (backend.quote_name(' content_types'), backend.quote_name('package'),428 (backend.quote_name('django_content_type'), backend.quote_name('package'), 429 429 app_label, backend.quote_name('python_module_name'), row[0]) 430 430 database_check.help_doc = "Checks that everything is installed in the database for the given model module name(s) and prints SQL statements if needed." 431 431 database_check.args = APP_ARGS -
contrib/contenttypes/models.py
7 7 class Meta: 8 8 verbose_name = _('package') 9 9 verbose_name_plural = _('packages') 10 db_table = ' packages'10 db_table = 'django_package' 11 11 ordering = ('name',) 12 12 13 13 def __repr__(self): … … 20 20 class Meta: 21 21 verbose_name = _('content type') 22 22 verbose_name_plural = _('content types') 23 db_table = ' content_types'23 db_table = 'django_content_type' 24 24 ordering = ('package', 'name') 25 25 unique_together = (('package', 'python_module_name'),) 26 26 -
contrib/auth/models.py
132 132 # The SQL below works out to the following, after DB quoting: 133 133 # cursor.execute(""" 134 134 # SELECT p.package, p.codename 135 # FROM auth_permission s p, auth_groups_permissions gp, auth_users_groups ug135 # FROM auth_permission p, auth_group_permissions gp, auth_user_groups ug 136 136 # WHERE p.id = gp.permission_id 137 137 # AND gp.group_id = ug.group_id 138 138 # AND ug.user_id = %s""", [self.id]) … … 143 143 AND gp.%s = ug.%s 144 144 AND ug.%s = %%s""" % ( 145 145 backend.quote_name('package'), backend.quote_name('codename'), 146 backend.quote_name('auth_permission s'), backend.quote_name('auth_groups_permissions'),146 backend.quote_name('auth_permission'), backend.quote_name('auth_group_permissions'), 147 147 backend.quote_name('auth_users_groups'), backend.quote_name('id'), 148 148 backend.quote_name('permission_id'), backend.quote_name('group_id'), 149 149 backend.quote_name('group_id'), backend.quote_name('user_id')) -
contrib/redirects/models.py
11 11 class Meta: 12 12 verbose_name = _('redirect') 13 13 verbose_name_plural = _('redirects') 14 db_table = 'django_redirect s'14 db_table = 'django_redirect' 15 15 unique_together=(('site', 'old_path'),) 16 16 ordering = ('old_path',) 17 17 class Admin: -
contrib/comments/models.py
86 86 site = models.ForeignKey(Site) 87 87 objects = CommentManager() 88 88 class Meta: 89 db_table = 'comments'90 89 verbose_name = _('Comment') 91 90 verbose_name_plural = _('Comments') 92 91 ordering = ('-submit_date',) … … 173 172 approved = models.BooleanField(_('approved by staff')) 174 173 site = models.ForeignKey(Site) 175 174 class Meta: 176 db_table = 'comments_free'177 175 verbose_name = _('Free comment') 178 176 verbose_name_plural = _('Free comments') 179 177 ordering = ('-submit_date',) … … 266 264 flag_date = models.DateTimeField(_('flag date'), auto_now_add=True) 267 265 objects = UserFlagManager() 268 266 class Meta: 269 db_table = 'comments_user_flags'270 267 verbose_name = _('User flag') 271 268 verbose_name_plural = _('User flags') 272 269 unique_together = (('user', 'comment'),) … … 279 276 comment = models.ForeignKey(Comment) 280 277 deletion_date = models.DateTimeField(_('deletion date'), auto_now_add=True) 281 278 class Meta: 282 db_table = 'comments_moderator_deletions'283 279 verbose_name = _('Moderator deletion') 284 280 verbose_name_plural = _('Moderator deletions') 285 281 unique_together = (('user', 'comment'),) -
contrib/flatpages/models.py
14 14 registration_required = models.BooleanField(_('registration required'), help_text=_("If this is checked, only logged-in users will be able to view the page.")) 15 15 sites = models.ManyToManyField(Site) 16 16 class Meta: 17 db_table = 'django_flatpage s'17 db_table = 'django_flatpage' 18 18 verbose_name = _('flat page') 19 19 verbose_name_plural = _('flat pages') 20 20 ordering = ('url',) -
contrib/sessions/models.py
37 37 expire_date = models.DateTimeField(_('expire date')) 38 38 objects = SessionManager() 39 39 class Meta: 40 db_table = 'django_session s'40 db_table = 'django_session' 41 41 verbose_name = _('session') 42 42 verbose_name_plural = _('sessions') 43 43 module_constants = { -
contrib/sites/models.py
11 11 name = models.CharField(_('display name'), maxlength=50) 12 12 objects = SiteManager() 13 13 class Meta: 14 db_table = ' sites'14 db_table = 'django_site' 15 15 verbose_name = _('site') 16 16 verbose_name_plural = _('sites') 17 17 ordering = ('domain',)