mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Allow setting a classname on the link element in TitleColumn
This commit is contained in:
parent
13aa7ec861
commit
968a3497a3
@ -1,7 +1,7 @@
|
||||
<td class="{% if column.classname %}{{ column.classname }} {% endif %}title">
|
||||
<div class="title-wrapper">
|
||||
{% if link_url %}
|
||||
<a href="{{ link_url }}">{{ value }}</a>
|
||||
<a href="{{ link_url }}" {% if link_classname %}class="{{ link_classname }}"{% endif %}>{{ value }}</a>
|
||||
{% else %}
|
||||
{{ value }}
|
||||
{% endif %}
|
||||
|
@ -73,7 +73,7 @@ class TestTable(TestCase):
|
||||
data = [blog, gallery]
|
||||
|
||||
table = Table([
|
||||
TitleColumn('hostname', url_name='wagtailsites:edit'),
|
||||
TitleColumn('hostname', url_name='wagtailsites:edit', link_classname='choose-site'),
|
||||
Column('site_name', label="Site name"),
|
||||
], data)
|
||||
|
||||
@ -87,7 +87,7 @@ class TestTable(TestCase):
|
||||
<tr>
|
||||
<td class="title">
|
||||
<div class="title-wrapper">
|
||||
<a href="/admin/sites/%d/">blog.example.com</a>
|
||||
<a href="/admin/sites/%d/" class="choose-site">blog.example.com</a>
|
||||
</div>
|
||||
</td>
|
||||
<td>My blog</td>
|
||||
@ -95,7 +95,7 @@ class TestTable(TestCase):
|
||||
<tr>
|
||||
<td class="title">
|
||||
<div class="title-wrapper">
|
||||
<a href="/admin/sites/%d/">gallery.example.com</a>
|
||||
<a href="/admin/sites/%d/" class="choose-site">gallery.example.com</a>
|
||||
</div>
|
||||
</td>
|
||||
<td>My gallery</td>
|
||||
|
@ -121,14 +121,16 @@ class TitleColumn(Column):
|
||||
"""A column where data is styled as a title and wrapped in a link"""
|
||||
cell_template_name = "wagtailadmin/tables/title_cell.html"
|
||||
|
||||
def __init__(self, name, url_name=None, get_url=None, **kwargs):
|
||||
def __init__(self, name, url_name=None, get_url=None, link_classname=None, **kwargs):
|
||||
super().__init__(name, **kwargs)
|
||||
self.url_name = url_name
|
||||
self._get_url_func = get_url
|
||||
self.link_classname = link_classname
|
||||
|
||||
def get_cell_context_data(self, instance, parent_context):
|
||||
context = super().get_cell_context_data(instance, parent_context)
|
||||
context['link_url'] = self.get_link_url(instance, parent_context)
|
||||
context['link_classname'] = self.link_classname
|
||||
return context
|
||||
|
||||
def get_link_url(self, instance, parent_context):
|
||||
|
Loading…
Reference in New Issue
Block a user