Ticket #9316: databrowse-encode-strings.diff

File databrowse-encode-strings.diff, 7.5 KB (added by Adam Vandenberg, 14 years ago)

Preliminary patch.

  • django/contrib/databrowse/datastructures.py

    diff --git a/django/contrib/databrowse/datastructures.py b/django/contrib/databrowse/datastructures.py
    index 4fcdba9..e4da894 100644
    a b These classes are light wrappers around Django's database API that provide  
    33convenience functionality and permalink functions for the databrowse app.
    44"""
    55
     6from django.contrib.databrowse.util import quote, unquote
    67from django.db import models
     8from django.db.models.query import QuerySet
    79from django.utils import formats
    810from django.utils.text import capfirst
    9 from django.utils.encoding import smart_unicode, smart_str, iri_to_uri
     11from django.utils.encoding import smart_unicode, smart_str
    1012from django.utils.safestring import mark_safe
    11 from django.db.models.query import QuerySet
     13
    1214
    1315EMPTY_VALUE = '(None)'
    1416DISPLAY_SIZE = 100
    1517
     18
    1619class EasyModel(object):
    1720    def __init__(self, site, model):
    1821        self.site = site
    class EasyModel(object):  
    5659    def fields(self):
    5760        return [EasyField(self, f) for f in (self.model._meta.fields + self.model._meta.many_to_many)]
    5861
     62
    5963class EasyField(object):
    6064    def __init__(self, easy_model, field):
    6165        self.model, self.field = easy_model, field
    class EasyField(object):  
    7377        elif self.field.rel:
    7478            return mark_safe('%s%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name))
    7579
     80
    7681class EasyChoice(object):
    7782    def __init__(self, easy_model, field, value, label):
    7883        self.model, self.field = easy_model, field
    class EasyChoice(object):  
    8287        return smart_str(u'<EasyChoice for %s.%s>' % (self.model.model._meta.object_name, self.field.name))
    8388
    8489    def url(self):
    85         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)))
     90        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, quote(self.value)))
     91
    8692
    8793class EasyInstance(object):
    8894    def __init__(self, easy_model, instance):
    class EasyInstance(object):  
    104110        return self.instance._get_pk_val()
    105111
    106112    def url(self):
    107         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())))
     113        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, quote(self.pk())))
    108114
    109115    def fields(self):
    110116        """
    class EasyInstance(object):  
    130136                'object_list': [EasyInstance(em, i) for i in getattr(self.instance, rel_object.get_accessor_name()).all()],
    131137            }
    132138
     139
    133140class EasyInstanceField(object):
    134141    def __init__(self, easy_model, instance, field):
    135142        self.model, self.field, self.instance = easy_model, field, instance
    class EasyInstanceField(object):  
    184191            if self.field.rel.to in self.model.model_list:
    185192                lst = []
    186193                for value in self.values():
    187                     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())))
     194                    url = mark_safe('%s%s/%s/objects/%s/' % (self.model.site.root_url, m.model._meta.app_label, m.model._meta.module_name, quote(value._get_pk_val())))
    188195                    lst.append((smart_unicode(value), url))
    189196            else:
    190197                lst = [(value, None) for value in self.values()]
    191198        elif self.field.choices:
    192199            lst = []
    193200            for value in self.values():
    194                 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)))
     201                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, quote(self.raw_value)))
    195202                lst.append((value, url))
    196203        elif isinstance(self.field, models.URLField):
    197204            val = self.values()[0]
    198             lst = [(val, iri_to_uri(val))]
     205            lst = [(val, quote(val))]
    199206        else:
    200207            lst = [(self.values()[0], None)]
    201208        return lst
    202209
     210
    203211class EasyQuerySet(QuerySet):
    204212    """
    205213    When creating (or cloning to) an `EasyQuerySet`, make sure to set the
  • django/contrib/databrowse/plugins/fieldchoices.py

    diff --git a/django/contrib/databrowse/plugins/fieldchoices.py b/django/contrib/databrowse/plugins/fieldchoices.py
    index e0c01e9..5450212 100644
    a b from django import http  
    22from django.db import models
    33from django.contrib.databrowse.datastructures import EasyModel
    44from django.contrib.databrowse.sites import DatabrowsePlugin
     5from django.contrib.databrowse.util import unquote, quote
    56from django.shortcuts import render_to_response
    67from django.utils.text import capfirst
    78from django.utils.encoding import smart_str, force_unicode
    89from django.utils.safestring import mark_safe
    9 import urllib
     10
    1011
    1112class FieldChoicePlugin(DatabrowsePlugin):
    1213    def __init__(self, field_filter=None):
    class FieldChoicePlugin(DatabrowsePlugin):  
    3940            return [mark_safe(u'%s%s/%s/%s/' % (
    4041                easy_instance_field.model.url(),
    4142                plugin_name, easy_instance_field.field.name,
    42                 urllib.quote(field_value, safe='')))]
     43                quote(field_value)))]
    4344
    4445    def model_view(self, request, model_databrowse, url):
    4546        self.model, self.site = model_databrowse.model, model_databrowse.site
    class FieldChoicePlugin(DatabrowsePlugin):  
    6566        return render_to_response('databrowse/fieldchoice_homepage.html', {'root_url': self.site.root_url, 'model': easy_model, 'field_list': field_list})
    6667
    6768    def field_view(self, request, field, value=None):
     69        value = unquote(value)
    6870        easy_model = EasyModel(self.site, self.model)
    6971        easy_field = easy_model.field(field.name)
    7072        if value is not None:
  • django/contrib/databrowse/templates/databrowse/fieldchoice_list.html

    diff --git a/django/contrib/databrowse/templates/databrowse/fieldchoice_list.html b/django/contrib/databrowse/templates/databrowse/fieldchoice_list.html
    index bb60a0e..eccb5d1 100644
    a b  
    11{% extends "databrowse/base_site.html" %}
     2{% load databrowse %}
    23
    34{% block title %}{{ model.verbose_name_plural|capfirst }} by {{ field.field.verbose_name }}{% endblock %}
    45
     
    1011
    1112<ul class="objectlist">
    1213{% for object in object_list %}
    13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object|iriencode }}/">{{ object }}</a></li>
     14<li class="{% cycle 'odd' 'even' %}"><a href="{{ object|alternate_quote }}/">{{ object }}</a></li>
    1415{% endfor %}
    1516</ul>
    1617
  • django/contrib/databrowse/urls.py

    diff --git a/django/contrib/databrowse/urls.py b/django/contrib/databrowse/urls.py
    index 9b85d14..2559686 100644
    a b  
    1 from django.conf.urls.defaults import *
     1from django.conf.urls.defaults import patterns
    22from django.contrib.databrowse import views
    33
    44# Note: The views in this URLconf all require a 'models' argument,
Back to Top