From 0568a408187f2d59594879ce346307a228cdc71e Mon Sep 17 00:00:00 2001
From: Simon Charette <charette.s@gmail.com>
Date: Tue, 29 Jan 2013 02:58:43 -0500
Subject: [PATCH] Fixed 19686 -- Use module_name instead of
object_name.lower()
---
django/contrib/admin/actions.py | 2 +-
django/contrib/admin/options.py | 8 ++++----
django/contrib/admin/util.py | 2 +-
django/contrib/admin/widgets.py | 2 +-
django/contrib/admindocs/views.py | 2 +-
django/contrib/auth/management/__init__.py | 2 +-
django/contrib/contenttypes/generic.py | 4 ++--
django/contrib/contenttypes/management.py | 2 +-
django/contrib/contenttypes/models.py | 10 +++++-----
django/core/management/sql.py | 4 ++--
django/core/xheaders.py | 2 +-
django/db/models/fields/related.py | 8 ++++----
django/db/models/loading.py | 2 +-
django/db/models/options.py | 8 ++++----
django/db/models/related.py | 6 +++---
django/views/generic/detail.py | 6 +++---
django/views/generic/list.py | 4 ++--
17 files changed, 37 insertions(+), 37 deletions(-)
diff --git a/django/contrib/admin/actions.py b/django/contrib/admin/actions.py
index 2011017..3a414d7 100644
a
|
b
|
def delete_selected(modeladmin, request, queryset):
|
75 | 75 | |
76 | 76 | # Display the confirmation page |
77 | 77 | return TemplateResponse(request, modeladmin.delete_selected_confirmation_template or [ |
78 | | "admin/%s/%s/delete_selected_confirmation.html" % (app_label, opts.object_name.lower()), |
| 78 | "admin/%s/%s/delete_selected_confirmation.html" % (app_label, opts.module_name), |
79 | 79 | "admin/%s/delete_selected_confirmation.html" % app_label, |
80 | 80 | "admin/delete_selected_confirmation.html" |
81 | 81 | ], context, current_app=modeladmin.admin_site.name) |
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 8e0aacc..311bb36 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
783 | 783 | form_template = self.change_form_template |
784 | 784 | |
785 | 785 | return TemplateResponse(request, form_template or [ |
786 | | "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()), |
| 786 | "admin/%s/%s/change_form.html" % (app_label, opts.module_name), |
787 | 787 | "admin/%s/change_form.html" % app_label, |
788 | 788 | "admin/change_form.html" |
789 | 789 | ], context, current_app=self.admin_site.name) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1283 | 1283 | context.update(extra_context or {}) |
1284 | 1284 | |
1285 | 1285 | return TemplateResponse(request, self.change_list_template or [ |
1286 | | 'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()), |
| 1286 | 'admin/%s/%s/change_list.html' % (app_label, opts.module_name), |
1287 | 1287 | 'admin/%s/change_list.html' % app_label, |
1288 | 1288 | 'admin/change_list.html' |
1289 | 1289 | ], context, current_app=self.admin_site.name) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1346 | 1346 | context.update(extra_context or {}) |
1347 | 1347 | |
1348 | 1348 | return TemplateResponse(request, self.delete_confirmation_template or [ |
1349 | | "admin/%s/%s/delete_confirmation.html" % (app_label, opts.object_name.lower()), |
| 1349 | "admin/%s/%s/delete_confirmation.html" % (app_label, opts.module_name), |
1350 | 1350 | "admin/%s/delete_confirmation.html" % app_label, |
1351 | 1351 | "admin/delete_confirmation.html" |
1352 | 1352 | ], context, current_app=self.admin_site.name) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1373 | 1373 | } |
1374 | 1374 | context.update(extra_context or {}) |
1375 | 1375 | return TemplateResponse(request, self.object_history_template or [ |
1376 | | "admin/%s/%s/object_history.html" % (app_label, opts.object_name.lower()), |
| 1376 | "admin/%s/%s/object_history.html" % (app_label, opts.module_name), |
1377 | 1377 | "admin/%s/object_history.html" % app_label, |
1378 | 1378 | "admin/object_history.html" |
1379 | 1379 | ], context, current_app=self.admin_site.name) |
diff --git a/django/contrib/admin/util.py b/django/contrib/admin/util.py
index 07013d1..07e4a38 100644
a
|
b
|
def get_deleted_objects(objs, opts, user, admin_site, using):
|
116 | 116 | admin_url = reverse('%s:%s_%s_change' |
117 | 117 | % (admin_site.name, |
118 | 118 | opts.app_label, |
119 | | opts.object_name.lower()), |
| 119 | opts.module_name), |
120 | 120 | None, (quote(obj._get_pk_val()),)) |
121 | 121 | p = '%s.%s' % (opts.app_label, |
122 | 122 | opts.get_delete_permission()) |
diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
index a388774..0b9a143 100644
a
|
b
|
class RelatedFieldWidgetWrapper(forms.Widget):
|
247 | 247 | |
248 | 248 | def render(self, name, value, *args, **kwargs): |
249 | 249 | rel_to = self.rel.to |
250 | | info = (rel_to._meta.app_label, rel_to._meta.object_name.lower()) |
| 250 | info = (rel_to._meta.app_label, rel_to._meta.module_name) |
251 | 251 | self.widget.choices = self.choices |
252 | 252 | output = [self.widget.render(name, value, *args, **kwargs)] |
253 | 253 | if self.can_add_related: |
diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py
index cb0c116..b257b19 100644
a
|
b
|
def model_detail(request, app_label, model_name):
|
189 | 189 | raise Http404(_("App %r not found") % app_label) |
190 | 190 | model = None |
191 | 191 | for m in models.get_models(app_mod): |
192 | | if m._meta.object_name.lower() == model_name: |
| 192 | if m._meta.module_name == model_name: |
193 | 193 | model = m |
194 | 194 | break |
195 | 195 | if model is None: |
diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
index a77bba0..527d0f6 100644
a
|
b
|
from django.utils.six.moves import input
|
17 | 17 | |
18 | 18 | |
19 | 19 | def _get_permission_codename(action, opts): |
20 | | return '%s_%s' % (action, opts.object_name.lower()) |
| 20 | return '%s_%s' % (action, opts.module_name) |
21 | 21 | |
22 | 22 | |
23 | 23 | def _get_all_permissions(opts, ctype): |
diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
index cda4d46..e64a0e5 100644
a
|
b
|
class BaseGenericInlineFormSet(BaseModelFormSet):
|
389 | 389 | opts = self.model._meta |
390 | 390 | self.instance = instance |
391 | 391 | self.rel_name = '-'.join(( |
392 | | opts.app_label, opts.object_name.lower(), |
| 392 | opts.app_label, opts.module_name, |
393 | 393 | self.ct_field.name, self.ct_fk_field.name, |
394 | 394 | )) |
395 | 395 | if self.instance is None or self.instance.pk is None: |
… |
… |
class BaseGenericInlineFormSet(BaseModelFormSet):
|
409 | 409 | @classmethod |
410 | 410 | def get_default_prefix(cls): |
411 | 411 | opts = cls.model._meta |
412 | | return '-'.join((opts.app_label, opts.object_name.lower(), |
| 412 | return '-'.join((opts.app_label, opts.module_name, |
413 | 413 | cls.ct_field.name, cls.ct_fk_field.name, |
414 | 414 | )) |
415 | 415 | |
diff --git a/django/contrib/contenttypes/management.py b/django/contrib/contenttypes/management.py
index 8329ab6..e458c59 100644
a
|
b
|
def update_contenttypes(app, created_models, verbosity=2, db=DEFAULT_DB_ALIAS, *
|
21 | 21 | # They all have the same app_label, get the first one. |
22 | 22 | app_label = app_models[0]._meta.app_label |
23 | 23 | app_models = dict( |
24 | | (model._meta.object_name.lower(), model) |
| 24 | (model._meta.module_name, model) |
25 | 25 | for model in app_models |
26 | 26 | ) |
27 | 27 | |
diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py
index b658655..67023a5 100644
a
|
b
|
class ContentTypeManager(models.Manager):
|
25 | 25 | return model._meta |
26 | 26 | |
27 | 27 | def _get_from_cache(self, opts): |
28 | | key = (opts.app_label, opts.object_name.lower()) |
| 28 | key = (opts.app_label, opts.module_name) |
29 | 29 | return self.__class__._cache[self.db][key] |
30 | 30 | |
31 | 31 | def get_for_model(self, model, for_concrete_model=True): |
… |
… |
class ContentTypeManager(models.Manager):
|
43 | 43 | # django.utils.functional.__proxy__ object. |
44 | 44 | ct, created = self.get_or_create( |
45 | 45 | app_label = opts.app_label, |
46 | | model = opts.object_name.lower(), |
| 46 | model = opts.module_name, |
47 | 47 | defaults = {'name': smart_text(opts.verbose_name_raw)}, |
48 | 48 | ) |
49 | 49 | self._add_to_cache(self.db, ct) |
… |
… |
class ContentTypeManager(models.Manager):
|
67 | 67 | ct = self._get_from_cache(opts) |
68 | 68 | except KeyError: |
69 | 69 | needed_app_labels.add(opts.app_label) |
70 | | needed_models.add(opts.object_name.lower()) |
| 70 | needed_models.add(opts.module_name) |
71 | 71 | needed_opts.add(opts) |
72 | 72 | else: |
73 | 73 | results[model] = ct |
… |
… |
class ContentTypeManager(models.Manager):
|
86 | 86 | # These weren't in the cache, or the DB, create them. |
87 | 87 | ct = self.create( |
88 | 88 | app_label=opts.app_label, |
89 | | model=opts.object_name.lower(), |
| 89 | model=opts.module_name, |
90 | 90 | name=smart_text(opts.verbose_name_raw), |
91 | 91 | ) |
92 | 92 | self._add_to_cache(self.db, ct) |
… |
… |
class ContentTypeManager(models.Manager):
|
119 | 119 | def _add_to_cache(self, using, ct): |
120 | 120 | """Insert a ContentType into the cache.""" |
121 | 121 | model = ct.model_class() |
122 | | key = (model._meta.app_label, model._meta.object_name.lower()) |
| 122 | key = (model._meta.app_label, model._meta.module_name) |
123 | 123 | self.__class__._cache.setdefault(using, {})[key] = ct |
124 | 124 | self.__class__._cache.setdefault(using, {})[ct.id] = ct |
125 | 125 | |
diff --git a/django/core/management/sql.py b/django/core/management/sql.py
index e46f4ae..e7f6685 100644
a
|
b
|
def custom_sql_for_model(model, style, connection):
|
173 | 173 | |
174 | 174 | # Find custom SQL, if it's available. |
175 | 175 | backend_name = connection.settings_dict['ENGINE'].split('.')[-1] |
176 | | sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), backend_name)), |
177 | | os.path.join(app_dir, "%s.sql" % opts.object_name.lower())] |
| 176 | sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.module_name, backend_name)), |
| 177 | os.path.join(app_dir, "%s.sql" % opts.module_name)] |
178 | 178 | for sql_file in sql_files: |
179 | 179 | if os.path.exists(sql_file): |
180 | 180 | with codecs.open(sql_file, 'U', encoding=settings.FILE_CHARSET) as fp: |
diff --git a/django/core/xheaders.py b/django/core/xheaders.py
index b650a3a..8903d27 100644
a
|
b
|
def populate_xheaders(request, response, model, object_id):
|
20 | 20 | if (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS |
21 | 21 | or (hasattr(request, 'user') and request.user.is_active |
22 | 22 | and request.user.is_staff)): |
23 | | response['X-Object-Type'] = "%s.%s" % (model._meta.app_label, model._meta.object_name.lower()) |
| 23 | response['X-Object-Type'] = "%s.%s" % (model._meta.app_label, model._meta.module_name) |
24 | 24 | response['X-Object-Id'] = str(object_id) |
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index ae792a3..2d0e3ce 100644
a
|
b
|
class RelatedField(object):
|
118 | 118 | self.do_related_class(other, cls) |
119 | 119 | |
120 | 120 | def set_attributes_from_rel(self): |
121 | | self.name = self.name or (self.rel.to._meta.object_name.lower() + '_' + self.rel.to._meta.pk.name) |
| 121 | self.name = self.name or (self.rel.to._meta.module_name + '_' + self.rel.to._meta.pk.name) |
122 | 122 | if self.verbose_name is None: |
123 | 123 | self.verbose_name = self.rel.to._meta.verbose_name |
124 | 124 | self.rel.field_name = self.rel.field_name or self.rel.to._meta.pk.name |
… |
… |
class RelatedField(object):
|
222 | 222 | # related object in a table-spanning query. It uses the lower-cased |
223 | 223 | # object_name by default, but this can be overridden with the |
224 | 224 | # "related_name" option. |
225 | | return self.rel.related_name or self.opts.object_name.lower() |
| 225 | return self.rel.related_name or self.opts.module_name |
226 | 226 | |
227 | 227 | |
228 | 228 | class SingleRelatedObjectDescriptor(object): |
… |
… |
class ForeignKey(RelatedField, Field):
|
983 | 983 | |
984 | 984 | def __init__(self, to, to_field=None, rel_class=ManyToOneRel, **kwargs): |
985 | 985 | try: |
986 | | to_name = to._meta.object_name.lower() |
| 986 | to_name = to._meta.module_name |
987 | 987 | except AttributeError: # to._meta doesn't exist, so it must be RECURSIVE_RELATIONSHIP_CONSTANT |
988 | 988 | assert isinstance(to, six.string_types), "%s(%r) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string %r" % (self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT) |
989 | 989 | else: |
… |
… |
def create_many_to_many_intermediary_model(field, klass):
|
1174 | 1174 | from_ = 'from_%s' % to.lower() |
1175 | 1175 | to = 'to_%s' % to.lower() |
1176 | 1176 | else: |
1177 | | from_ = klass._meta.object_name.lower() |
| 1177 | from_ = klass._meta.module_name |
1178 | 1178 | to = to.lower() |
1179 | 1179 | meta = type('Meta', (object,), { |
1180 | 1180 | 'db_table': field._get_m2m_db_table(klass._meta), |
diff --git a/django/db/models/loading.py b/django/db/models/loading.py
index 56edc36..391a279 100644
a
|
b
|
class AppCache(object):
|
239 | 239 | for model in models: |
240 | 240 | # Store as 'name: model' pair in a dictionary |
241 | 241 | # in the app_models dictionary |
242 | | model_name = model._meta.object_name.lower() |
| 242 | model_name = model._meta.module_name |
243 | 243 | model_dict = self.app_models.setdefault(app_label, SortedDict()) |
244 | 244 | if model_name in model_dict: |
245 | 245 | # The same model may be imported via different paths (e.g. |
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 952596b..c8b4690 100644
a
|
b
|
class Options(object):
|
217 | 217 | case insensitive, so we make sure we are case insensitive here. |
218 | 218 | """ |
219 | 219 | if self.swappable: |
220 | | model_label = '%s.%s' % (self.app_label, self.object_name.lower()) |
| 220 | model_label = '%s.%s' % (self.app_label, self.module_name) |
221 | 221 | swapped_for = getattr(settings, self.swappable, None) |
222 | 222 | if swapped_for: |
223 | 223 | try: |
… |
… |
class Options(object):
|
371 | 371 | return cache |
372 | 372 | |
373 | 373 | def get_add_permission(self): |
374 | | return 'add_%s' % self.object_name.lower() |
| 374 | return 'add_%s' % self.module_name |
375 | 375 | |
376 | 376 | def get_change_permission(self): |
377 | | return 'change_%s' % self.object_name.lower() |
| 377 | return 'change_%s' % self.module_name |
378 | 378 | |
379 | 379 | def get_delete_permission(self): |
380 | | return 'delete_%s' % self.object_name.lower() |
| 380 | return 'delete_%s' % self.module_name |
381 | 381 | |
382 | 382 | def get_all_related_objects(self, local_only=False, include_hidden=False, |
383 | 383 | include_proxy_eq=False): |
diff --git a/django/db/models/related.py b/django/db/models/related.py
index 2693213..e904269 100644
a
|
b
|
class RelatedObject(object):
|
17 | 17 | self.opts = model._meta |
18 | 18 | self.field = field |
19 | 19 | self.name = '%s:%s' % (self.opts.app_label, self.opts.module_name) |
20 | | self.var_name = self.opts.object_name.lower() |
| 20 | self.var_name = self.opts.module_name |
21 | 21 | |
22 | 22 | def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH, |
23 | 23 | limit_to_currently_related=False): |
… |
… |
class RelatedObject(object):
|
56 | 56 | # If this is a symmetrical m2m relation on self, there is no reverse accessor. |
57 | 57 | if getattr(self.field.rel, 'symmetrical', False) and self.model == self.parent_model: |
58 | 58 | return None |
59 | | return self.field.rel.related_name or (self.opts.object_name.lower() + '_set') |
| 59 | return self.field.rel.related_name or (self.opts.module_name + '_set') |
60 | 60 | else: |
61 | | return self.field.rel.related_name or (self.opts.object_name.lower()) |
| 61 | return self.field.rel.related_name or (self.opts.module_name) |
62 | 62 | |
63 | 63 | def get_cache_name(self): |
64 | 64 | return "_%s_cache" % self.get_accessor_name() |
diff --git a/django/views/generic/detail.py b/django/views/generic/detail.py
index c27b92b..27215fe 100644
a
|
b
|
class SingleObjectMixin(ContextMixin):
|
84 | 84 | if self.context_object_name: |
85 | 85 | return self.context_object_name |
86 | 86 | elif isinstance(obj, models.Model): |
87 | | return obj._meta.object_name.lower() |
| 87 | return obj._meta.module_name |
88 | 88 | else: |
89 | 89 | return None |
90 | 90 | |
… |
… |
class SingleObjectTemplateResponseMixin(TemplateResponseMixin):
|
144 | 144 | if isinstance(self.object, models.Model): |
145 | 145 | names.append("%s/%s%s.html" % ( |
146 | 146 | self.object._meta.app_label, |
147 | | self.object._meta.object_name.lower(), |
| 147 | self.object._meta.module_name, |
148 | 148 | self.template_name_suffix |
149 | 149 | )) |
150 | 150 | elif hasattr(self, 'model') and self.model is not None and issubclass(self.model, models.Model): |
151 | 151 | names.append("%s/%s%s.html" % ( |
152 | 152 | self.model._meta.app_label, |
153 | | self.model._meta.object_name.lower(), |
| 153 | self.model._meta.module_name, |
154 | 154 | self.template_name_suffix |
155 | 155 | )) |
156 | 156 | return names |
diff --git a/django/views/generic/list.py b/django/views/generic/list.py
index 1f28616..48f7783 100644
a
|
b
|
class MultipleObjectMixin(ContextMixin):
|
97 | 97 | if self.context_object_name: |
98 | 98 | return self.context_object_name |
99 | 99 | elif hasattr(object_list, 'model'): |
100 | | return '%s_list' % object_list.model._meta.object_name.lower() |
| 100 | return '%s_list' % object_list.model._meta.module_name |
101 | 101 | else: |
102 | 102 | return None |
103 | 103 | |
… |
… |
class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
|
177 | 177 | # generated ones. |
178 | 178 | if hasattr(self.object_list, 'model'): |
179 | 179 | opts = self.object_list.model._meta |
180 | | names.append("%s/%s%s.html" % (opts.app_label, opts.object_name.lower(), self.template_name_suffix)) |
| 180 | names.append("%s/%s%s.html" % (opts.app_label, opts.module_name, self.template_name_suffix)) |
181 | 181 | |
182 | 182 | return names |
183 | 183 | |