Ticket #8261: show_on_site.diff

File show_on_site.diff, 1.8 KB (added by redduck666, 7 years ago)
  • options.py

     
    381381        """
    382382        formset.save()
    383383
     384    def show_on_site(self, obj):
     385        """Allow customizing of "View on site" URL's, should return the URL"""
     386        return False
     387
    384388    def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
    385389        opts = self.model._meta
    386390        app_label = opts.app_label
     
    393397            'has_delete_permission': self.has_delete_permission(request, obj),
    394398            'has_file_field': True, # FIXME - this should check if form or formsets have a FileField,
    395399            'has_absolute_url': hasattr(self.model, 'get_absolute_url'),
     400            'absolute_url': self.show_on_site(obj),
    396401            'ordered_objects': ordered_objects,
    397402            'form_url': mark_safe(form_url),
    398403            'opts': opts,
  • templates/admin/change_form.html

     
    2525{% block object-tools %}
    2626{% if change %}{% if not is_popup %}
    2727  <ul class="object-tools"><li><a href="history/" class="historylink">{% trans "History" %}</a></li>
    28   {% if has_absolute_url %}<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
     28  {% if has_absolute_url or absolute_url %}<li><a href="{% if absolute_url %}{{ absolute_url }}{% else %}../../../r/{{ content_type_id }}/{{ object_id }}/{% endif %}" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
    2929  </ul>
    3030{% endif %}{% endif %}
    3131{% endblock %}
Back to Top