-
Notifications
You must be signed in to change notification settings - Fork 2
feat: GH-999 let CMS admin change header logo #1083
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
base: main
Are you sure you want to change the base?
Changes from all commits
e2f7c53
f52b8b2
ead8569
53cfef6
e1d19d9
9fef1c3
7459528
d156af6
d5b2a36
c7f4454
15a1c2d
053fdd7
79f14b3
c42f211
15fc05c
07c0c2a
27fa19d
96ed5cd
7070552
3ee0438
fc6bb82
1937592
fc7eb38
0d4fd91
42a801a
c85cc71
2cabc1c
e56e434
b737a87
34988a7
440ceba
606a0eb
559dbf7
9beaf61
a4f1a43
1d01d08
9ff3bc2
958e340
74241ec
56931f1
f878b60
97d3382
d8d6114
7450f3f
a6b9209
4c79ddf
cead748
950ed99
d361e90
1d96a54
39a8386
b41b1a6
791d412
0d31361
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class TaccsiteHeaderLogoConfig(AppConfig): | ||
| name = 'djangocms_tacc_header_logo' | ||
| verbose_name = 'Header logo' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from cms.plugin_pool import plugin_pool | ||
| from django.utils.translation import gettext_lazy as _ | ||
|
|
||
| from djangocms_picture.cms_plugins import PicturePlugin | ||
| from djangocms_picture.models import Picture | ||
|
|
||
| from .forms import TaccsiteHeaderLogoForm | ||
|
|
||
| HEADER_LOGO_ID = 'header-logo' | ||
| HEADER_LOGO_CLASS = 'navbar-brand' | ||
|
|
||
|
|
||
| @plugin_pool.register_plugin | ||
| class TaccsiteHeaderLogoPlugin(PicturePlugin): | ||
| """ | ||
| Components > "Header logo" Plugin | ||
| """ | ||
| model = Picture | ||
| form = TaccsiteHeaderLogoForm | ||
| module = 'TACC Site' | ||
| name = _('Header logo') | ||
|
|
||
| def render(self, context, instance, placeholder): | ||
| if not instance.attributes: | ||
| instance.attributes = {} | ||
|
|
||
| existing_class = instance.attributes.get('class', '') | ||
| instance.attributes['class'] = f'{HEADER_LOGO_CLASS} {existing_class}'.strip() | ||
| instance.attributes['id'] = HEADER_LOGO_ID | ||
|
|
||
| return super().render(context, instance, placeholder) |
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set default configuration of a Picture-as-Header-logo. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| from cms.models import Page | ||
| from django.conf import settings | ||
| from django.contrib.sites.models import Site | ||
| from djangocms_picture.forms import PictureForm | ||
|
|
||
| HEADER_LOGO_TEMPLATE_WITH_PORTAL = 'portal_logo' | ||
|
|
||
|
|
||
| def default_home_page(): | ||
| site = Site.objects.get_current() | ||
| return Page.objects.filter(is_home=True, node__site=site).first() | ||
|
|
||
|
|
||
| class TaccsiteHeaderLogoForm(PictureForm): | ||
| """ | ||
| Defaults for new Header logo plugins only (admin add form). | ||
|
|
||
| On a TACC/Core-Portal instance, defaults to Portal logo picture template. | ||
| """ | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| super().__init__(*args, **kwargs) | ||
| if self.instance.pk: | ||
| return | ||
|
|
||
| if settings.PORTAL_IS_TACC_CORE_PORTAL: | ||
| self.initial.setdefault('template', HEADER_LOGO_TEMPLATE_WITH_PORTAL) | ||
|
|
||
| home = default_home_page() | ||
| if home is not None: | ||
| self.initial.setdefault('link_page', home.pk) | ||
|
|
||
| self.initial.setdefault('use_no_cropping', True) | ||
| self.initial.setdefault('use_automatic_scaling', False) | ||
|
|
||
| attributes = dict(self.initial.get('attributes') or {}) | ||
| attributes.setdefault('alt', 'Project logo') | ||
| self.initial['attributes'] = attributes |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # GH-999: Editable Header | ||
|
|
||
| Related: | ||
|
|
||
| - [#999](https://github.com/TACC/Core-CMS/issues/999) | ||
| - [#1083](https://github.com/TACC/Core-CMS/pull/1083) | ||
|
|
||
| ## Status as of 2026-06 | ||
|
|
||
| | State | Description | | ||
| | ------------------- | --------------------------------- | | ||
| | one placeholder | `header-logo` static placeholder | | ||
| | if plugin is added | `TaccsiteHeaderLogoPlugin` is only option | | ||
| | if plugin not added | renders settings-based logo | | ||
|
|
||
| The branding and navs and search are still settings-based. | ||
|
|
||
| ## Known Limitations | ||
|
|
||
| | Issue | Summary | Why Allow This? | | ||
| | --- | --- | --- | | ||
| | [#1185](https://github.com/TACC/Core-CMS/issues/1185) | Header logo without a link is **missing** `class="portal-logo"` on `<img>`. | Default form links logo to home, so typical sites are unaffected. | | ||
|
|
||
| ## How to Add Other Header Plugins | ||
|
|
||
| Requirements: | ||
|
|
||
| - (for [CMS editor UX](#cms-editor-ux)) plugins render where `{% static_placeholder %}` sits | ||
| - (to skip [Failed Ideas](#failed-ideas)) pick one option from below | ||
|
|
||
| ### A. Wrapper Plugin | ||
|
|
||
| | Pros | Cons | | ||
| | ------------------------------ | ---------------------------------------------- | | ||
| | One placeholder | Extra container plugin | | ||
| | Layout management consolidated | Build/Maintain wrapper | | ||
| | | Must deprecate or migrate legacy `header-logo` | | ||
|
|
||
| ### B. Multiple Placeholders | ||
|
|
||
| | Pros | Cons | | ||
| | ---------------------------------- | ---------------------------------- | | ||
| | Typical CMS usage | Several placeholders to configure | | ||
| | | Layout management not consolidated | | ||
| | Can keep using `header-logo` as is | | | ||
|
|
||
| ## CMS Editor UX | ||
|
|
||
| Requirements: | ||
|
|
||
| - Static placeholder always visible in Structure mode. | ||
| - Edit plugin: auto-refreshes page preview. | ||
| - Add/Delete plugin: auto-refreshes page preview. | ||
| - Structure mode button toggles render of Structure sidebar. | ||
|
|
||
| ## Failed Ideas | ||
|
|
||
| | Idea | Problem | | ||
| | --- | --- | | ||
| | `ContentRenderer` / template tag for the logo instead of `{% static_placeholder %}` at the logo | Structure and preview break; Picture edits need refresh (removed in [#1189](https://github.com/TACC/Core-CMS/pull/1189)) | | ||
| | Published markup from code, placeholder somewhere else | Duplicate logo surfaces; draft image lags behind preview | | ||
| | Child plugins under the logo, HTML rendered elsewhere | Structure/preview break | | ||
| | `{% static_placeholder %}` not where the logo shows | Bad WYSIWYG; toolbar/Structure bugs | | ||
| | Per-region render registry (not Option A or B) | Live site publish-only; bad edit UX | | ||
| | Option A wrapper before more header plugins exist | Two plugins for one logo | | ||
| | Plugin `cache = False` only | Does not fix placeholder vs programmatic render | | ||
| | Edit-only placeholder at top of header | Structure JS errors; no real preview | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
| ] | ||
| DJANGOCMS_PICTURE_TEMPLATES = [ | ||
| ('no_link_to_ext_image', _('Do not link to external image')), | ||
| ('portal_logo', _('Portal logo')), | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To load |
||
| ] | ||
|
|
||
| ######################## | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -494,6 +494,7 @@ def gettext(s): return s | |
| 'taccsite_card', | ||
| 'djangocms_tacc_image_gallery', | ||
| 'djangocms_tacc_system_monitor', | ||
| 'djangocms_tacc_header_logo', | ||
|
|
||
| # TACC CMS Plugins - DECPRECATED | ||
| 'taccsite_cms.contrib.taccsite_blockquote', | ||
|
|
@@ -567,6 +568,17 @@ def get_subdirs_as_module_names(path): | |
|
|
||
| CMS_PERMISSION = True | ||
| CMS_PLACEHOLDER_CONF = { | ||
| None: { | ||
| 'excluded_plugins': ['TaccsiteHeaderLogoPlugin'], | ||
| }, | ||
| 'header-logo': { | ||
| 'name': _('Header logo'), | ||
| 'plugins': ['TaccsiteHeaderLogoPlugin'], | ||
| 'excluded_plugins': [], | ||
| 'limits': { | ||
| 'global': 1, | ||
| }, | ||
| }, | ||
|
Comment on lines
+571
to
+581
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name the placeholder and limit its content to a header logo. |
||
| 'footer-content': { | ||
| 'name': _('Footer content'), | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,9 @@ | |
| {{ instance.attributes_str }} | ||
| {% endblock %} | ||
| {# /TACC #} | ||
| {# TACC (allow attributes to be force-added to <img>): #} | ||
| {% block picture_attributes_img %}{% if picture_img_class %}class="{{ picture_img_class }}"{% endif %}{% endblock %} | ||
| {# /TACC #} | ||
|
Comment on lines
+62
to
+64
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This lets us force the class on Caution If Footnotes
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Important I accept this bug for now.1 I document this bug for now. Footnotes
|
||
| > | ||
| {% endlocalize %} | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| {% extends "djangocms_picture/default/picture.html" %} | ||
| {% block picture_attributes_img %}class="portal-logo"{% endblock %} |
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The keystone code is in this file. |
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.
Create header logo plugin (extends Picture) so we can control:
forms.py)