Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed various unnecessary instances of mark_safe applied to URLs

Also fixed some test breakages introduced in last commit
  • Loading branch information...
commit b0eee0ba4bcc15c767a64794caff9d233f12a5d5 1 parent a92e7f3
Luke Plant authored July 03, 2012
3  django/contrib/admin/models.py
@@ -6,7 +6,6 @@
6 6
 from django.contrib.admin.util import quote
7 7
 from django.utils.translation import ugettext_lazy as _
8 8
 from django.utils.encoding import smart_unicode
9  
-from django.utils.safestring import mark_safe
10 9
 
11 10
 ADDITION = 1
12 11
 CHANGE = 2
@@ -66,5 +65,5 @@ def get_admin_url(self):
66 65
         This is relative to the Django admin index page.
67 66
         """
68 67
         if self.content_type and self.object_id:
69  
-            return mark_safe("%s/%s/%s/" % (self.content_type.app_label, self.content_type.model, quote(self.object_id)))
  68
+            return "%s/%s/%s/" % (self.content_type.app_label, self.content_type.model, quote(self.object_id))
70 69
         return None
2  django/contrib/admin/options.py
@@ -745,7 +745,7 @@ def render_change_form(self, request, context, add=False, change=False, form_url
745 745
             'has_file_field': True, # FIXME - this should check if form or formsets have a FileField,
746 746
             'has_absolute_url': hasattr(self.model, 'get_absolute_url'),
747 747
             'ordered_objects': ordered_objects,
748  
-            'form_url': mark_safe(form_url),
  748
+            'form_url': form_url,
749 749
             'opts': opts,
750 750
             'content_type_id': ContentType.objects.get_for_model(self.model).id,
751 751
             'save_as': self.save_as,
2  django/contrib/admindocs/templates/admin_doc/bookmarklets.html
@@ -22,7 +22,7 @@
22 22
 {% endblocktrans %}
23 23
 
24 24
 <div id="content-main">
25  
-    <h3><a href="javascript:(function(){if(typeof ActiveXObject!='undefined'){x=new ActiveXObject('Microsoft.XMLHTTP')}else if(typeof XMLHttpRequest!='undefined'){x=new XMLHttpRequest()}else{return;}x.open('HEAD',location.href,false);x.send(null);try{view=x.getResponseHeader('x-view');}catch(e){alert('No view found for this page');return;}if(view=='undefined'){alert('No view found for this page');}document.location='{{ admin_url }}doc/views/'+view+'/';})()">{% trans "Documentation for this page" %}</a></h3>
  25
+    <h3><a href="javascript:(function(){if(typeof ActiveXObject!='undefined'){x=new ActiveXObject('Microsoft.XMLHTTP')}else if(typeof XMLHttpRequest!='undefined'){x=new XMLHttpRequest()}else{return;}x.open('HEAD',location.href,false);x.send(null);try{view=x.getResponseHeader('x-view');}catch(e){alert('No view found for this page');return;}if(view=='undefined'){alert('No view found for this page');}document.location='{{ admin_url|escapejs }}doc/views/'+view+'/';})()">{% trans "Documentation for this page" %}</a></h3>
26 26
     <p>{% trans "Jumps you from any page to the documentation for the view that generates that page." %}</p>
27 27
 
28 28
     <h3><a href="javascript:(function(){if(typeof ActiveXObject!='undefined'){x=new ActiveXObject('Microsoft.XMLHTTP')}else if(typeof XMLHttpRequest!='undefined'){x=new XMLHttpRequest()}else{return;}x.open('GET',location.href,false);x.send(null);try{type=x.getResponseHeader('x-object-type');id=x.getResponseHeader('x-object-id');}catch(e){type='(none)';id='(none)';}d=document;b=d.body;e=d.createElement('div');e.id='xxxhhh';s=e.style;s.position='absolute';s.left='10px';s.top='10px';s.font='10px monospace';s.border='1px black solid';s.padding='4px';s.backgroundColor='#eee';e.appendChild(d.createTextNode('Type: '+type));e.appendChild(d.createElement('br'));e.appendChild(d.createTextNode('ID: '+id));e.appendChild(d.createElement('br'));l=d.createElement('a');l.href='#';l.onclick=function(){b.removeChild(e);};l.appendChild(d.createTextNode('[close]'));l.style.textDecoration='none';e.appendChild(l);b.appendChild(e);})();">{% trans "Show object ID" %}</a></h3>
2  django/contrib/admindocs/views.py
@@ -37,7 +37,7 @@ def bookmarklets(request):
37 37
     admin_root = urlresolvers.reverse('admin:index')
38 38
     return render_to_response('admin_doc/bookmarklets.html', {
39 39
         'root_path': admin_root,
40  
-        'admin_url': mark_safe("%s://%s%s" % (request.is_secure() and 'https' or 'http', request.get_host(), admin_root)),
  40
+        'admin_url': "%s://%s%s" % (request.is_secure() and 'https' or 'http', request.get_host(), admin_root),
41 41
     }, context_instance=RequestContext(request))
42 42
 
43 43
 @staff_member_required
2  django/contrib/auth/admin.py
@@ -134,7 +134,7 @@ def user_change_password(self, request, id, form_url=''):
134 134
         context = {
135 135
             'title': _('Change password: %s') % escape(user.username),
136 136
             'adminForm': adminForm,
137  
-            'form_url': mark_safe(form_url),
  137
+            'form_url': form_url,
138 138
             'form': form,
139 139
             'is_popup': '_popup' in request.REQUEST,
140 140
             'add': True,
15  django/contrib/databrowse/datastructures.py
@@ -8,7 +8,6 @@
8 8
 from django.utils import formats
9 9
 from django.utils.text import capfirst
10 10
 from django.utils.encoding import smart_unicode, smart_str, iri_to_uri
11  
-from django.utils.safestring import mark_safe
12 11
 from django.db.models.query import QuerySet
13 12
 
14 13
 EMPTY_VALUE = '(None)'
@@ -30,7 +29,7 @@ def model_databrowse(self):
30 29
         return self.site.registry[self.model]
31 30
 
32 31
     def url(self):
33  
-        return mark_safe('%s%s/%s/' % (self.site.root_url, self.model._meta.app_label, self.model._meta.module_name))
  32
+        return '%s%s/%s/' % (self.site.root_url, self.model._meta.app_label, self.model._meta.module_name)
34 33
 
35 34
     def objects(self, **kwargs):
36 35
         return self.get_query_set().filter(**kwargs)
@@ -70,9 +69,9 @@ def choices(self):
70 69
 
71 70
     def url(self):
72 71
         if self.field.choices:
73  
-            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))
  72
+            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)
74 73
         elif self.field.rel:
75  
-            return mark_safe('%s%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name))
  74
+            return '%s%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name)
76 75
 
77 76
 class EasyChoice(object):
78 77
     def __init__(self, easy_model, field, value, label):
@@ -83,7 +82,7 @@ def __repr__(self):
83 82
         return smart_str('<EasyChoice for %s.%s>' % (self.model.model._meta.object_name, self.field.name))
84 83
 
85 84
     def url(self):
86  
-        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)))
  85
+        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))
87 86
 
88 87
 class EasyInstance(object):
89 88
     def __init__(self, easy_model, instance):
@@ -105,7 +104,7 @@ def pk(self):
105 104
         return self.instance._get_pk_val()
106 105
 
107 106
     def url(self):
108  
-        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())))
  107
+        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()))
109 108
 
110 109
     def fields(self):
111 110
         """
@@ -187,14 +186,14 @@ def urls(self):
187 186
                 for value in self.values():
188 187
                     if value is None:
189 188
                         continue
190  
-                    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())))
  189
+                    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()))
191 190
                     lst.append((smart_unicode(value), url))
192 191
             else:
193 192
                 lst = [(value, None) for value in self.values()]
194 193
         elif self.field.choices:
195 194
             lst = []
196 195
             for value in self.values():
197  
-                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)))
  196
+                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))
198 197
                 lst.append((value, url))
199 198
         elif isinstance(self.field, models.URLField):
200 199
             val = self.values()[0]
5  django/contrib/databrowse/plugins/calendars.py
@@ -8,7 +8,6 @@
8 8
 from django.utils.html import format_html, format_html_join
9 9
 from django.utils.text import capfirst
10 10
 from django.utils.encoding import force_unicode
11  
-from django.utils.safestring import mark_safe
12 11
 from django.views.generic import dates
13 12
 from django.utils import datetime_safe
14 13
 
@@ -72,12 +71,12 @@ def model_index_html(self, request, model, site):
72 71
     def urls(self, plugin_name, easy_instance_field):
73 72
         if isinstance(easy_instance_field.field, models.DateField):
74 73
             d = easy_instance_field.raw_value
75  
-            return [mark_safe('%s%s/%s/%s/%s/%s/' % (
  74
+            return ['%s%s/%s/%s/%s/%s/' % (
76 75
                 easy_instance_field.model.url(),
77 76
                 plugin_name, easy_instance_field.field.name,
78 77
                 str(d.year),
79 78
                 datetime_safe.new_date(d).strftime('%b').lower(),
80  
-                d.day))]
  79
+                d.day)]
81 80
 
82 81
     def model_view(self, request, model_databrowse, url):
83 82
         self.model, self.site = model_databrowse.model, model_databrowse.site
5  django/contrib/databrowse/plugins/fieldchoices.py
@@ -8,7 +8,6 @@
8 8
 from django.utils.html import format_html, format_html_join
9 9
 from django.utils.text import capfirst
10 10
 from django.utils.encoding import smart_str, force_unicode
11  
-from django.utils.safestring import mark_safe
12 11
 import urllib
13 12
 
14 13
 class FieldChoicePlugin(DatabrowsePlugin):
@@ -40,10 +39,10 @@ def model_index_html(self, request, model, site):
40 39
     def urls(self, plugin_name, easy_instance_field):
41 40
         if easy_instance_field.field in self.field_dict(easy_instance_field.model.model).values():
42 41
             field_value = smart_str(easy_instance_field.raw_value)
43  
-            return [mark_safe('%s%s/%s/%s/' % (
  42
+            return ['%s%s/%s/%s/' % (
44 43
                 easy_instance_field.model.url(),
45 44
                 plugin_name, easy_instance_field.field.name,
46  
-                urllib.quote(field_value, safe='')))]
  45
+                urllib.quote(field_value, safe=''))]
47 46
 
48 47
     def model_view(self, request, model_databrowse, url):
49 48
         self.model, self.site = model_databrowse.model, model_databrowse.site
4  django/contrib/gis/maps/google/gmap.py
@@ -11,7 +11,7 @@ class GoogleMapException(Exception):
11 11
 
12 12
 # The default Google Maps URL (for the API javascript)
13 13
 # TODO: Internationalize for Japan, UK, etc.
14  
-GOOGLE_MAPS_URL='http://maps.google.com/maps?file=api&amp;v=%s&amp;key='
  14
+GOOGLE_MAPS_URL='http://maps.google.com/maps?file=api&v=%s&key='
15 15
 
16 16
 
17 17
 class GoogleMap(object):
@@ -49,7 +49,7 @@ def __init__(self, key=None, api_url=None, version=None,
49 49
 
50 50
         # Can specify the API URL in the `api_url` keyword.
51 51
         if not api_url:
52  
-            self.api_url = mark_safe(getattr(settings, 'GOOGLE_MAPS_URL', GOOGLE_MAPS_URL) % self.version)
  52
+            self.api_url = getattr(settings, 'GOOGLE_MAPS_URL', GOOGLE_MAPS_URL) % self.version
53 53
         else:
54 54
             self.api_url = api_url
55 55
 
8  tests/regressiontests/admin_views/tests.py
@@ -1369,19 +1369,19 @@ def test_get_change_view(self):
1369 1369
     def test_changelist_to_changeform_link(self):
1370 1370
         "The link from the changelist referring to the changeform of the object should be quoted"
1371 1371
         response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/')
1372  
-        should_contain = """<th><a href="%s/">%s</a></th></tr>""" % (quote(self.pk), escape(self.pk))
  1372
+        should_contain = """<th><a href="%s/">%s</a></th></tr>""" % (escape(quote(self.pk)), escape(self.pk))
1373 1373
         self.assertContains(response, should_contain)
1374 1374
 
1375 1375
     def test_recentactions_link(self):
1376 1376
         "The link from the recent actions list referring to the changeform of the object should be quoted"
1377 1377
         response = self.client.get('/test_admin/admin/')
1378  
-        should_contain = """<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>""" % (quote(self.pk), escape(self.pk))
  1378
+        should_contain = """<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>""" % (escape(quote(self.pk)), escape(self.pk))
1379 1379
         self.assertContains(response, should_contain)
1380 1380
 
1381 1381
     def test_recentactions_without_content_type(self):
1382 1382
         "If a LogEntry is missing content_type it will not display it in span tag under the hyperlink."
1383 1383
         response = self.client.get('/test_admin/admin/')
1384  
-        should_contain = """<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>""" % (quote(self.pk), escape(self.pk))
  1384
+        should_contain = """<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>""" % (escape(quote(self.pk)), escape(self.pk))
1385 1385
         self.assertContains(response, should_contain)
1386 1386
         should_contain = "Model with string primary key" # capitalized in Recent Actions
1387 1387
         self.assertContains(response, should_contain)
@@ -1402,7 +1402,7 @@ def test_deleteconfirmation_link(self):
1402 1402
         "The link from the delete confirmation page referring back to the changeform of the object should be quoted"
1403 1403
         response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/delete/' % quote(self.pk))
1404 1404
         # this URL now comes through reverse(), thus iri_to_uri encoding
1405  
-        should_contain = """/%s/">%s</a>""" % (iri_to_uri(quote(self.pk)), escape(self.pk))
  1405
+        should_contain = """/%s/">%s</a>""" % (escape(iri_to_uri(quote(self.pk))), escape(self.pk))
1406 1406
         self.assertContains(response, should_contain)
1407 1407
 
1408 1408
     def test_url_conflicts_with_add(self):

0 notes on commit b0eee0b

Please sign in to comment.
Something went wrong with that request. Please try again.