Removed various unnecessary instances of mark_safe applied to URLs
Also fixed some test breakages introduced in last commit
This commit is contained in:
parent
a92e7f37c4
commit
b0eee0ba4b
|
@ -6,7 +6,6 @@ from django.contrib.auth.models import User
|
||||||
from django.contrib.admin.util import quote
|
from django.contrib.admin.util import quote
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.utils.encoding import smart_unicode
|
from django.utils.encoding import smart_unicode
|
||||||
from django.utils.safestring import mark_safe
|
|
||||||
|
|
||||||
ADDITION = 1
|
ADDITION = 1
|
||||||
CHANGE = 2
|
CHANGE = 2
|
||||||
|
@ -66,5 +65,5 @@ class LogEntry(models.Model):
|
||||||
This is relative to the Django admin index page.
|
This is relative to the Django admin index page.
|
||||||
"""
|
"""
|
||||||
if self.content_type and self.object_id:
|
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
|
return None
|
||||||
|
|
|
@ -745,7 +745,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||||
'has_file_field': True, # FIXME - this should check if form or formsets have a FileField,
|
'has_file_field': True, # FIXME - this should check if form or formsets have a FileField,
|
||||||
'has_absolute_url': hasattr(self.model, 'get_absolute_url'),
|
'has_absolute_url': hasattr(self.model, 'get_absolute_url'),
|
||||||
'ordered_objects': ordered_objects,
|
'ordered_objects': ordered_objects,
|
||||||
'form_url': mark_safe(form_url),
|
'form_url': form_url,
|
||||||
'opts': opts,
|
'opts': opts,
|
||||||
'content_type_id': ContentType.objects.get_for_model(self.model).id,
|
'content_type_id': ContentType.objects.get_for_model(self.model).id,
|
||||||
'save_as': self.save_as,
|
'save_as': self.save_as,
|
||||||
|
|
|
@ -22,7 +22,7 @@ your computer is "internal").</p>
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
|
|
||||||
<div id="content-main">
|
<div id="content-main">
|
||||||
<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>
|
<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>
|
||||||
<p>{% trans "Jumps you from any page to the documentation for the view that generates that page." %}</p>
|
<p>{% trans "Jumps you from any page to the documentation for the view that generates that page." %}</p>
|
||||||
|
|
||||||
<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>
|
<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>
|
||||||
|
|
|
@ -37,7 +37,7 @@ def bookmarklets(request):
|
||||||
admin_root = urlresolvers.reverse('admin:index')
|
admin_root = urlresolvers.reverse('admin:index')
|
||||||
return render_to_response('admin_doc/bookmarklets.html', {
|
return render_to_response('admin_doc/bookmarklets.html', {
|
||||||
'root_path': admin_root,
|
'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))
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
@staff_member_required
|
@staff_member_required
|
||||||
|
|
|
@ -134,7 +134,7 @@ class UserAdmin(admin.ModelAdmin):
|
||||||
context = {
|
context = {
|
||||||
'title': _('Change password: %s') % escape(user.username),
|
'title': _('Change password: %s') % escape(user.username),
|
||||||
'adminForm': adminForm,
|
'adminForm': adminForm,
|
||||||
'form_url': mark_safe(form_url),
|
'form_url': form_url,
|
||||||
'form': form,
|
'form': form,
|
||||||
'is_popup': '_popup' in request.REQUEST,
|
'is_popup': '_popup' in request.REQUEST,
|
||||||
'add': True,
|
'add': True,
|
||||||
|
|
|
@ -8,7 +8,6 @@ from django.db import models
|
||||||
from django.utils import formats
|
from django.utils import formats
|
||||||
from django.utils.text import capfirst
|
from django.utils.text import capfirst
|
||||||
from django.utils.encoding import smart_unicode, smart_str, iri_to_uri
|
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
|
from django.db.models.query import QuerySet
|
||||||
|
|
||||||
EMPTY_VALUE = '(None)'
|
EMPTY_VALUE = '(None)'
|
||||||
|
@ -30,7 +29,7 @@ class EasyModel(object):
|
||||||
return self.site.registry[self.model]
|
return self.site.registry[self.model]
|
||||||
|
|
||||||
def url(self):
|
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):
|
def objects(self, **kwargs):
|
||||||
return self.get_query_set().filter(**kwargs)
|
return self.get_query_set().filter(**kwargs)
|
||||||
|
@ -70,9 +69,9 @@ class EasyField(object):
|
||||||
|
|
||||||
def url(self):
|
def url(self):
|
||||||
if self.field.choices:
|
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:
|
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):
|
class EasyChoice(object):
|
||||||
def __init__(self, easy_model, field, value, label):
|
def __init__(self, easy_model, field, value, label):
|
||||||
|
@ -83,7 +82,7 @@ class EasyChoice(object):
|
||||||
return smart_str('<EasyChoice for %s.%s>' % (self.model.model._meta.object_name, self.field.name))
|
return smart_str('<EasyChoice for %s.%s>' % (self.model.model._meta.object_name, self.field.name))
|
||||||
|
|
||||||
def url(self):
|
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):
|
class EasyInstance(object):
|
||||||
def __init__(self, easy_model, instance):
|
def __init__(self, easy_model, instance):
|
||||||
|
@ -105,7 +104,7 @@ class EasyInstance(object):
|
||||||
return self.instance._get_pk_val()
|
return self.instance._get_pk_val()
|
||||||
|
|
||||||
def url(self):
|
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):
|
def fields(self):
|
||||||
"""
|
"""
|
||||||
|
@ -187,14 +186,14 @@ class EasyInstanceField(object):
|
||||||
for value in self.values():
|
for value in self.values():
|
||||||
if value is None:
|
if value is None:
|
||||||
continue
|
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))
|
lst.append((smart_unicode(value), url))
|
||||||
else:
|
else:
|
||||||
lst = [(value, None) for value in self.values()]
|
lst = [(value, None) for value in self.values()]
|
||||||
elif self.field.choices:
|
elif self.field.choices:
|
||||||
lst = []
|
lst = []
|
||||||
for value in self.values():
|
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))
|
lst.append((value, url))
|
||||||
elif isinstance(self.field, models.URLField):
|
elif isinstance(self.field, models.URLField):
|
||||||
val = self.values()[0]
|
val = self.values()[0]
|
||||||
|
|
|
@ -8,7 +8,6 @@ from django.shortcuts import render_to_response
|
||||||
from django.utils.html import format_html, format_html_join
|
from django.utils.html import format_html, format_html_join
|
||||||
from django.utils.text import capfirst
|
from django.utils.text import capfirst
|
||||||
from django.utils.encoding import force_unicode
|
from django.utils.encoding import force_unicode
|
||||||
from django.utils.safestring import mark_safe
|
|
||||||
from django.views.generic import dates
|
from django.views.generic import dates
|
||||||
from django.utils import datetime_safe
|
from django.utils import datetime_safe
|
||||||
|
|
||||||
|
@ -72,12 +71,12 @@ class CalendarPlugin(DatabrowsePlugin):
|
||||||
def urls(self, plugin_name, easy_instance_field):
|
def urls(self, plugin_name, easy_instance_field):
|
||||||
if isinstance(easy_instance_field.field, models.DateField):
|
if isinstance(easy_instance_field.field, models.DateField):
|
||||||
d = easy_instance_field.raw_value
|
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(),
|
easy_instance_field.model.url(),
|
||||||
plugin_name, easy_instance_field.field.name,
|
plugin_name, easy_instance_field.field.name,
|
||||||
str(d.year),
|
str(d.year),
|
||||||
datetime_safe.new_date(d).strftime('%b').lower(),
|
datetime_safe.new_date(d).strftime('%b').lower(),
|
||||||
d.day))]
|
d.day)]
|
||||||
|
|
||||||
def model_view(self, request, model_databrowse, url):
|
def model_view(self, request, model_databrowse, url):
|
||||||
self.model, self.site = model_databrowse.model, model_databrowse.site
|
self.model, self.site = model_databrowse.model, model_databrowse.site
|
||||||
|
|
|
@ -8,7 +8,6 @@ from django.shortcuts import render_to_response
|
||||||
from django.utils.html import format_html, format_html_join
|
from django.utils.html import format_html, format_html_join
|
||||||
from django.utils.text import capfirst
|
from django.utils.text import capfirst
|
||||||
from django.utils.encoding import smart_str, force_unicode
|
from django.utils.encoding import smart_str, force_unicode
|
||||||
from django.utils.safestring import mark_safe
|
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
class FieldChoicePlugin(DatabrowsePlugin):
|
class FieldChoicePlugin(DatabrowsePlugin):
|
||||||
|
@ -40,10 +39,10 @@ class FieldChoicePlugin(DatabrowsePlugin):
|
||||||
def urls(self, plugin_name, easy_instance_field):
|
def urls(self, plugin_name, easy_instance_field):
|
||||||
if easy_instance_field.field in self.field_dict(easy_instance_field.model.model).values():
|
if easy_instance_field.field in self.field_dict(easy_instance_field.model.model).values():
|
||||||
field_value = smart_str(easy_instance_field.raw_value)
|
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(),
|
easy_instance_field.model.url(),
|
||||||
plugin_name, easy_instance_field.field.name,
|
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):
|
def model_view(self, request, model_databrowse, url):
|
||||||
self.model, self.site = model_databrowse.model, model_databrowse.site
|
self.model, self.site = model_databrowse.model, model_databrowse.site
|
||||||
|
|
|
@ -11,7 +11,7 @@ class GoogleMapException(Exception):
|
||||||
|
|
||||||
# The default Google Maps URL (for the API javascript)
|
# The default Google Maps URL (for the API javascript)
|
||||||
# TODO: Internationalize for Japan, UK, etc.
|
# 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):
|
class GoogleMap(object):
|
||||||
|
@ -49,7 +49,7 @@ class GoogleMap(object):
|
||||||
|
|
||||||
# Can specify the API URL in the `api_url` keyword.
|
# Can specify the API URL in the `api_url` keyword.
|
||||||
if not api_url:
|
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:
|
else:
|
||||||
self.api_url = api_url
|
self.api_url = api_url
|
||||||
|
|
||||||
|
|
|
@ -1369,19 +1369,19 @@ class AdminViewStringPrimaryKeyTest(TestCase):
|
||||||
def test_changelist_to_changeform_link(self):
|
def test_changelist_to_changeform_link(self):
|
||||||
"The link from the changelist referring to the changeform of the object should be quoted"
|
"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/')
|
response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/')
|
||||||
should_contain = """<th><a href="%s/">%s</a></th></tr>""" % (quote(self.pk), escape(self.pk))
|
should_contain = """<th><a href="%s/">%s</a></th></tr>""" % (escape(quote(self.pk)), escape(self.pk))
|
||||||
self.assertContains(response, should_contain)
|
self.assertContains(response, should_contain)
|
||||||
|
|
||||||
def test_recentactions_link(self):
|
def test_recentactions_link(self):
|
||||||
"The link from the recent actions list referring to the changeform of the object should be quoted"
|
"The link from the recent actions list referring to the changeform of the object should be quoted"
|
||||||
response = self.client.get('/test_admin/admin/')
|
response = self.client.get('/test_admin/admin/')
|
||||||
should_contain = """<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>""" % (quote(self.pk), escape(self.pk))
|
should_contain = """<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>""" % (escape(quote(self.pk)), escape(self.pk))
|
||||||
self.assertContains(response, should_contain)
|
self.assertContains(response, should_contain)
|
||||||
|
|
||||||
def test_recentactions_without_content_type(self):
|
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."
|
"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/')
|
response = self.client.get('/test_admin/admin/')
|
||||||
should_contain = """<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>""" % (quote(self.pk), escape(self.pk))
|
should_contain = """<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>""" % (escape(quote(self.pk)), escape(self.pk))
|
||||||
self.assertContains(response, should_contain)
|
self.assertContains(response, should_contain)
|
||||||
should_contain = "Model with string primary key" # capitalized in Recent Actions
|
should_contain = "Model with string primary key" # capitalized in Recent Actions
|
||||||
self.assertContains(response, should_contain)
|
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"
|
"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))
|
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
|
# this URL now comes through reverse(), thus iri_to_uri encoding
|
||||||
should_contain = """/%s/">%s</a>""" % (iri_to_uri(quote(self.pk)), escape(self.pk))
|
should_contain = """/%s/">%s</a>""" % (escape(iri_to_uri(quote(self.pk))), escape(self.pk))
|
||||||
self.assertContains(response, should_contain)
|
self.assertContains(response, should_contain)
|
||||||
|
|
||||||
def test_url_conflicts_with_add(self):
|
def test_url_conflicts_with_add(self):
|
||||||
|
|
Loading…
Reference in New Issue