kopia lustrzana https://github.com/wagtail/wagtail
rodzic
ae73491222
commit
638761687b
|
@ -11,6 +11,7 @@ Changelog
|
||||||
* Maintenance: Update BeautifulSoup upper bound to 4.12.x (scott-8)
|
* Maintenance: Update BeautifulSoup upper bound to 4.12.x (scott-8)
|
||||||
* Maintenance: Migrate initialization of classes (such as `body.ready`) from multiple JavaScript implementations to one Stimulus controller `w-init` (Chiemezuo Akujobi)
|
* Maintenance: Migrate initialization of classes (such as `body.ready`) from multiple JavaScript implementations to one Stimulus controller `w-init` (Chiemezuo Akujobi)
|
||||||
* Maintenance: Adopt the usage of of translate string literals using `arg=_('...')` in all `wagtailadmin` module templates (Chiemezuo Akujobi)
|
* Maintenance: Adopt the usage of of translate string literals using `arg=_('...')` in all `wagtailadmin` module templates (Chiemezuo Akujobi)
|
||||||
|
* Maintenance: Migrate the contrib styleguide index view to a class based view (Chiemezuo Akujobi)
|
||||||
|
|
||||||
|
|
||||||
5.2 LTS (xx.xx.xxxx) - IN DEVELOPMENT
|
5.2 LTS (xx.xx.xxxx) - IN DEVELOPMENT
|
||||||
|
|
|
@ -31,6 +31,7 @@ depth: 1
|
||||||
* Update BeautifulSoup upper bound to 4.12.x (scott-8)
|
* Update BeautifulSoup upper bound to 4.12.x (scott-8)
|
||||||
* Migrate initialization of classes (such as `body.ready`) from multiple JavaScript implementations to one Stimulus controller `w-init` (Chiemezuo Akujobi)
|
* Migrate initialization of classes (such as `body.ready`) from multiple JavaScript implementations to one Stimulus controller `w-init` (Chiemezuo Akujobi)
|
||||||
* Adopt the usage of of translate string literals using `arg=_('...')` in all `wagtailadmin` module templates (Chiemezuo Akujobi)
|
* Adopt the usage of of translate string literals using `arg=_('...')` in all `wagtailadmin` module templates (Chiemezuo Akujobi)
|
||||||
|
* Migrate the contrib styleguide index view to a class based view (Chiemezuo Akujobi)
|
||||||
|
|
||||||
|
|
||||||
## Upgrade considerations - changes affecting all projects
|
## Upgrade considerations - changes affecting all projects
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% extends "wagtailadmin/base.html" %}
|
{% extends "wagtailadmin/generic/base.html" %}
|
||||||
{% load wagtailadmin_tags i18n %}
|
{% load wagtailadmin_tags i18n %}
|
||||||
|
|
||||||
{% block extra_css %}
|
{% block extra_css %}
|
||||||
|
@ -7,7 +7,6 @@
|
||||||
{{ example_form.media.css }}
|
{{ example_form.media.css }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block titletag %}{% trans 'Styleguide' %}{% endblock %}
|
|
||||||
{% block bodyclass %}styleguide{% endblock %}
|
{% block bodyclass %}styleguide{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
|
@ -6,13 +6,14 @@ from collections import defaultdict
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.template.response import TemplateResponse
|
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
from django.views.generic.base import TemplateView
|
||||||
|
|
||||||
from wagtail import hooks
|
from wagtail import hooks
|
||||||
from wagtail.admin import messages
|
from wagtail.admin import messages
|
||||||
from wagtail.admin.forms.search import SearchForm
|
from wagtail.admin.forms.search import SearchForm
|
||||||
from wagtail.admin.rich_text import get_rich_text_editor_widget
|
from wagtail.admin.rich_text import get_rich_text_editor_widget
|
||||||
|
from wagtail.admin.views.generic import WagtailAdminTemplateMixin
|
||||||
from wagtail.admin.widgets import (
|
from wagtail.admin.widgets import (
|
||||||
AdminAutoHeightTextInput,
|
AdminAutoHeightTextInput,
|
||||||
AdminDateInput,
|
AdminDateInput,
|
||||||
|
@ -95,58 +96,65 @@ icon_id_pattern = re.compile(r"id=\"icon-([a-z0-9-]+)\"")
|
||||||
icon_comment_pattern = re.compile(r"<!--!(.*?)-->")
|
icon_comment_pattern = re.compile(r"<!--!(.*?)-->")
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
class IndexView(WagtailAdminTemplateMixin, TemplateView):
|
||||||
|
template_name = "wagtailstyleguide/base.html"
|
||||||
|
page_title = _("Styleguide")
|
||||||
|
|
||||||
form = SearchForm(placeholder=_("Search something"))
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
example_form = ExampleForm()
|
messages.success(
|
||||||
|
self.request,
|
||||||
messages.success(
|
_("Success message"),
|
||||||
request,
|
buttons=[
|
||||||
_("Success message"),
|
messages.button("", _("View live")),
|
||||||
buttons=[messages.button("", _("View live")), messages.button("", _("Edit"))],
|
messages.button("", _("Edit")),
|
||||||
)
|
],
|
||||||
messages.warning(
|
)
|
||||||
request,
|
messages.warning(
|
||||||
_("Warning message"),
|
self.request,
|
||||||
buttons=[messages.button("", _("View live")), messages.button("", _("Edit"))],
|
_("Warning message"),
|
||||||
)
|
buttons=[
|
||||||
messages.error(
|
messages.button("", _("View live")),
|
||||||
request,
|
messages.button("", _("Edit")),
|
||||||
_("Error message"),
|
],
|
||||||
buttons=[messages.button("", _("View live")), messages.button("", _("Edit"))],
|
)
|
||||||
)
|
messages.error(
|
||||||
|
self.request,
|
||||||
paginator = Paginator(list(range(100)), 10)
|
_("Error message"),
|
||||||
page = paginator.page(2)
|
buttons=[
|
||||||
|
messages.button("", _("View live")),
|
||||||
icon_hooks = hooks.get_hooks("register_icons")
|
messages.button("", _("Edit")),
|
||||||
registered_icons = itertools.chain.from_iterable(hook([]) for hook in icon_hooks)
|
],
|
||||||
all_icons = defaultdict(list)
|
|
||||||
for icon_path in registered_icons:
|
|
||||||
folder, filename = os.path.split(icon_path)
|
|
||||||
icon = render_to_string(icon_path)
|
|
||||||
id_match = icon_id_pattern.search(icon)
|
|
||||||
name = id_match.group(1) if id_match else None
|
|
||||||
source_match = icon_comment_pattern.search(icon)
|
|
||||||
|
|
||||||
all_icons[folder].append(
|
|
||||||
{
|
|
||||||
"folder": folder,
|
|
||||||
"file_path": icon_path,
|
|
||||||
"name": name,
|
|
||||||
"source": source_match.group(1) if source_match else None,
|
|
||||||
"icon": icon,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return TemplateResponse(
|
context["all_icons"] = self.get_icons()
|
||||||
request,
|
context["example_form"] = ExampleForm()
|
||||||
"wagtailstyleguide/base.html",
|
context["example_page"] = Paginator(list(range(100)), 10).page(2)
|
||||||
{
|
context["search_form"] = SearchForm(placeholder=_("Search something"))
|
||||||
"all_icons": all_icons.items(),
|
|
||||||
"search_form": form,
|
return context
|
||||||
"example_form": example_form,
|
|
||||||
"example_page": page,
|
def get_icons(self):
|
||||||
},
|
icon_hooks = hooks.get_hooks("register_icons")
|
||||||
)
|
registered_icons = itertools.chain.from_iterable(
|
||||||
|
hook([]) for hook in icon_hooks
|
||||||
|
)
|
||||||
|
all_icons = defaultdict(list)
|
||||||
|
for icon_path in registered_icons:
|
||||||
|
folder, filename = os.path.split(icon_path)
|
||||||
|
icon = render_to_string(icon_path)
|
||||||
|
id_match = icon_id_pattern.search(icon)
|
||||||
|
name = id_match.group(1) if id_match else None
|
||||||
|
source_match = icon_comment_pattern.search(icon)
|
||||||
|
|
||||||
|
all_icons[folder].append(
|
||||||
|
{
|
||||||
|
"folder": folder,
|
||||||
|
"file_path": icon_path,
|
||||||
|
"name": name,
|
||||||
|
"source": source_match.group(1) if source_match else None,
|
||||||
|
"icon": icon,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return all_icons.items()
|
||||||
|
|
|
@ -10,7 +10,7 @@ from . import views
|
||||||
@hooks.register("register_admin_urls")
|
@hooks.register("register_admin_urls")
|
||||||
def register_admin_urls():
|
def register_admin_urls():
|
||||||
return [
|
return [
|
||||||
path("styleguide/", views.index, name="wagtailstyleguide"),
|
path("styleguide/", views.IndexView.as_view(), name="wagtailstyleguide"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue