From b0eee0ba4bcc15c767a64794caff9d233f12a5d5 Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Tue, 3 Jul 2012 00:33:44 +0100 Subject: [PATCH] Removed various unnecessary instances of mark_safe applied to URLs Also fixed some test breakages introduced in last commit --- django/contrib/admin/models.py | 3 +-- django/contrib/admin/options.py | 2 +- .../templates/admin_doc/bookmarklets.html | 2 +- django/contrib/admindocs/views.py | 2 +- django/contrib/auth/admin.py | 2 +- django/contrib/databrowse/datastructures.py | 15 +++++++-------- django/contrib/databrowse/plugins/calendars.py | 5 ++--- django/contrib/databrowse/plugins/fieldchoices.py | 5 ++--- django/contrib/gis/maps/google/gmap.py | 4 ++-- tests/regressiontests/admin_views/tests.py | 8 ++++---- 10 files changed, 22 insertions(+), 26 deletions(-) diff --git a/django/contrib/admin/models.py b/django/contrib/admin/models.py index 93d8f307c0..58bbbabfdf 100644 --- a/django/contrib/admin/models.py +++ b/django/contrib/admin/models.py @@ -6,7 +6,6 @@ from django.contrib.auth.models import User from django.contrib.admin.util import quote from django.utils.translation import ugettext_lazy as _ from django.utils.encoding import smart_unicode -from django.utils.safestring import mark_safe ADDITION = 1 CHANGE = 2 @@ -66,5 +65,5 @@ class LogEntry(models.Model): This is relative to the Django admin index page. """ if self.content_type and self.object_id: - return mark_safe("%s/%s/%s/" % (self.content_type.app_label, self.content_type.model, quote(self.object_id))) + return "%s/%s/%s/" % (self.content_type.app_label, self.content_type.model, quote(self.object_id)) return None diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 665e3f76b8..4d23f8f384 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -745,7 +745,7 @@ class ModelAdmin(BaseModelAdmin): 'has_file_field': True, # FIXME - this should check if form or formsets have a FileField, 'has_absolute_url': hasattr(self.model, 'get_absolute_url'), 'ordered_objects': ordered_objects, - 'form_url': mark_safe(form_url), + 'form_url': form_url, 'opts': opts, 'content_type_id': ContentType.objects.get_for_model(self.model).id, 'save_as': self.save_as, diff --git a/django/contrib/admindocs/templates/admin_doc/bookmarklets.html b/django/contrib/admindocs/templates/admin_doc/bookmarklets.html index cde285481d..819beea326 100644 --- a/django/contrib/admindocs/templates/admin_doc/bookmarklets.html +++ b/django/contrib/admindocs/templates/admin_doc/bookmarklets.html @@ -22,7 +22,7 @@ your computer is "internal").

{% endblocktrans %}
-

{% trans "Documentation for this page" %}

+

{% trans "Documentation for this page" %}

{% trans "Jumps you from any page to the documentation for the view that generates that page." %}

{% trans "Show object ID" %}

diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py index aad698836e..5649398cc8 100644 --- a/django/contrib/admindocs/views.py +++ b/django/contrib/admindocs/views.py @@ -37,7 +37,7 @@ def bookmarklets(request): admin_root = urlresolvers.reverse('admin:index') return render_to_response('admin_doc/bookmarklets.html', { 'root_path': admin_root, - 'admin_url': mark_safe("%s://%s%s" % (request.is_secure() and 'https' or 'http', request.get_host(), admin_root)), + 'admin_url': "%s://%s%s" % (request.is_secure() and 'https' or 'http', request.get_host(), admin_root), }, context_instance=RequestContext(request)) @staff_member_required diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py index f14b3d219b..ad61904041 100644 --- a/django/contrib/auth/admin.py +++ b/django/contrib/auth/admin.py @@ -134,7 +134,7 @@ class UserAdmin(admin.ModelAdmin): context = { 'title': _('Change password: %s') % escape(user.username), 'adminForm': adminForm, - 'form_url': mark_safe(form_url), + 'form_url': form_url, 'form': form, 'is_popup': '_popup' in request.REQUEST, 'add': True, diff --git a/django/contrib/databrowse/datastructures.py b/django/contrib/databrowse/datastructures.py index 6a78b3688b..687aa87f03 100644 --- a/django/contrib/databrowse/datastructures.py +++ b/django/contrib/databrowse/datastructures.py @@ -8,7 +8,6 @@ from django.db import models from django.utils import formats from django.utils.text import capfirst from django.utils.encoding import smart_unicode, smart_str, iri_to_uri -from django.utils.safestring import mark_safe from django.db.models.query import QuerySet EMPTY_VALUE = '(None)' @@ -30,7 +29,7 @@ class EasyModel(object): return self.site.registry[self.model] def url(self): - return mark_safe('%s%s/%s/' % (self.site.root_url, self.model._meta.app_label, self.model._meta.module_name)) + return '%s%s/%s/' % (self.site.root_url, self.model._meta.app_label, self.model._meta.module_name) def objects(self, **kwargs): return self.get_query_set().filter(**kwargs) @@ -70,9 +69,9 @@ class EasyField(object): def url(self): if self.field.choices: - return mark_safe('%s%s/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.name)) + return '%s%s/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.name) elif self.field.rel: - return mark_safe('%s%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name)) + return '%s%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name) class EasyChoice(object): def __init__(self, easy_model, field, value, label): @@ -83,7 +82,7 @@ class EasyChoice(object): return smart_str('' % (self.model.model._meta.object_name, self.field.name)) def url(self): - return mark_safe('%s%s/%s/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.field.name, iri_to_uri(self.value))) + return '%s%s/%s/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.field.name, iri_to_uri(self.value)) class EasyInstance(object): def __init__(self, easy_model, instance): @@ -105,7 +104,7 @@ class EasyInstance(object): return self.instance._get_pk_val() def url(self): - return mark_safe('%s%s/%s/objects/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, iri_to_uri(self.pk()))) + return '%s%s/%s/objects/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, iri_to_uri(self.pk())) def fields(self): """ @@ -187,14 +186,14 @@ class EasyInstanceField(object): for value in self.values(): if value is None: continue - url = mark_safe('%s%s/%s/objects/%s/' % (self.model.site.root_url, m.model._meta.app_label, m.model._meta.module_name, iri_to_uri(value._get_pk_val()))) + url = '%s%s/%s/objects/%s/' % (self.model.site.root_url, m.model._meta.app_label, m.model._meta.module_name, iri_to_uri(value._get_pk_val())) lst.append((smart_unicode(value), url)) else: lst = [(value, None) for value in self.values()] elif self.field.choices: lst = [] for value in self.values(): - url = mark_safe('%s%s/%s/fields/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.name, iri_to_uri(self.raw_value))) + url = '%s%s/%s/fields/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.name, iri_to_uri(self.raw_value)) lst.append((value, url)) elif isinstance(self.field, models.URLField): val = self.values()[0] diff --git a/django/contrib/databrowse/plugins/calendars.py b/django/contrib/databrowse/plugins/calendars.py index c842498934..7bdd1e0032 100644 --- a/django/contrib/databrowse/plugins/calendars.py +++ b/django/contrib/databrowse/plugins/calendars.py @@ -8,7 +8,6 @@ from django.shortcuts import render_to_response from django.utils.html import format_html, format_html_join from django.utils.text import capfirst from django.utils.encoding import force_unicode -from django.utils.safestring import mark_safe from django.views.generic import dates from django.utils import datetime_safe @@ -72,12 +71,12 @@ class CalendarPlugin(DatabrowsePlugin): def urls(self, plugin_name, easy_instance_field): if isinstance(easy_instance_field.field, models.DateField): d = easy_instance_field.raw_value - return [mark_safe('%s%s/%s/%s/%s/%s/' % ( + return ['%s%s/%s/%s/%s/%s/' % ( easy_instance_field.model.url(), plugin_name, easy_instance_field.field.name, str(d.year), datetime_safe.new_date(d).strftime('%b').lower(), - d.day))] + d.day)] def model_view(self, request, model_databrowse, url): self.model, self.site = model_databrowse.model, model_databrowse.site diff --git a/django/contrib/databrowse/plugins/fieldchoices.py b/django/contrib/databrowse/plugins/fieldchoices.py index f3bd829e61..4b1f0e6614 100644 --- a/django/contrib/databrowse/plugins/fieldchoices.py +++ b/django/contrib/databrowse/plugins/fieldchoices.py @@ -8,7 +8,6 @@ from django.shortcuts import render_to_response from django.utils.html import format_html, format_html_join from django.utils.text import capfirst from django.utils.encoding import smart_str, force_unicode -from django.utils.safestring import mark_safe import urllib class FieldChoicePlugin(DatabrowsePlugin): @@ -40,10 +39,10 @@ class FieldChoicePlugin(DatabrowsePlugin): def urls(self, plugin_name, easy_instance_field): if easy_instance_field.field in self.field_dict(easy_instance_field.model.model).values(): field_value = smart_str(easy_instance_field.raw_value) - return [mark_safe('%s%s/%s/%s/' % ( + return ['%s%s/%s/%s/' % ( easy_instance_field.model.url(), plugin_name, easy_instance_field.field.name, - urllib.quote(field_value, safe='')))] + urllib.quote(field_value, safe=''))] def model_view(self, request, model_databrowse, url): self.model, self.site = model_databrowse.model, model_databrowse.site diff --git a/django/contrib/gis/maps/google/gmap.py b/django/contrib/gis/maps/google/gmap.py index 49515c0dce..72c50eab0f 100644 --- a/django/contrib/gis/maps/google/gmap.py +++ b/django/contrib/gis/maps/google/gmap.py @@ -11,7 +11,7 @@ class GoogleMapException(Exception): # The default Google Maps URL (for the API javascript) # TODO: Internationalize for Japan, UK, etc. -GOOGLE_MAPS_URL='http://maps.google.com/maps?file=api&v=%s&key=' +GOOGLE_MAPS_URL='http://maps.google.com/maps?file=api&v=%s&key=' class GoogleMap(object): @@ -49,7 +49,7 @@ class GoogleMap(object): # Can specify the API URL in the `api_url` keyword. if not api_url: - self.api_url = mark_safe(getattr(settings, 'GOOGLE_MAPS_URL', GOOGLE_MAPS_URL) % self.version) + self.api_url = getattr(settings, 'GOOGLE_MAPS_URL', GOOGLE_MAPS_URL) % self.version else: self.api_url = api_url diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 937b086d40..49ec3c1945 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -1369,19 +1369,19 @@ class AdminViewStringPrimaryKeyTest(TestCase): def test_changelist_to_changeform_link(self): "The link from the changelist referring to the changeform of the object should be quoted" response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/') - should_contain = """%s""" % (quote(self.pk), escape(self.pk)) + should_contain = """%s""" % (escape(quote(self.pk)), escape(self.pk)) self.assertContains(response, should_contain) def test_recentactions_link(self): "The link from the recent actions list referring to the changeform of the object should be quoted" response = self.client.get('/test_admin/admin/') - should_contain = """%s""" % (quote(self.pk), escape(self.pk)) + should_contain = """%s""" % (escape(quote(self.pk)), escape(self.pk)) self.assertContains(response, should_contain) def test_recentactions_without_content_type(self): "If a LogEntry is missing content_type it will not display it in span tag under the hyperlink." response = self.client.get('/test_admin/admin/') - should_contain = """%s""" % (quote(self.pk), escape(self.pk)) + should_contain = """%s""" % (escape(quote(self.pk)), escape(self.pk)) self.assertContains(response, should_contain) should_contain = "Model with string primary key" # capitalized in Recent Actions self.assertContains(response, should_contain) @@ -1402,7 +1402,7 @@ class AdminViewStringPrimaryKeyTest(TestCase): "The link from the delete confirmation page referring back to the changeform of the object should be quoted" response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/delete/' % quote(self.pk)) # this URL now comes through reverse(), thus iri_to_uri encoding - should_contain = """/%s/">%s""" % (iri_to_uri(quote(self.pk)), escape(self.pk)) + should_contain = """/%s/">%s""" % (escape(iri_to_uri(quote(self.pk))), escape(self.pk)) self.assertContains(response, should_contain) def test_url_conflicts_with_add(self):