Skip to content

Commit 94bba04

Browse files
authored
Merge pull request #79 from scieloorg/reorder_menu_enable_svg
Reorganiza admin Wagtail, SVG, logo e indexação de imagens
2 parents 414d0dd + 663be66 commit 94bba04

17 files changed

Lines changed: 306 additions & 151 deletions

File tree

config/menu.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
WAGTAIL_MENU_APPS_ORDER = [
2+
"markup_doc",
23
"xml_manager",
34
"reference",
45
"tracker",
6+
"model_ai",
57
"django_celery_beat",
68
]
79

810

911
def get_menu_order(app_name):
1012
try:
1113
return WAGTAIL_MENU_APPS_ORDER.index(app_name) + 1
12-
except:
14+
except ValueError:
1315
return 9000

config/settings/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,16 @@
233233
# e.g. in notification emails. Don't include '/admin' or a trailing slash
234234
WAGTAILADMIN_BASE_URL = "http://example.com"
235235

236+
WAGTAILIMAGES_EXTENSIONS = [
237+
"avif",
238+
"gif",
239+
"jpg",
240+
"jpeg",
241+
"png",
242+
"webp",
243+
"svg",
244+
]
245+
236246
# Allowed file extensions for documents in the document library.
237247
# This can be omitted to allow all files, but note that this may present a security risk
238248
# if untrusted users are allowed to upload files -
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from django.db import migrations
2+
3+
4+
class Migration(migrations.Migration):
5+
dependencies = [
6+
("core", "0001_initial"),
7+
]
8+
9+
operations = [
10+
migrations.RunSQL(
11+
sql="""
12+
DO $$
13+
BEGIN
14+
IF EXISTS (
15+
SELECT 1
16+
FROM information_schema.columns
17+
WHERE table_schema = current_schema()
18+
AND table_name = 'wagtailsearch_indexentry'
19+
AND column_name = 'title_text'
20+
) THEN
21+
UPDATE wagtailsearch_indexentry
22+
SET title_text = COALESCE(title_text, ''),
23+
body_text = COALESCE(body_text, '');
24+
25+
ALTER TABLE wagtailsearch_indexentry
26+
ALTER COLUMN title_text SET DEFAULT '',
27+
ALTER COLUMN body_text SET DEFAULT '';
28+
END IF;
29+
END $$;
30+
""",
31+
reverse_sql=migrations.RunSQL.noop,
32+
),
33+
]

core/wagtail_hooks.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
3+
from django.db.models.signals import pre_save
4+
from wagtail.images import get_image_model
5+
6+
7+
def ensure_image_title(sender, instance, **kwargs):
8+
if (instance.title or "").strip():
9+
return
10+
if not instance.file:
11+
return
12+
basename = os.path.basename(instance.file.name)
13+
instance.title = os.path.splitext(basename)[0]
14+
15+
16+
pre_save.connect(ensure_image_title, sender=get_image_model())
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.custom-admin-logo {
2+
display: block;
3+
max-height: 2.5rem;
4+
max-width: 100%;
5+
width: auto;
6+
height: auto;
7+
}
8+
9+
.custom-admin-logo--login {
10+
max-height: 4rem;
11+
margin: 0 auto;
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% extends "wagtailadmin/base.html" %}
2+
3+
{% block branding_logo %}
4+
{% include "wagtailadmin/includes/admin_logo.html" %}
5+
{% endblock %}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% if settings.core_settings.customsettings.admin_logo %}
2+
<img
3+
src="{{ settings.core_settings.customsettings.admin_logo.file.url }}"
4+
alt="{{ settings.core_settings.customsettings.name|default:'SciELO XML Tools' }}"
5+
class="custom-admin-logo"
6+
/>
7+
{% else %}
8+
{% include "wagtailadmin/logo.html" %}
9+
{% endif %}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% if settings.core_settings.customsettings.admin_logo %}
2+
<img
3+
src="{{ settings.core_settings.customsettings.admin_logo.file.url }}"
4+
alt="{{ settings.core_settings.customsettings.name|default:'SciELO XML Tools' }}"
5+
class="custom-admin-logo custom-admin-logo--login"
6+
/>
7+
{% else %}
8+
{% include "wagtailadmin/logo.html" with wordmark="True" %}
9+
{% endif %}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% extends "wagtailadmin/login.html" %}
2+
3+
{% block branding_logo %}
4+
<div class="login-logo">
5+
{% include "wagtailadmin/includes/admin_logo_login.html" %}
6+
</div>
7+
{% endblock %}

core_settings/wagtail_hooks.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.templatetags.static import static
2+
from django.utils.html import format_html
3+
from wagtail import hooks
4+
5+
6+
@hooks.register("insert_global_admin_css")
7+
def admin_logo_css():
8+
return format_html(
9+
'<link rel="stylesheet" href="{}">',
10+
static("core_settings/css/admin_logo.css"),
11+
)

0 commit comments

Comments
 (0)