Code

Ticket #19689: 0001-Fixed-19686-Use-module_name-instead-of-object_name.l.patch

File 0001-Fixed-19686-Use-module_name-instead-of-object_name.l.patch, 19.0 KB (added by charettes, 15 months ago)
  • django/contrib/admin/actions.py

    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): 
    7575 
    7676    # Display the confirmation page 
    7777    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), 
    7979        "admin/%s/delete_selected_confirmation.html" % app_label, 
    8080        "admin/delete_selected_confirmation.html" 
    8181    ], context, current_app=modeladmin.admin_site.name) 
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index 8e0aacc..311bb36 100644
    a b class ModelAdmin(BaseModelAdmin): 
    783783            form_template = self.change_form_template 
    784784 
    785785        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), 
    787787            "admin/%s/change_form.html" % app_label, 
    788788            "admin/change_form.html" 
    789789        ], context, current_app=self.admin_site.name) 
    class ModelAdmin(BaseModelAdmin): 
    12831283        context.update(extra_context or {}) 
    12841284 
    12851285        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), 
    12871287            'admin/%s/change_list.html' % app_label, 
    12881288            'admin/change_list.html' 
    12891289        ], context, current_app=self.admin_site.name) 
    class ModelAdmin(BaseModelAdmin): 
    13461346        context.update(extra_context or {}) 
    13471347 
    13481348        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), 
    13501350            "admin/%s/delete_confirmation.html" % app_label, 
    13511351            "admin/delete_confirmation.html" 
    13521352        ], context, current_app=self.admin_site.name) 
    class ModelAdmin(BaseModelAdmin): 
    13731373        } 
    13741374        context.update(extra_context or {}) 
    13751375        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), 
    13771377            "admin/%s/object_history.html" % app_label, 
    13781378            "admin/object_history.html" 
    13791379        ], context, current_app=self.admin_site.name) 
  • django/contrib/admin/util.py

    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): 
    116116            admin_url = reverse('%s:%s_%s_change' 
    117117                                % (admin_site.name, 
    118118                                   opts.app_label, 
    119                                    opts.object_name.lower()), 
     119                                   opts.module_name), 
    120120                                None, (quote(obj._get_pk_val()),)) 
    121121            p = '%s.%s' % (opts.app_label, 
    122122                           opts.get_delete_permission()) 
  • django/contrib/admin/widgets.py

    diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
    index a388774..0b9a143 100644
    a b class RelatedFieldWidgetWrapper(forms.Widget): 
    247247 
    248248    def render(self, name, value, *args, **kwargs): 
    249249        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) 
    251251        self.widget.choices = self.choices 
    252252        output = [self.widget.render(name, value, *args, **kwargs)] 
    253253        if self.can_add_related: 
  • django/contrib/admindocs/views.py

    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): 
    189189        raise Http404(_("App %r not found") % app_label) 
    190190    model = None 
    191191    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: 
    193193            model = m 
    194194            break 
    195195    if model is None: 
  • django/contrib/auth/management/__init__.py

    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 
    1717 
    1818 
    1919def _get_permission_codename(action, opts): 
    20     return '%s_%s' % (action, opts.object_name.lower()) 
     20    return '%s_%s' % (action, opts.module_name) 
    2121 
    2222 
    2323def _get_all_permissions(opts, ctype): 
  • django/contrib/contenttypes/generic.py

    diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
    index cda4d46..e64a0e5 100644
    a b class BaseGenericInlineFormSet(BaseModelFormSet): 
    389389        opts = self.model._meta 
    390390        self.instance = instance 
    391391        self.rel_name = '-'.join(( 
    392             opts.app_label, opts.object_name.lower(), 
     392            opts.app_label, opts.module_name, 
    393393            self.ct_field.name, self.ct_fk_field.name, 
    394394        )) 
    395395        if self.instance is None or self.instance.pk is None: 
    class BaseGenericInlineFormSet(BaseModelFormSet): 
    409409    @classmethod 
    410410    def get_default_prefix(cls): 
    411411        opts = cls.model._meta 
    412         return '-'.join((opts.app_label, opts.object_name.lower(), 
     412        return '-'.join((opts.app_label, opts.module_name, 
    413413                        cls.ct_field.name, cls.ct_fk_field.name, 
    414414        )) 
    415415 
  • django/contrib/contenttypes/management.py

    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, * 
    2121    # They all have the same app_label, get the first one. 
    2222    app_label = app_models[0]._meta.app_label 
    2323    app_models = dict( 
    24         (model._meta.object_name.lower(), model) 
     24        (model._meta.module_name, model) 
    2525        for model in app_models 
    2626    ) 
    2727 
  • django/contrib/contenttypes/models.py

    diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py
    index b658655..67023a5 100644
    a b class ContentTypeManager(models.Manager): 
    2525        return model._meta 
    2626 
    2727    def _get_from_cache(self, opts): 
    28         key = (opts.app_label, opts.object_name.lower()) 
     28        key = (opts.app_label, opts.module_name) 
    2929        return self.__class__._cache[self.db][key] 
    3030 
    3131    def get_for_model(self, model, for_concrete_model=True): 
    class ContentTypeManager(models.Manager): 
    4343            # django.utils.functional.__proxy__ object. 
    4444            ct, created = self.get_or_create( 
    4545                app_label = opts.app_label, 
    46                 model = opts.object_name.lower(), 
     46                model = opts.module_name, 
    4747                defaults = {'name': smart_text(opts.verbose_name_raw)}, 
    4848            ) 
    4949            self._add_to_cache(self.db, ct) 
    class ContentTypeManager(models.Manager): 
    6767                ct = self._get_from_cache(opts) 
    6868            except KeyError: 
    6969                needed_app_labels.add(opts.app_label) 
    70                 needed_models.add(opts.object_name.lower()) 
     70                needed_models.add(opts.module_name) 
    7171                needed_opts.add(opts) 
    7272            else: 
    7373                results[model] = ct 
    class ContentTypeManager(models.Manager): 
    8686            # These weren't in the cache, or the DB, create them. 
    8787            ct = self.create( 
    8888                app_label=opts.app_label, 
    89                 model=opts.object_name.lower(), 
     89                model=opts.module_name, 
    9090                name=smart_text(opts.verbose_name_raw), 
    9191            ) 
    9292            self._add_to_cache(self.db, ct) 
    class ContentTypeManager(models.Manager): 
    119119    def _add_to_cache(self, using, ct): 
    120120        """Insert a ContentType into the cache.""" 
    121121        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) 
    123123        self.__class__._cache.setdefault(using, {})[key] = ct 
    124124        self.__class__._cache.setdefault(using, {})[ct.id] = ct 
    125125 
  • django/core/management/sql.py

    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): 
    173173 
    174174    # Find custom SQL, if it's available. 
    175175    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)] 
    178178    for sql_file in sql_files: 
    179179        if os.path.exists(sql_file): 
    180180            with codecs.open(sql_file, 'U', encoding=settings.FILE_CHARSET) as fp: 
  • django/core/xheaders.py

    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): 
    2020    if (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS 
    2121            or (hasattr(request, 'user') and request.user.is_active 
    2222                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) 
    2424        response['X-Object-Id'] = str(object_id) 
  • django/db/models/fields/related.py

    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): 
    118118            self.do_related_class(other, cls) 
    119119 
    120120    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) 
    122122        if self.verbose_name is None: 
    123123            self.verbose_name = self.rel.to._meta.verbose_name 
    124124        self.rel.field_name = self.rel.field_name or self.rel.to._meta.pk.name 
    class RelatedField(object): 
    222222        # related object in a table-spanning query. It uses the lower-cased 
    223223        # object_name by default, but this can be overridden with the 
    224224        # "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 
    226226 
    227227 
    228228class SingleRelatedObjectDescriptor(object): 
    class ForeignKey(RelatedField, Field): 
    983983 
    984984    def __init__(self, to, to_field=None, rel_class=ManyToOneRel, **kwargs): 
    985985        try: 
    986             to_name = to._meta.object_name.lower() 
     986            to_name = to._meta.module_name 
    987987        except AttributeError:  # to._meta doesn't exist, so it must be RECURSIVE_RELATIONSHIP_CONSTANT 
    988988            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) 
    989989        else: 
    def create_many_to_many_intermediary_model(field, klass): 
    11741174        from_ = 'from_%s' % to.lower() 
    11751175        to = 'to_%s' % to.lower() 
    11761176    else: 
    1177         from_ = klass._meta.object_name.lower() 
     1177        from_ = klass._meta.module_name 
    11781178        to = to.lower() 
    11791179    meta = type('Meta', (object,), { 
    11801180        'db_table': field._get_m2m_db_table(klass._meta), 
  • django/db/models/loading.py

    diff --git a/django/db/models/loading.py b/django/db/models/loading.py
    index 56edc36..391a279 100644
    a b class AppCache(object): 
    239239        for model in models: 
    240240            # Store as 'name: model' pair in a dictionary 
    241241            # in the app_models dictionary 
    242             model_name = model._meta.object_name.lower() 
     242            model_name = model._meta.module_name 
    243243            model_dict = self.app_models.setdefault(app_label, SortedDict()) 
    244244            if model_name in model_dict: 
    245245                # The same model may be imported via different paths (e.g. 
  • django/db/models/options.py

    diff --git a/django/db/models/options.py b/django/db/models/options.py
    index 952596b..c8b4690 100644
    a b class Options(object): 
    217217        case insensitive, so we make sure we are case insensitive here. 
    218218        """ 
    219219        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) 
    221221            swapped_for = getattr(settings, self.swappable, None) 
    222222            if swapped_for: 
    223223                try: 
    class Options(object): 
    371371        return cache 
    372372 
    373373    def get_add_permission(self): 
    374         return 'add_%s' % self.object_name.lower() 
     374        return 'add_%s' % self.module_name 
    375375 
    376376    def get_change_permission(self): 
    377         return 'change_%s' % self.object_name.lower() 
     377        return 'change_%s' % self.module_name 
    378378 
    379379    def get_delete_permission(self): 
    380         return 'delete_%s' % self.object_name.lower() 
     380        return 'delete_%s' % self.module_name 
    381381 
    382382    def get_all_related_objects(self, local_only=False, include_hidden=False, 
    383383                                include_proxy_eq=False): 
  • django/db/models/related.py

    diff --git a/django/db/models/related.py b/django/db/models/related.py
    index 2693213..e904269 100644
    a b class RelatedObject(object): 
    1717        self.opts = model._meta 
    1818        self.field = field 
    1919        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 
    2121 
    2222    def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH, 
    2323                    limit_to_currently_related=False): 
    class RelatedObject(object): 
    5656            # If this is a symmetrical m2m relation on self, there is no reverse accessor. 
    5757            if getattr(self.field.rel, 'symmetrical', False) and self.model == self.parent_model: 
    5858                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') 
    6060        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) 
    6262 
    6363    def get_cache_name(self): 
    6464        return "_%s_cache" % self.get_accessor_name() 
  • django/views/generic/detail.py

    diff --git a/django/views/generic/detail.py b/django/views/generic/detail.py
    index c27b92b..27215fe 100644
    a b class SingleObjectMixin(ContextMixin): 
    8484        if self.context_object_name: 
    8585            return self.context_object_name 
    8686        elif isinstance(obj, models.Model): 
    87             return obj._meta.object_name.lower() 
     87            return obj._meta.module_name 
    8888        else: 
    8989            return None 
    9090 
    class SingleObjectTemplateResponseMixin(TemplateResponseMixin): 
    144144        if isinstance(self.object, models.Model): 
    145145            names.append("%s/%s%s.html" % ( 
    146146                self.object._meta.app_label, 
    147                 self.object._meta.object_name.lower(), 
     147                self.object._meta.module_name, 
    148148                self.template_name_suffix 
    149149            )) 
    150150        elif hasattr(self, 'model') and self.model is not None and issubclass(self.model, models.Model): 
    151151            names.append("%s/%s%s.html" % ( 
    152152                self.model._meta.app_label, 
    153                 self.model._meta.object_name.lower(), 
     153                self.model._meta.module_name, 
    154154                self.template_name_suffix 
    155155            )) 
    156156        return names 
  • django/views/generic/list.py

    diff --git a/django/views/generic/list.py b/django/views/generic/list.py
    index 1f28616..48f7783 100644
    a b class MultipleObjectMixin(ContextMixin): 
    9797        if self.context_object_name: 
    9898            return self.context_object_name 
    9999        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 
    101101        else: 
    102102            return None 
    103103 
    class MultipleObjectTemplateResponseMixin(TemplateResponseMixin): 
    177177        # generated ones. 
    178178        if hasattr(self.object_list, 'model'): 
    179179            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)) 
    181181 
    182182        return names 
    183183