Ticket #13165: change_links.diff
File change_links.diff, 5.6 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/helpers.py
12 12 from django.utils.html import escape, conditional_escape 13 13 from django.utils.safestring import mark_safe 14 14 from django.utils.translation import ugettext_lazy as _ 15 from django.core.urlresolvers import reverse, NoReverseMatch 15 16 16 17 17 ACTION_CHECKBOX_NAME = '_selected_action' 18 18 19 19 class ActionForm(forms.Form): … … 186 186 result_repr = display_for_field(value, f) 187 187 return conditional_escape(result_repr) 188 188 189 def change_url(self): 190 """ Return admin change URL for field if applicable. """ 191 field, obj, model_admin = \ 192 self.field['field'], self.form.instance, self.model_admin 193 try: 194 f, attr, value = lookup_field(field, obj, model_admin) 195 except (AttributeError, ValueError, ObjectDoesNotExist): 196 return None 197 else: 198 rel = getattr(f,'rel') 199 if rel and rel.to in model_admin.admin_site._registry: 200 try: 201 return reverse('admin:%s_%s_change' % ( 202 rel.to._meta.app_label, 203 rel.to._meta.object_name.lower()), 204 args=(value.pk,), 205 current_app=model_admin.admin_site.name) 206 except NoReverseMatch: 207 return None # fail silently 208 else: 209 return None # not a related field 210 211 189 212 class InlineAdminFormSet(object): 190 213 """ 191 214 A wrapper around an inline formset for use in the admin system. -
django/contrib/admin/widgets.py
242 242 output.append(u'<a href="%s" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \ 243 243 (related_url, name)) 244 244 output.append(u'<img src="%simg/admin/icon_addlink.gif" width="10" height="10" alt="%s"/></a>' % (settings.ADMIN_MEDIA_PREFIX, _('Add Another'))) 245 246 if value: # (a related object is selected) 247 try: 248 related_object = rel_to.objects.get(pk=value) 249 except: 250 # probably a TypeError (e.g. value is list for 251 # multiple-select widgets), but fail silently regardless 252 pass 253 else: 254 try: 255 change_related_url = reverse( 256 'admin:%s_%s_change' % info, 257 args=(related_object.id,), 258 current_app=self.admin_site.name) 259 except NoReverseMatch: 260 # fail silently 261 pass 262 else: 263 params = { 264 'url': change_related_url, 265 'admin_media_prefix': settings.ADMIN_MEDIA_PREFIX, 266 'text': _('edit %s' % related_object), 267 } 268 output.append(u' <a href="%(url)s" class="change_link"><img src="%(admin_media_prefix)simg/admin/icon_changelink.gif" width="10" height="10" alt="%(text)s" title="%(text)s"/> %(text)s</a>' % params) 269 245 270 return mark_safe(u''.join(output)) 246 271 247 272 def build_attrs(self, extra_attrs=None, **kwargs): -
django/contrib/admin/templates/admin/edit_inline/tabular.html
44 45 {% for field in line %} 45 46 <td class="{{ field.field.name }}"> 46 47 {% if field.is_readonly %} 47 <p>{{ field.contents }} </p>48 <p>{{ field.contents }} {% if field.change_url %}<a href="{{ field.change_url }}" class="readonly_field_change_link"><img src="{% admin_media_prefix %}img/admin/icon_changelink.gif" width="10" height="10" alt="{% trans "edit" %}" title="{% trans "edit" %}"/></a>{% endif %}</p> 48 49 {% else %} 49 50 {{ field.field.errors.as_ul }} 50 51 {{ field.field }} -
django/contrib/admin/templates/admin/includes/fieldset.html
1 {% load i18n adminmedia %} 1 2 <fieldset class="module aligned {{ fieldset.classes }}"> 2 3 {% if fieldset.name %}<h2>{{ fieldset.name }}</h2>{% endif %} 3 4 {% if fieldset.description %} … … 13 14 {% else %} 14 15 {{ field.label_tag }} 15 16 {% if field.is_readonly %} 16 <p>{{ field.contents }} </p>17 <p>{{ field.contents }} {% if field.change_url %}<a href="{{ field.change_url }}" class="readonly_field_change_link"><img src="{% admin_media_prefix %}img/admin/icon_changelink.gif" width="10" height="10" alt="{% trans "edit" %}" title="{% trans "edit" %}"/></a>{% endif %}</p> 17 18 {% else %} 18 19 {{ field.field }} 19 20 {% endif %}