-
Notifications
You must be signed in to change notification settings - Fork 17
School data portal pages #1650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mwvolo
wants to merge
10
commits into
main
Choose a base branch
from
school-data-portal-pages
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
School data portal pages #1650
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
68b16de
update schools to only fetch real schools
mwvolo a15ba4d
add wagtail autocomplete
mwvolo ba61531
add field to capture school on flex pages
mwvolo 545de6b
hide the school field unless the page is a landing page
mwvolo 6870b75
add salesforce id to response
mwvolo 9ec28ce
Update salesforce/models.py
mwvolo 9fed203
Update pages/static/pages/conditional-school-field.js
mwvolo 6e0d2fc
cache school data on response
mwvolo 362791f
Merge branch 'school-data-portal-pages' of https://github.com/opensta…
mwvolo 3d492e4
Update pages/wagtail_hooks.py
mwvolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Generated by Django 5.1.12 on 2025-12-05 18:24 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("pages", "0162_assignable_cta_section_footer"), | ||
| ("salesforce", "0114_school_industry"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="rootpage", | ||
| name="school", | ||
| field=models.ForeignKey( | ||
| blank=True, | ||
| help_text="Link a school to this landing page. School information will be included in the API response.", | ||
| null=True, | ||
| on_delete=django.db.models.deletion.SET_NULL, | ||
| related_name="+", | ||
| to="salesforce.school", | ||
| ), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| (function() { | ||
| // Get jQuery - try django.jQuery first (Django admin), then fall back to regular jQuery | ||
| var getJQuery = function() { | ||
| if (typeof django !== 'undefined' && django.jQuery) { | ||
| return django.jQuery; | ||
| } else if (typeof jQuery !== 'undefined') { | ||
| return jQuery; | ||
| } else if (typeof $ !== 'undefined') { | ||
| return $; | ||
| } | ||
| return null; | ||
| }; | ||
|
|
||
| // Wait for jQuery to be available | ||
| var init = function() { | ||
| var $ = getJQuery(); | ||
| if (!$) { | ||
| // jQuery not ready yet, try again | ||
| setTimeout(init, 50); | ||
| return; | ||
| } | ||
|
|
||
| $(document).ready(function(){ | ||
| function checkAndToggleSchoolField() { | ||
| // Find the layout StreamField container | ||
| // Wagtail StreamFields have a data-contentpath attribute | ||
| var $layoutField = $('[data-contentpath="layout"]'); | ||
|
|
||
| if ($layoutField.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| // Check if there's a block with type "landing" (displayed as "Landing Page") | ||
| var hasLandingPage = false; | ||
|
|
||
| // Method 1: Check for the block type label "Landing Page" in the layout field | ||
| var $landingPageLabel = $layoutField.find('.c-sf-block_type').filter(function() { | ||
| return $(this).text().trim() === 'Landing Page'; | ||
| }); | ||
|
|
||
| if ($landingPageLabel.length > 0) { | ||
| hasLandingPage = true; | ||
| } else { | ||
| // Method 2: Check hidden inputs for block type value "landing" | ||
| $layoutField.find('input[type="hidden"][name*="type"], input[type="hidden"][name*="block_type"]').each(function() { | ||
| if ($(this).val() === 'landing') { | ||
| hasLandingPage = true; | ||
| return false; // break | ||
| } | ||
| }); | ||
|
|
||
| // Method 3: Check StreamField value directly via JSON data | ||
| if (!hasLandingPage) { | ||
| var $hiddenInput = $layoutField.find('input[type="hidden"][name*="layout"]'); | ||
| if ($hiddenInput.length > 0) { | ||
| try { | ||
| var streamValue = JSON.parse($hiddenInput.val() || '[]'); | ||
| if (Array.isArray(streamValue) && streamValue.length > 0) { | ||
| hasLandingPage = streamValue[0].type === 'landing'; | ||
| } | ||
| } catch (e) { | ||
| // JSON parse failed, continue with other methods | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Find the School field panel | ||
| // Try multiple selectors based on Wagtail panel structure | ||
| var $schoolPanel = null; | ||
|
|
||
| // Try by ID first (based on image description showing panel IDs) | ||
| var schoolPanelIds = [ | ||
| '#panel-child-content-school', | ||
| '#panel-child-content-school-section', | ||
| '[id*="panel"][id*="school"]' | ||
| ]; | ||
|
|
||
| for (var i = 0; i < schoolPanelIds.length; i++) { | ||
| var $found = $(schoolPanelIds[i]).closest('.w-panel, section.w-panel'); | ||
| if ($found.length > 0) { | ||
| $schoolPanel = $found; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // If not found by ID, try finding by label/heading text "School" | ||
| // Scope search to the form container to avoid false matches | ||
| if (!$schoolPanel || $schoolPanel.length === 0) { | ||
| var $formContainer = $('.w-form-width, .w-form, [class*="wagtail"]').first(); | ||
| if ($formContainer.length === 0) { | ||
| $formContainer = $('form').first(); | ||
| } | ||
|
|
||
| $formContainer.find('label, .w-panel_heading, h2, [data-panel-heading-text]').each(function() { | ||
| var $el = $(this); | ||
| var text = $el.text().trim(); | ||
| if (text.toLowerCase() === 'school') { | ||
| $schoolPanel = $el.closest('.w-panel, section.w-panel'); | ||
| if ($schoolPanel.length > 0) { | ||
| return false; // break | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| // Last resort: try finding by data-contentpath | ||
| if (!$schoolPanel || $schoolPanel.length === 0) { | ||
| $schoolPanel = $('[data-contentpath="school"]').closest('.w-panel, section.w-panel'); | ||
| } | ||
|
|
||
| // Show or hide the School panel | ||
| if ($schoolPanel && $schoolPanel.length > 0) { | ||
| if (hasLandingPage) { | ||
| $schoolPanel.show(); | ||
| } else { | ||
| $schoolPanel.hide(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Check on page load | ||
| checkAndToggleSchoolField(); | ||
|
|
||
| // Also check after a delay to ensure StreamField is fully initialized | ||
| setTimeout(checkAndToggleSchoolField, 500); | ||
|
|
||
| // Listen for StreamField changes (when blocks are added/removed/changed) | ||
| // Wagtail triggers custom events on StreamField changes | ||
| $(document).on('wagtail:stream-field-block-added wagtail:stream-field-block-removed wagtail:stream-field-block-moved', function() { | ||
| setTimeout(checkAndToggleSchoolField, 100); | ||
| }); | ||
|
|
||
| // Also listen for any changes in the layout field container | ||
| var $layoutField = $('[data-contentpath="layout"]'); | ||
| if ($layoutField.length > 0) { | ||
| // Use MutationObserver to watch for DOM changes in the layout field | ||
| var observer = new MutationObserver(function(mutations) { | ||
| checkAndToggleSchoolField(); | ||
| }); | ||
|
|
||
| observer.observe($layoutField[0], { | ||
| childList: true, | ||
| subtree: true, | ||
| attributes: true, | ||
| characterData: true | ||
| }); | ||
| } | ||
|
|
||
| // Fallback: Also check periodically (with debouncing) | ||
| var checkTimeout; | ||
| $(document).on('change click input', '[data-contentpath="layout"]', function() { | ||
| clearTimeout(checkTimeout); | ||
| checkTimeout = setTimeout(checkAndToggleSchoolField, 200); | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| // Start initialization | ||
| init(); | ||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from django.templatetags.static import static | ||
| from django.utils.html import format_html | ||
| from wagtail import hooks | ||
| from pages.models import RootPage | ||
|
|
||
| @hooks.register('insert_editor_js') | ||
| def conditional_school_field_js(request): | ||
| """Inject JavaScript to conditionally show school field only for RootPage edit views""" | ||
| # Only inject JS if editing a RootPage instance | ||
| if hasattr(request, 'instance') and isinstance(getattr(request, 'instance', None), RootPage): | ||
| return format_html( | ||
| '<script src="{}"></script>', | ||
| static('pages/conditional-school-field.js') | ||
| ) | ||
| return '' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Generated by Django 5.1.12 on 2025-12-05 17:28 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("salesforce", "0113_school_created_school_updated"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="school", | ||
| name="industry", | ||
| field=models.CharField(blank=True, max_length=255, null=True), | ||
| ), | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: JS injection check relies on non-existent request attribute
The
insert_editor_jshook checks forrequest.instanceto determine whether to inject the JavaScript, but Django request objects do not have aninstanceattribute. Wagtail does not attach the page instance being edited to the request object. This means the conditionhasattr(request, 'instance')will always beFalse, and the conditional school field JavaScript will never be loaded when editingRootPageinstances.