mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-29 09:33:54 +01:00
Reimplement wagtailsites/index.html with wagtail.admin.tables
This commit is contained in:
parent
48a2813f39
commit
ddf7d2b938
@ -0,0 +1,7 @@
|
|||||||
|
<td {% if column.classname %}class="{{ column.classname }}"{% endif %}>
|
||||||
|
{% if value %}
|
||||||
|
{% if column.true_label %}<div class="status-tag primary">{{ column.true_label }}</div>{% endif %}
|
||||||
|
{% else %}
|
||||||
|
{% if column.false_label %}<div class="status-tag primary">{{ column.false_label }}</div>{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
@ -120,6 +120,16 @@ class TitleColumn(Column):
|
|||||||
return reverse(self.url_name, args=(instance.pk,))
|
return reverse(self.url_name, args=(instance.pk,))
|
||||||
|
|
||||||
|
|
||||||
|
class StatusFlagColumn(Column):
|
||||||
|
"""Represents a boolean value as a status tag (or lack thereof, if the corresponding label is None)"""
|
||||||
|
cell_template_name = "wagtailadmin/tables/status_flag_cell.html"
|
||||||
|
|
||||||
|
def __init__(self, name, true_label=None, false_label=None, **kwargs):
|
||||||
|
super().__init__(name, **kwargs)
|
||||||
|
self.true_label = true_label
|
||||||
|
self.false_label = false_label
|
||||||
|
|
||||||
|
|
||||||
class Table(Component):
|
class Table(Component):
|
||||||
template_name = "wagtailadmin/tables/table.html"
|
template_name = "wagtailadmin/tables/table.html"
|
||||||
classname = 'listing'
|
classname = 'listing'
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
{% extends "wagtailadmin/generic/index.html" %}
|
|
||||||
{% load i18n %}
|
|
||||||
|
|
||||||
{% block listing %}
|
|
||||||
<div class="nice-padding">
|
|
||||||
<table class="listing">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th class="hostname">
|
|
||||||
{% if ordering == "name" %}
|
|
||||||
<a href="{% url 'wagtailsites:index' %}" class="icon icon-arrow-down-after teal">
|
|
||||||
{% trans "Site" %}
|
|
||||||
</a>
|
|
||||||
{% else %}
|
|
||||||
<a href="{% url 'wagtailsites:index' %}?ordering=name" class="icon icon-arrow-down-after">
|
|
||||||
{% trans "Site" %}
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
|
||||||
</th>
|
|
||||||
<th class="port">{% trans "Port" %}</th>
|
|
||||||
<th class="site-name">{% trans "Site name" %}</th>
|
|
||||||
<th class="root-page">{% trans "Root page" %}</th>
|
|
||||||
<th class="is-default-site">{% trans "Default?" %}</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for site in sites %}
|
|
||||||
<tr>
|
|
||||||
<td class="hostname title">
|
|
||||||
<div class="title-wrapper">
|
|
||||||
<a href="{% url 'wagtailsites:edit' site.id %}">{{ site.hostname }}</a>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td class="port">{{ site.port }}</td>
|
|
||||||
<td class="site-name">
|
|
||||||
{% if site.site_name %}{{ site.site_name }}{% endif %}
|
|
||||||
</td>
|
|
||||||
<td class="root-page">{{ site.root_page }}</td>
|
|
||||||
<td class="is-default-site">
|
|
||||||
{% if site.is_default_site %}<div class="status-tag primary">{% trans "Default" %}</div>{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
@ -18,7 +18,7 @@ class TestSiteIndexView(TestCase, WagtailTestUtils):
|
|||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
response = self.get()
|
response = self.get()
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertTemplateUsed(response, 'wagtailsites/index.html')
|
self.assertTemplateUsed(response, 'wagtailadmin/generic/index.html')
|
||||||
|
|
||||||
def test_pagination(self):
|
def test_pagination(self):
|
||||||
pages = ['0', '1', '-1', '9999', 'Not a page']
|
pages = ['0', '1', '-1', '9999', 'Not a page']
|
||||||
@ -276,7 +276,7 @@ class TestLimitedPermissions(TestCase, WagtailTestUtils):
|
|||||||
def test_get_index(self):
|
def test_get_index(self):
|
||||||
response = self.client.get(reverse('wagtailsites:index'))
|
response = self.client.get(reverse('wagtailsites:index'))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertTemplateUsed(response, 'wagtailsites/index.html')
|
self.assertTemplateUsed(response, 'wagtailadmin/generic/index.html')
|
||||||
|
|
||||||
def test_get_create_view(self):
|
def test_get_create_view(self):
|
||||||
response = self.client.get(reverse('wagtailsites:add'))
|
response = self.client.get(reverse('wagtailsites:add'))
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from django.utils.translation import gettext_lazy
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from wagtail.admin.ui.tables import Column, StatusFlagColumn, TitleColumn
|
||||||
from wagtail.admin.views import generic
|
from wagtail.admin.views import generic
|
||||||
from wagtail.admin.viewsets.model import ModelViewSet
|
from wagtail.admin.viewsets.model import ModelViewSet
|
||||||
from wagtail.core.models import Site
|
from wagtail.core.models import Site
|
||||||
@ -8,30 +9,36 @@ from wagtail.sites.forms import SiteForm
|
|||||||
|
|
||||||
|
|
||||||
class IndexView(generic.IndexView):
|
class IndexView(generic.IndexView):
|
||||||
template_name = 'wagtailsites/index.html'
|
page_title = _("Sites")
|
||||||
page_title = gettext_lazy("Sites")
|
add_item_label = _("Add a site")
|
||||||
add_item_label = gettext_lazy("Add a site")
|
|
||||||
context_object_name = 'sites'
|
context_object_name = 'sites'
|
||||||
|
columns = [
|
||||||
|
TitleColumn('hostname', label=_("Site"), sort_key='hostname', url_name='wagtailsites:edit'),
|
||||||
|
Column('port'),
|
||||||
|
Column('site_name'),
|
||||||
|
Column('root_page'),
|
||||||
|
StatusFlagColumn('is_default_site', label=_("Default?"), true_label=_("Default")),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class CreateView(generic.CreateView):
|
class CreateView(generic.CreateView):
|
||||||
page_title = gettext_lazy("Add site")
|
page_title = _("Add site")
|
||||||
success_message = gettext_lazy("Site '{0}' created.")
|
success_message = _("Site '{0}' created.")
|
||||||
template_name = 'wagtailsites/create.html'
|
template_name = 'wagtailsites/create.html'
|
||||||
|
|
||||||
|
|
||||||
class EditView(generic.EditView):
|
class EditView(generic.EditView):
|
||||||
success_message = gettext_lazy("Site '{0}' updated.")
|
success_message = _("Site '{0}' updated.")
|
||||||
error_message = gettext_lazy("The site could not be saved due to errors.")
|
error_message = _("The site could not be saved due to errors.")
|
||||||
delete_item_label = gettext_lazy("Delete site")
|
delete_item_label = _("Delete site")
|
||||||
context_object_name = 'site'
|
context_object_name = 'site'
|
||||||
template_name = 'wagtailsites/edit.html'
|
template_name = 'wagtailsites/edit.html'
|
||||||
|
|
||||||
|
|
||||||
class DeleteView(generic.DeleteView):
|
class DeleteView(generic.DeleteView):
|
||||||
success_message = gettext_lazy("Site '{0}' deleted.")
|
success_message = _("Site '{0}' deleted.")
|
||||||
page_title = gettext_lazy("Delete site")
|
page_title = _("Delete site")
|
||||||
confirmation_message = gettext_lazy("Are you sure you want to delete this site?")
|
confirmation_message = _("Are you sure you want to delete this site?")
|
||||||
|
|
||||||
|
|
||||||
class SiteViewSet(ModelViewSet):
|
class SiteViewSet(ModelViewSet):
|
||||||
|
Loading…
Reference in New Issue
Block a user