Skip to content
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

feat: tup 706 conditionally serve raw markup #872

Closed

Conversation

wesleyboar
Copy link
Member

@wesleyboar wesleyboar commented Sep 13, 2024

Overview

Goal: Render TACC News outside of TACC (when we should not just link the user).

Important

Supports requirement for LCCF website to show LCCF news from TACC.

Feature: Allow client to load raw page content markup (no header, no footer).

Use Case? Load news pages of one website (e.g. TACC) on other websites (e.g. LCCF, WeTeach CS). By having raw markup available at a URL, another website can load and inject that markup on its own page, thus borrowing news articles and lists rather than duplicating them.

Proof of Concept? In #868, I create and run an app that injects remote content. (I am still thinking how/when best to run the app.)

Bonus: Allow dev to render a page with any Core template (or one of their own).

Use Case? Test new templates for future custom CMS features without editing Core.

How to Use One of Their Own? Add (or override) a template into taccsite_cms/templates via Dockerfile, as is done in some Core-CMS-Custom projects (apcd_cms, ecep_cms) and TUP (tup-cms).

Related

Changes

  • added middleware to change template at runtime before render

Testing

  1. In custom_app_settings.py, add new middleware to CUSTOM_MIDDLEWARE e.g.

    CUSTOM_MIDDLEWARE = ['taccsite_cms.middleware.cms_template.CMSTemplateMiddleware']
  2. Load pages with recognized query parameters.

    ?raw template=raw.html
    good - raw good - template raw html
  3. Verify page loads with raw.html template.

  4. Load pages with ineffectual query parameters.

    (no query) ?rawng template=raw template=raw
    noop noop - rawng noop - template noop - template raw
  5. Verify page loads with template that the page would normally use.

wesleyboar and others added 30 commits July 19, 2024 15:54
NOT WORKING! Fails with:

> NoReverseMatch at /feed/
> '' is not a registered namespace
Fails, because it renders nothing.
Load `/blog/remote`.

BREAKING CHANGE: Changed `/blog` to `/blog/local`
⚠️ Does NOT render feed items.
This reverts commit 6bece39.

This did not fix anything. `SESSION_COOKIE_SECURE=False` is still required locally.
- ✓ fix links to articles
- ✓ fix pagination links
@wesleyboar wesleyboar mentioned this pull request Sep 13, 2024
11 tasks
@wesleyboar wesleyboar added feature A new feature or replacement of present feature effort XS Extra small effort task (~¼ a week) — does not include review time labels Sep 13, 2024
@wesleyboar wesleyboar marked this pull request as ready for review September 13, 2024 21:22
@wesleyboar wesleyboar changed the title feat: tup 706 serve raw content conditionally feat: tup 706 conditionally serve raw markup Sep 16, 2024
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')

class CMSTemplateMiddleware(ToolbarMiddleware):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking: is this the most descriptive name for the middleware class name?

Copy link
Member Author

@wesleyboar wesleyboar Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. What I know:

  • It allows one to explicitly swap to one of the CMS_TEMPLATES.
  • It supports shorthand for implicit swap i.e. ?raw.
  • It seems typical to prepend append the name of a Django class with the kind of class it is.

What about these names:

  • CMSTemplateSwapMiddleware
  • CMSTemplateChangeMiddleware
  • CMSTemplateOverrideMiddleware

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any of those proposed is great, thanks @wesleyboar

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed… but PR closed, because the ?template=….html feature already works by default. 😅

@wesleyboar
Copy link
Member Author

wesleyboar commented Feb 6, 2025

Important

?template=whatever.html works without this middleware.

Testing

  1. Load page on this branch, without registering middleware, with ?template=raw.html and again with ?raw locally without registering middleware:
    • ?template=raw.html changes CMS page template
  2. Load page on old site before this PR with ?template=fullwidth.html:
    • template changes
  3. Load page on Django CMS demo About page with ?template=full-width.html and then without ?template=full-width.html:
    • different page templates used
  4. Load DesignSafe-CI without any ?template and with ?template=cms_homepage.html:
    • layout changes (specifically, navbar layout)
Video of Test on Official Demo
official.demo.test.template.query.param.mov

No wonder I had such difficulty debugging when this middleware worked and didn't work… half of it was supported by default!

@wesleyboar wesleyboar closed this Feb 6, 2025
@wesleyboar wesleyboar deleted the feat/tup-706-serve-raw-blog-content-conditionally branch February 6, 2025 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort XS Extra small effort task (~¼ a week) — does not include review time feature A new feature or replacement of present feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants