Permalink
Browse files

Fixed #19689 -- Renamed `Model._meta.module_name` to `model_name`.

  • Loading branch information...
1 parent 826d9de commit ec469ade2b04b94bfeb59fb0fc7d9300470be615 @charettes charettes committed Feb 5, 2013
@@ -75,7 +75,7 @@ def delete_selected(modeladmin, request, queryset):
# Display the confirmation page
return TemplateResponse(request, modeladmin.delete_selected_confirmation_template or [
- "admin/%s/%s/delete_selected_confirmation.html" % (app_label, opts.object_name.lower()),
+ "admin/%s/%s/delete_selected_confirmation.html" % (app_label, opts.model_name),
"admin/%s/delete_selected_confirmation.html" % app_label,
"admin/delete_selected_confirmation.html"
], context, current_app=modeladmin.admin_site.name)
@@ -371,7 +371,7 @@ def wrapper(*args, **kwargs):
return self.admin_site.admin_view(view)(*args, **kwargs)
return update_wrapper(wrapper, view)
- info = self.model._meta.app_label, self.model._meta.module_name
+ info = self.model._meta.app_label, self.model._meta.model_name
urlpatterns = patterns('',
url(r'^$',
@@ -783,7 +783,7 @@ def render_change_form(self, request, context, add=False, change=False, form_url
form_template = self.change_form_template
return TemplateResponse(request, form_template or [
- "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
+ "admin/%s/%s/change_form.html" % (app_label, opts.model_name),
"admin/%s/change_form.html" % app_label,
"admin/change_form.html"
], context, current_app=self.admin_site.name)
@@ -803,7 +803,7 @@ def response_add(self, request, obj, post_url_continue=None):
self.message_user(request, msg)
if post_url_continue is None:
post_url_continue = reverse('admin:%s_%s_change' %
- (opts.app_label, opts.module_name),
+ (opts.app_label, opts.model_name),
args=(pk_value,),
current_app=self.admin_site.name)
if "_popup" in request.POST:
@@ -845,14 +845,14 @@ def response_change(self, request, obj):
msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict
self.message_user(request, msg)
return HttpResponseRedirect(reverse('admin:%s_%s_change' %
- (opts.app_label, opts.module_name),
+ (opts.app_label, opts.model_name),
args=(pk_value,),
current_app=self.admin_site.name))
elif "_addanother" in request.POST:
msg = _('The %(name)s "%(obj)s" was changed successfully. You may add another %(name)s below.') % msg_dict
self.message_user(request, msg)
return HttpResponseRedirect(reverse('admin:%s_%s_add' %
- (opts.app_label, opts.module_name),
+ (opts.app_label, opts.model_name),
current_app=self.admin_site.name))
else:
msg = _('The %(name)s "%(obj)s" was changed successfully.') % msg_dict
@@ -867,7 +867,7 @@ def response_post_save_add(self, request, obj):
opts = self.model._meta
if self.has_change_permission(request, None):
post_url = reverse('admin:%s_%s_changelist' %
- (opts.app_label, opts.module_name),
+ (opts.app_label, opts.model_name),
current_app=self.admin_site.name)
else:
post_url = reverse('admin:index',
@@ -882,7 +882,7 @@ def response_post_save_change(self, request, obj):
opts = self.model._meta
if self.has_change_permission(request, None):
post_url = reverse('admin:%s_%s_changelist' %
- (opts.app_label, opts.module_name),
+ (opts.app_label, opts.model_name),
current_app=self.admin_site.name)
else:
post_url = reverse('admin:index',
@@ -1060,7 +1060,7 @@ def change_view(self, request, object_id, form_url='', extra_context=None):
if request.method == 'POST' and "_saveasnew" in request.POST:
return self.add_view(request, form_url=reverse('admin:%s_%s_add' %
- (opts.app_label, opts.module_name),
+ (opts.app_label, opts.model_name),
current_app=self.admin_site.name))
ModelForm = self.get_form(request, obj)
@@ -1283,7 +1283,7 @@ def changelist_view(self, request, extra_context=None):
context.update(extra_context or {})
return TemplateResponse(request, self.change_list_template or [
- 'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
+ 'admin/%s/%s/change_list.html' % (app_label, opts.model_name),
'admin/%s/change_list.html' % app_label,
'admin/change_list.html'
], context, current_app=self.admin_site.name)
@@ -1323,7 +1323,7 @@ def delete_view(self, request, object_id, extra_context=None):
return HttpResponseRedirect(reverse('admin:index',
current_app=self.admin_site.name))
return HttpResponseRedirect(reverse('admin:%s_%s_changelist' %
- (opts.app_label, opts.module_name),
+ (opts.app_label, opts.model_name),
current_app=self.admin_site.name))
object_name = force_text(opts.verbose_name)
@@ -1346,7 +1346,7 @@ def delete_view(self, request, object_id, extra_context=None):
context.update(extra_context or {})
return TemplateResponse(request, self.delete_confirmation_template or [
- "admin/%s/%s/delete_confirmation.html" % (app_label, opts.object_name.lower()),
+ "admin/%s/%s/delete_confirmation.html" % (app_label, opts.model_name),
"admin/%s/delete_confirmation.html" % app_label,
"admin/delete_confirmation.html"
], context, current_app=self.admin_site.name)
@@ -1373,7 +1373,7 @@ def history_view(self, request, object_id, extra_context=None):
}
context.update(extra_context or {})
return TemplateResponse(request, self.object_history_template or [
- "admin/%s/%s/object_history.html" % (app_label, opts.object_name.lower()),
+ "admin/%s/%s/object_history.html" % (app_label, opts.model_name),
"admin/%s/object_history.html" % app_label,
"admin/object_history.html"
], context, current_app=self.admin_site.name)
@@ -247,7 +247,7 @@ def wrapper(*args, **kwargs):
# Add in each model's views.
for model, model_admin in six.iteritems(self._registry):
urlpatterns += patterns('',
- url(r'^%s/%s/' % (model._meta.app_label, model._meta.module_name),
+ url(r'^%s/%s/' % (model._meta.app_label, model._meta.model_name),
include(model_admin.urls))
)
return urlpatterns
@@ -351,7 +351,7 @@ def index(self, request, extra_context=None):
# Check whether user has any perm for this module.
# If so, add the module to the model_list.
if True in perms.values():
- info = (app_label, model._meta.module_name)
+ info = (app_label, model._meta.model_name)
model_dict = {
'name': capfirst(model._meta.verbose_name_plural),
'object_name': model._meta.object_name,
@@ -407,7 +407,7 @@ def app_index(self, request, app_label, extra_context=None):
# Check whether user has any perm for this module.
# If so, add the module to the model_list.
if True in perms.values():
- info = (app_label, model._meta.module_name)
+ info = (app_label, model._meta.model_name)
model_dict = {
'name': capfirst(model._meta.verbose_name_plural),
'object_name': model._meta.object_name,
@@ -19,7 +19,7 @@
{% endblock %}
{% endif %}
{% block content %}<div id="content-main">
-<form action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
+<form action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
<div>
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
{% if form.errors %}
@@ -35,7 +35,7 @@
</ul>
{% endif %}{% endif %}
{% endblock %}
-<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
+<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
<div>
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
{% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %}
@@ -1,12 +1,11 @@
-from django.core.urlresolvers import reverse
from django import template
from django.contrib.admin.util import quote
register = template.Library()
@register.filter
def admin_urlname(value, arg):
- return 'admin:%s_%s_%s' % (value.app_label, value.module_name, arg)
+ return 'admin:%s_%s_%s' % (value.app_label, value.model_name, arg)
@register.filter
@@ -116,7 +116,7 @@ def format_callback(obj):
admin_url = reverse('%s:%s_%s_change'
% (admin_site.name,
opts.app_label,
- opts.object_name.lower()),
+ opts.model_name),
None, (quote(obj._get_pk_val()),))
p = '%s.%s' % (opts.app_label,
opts.get_delete_permission())
@@ -379,6 +379,6 @@ def construct_search(field_name):
def url_for_result(self, result):
pk = getattr(result, self.pk_attname)
return reverse('admin:%s_%s_change' % (self.opts.app_label,
- self.opts.module_name),
+ self.opts.model_name),
args=(quote(pk),),
current_app=self.model_admin.admin_site.name)
@@ -147,7 +147,7 @@ def render(self, name, value, attrs=None):
# The related object is registered with the same AdminSite
related_url = reverse('admin:%s_%s_changelist' %
(rel_to._meta.app_label,
- rel_to._meta.module_name),
+ rel_to._meta.model_name),
current_app=self.admin_site.name)
params = self.url_parameters()
@@ -247,7 +247,7 @@ def media(self):
def render(self, name, value, *args, **kwargs):
rel_to = self.rel.to
- info = (rel_to._meta.app_label, rel_to._meta.object_name.lower())
+ info = (rel_to._meta.app_label, rel_to._meta.model_name)
self.widget.choices = self.choices
output = [self.widget.render(name, value, *args, **kwargs)]
if self.can_add_related:
@@ -189,7 +189,7 @@ def model_detail(request, app_label, model_name):
raise Http404(_("App %r not found") % app_label)
model = None
for m in models.get_models(app_mod):
- if m._meta.object_name.lower() == model_name:
+ if m._meta.model_name == model_name:
model = m
break
if model is None:
@@ -224,12 +224,12 @@ def model_detail(request, app_label, model_name):
fields.append({
'name': "%s.all" % field.name,
"data_type": 'List',
- 'verbose': utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.module_name),
+ 'verbose': utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.model_name),
})
fields.append({
'name' : "%s.count" % field.name,
'data_type' : 'Integer',
- 'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.module_name),
+ 'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.model_name),
})
# Gather model methods.
@@ -243,7 +243,7 @@ def model_detail(request, app_label, model_name):
continue
verbose = func.__doc__
if verbose:
- verbose = utils.parse_rst(utils.trim_docstring(verbose), 'model', _('model:') + opts.module_name)
+ verbose = utils.parse_rst(utils.trim_docstring(verbose), 'model', _('model:') + opts.model_name)
fields.append({
'name': func_name,
'data_type': get_return_data_type(func_name),
@@ -257,12 +257,12 @@ def model_detail(request, app_label, model_name):
fields.append({
'name' : "%s.all" % accessor,
'data_type' : 'List',
- 'verbose' : utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.module_name),
+ 'verbose' : utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.model_name),
})
fields.append({
'name' : "%s.count" % accessor,
'data_type' : 'Integer',
- 'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.module_name),
+ 'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.model_name),
})
return render_to_response('admin_doc/model_detail.html', {
'root_path': urlresolvers.reverse('admin:index'),
@@ -2,22 +2,22 @@
# the template system can understand.
class PermLookupDict(object):
- def __init__(self, user, module_name):
- self.user, self.module_name = user, module_name
+ def __init__(self, user, app_label):
+ self.user, self.app_label = user, app_label
def __repr__(self):
return str(self.user.get_all_permissions())
def __getitem__(self, perm_name):
- return self.user.has_perm("%s.%s" % (self.module_name, perm_name))
+ return self.user.has_perm("%s.%s" % (self.app_label, perm_name))
def __iter__(self):
# To fix 'item in perms.someapp' and __getitem__ iteraction we need to
# define __iter__. See #18979 for details.
raise TypeError("PermLookupDict is not iterable.")
def __bool__(self):
- return self.user.has_module_perms(self.module_name)
+ return self.user.has_module_perms(self.app_label)
def __nonzero__(self): # Python 2 compatibility
return type(self).__bool__(self)
@@ -27,8 +27,8 @@ class PermWrapper(object):
def __init__(self, user):
self.user = user
- def __getitem__(self, module_name):
- return PermLookupDict(self.user, module_name)
+ def __getitem__(self, app_label):
+ return PermLookupDict(self.user, app_label)
def __iter__(self):
# I am large, I contain multitudes.
@@ -41,8 +41,8 @@ def __contains__(self, perm_name):
if '.' not in perm_name:
# The name refers to module.
return bool(self[perm_name])
- module_name, perm_name = perm_name.split('.', 1)
- return self[module_name][perm_name]
+ app_label, perm_name = perm_name.split('.', 1)
+ return self[app_label][perm_name]
def auth(request):
@@ -17,7 +17,7 @@
def _get_permission_codename(action, opts):
- return '%s_%s' % (action, opts.object_name.lower())
+ return '%s_%s' % (action, opts.model_name)
def _get_all_permissions(opts, ctype):
@@ -302,7 +302,7 @@ def register(self, model_or_iterable, moderation_class):
model_or_iterable = [model_or_iterable]
for model in model_or_iterable:
if model in self._registry:
- raise AlreadyModerated("The model '%s' is already being moderated" % model._meta.module_name)
+ raise AlreadyModerated("The model '%s' is already being moderated" % model._meta.model_name)
self._registry[model] = moderation_class(model)
def unregister(self, model_or_iterable):
@@ -318,7 +318,7 @@ def unregister(self, model_or_iterable):
model_or_iterable = [model_or_iterable]
for model in model_or_iterable:
if model not in self._registry:
- raise NotModerated("The model '%s' is not currently being moderated" % model._meta.module_name)
+ raise NotModerated("The model '%s' is not currently being moderated" % model._meta.model_name)
del self._registry[model]
def pre_save_moderation(self, sender, comment, request, **kwargs):
@@ -86,10 +86,10 @@ def post_comment(request, next=None, using=None):
# These first two exist for purely historical reasons.
# Django v1.0 and v1.1 allowed the underscore format for
# preview templates, so we have to preserve that format.
- "comments/%s_%s_preview.html" % (model._meta.app_label, model._meta.module_name),
+ "comments/%s_%s_preview.html" % (model._meta.app_label, model._meta.model_name),
"comments/%s_preview.html" % model._meta.app_label,
# Now the usual directory based template hierarchy.
- "comments/%s/%s/preview.html" % (model._meta.app_label, model._meta.module_name),
+ "comments/%s/%s/preview.html" % (model._meta.app_label, model._meta.model_name),
"comments/%s/preview.html" % model._meta.app_label,
"comments/preview.html",
]
@@ -389,7 +389,7 @@ def __init__(self, data=None, files=None, instance=None, save_as_new=None,
opts = self.model._meta
self.instance = instance
self.rel_name = '-'.join((
- opts.app_label, opts.object_name.lower(),
+ opts.app_label, opts.model_name,
self.ct_field.name, self.ct_fk_field.name,
))
if self.instance is None or self.instance.pk is None:
@@ -409,7 +409,7 @@ def __init__(self, data=None, files=None, instance=None, save_as_new=None,
@classmethod
def get_default_prefix(cls):
opts = cls.model._meta
- return '-'.join((opts.app_label, opts.object_name.lower(),
+ return '-'.join((opts.app_label, opts.model_name,
cls.ct_field.name, cls.ct_fk_field.name,
))
@@ -21,7 +21,7 @@ def update_contenttypes(app, created_models, verbosity=2, db=DEFAULT_DB_ALIAS, *
# They all have the same app_label, get the first one.
app_label = app_models[0]._meta.app_label
app_models = dict(
- (model._meta.object_name.lower(), model)
+ (model._meta.model_name, model)
for model in app_models
)
Oops, something went wrong.

1 comment on commit ec469ad

Owner

timgraham commented on ec469ad Aug 4, 2013

Is model_name still considered private API? (#20853)

Please sign in to comment.