Skip to content

Commit

Permalink
Support #385
Browse files Browse the repository at this point in the history
  • Loading branch information
nutjob4life committed Jan 15, 2025
1 parent b20ed58 commit 4ea8fe3
Show file tree
Hide file tree
Showing 36 changed files with 1,977 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
{% block branding_logo %}
<img alt='Logo of the National Institutes of Health' src='{% static "edrn.theme/images/nih.png" %}'/>
{% endblock %}
{# -*- Django HTML -*- #}
{# -*- HTML (Jinja) -*- #}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
{% block branding_welcome %}
Editor's Controls for {{site_name}}
{% endblock %}
{# -*- Django HTML -*- #}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
{% block branding_logo %}
<!-- Sorry, no wagtail logo here -->
{% endblock %}
{# -*- Django HTML -*- #}
{# -*- HTML (Jinja) -*- #}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# encoding: utf-8

'''😌 EDRN Site Content: remove old explorer, create new one.'''

from django.conf import settings
from django.core.management.base import BaseCommand
from edrnsite.content.models import FlexPage
from edrnsite.policy.management.commands.utils import set_site
from edrnsite.streams.views import update_data_element_explorer_trees
from wagtail.models import Page
from wagtail.rich_text import RichText


_help_html = '''<p>To use the data models:</p>
<ul>
<li>Click/tap on the triangle icon to the left of each section to expand and view its contents.</li>
<li>Click/tap on the text within a section to access detailed information about the model, including its specific attributes and details.</li>
</ul>'''

_faq_html = '''<p>For questions about the data models, <a href="mailto:ic-portal@jpl.nasa.gov">email
the Informatics Center</a>.'''


class Command(BaseCommand):
help = 'Replace old CDE viewer page with new block-based explorer flex page'

def _update_cde_explorer(self, home_page):
# There should be just one current CDEExplorerPage
count = Page.objects.filter(slug='edrn-data-model').count()
if count > 1:
raise ValueError("There's more than one edrn-data-model! Not sure what to do")
elif count == 0:
self.stdout.write('No edrn-data-model found, so using existing "cde" page as the parent')
parent = FlexPage.objects.filter(slug='cde').first()
assert parent is not None
else:
self.stdout.write('Found the one edrn-data-model, deleting it')
page = Page.objects.filter(slug='edrn-data-model').first()
parent = page.get_parent()
page.delete()
parent.refresh_from_db()

self.stdout.write('Creating new EDRN Data Model page')
page = FlexPage(title='EDRN Data Model', slug='edrn-data-model', show_in_menus=False)
parent.add_child(instance=page)

page.body.append(('rich_text', RichText(_help_html)))
page.body.append(('data_explorer', {
'title': 'Biomarker Data Models',
'block_id': 'bio', 'spreadsheet_id': '1Kjkvi-bF5GNpAzvq4Kq6r4g1WpceIyP0Srs2OHJJtGs',
}))
page.body.append(('data_explorer', {
'title': 'Cancer Biomarker Data Commons (LabCAS) Data Model',
'block_id': 'lab', 'spreadsheet_id': '1btbwoROmVbZlzSLBn3DQ_6rakZ48j24p-NoOkI3OCFg'
}))
page.body.append(('rich_text', RichText(_faq_html)))
page.save()
update_data_element_explorer_trees()

def handle(self, *args, **options):
self.stdout.write('Updating CDE explorer')

old = getattr(settings, 'WAGTAILREDIRECTS_AUTO_CREATE', True)
try:
settings.WAGTAILREDIRECTS_AUTO_CREATE = False
settings.WAGTAILSEARCH_BACKENDS['default']['AUTO_UPDATE'] = False
site, home_page = set_site()
self._update_cde_explorer(home_page)

finally:
settings.WAGTAILREDIRECTS_AUTO_CREATE = old
settings.WAGTAILSEARCH_BACKENDS['default']['AUTO_UPDATE'] = True
self.stdout.write("Job's done!")
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Generated by Django 4.2.17 on 2025-01-10 18:20

from django.db import migrations
import edrnsite.streams.blocks
import wagtail.blocks
import wagtail.contrib.typed_table_block.blocks
import wagtail.fields
import wagtail.images.blocks


class Migration(migrations.Migration):

dependencies = [
("edrnsitecontent", "0034_biomarkersubmissionformpage"),
]

operations = [
migrations.AlterField(
model_name="flexpage",
name="body",
field=wagtail.fields.StreamField(
[
(
"rich_text",
wagtail.blocks.RichTextBlock(
help_text="Richly formatted text",
icon="doc-full",
label="Rich Text",
),
),
(
"cards",
wagtail.blocks.StructBlock(
[
(
"cards",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
(
"title",
wagtail.blocks.CharBlock(
help_text="Title of this card, max 100 chars",
max_length=100,
),
)
]
)
),
)
]
),
),
("table", edrnsite.streams.blocks.TableBlock()),
(
"data_explorer",
wagtail.blocks.StructBlock(
[
(
"attribute_help_text",
wagtail.blocks.CharBlock(
default="Click/tap on an attribute box below to view details about each attribute",
help_text="Helpful text to tell users that attribute buttons can be clicked",
max_length=300,
required=False,
),
)
]
),
),
(
"block_quote",
edrnsite.streams.blocks.BlockQuoteBlock(
help_text="Block quote"
),
),
(
"typed_table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"text",
wagtail.blocks.CharBlock(
help_text="Plain text cell"
),
),
(
"rich_text",
wagtail.blocks.RichTextBlock(
help_text="Rich text cell"
),
),
(
"numeric",
wagtail.blocks.FloatBlock(help_text="Numeric cell"),
),
(
"integer",
wagtail.blocks.IntegerBlock(
help_text="Integer cell"
),
),
(
"page",
wagtail.blocks.PageChooserBlock(
help_text="Page within the site"
),
),
]
),
),
(
"carousel",
wagtail.blocks.StructBlock(
[
(
"media",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
(
"image",
wagtail.images.blocks.ImageChooserBlock(),
),
(
"label",
wagtail.blocks.CharBlock(
help_text="Overlaid label, if any",
max_length=120,
required=False,
),
),
(
"caption",
wagtail.blocks.CharBlock(
help_text="Overlaid caption, if any",
max_length=400,
required=False,
),
),
]
)
),
)
]
),
),
(
"raw_html",
wagtail.blocks.RawHTMLBlock(
help_text="Raw HTML (use with care)"
),
),
],
blank=True,
null=True,
use_json_field=True,
),
),
]
Loading

0 comments on commit 4ea8fe3

Please sign in to comment.