Skip to content

Commit 4ea8fe3

Browse files
committed
Support #385
1 parent b20ed58 commit 4ea8fe3

36 files changed

+1977
-12
lines changed

src/edrn.theme/src/edrn/theme/templates/wagtailadmin/base.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
{% block branding_logo %}
44
<img alt='Logo of the National Institutes of Health' src='{% static "edrn.theme/images/nih.png" %}'/>
55
{% endblock %}
6-
{# -*- Django HTML -*- #}
6+
{# -*- HTML (Jinja) -*- #}

src/edrn.theme/src/edrn/theme/templates/wagtailadmin/home.html

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
{% block branding_welcome %}
44
Editor's Controls for {{site_name}}
55
{% endblock %}
6-
{# -*- Django HTML -*- #}

src/edrn.theme/src/edrn/theme/templates/wagtailadmin/login.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
{% block branding_logo %}
2121
<!-- Sorry, no wagtail logo here -->
2222
{% endblock %}
23-
{# -*- Django HTML -*- #}
23+
{# -*- HTML (Jinja) -*- #}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# encoding: utf-8
2+
3+
'''😌 EDRN Site Content: remove old explorer, create new one.'''
4+
5+
from django.conf import settings
6+
from django.core.management.base import BaseCommand
7+
from edrnsite.content.models import FlexPage
8+
from edrnsite.policy.management.commands.utils import set_site
9+
from edrnsite.streams.views import update_data_element_explorer_trees
10+
from wagtail.models import Page
11+
from wagtail.rich_text import RichText
12+
13+
14+
_help_html = '''<p>To use the data models:</p>
15+
<ul>
16+
<li>Click/tap on the triangle icon to the left of each section to expand and view its contents.</li>
17+
<li>Click/tap on the text within a section to access detailed information about the model, including its specific attributes and details.</li>
18+
</ul>'''
19+
20+
_faq_html = '''<p>For questions about the data models, <a href="mailto:[email protected]">email
21+
the Informatics Center</a>.'''
22+
23+
24+
class Command(BaseCommand):
25+
help = 'Replace old CDE viewer page with new block-based explorer flex page'
26+
27+
def _update_cde_explorer(self, home_page):
28+
# There should be just one current CDEExplorerPage
29+
count = Page.objects.filter(slug='edrn-data-model').count()
30+
if count > 1:
31+
raise ValueError("There's more than one edrn-data-model! Not sure what to do")
32+
elif count == 0:
33+
self.stdout.write('No edrn-data-model found, so using existing "cde" page as the parent')
34+
parent = FlexPage.objects.filter(slug='cde').first()
35+
assert parent is not None
36+
else:
37+
self.stdout.write('Found the one edrn-data-model, deleting it')
38+
page = Page.objects.filter(slug='edrn-data-model').first()
39+
parent = page.get_parent()
40+
page.delete()
41+
parent.refresh_from_db()
42+
43+
self.stdout.write('Creating new EDRN Data Model page')
44+
page = FlexPage(title='EDRN Data Model', slug='edrn-data-model', show_in_menus=False)
45+
parent.add_child(instance=page)
46+
47+
page.body.append(('rich_text', RichText(_help_html)))
48+
page.body.append(('data_explorer', {
49+
'title': 'Biomarker Data Models',
50+
'block_id': 'bio', 'spreadsheet_id': '1Kjkvi-bF5GNpAzvq4Kq6r4g1WpceIyP0Srs2OHJJtGs',
51+
}))
52+
page.body.append(('data_explorer', {
53+
'title': 'Cancer Biomarker Data Commons (LabCAS) Data Model',
54+
'block_id': 'lab', 'spreadsheet_id': '1btbwoROmVbZlzSLBn3DQ_6rakZ48j24p-NoOkI3OCFg'
55+
}))
56+
page.body.append(('rich_text', RichText(_faq_html)))
57+
page.save()
58+
update_data_element_explorer_trees()
59+
60+
def handle(self, *args, **options):
61+
self.stdout.write('Updating CDE explorer')
62+
63+
old = getattr(settings, 'WAGTAILREDIRECTS_AUTO_CREATE', True)
64+
try:
65+
settings.WAGTAILREDIRECTS_AUTO_CREATE = False
66+
settings.WAGTAILSEARCH_BACKENDS['default']['AUTO_UPDATE'] = False
67+
site, home_page = set_site()
68+
self._update_cde_explorer(home_page)
69+
70+
finally:
71+
settings.WAGTAILREDIRECTS_AUTO_CREATE = old
72+
settings.WAGTAILSEARCH_BACKENDS['default']['AUTO_UPDATE'] = True
73+
self.stdout.write("Job's done!")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Generated by Django 4.2.17 on 2025-01-10 18:20
2+
3+
from django.db import migrations
4+
import edrnsite.streams.blocks
5+
import wagtail.blocks
6+
import wagtail.contrib.typed_table_block.blocks
7+
import wagtail.fields
8+
import wagtail.images.blocks
9+
10+
11+
class Migration(migrations.Migration):
12+
13+
dependencies = [
14+
("edrnsitecontent", "0034_biomarkersubmissionformpage"),
15+
]
16+
17+
operations = [
18+
migrations.AlterField(
19+
model_name="flexpage",
20+
name="body",
21+
field=wagtail.fields.StreamField(
22+
[
23+
(
24+
"rich_text",
25+
wagtail.blocks.RichTextBlock(
26+
help_text="Richly formatted text",
27+
icon="doc-full",
28+
label="Rich Text",
29+
),
30+
),
31+
(
32+
"cards",
33+
wagtail.blocks.StructBlock(
34+
[
35+
(
36+
"cards",
37+
wagtail.blocks.ListBlock(
38+
wagtail.blocks.StructBlock(
39+
[
40+
(
41+
"title",
42+
wagtail.blocks.CharBlock(
43+
help_text="Title of this card, max 100 chars",
44+
max_length=100,
45+
),
46+
)
47+
]
48+
)
49+
),
50+
)
51+
]
52+
),
53+
),
54+
("table", edrnsite.streams.blocks.TableBlock()),
55+
(
56+
"data_explorer",
57+
wagtail.blocks.StructBlock(
58+
[
59+
(
60+
"attribute_help_text",
61+
wagtail.blocks.CharBlock(
62+
default="Click/tap on an attribute box below to view details about each attribute",
63+
help_text="Helpful text to tell users that attribute buttons can be clicked",
64+
max_length=300,
65+
required=False,
66+
),
67+
)
68+
]
69+
),
70+
),
71+
(
72+
"block_quote",
73+
edrnsite.streams.blocks.BlockQuoteBlock(
74+
help_text="Block quote"
75+
),
76+
),
77+
(
78+
"typed_table",
79+
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
80+
[
81+
(
82+
"text",
83+
wagtail.blocks.CharBlock(
84+
help_text="Plain text cell"
85+
),
86+
),
87+
(
88+
"rich_text",
89+
wagtail.blocks.RichTextBlock(
90+
help_text="Rich text cell"
91+
),
92+
),
93+
(
94+
"numeric",
95+
wagtail.blocks.FloatBlock(help_text="Numeric cell"),
96+
),
97+
(
98+
"integer",
99+
wagtail.blocks.IntegerBlock(
100+
help_text="Integer cell"
101+
),
102+
),
103+
(
104+
"page",
105+
wagtail.blocks.PageChooserBlock(
106+
help_text="Page within the site"
107+
),
108+
),
109+
]
110+
),
111+
),
112+
(
113+
"carousel",
114+
wagtail.blocks.StructBlock(
115+
[
116+
(
117+
"media",
118+
wagtail.blocks.ListBlock(
119+
wagtail.blocks.StructBlock(
120+
[
121+
(
122+
"image",
123+
wagtail.images.blocks.ImageChooserBlock(),
124+
),
125+
(
126+
"label",
127+
wagtail.blocks.CharBlock(
128+
help_text="Overlaid label, if any",
129+
max_length=120,
130+
required=False,
131+
),
132+
),
133+
(
134+
"caption",
135+
wagtail.blocks.CharBlock(
136+
help_text="Overlaid caption, if any",
137+
max_length=400,
138+
required=False,
139+
),
140+
),
141+
]
142+
)
143+
),
144+
)
145+
]
146+
),
147+
),
148+
(
149+
"raw_html",
150+
wagtail.blocks.RawHTMLBlock(
151+
help_text="Raw HTML (use with care)"
152+
),
153+
),
154+
],
155+
blank=True,
156+
null=True,
157+
use_json_field=True,
158+
),
159+
),
160+
]

0 commit comments

Comments
 (0)