From e4492dd481963f253bdfeeccc16878b7a10b0668 Mon Sep 17 00:00:00 2001 From: Wesley B <62723358+wesleyboar@users.noreply.github.com> Date: Tue, 16 Jun 2026 14:24:00 -0500 Subject: [PATCH] feat(gh-999): default Header logo form values on add New HeaderLogoForm pre-fills home link, height 50, original image, and mr-5 for editors; addresses #1083 follow-up. Plan doc notes deferred settings parity. --- docs/gh-999-editable-header-plan.md | 1 + .../taccsite_header_logo/cms_plugins.py | 3 ++ .../contrib/taccsite_header_logo/forms.py | 34 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 taccsite_cms/contrib/taccsite_header_logo/forms.py diff --git a/docs/gh-999-editable-header-plan.md b/docs/gh-999-editable-header-plan.md index cdf717c63..70e089a9b 100644 --- a/docs/gh-999-editable-header-plan.md +++ b/docs/gh-999-editable-header-plan.md @@ -21,6 +21,7 @@ Plan for [#999 Let CMS Admin Edit Header](https://github.com/TACC/Core-CMS/issue - **Render:** Standard Picture template at `{% static_placeholder "header-content" %}`. - **Empty placeholder:** `or` fallback [`header_logo_via_settings.html`](taccsite_cms/templates/header_logo_via_settings.html) (`LOGO` / `PORTAL_LOGO`). - **Branding images (PR 3):** nested Pictures under TACC Header Branding — not top-level. +- **Follow-up:** Match `PORTAL_LOGO` / `header_logo_via_settings.html` defaults to Header logo form defaults (margin, height, link) and Core-Styles — deferred until willing to test Core-Styles. ## PR stack diff --git a/taccsite_cms/contrib/taccsite_header_logo/cms_plugins.py b/taccsite_cms/contrib/taccsite_header_logo/cms_plugins.py index 3a8c8b32e..25dc0470b 100644 --- a/taccsite_cms/contrib/taccsite_header_logo/cms_plugins.py +++ b/taccsite_cms/contrib/taccsite_header_logo/cms_plugins.py @@ -4,6 +4,8 @@ from djangocms_picture.cms_plugins import PicturePlugin from djangocms_picture.models import Picture +from .forms import HeaderLogoForm + HEADER_LOGO_ELEMENT_ID = 'header-logo' @@ -15,6 +17,7 @@ class HeaderLogoPlugin(PicturePlugin): Full Picture plugin; default id="header-logo" when not set in Attributes. """ model = Picture + form = HeaderLogoForm module = _('TACC Header') name = _('Header logo') diff --git a/taccsite_cms/contrib/taccsite_header_logo/forms.py b/taccsite_cms/contrib/taccsite_header_logo/forms.py new file mode 100644 index 000000000..787b9a680 --- /dev/null +++ b/taccsite_cms/contrib/taccsite_header_logo/forms.py @@ -0,0 +1,34 @@ +from cms.models import Page +from django.contrib.sites.models import Site +from djangocms_picture.forms import PictureForm + + +def default_home_page(): + site = Site.objects.get_current() + return Page.objects.filter(is_home=True, node__site=site).first() + + +class HeaderLogoForm(PictureForm): + """ + Defaults for new Header logo plugins only (admin add form). + + With a link, TACC default picture.html puts Attributes (e.g. class mr-5) on + the , not the . + """ + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + if self.instance.pk: + return + + home = default_home_page() + if home is not None: + self.initial.setdefault('link_page', home.pk) + + self.initial.setdefault('height', 50) + self.initial.setdefault('use_no_cropping', True) + self.initial.setdefault('use_automatic_scaling', False) + + attributes = dict(self.initial.get('attributes') or {}) + attributes.setdefault('class', 'mr-5') + self.initial['attributes'] = attributes