Some docstring changes and tweaks; made all string components unicode (for safer string interpolation).
authorJustin Bronn <jbronn@geodjango.org>
Wed Aug 13 14:00:07 2008 -0500 (3 years ago)
changeset 8cd29cac59e92
parent 7 463e4a400978
child 9 9cf63a5913ee
Some docstring changes and tweaks; made all string components unicode (for safer string interpolation).
widgets.py
     1.1 --- a/widgets.py	Sat Jul 26 14:02:25 2008 -0500
     1.2 +++ b/widgets.py	Wed Aug 13 14:00:07 2008 -0500
     1.3 @@ -1,4 +1,5 @@
     1.4  from django import forms
     1.5 +from django.conf import settings
     1.6  from django.utils.safestring import mark_safe
     1.7  
     1.8  #### Custom Widgets ####
     1.9 @@ -9,20 +10,19 @@
    1.10      Used in both `LimitedForeignKeyWidget` and `LimitedManyToManyWidget`.
    1.11      """
    1.12      def change_related(self, name):
    1.13 -        from django.conf import settings
    1.14          # Constructing the admin URL for the related model.
    1.15 -        related_url = '../../../%s/%s/' % (self.rel.to._meta.app_label, self.rel.to._meta.object_name.lower())
    1.16 +        related_url = u'../../../%s/%s/' % (self.rel.to._meta.app_label, self.rel.to._meta.object_name.lower())
    1.17          if self.rel.limit_choices_to:
    1.18 -            url = '?' + '&amp;'.join(['%s=%s' % (k, v) for k, v in self.rel.limit_choices_to.items()])
    1.19 +            url = u'?' + '&amp;'.join([u'%s=%s' % (k, v) for k, v in self.rel.limit_choices_to.items()])
    1.20          else:
    1.21 -            url = ''
    1.22 +            url = u''
    1.23              
    1.24          # TODO: "id_" is hard-coded here. This should instead use the correct
    1.25          # API to determine the ID dynamically.
    1.26          output = []
    1.27 -        output.append('<a href="%s%s" class="related-lookup" id="lookup_id_%s" onclick="return showRelatedObjectLookupPopup(this);"> ' % \
    1.28 +        output.append(u'<a href="%s%s" class="related-lookup" id="lookup_id_%s" onclick="return showRelatedObjectLookupPopup(this);"> ' % \
    1.29                            (related_url, url, name))
    1.30 -        output.append('<img src="%simg/admin/selector-search.gif" width="16" height="16" alt="Lookup"></a>' % settings.ADMIN_MEDIA_PREFIX)
    1.31 +        output.append(u'<img src="%simg/admin/selector-search.gif" width="16" height="16" alt="Lookup"></a>' % settings.ADMIN_MEDIA_PREFIX)
    1.32          output.append(u'<a href="%sadd/" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \
    1.33                            (related_url, name))
    1.34          output.append(u'<img src="%simg/admin/icon_addlink.gif" width="10" height="10" alt="Add Another"/></a>' % settings.ADMIN_MEDIA_PREFIX)
    1.35 @@ -30,9 +30,9 @@
    1.36  
    1.37  class LimitedForeignKeyWidget(forms.HiddenInput, LimitedMixin):
    1.38      """
    1.39 -    This widget adds the 'looking-glass' icon enabling the user to select a 
    1.40 -    different model for their `ForeignKey` relations.  Based on the 
    1.41 -    newforms-admin `ForeignKeyRawIdWidget`.
    1.42 +    This widget adds the 'looking-glass' and 'add' icon links, which allow
    1.43 +    the user to select and/or create a different model for their `ForeignKey` 
    1.44 +    relations.  Based on the admin's `ForeignKeyRawIdWidget`.
    1.45      """
    1.46      def __init__(self, rel, attrs=None):
    1.47          self.rel = rel
    1.48 @@ -54,7 +54,7 @@
    1.49          if value:
    1.50              desc = desc % self.rel.to.objects.get(pk=value)
    1.51          else:
    1.52 -            desc = desc % 'None'
    1.53 +            desc = desc % u'None'
    1.54          output.append(desc)
    1.55  
    1.56          # Getting the HTML that allows the user to change the related model.
    1.57 @@ -64,8 +64,9 @@
    1.58  
    1.59  class LimitedManyToManyWidget(forms.SelectMultiple, LimitedMixin):
    1.60      """
    1.61 -    This widget adds the 'looking-glass' icon enabling the user to select a 
    1.62 -    different model for their `ManyToManyField` relations.
    1.63 +    This widget adds the 'looking-glass' and 'add' icon links, which allow
    1.64 +    the user to select and/or create a different model for their 
    1.65 +    `ManyToManyField` relations.
    1.66      """
    1.67      def __init__(self, rel, attrs=None):
    1.68          self.rel = rel