From 7d56f8d8dbf1805c3a0535d6278c3298473920a4 Mon Sep 17 00:00:00 2001 From: Wesley B <62723358+wesleyboar@users.noreply.github.com> Date: Fri, 13 Sep 2024 17:41:07 -0500 Subject: [PATCH] =?UTF-8?q?refactor:=20djangocms=5Fblog=5Fcustom=E2=80=A6?= =?UTF-8?q?=20=E2=86=92=20remote=5Fcontent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This changes remote blog load to be remote anything load. This removes the failed custom feed (archived in TACC/Core-CMS#874): https://github.com/TACC/Core-CMS/pull/874 --- apps/djangocms_blog_customizations/apps.py | 5 --- apps/djangocms_blog_customizations/feeds.py | 26 --------------- apps/djangocms_blog_customizations/urls.py | 32 ------------------- .../__init__.py | 0 apps/remote_content/apps.py | 4 +++ .../templates/remote_content/markup.html} | 0 apps/remote_content/urls.py | 17 ++++++++++ .../views.py | 15 ++++----- taccsite_cms/custom_app_settings.example.py | 2 +- 9 files changed, 28 insertions(+), 73 deletions(-) delete mode 100644 apps/djangocms_blog_customizations/apps.py delete mode 100644 apps/djangocms_blog_customizations/feeds.py delete mode 100644 apps/djangocms_blog_customizations/urls.py rename apps/{djangocms_blog_customizations => remote_content}/__init__.py (100%) create mode 100644 apps/remote_content/apps.py rename apps/{djangocms_blog_customizations/templates/djangocms_blog_customizations/remote.html => remote_content/templates/remote_content/markup.html} (100%) create mode 100644 apps/remote_content/urls.py rename apps/{djangocms_blog_customizations => remote_content}/views.py (77%) diff --git a/apps/djangocms_blog_customizations/apps.py b/apps/djangocms_blog_customizations/apps.py deleted file mode 100644 index 90394df2f..000000000 --- a/apps/djangocms_blog_customizations/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig -from django.utils.translation import gettext_lazy as _ - -class customBlogAppConfig(AppConfig): - name = 'apps.djangocms_blog_customizations' diff --git a/apps/djangocms_blog_customizations/feeds.py b/apps/djangocms_blog_customizations/feeds.py deleted file mode 100644 index a1d008ece..000000000 --- a/apps/djangocms_blog_customizations/feeds.py +++ /dev/null @@ -1,26 +0,0 @@ -from aldryn_apphooks_config.utils import get_app_instance -from django.utils.feedgenerator import Rss201rev2Feed - -from djangocms_blog.feeds import LatestEntriesFeed as DjangoCMSBlogLatestEntriesFeed -from djangocms_blog.settings import get_setting -from djangocms_blog.cms_appconfig import BlogConfig - -# XXX: This file is loaded, but it does NOT override the feed -# XXX: Logging via logger fails anywhere; via print fails inside any method -class LatestEntriesFeed(DjangoCMSBlogLatestEntriesFeed): - feed_type = Rss201rev2Feed - feed_items_number = get_setting("FEED_LATEST_ITEMS") - - def __call__(self, request, *args, **kwargs): - namespace = get_setting("AUTO_NAMESPACE") - - self.request = request - self.namespace = get_setting("AUTO_NAMESPACE") - self.config = BlogConfig.objects.get(namespace=namespace) - - return super().__call__(request, *args, **kwargs) - - def items(self): - items = super().items() - - return items diff --git a/apps/djangocms_blog_customizations/urls.py b/apps/djangocms_blog_customizations/urls.py deleted file mode 100644 index 4eee7b1c5..000000000 --- a/apps/djangocms_blog_customizations/urls.py +++ /dev/null @@ -1,32 +0,0 @@ -import re - -from django.urls import re_path -# from django.conf import settings - -from .feeds import LatestEntriesFeed -from .views import BlogView, BlogRemoteView - - -app_name = 'djangocms_blog_customizations' - -# blogRemoteUrlPattern = r'^' + re.escape(settings.PORTAL_BLOG_REMOTE_CLIENT_PATH) -urlpatterns = [ - # To render styled Blog feed - # XXX: Does NOT style the feed - # XXX: Does NOT customize the feed - # FAQ: See errors at `/blog/feed/`, items at `/blog/feed/fb` - # FAQ: See Blog app feed root at `/news/feed/`, items at `/news/feed/fb` - re_path(r'^feed/', LatestEntriesFeed(), name='feed'), - - # To render current blog, content only (no Core-CMS base.html) - # XXX: Does NOT render blog content - # XXX: Does NOT escape Core-CMS base.html - # FAQ: URL is `/blog/local` - re_path(r'^local/', BlogView, name='base'), - - # To render a blog (or any page) from another website - # XXX: URLs are still local - # XXX: Is NOT blog-specific, so should be a generic feature - # TODO: Use settings.PORTAL_BLOG_REMOTE_CLIENT_PATH - re_path(r'^remote/', BlogRemoteView.as_view(), name='remote'), -] diff --git a/apps/djangocms_blog_customizations/__init__.py b/apps/remote_content/__init__.py similarity index 100% rename from apps/djangocms_blog_customizations/__init__.py rename to apps/remote_content/__init__.py diff --git a/apps/remote_content/apps.py b/apps/remote_content/apps.py new file mode 100644 index 000000000..a759ec1b8 --- /dev/null +++ b/apps/remote_content/apps.py @@ -0,0 +1,4 @@ +from django.apps import AppConfig + +class remoteContentAppConfig(AppConfig): + name = 'apps.remote_content' diff --git a/apps/djangocms_blog_customizations/templates/djangocms_blog_customizations/remote.html b/apps/remote_content/templates/remote_content/markup.html similarity index 100% rename from apps/djangocms_blog_customizations/templates/djangocms_blog_customizations/remote.html rename to apps/remote_content/templates/remote_content/markup.html diff --git a/apps/remote_content/urls.py b/apps/remote_content/urls.py new file mode 100644 index 000000000..502538b8d --- /dev/null +++ b/apps/remote_content/urls.py @@ -0,0 +1,17 @@ +import re + +from django.urls import re_path +# from django.conf import settings + +from .views import RemoteMarkup + + +app_name = 'remote_content' + +# blogRemoteUrlPattern = r'^' + re.escape(settings.PORTAL_REMOTE_CONTENT_CLIENT_PATH) +urlpatterns = [ + # To render a blog (or any page) from another website + # TODO: Use query parameter, not URL path + # TODO: Use settings.PORTAL_REMOTE_CONTENT_CLIENT_PATH + re_path(r'^markup/', RemoteMarkup.as_view(), name='remote_markup'), +] diff --git a/apps/djangocms_blog_customizations/views.py b/apps/remote_content/views.py similarity index 77% rename from apps/djangocms_blog_customizations/views.py rename to apps/remote_content/views.py index 823a086f3..fbe635860 100644 --- a/apps/djangocms_blog_customizations/views.py +++ b/apps/remote_content/views.py @@ -7,11 +7,8 @@ from django.shortcuts import render from django.views.generic.base import TemplateView -def BlogView(request): - return render(request, 'djangocms_blog/base.html') - -class BlogRemoteView(TemplateView): - template_name = 'djangocms_blog_customizations/remote.html' +class RemoteMarkup(TemplateView): + template_name = 'remote_content/markup.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -24,8 +21,8 @@ def get_context_data(self, **kwargs): return context def get_source_url(self): - client_path = settings.PORTAL_BLOG_REMOTE_CLIENT_PATH - source_root = settings.PORTAL_BLOG_REMOTE_SOURCE_ROOT + client_path = settings.PORTAL_REMOTE_CONTENT_CLIENT_PATH + source_root = settings.PORTAL_REMOTE_CONTENT_SOURCE_ROOT client = urlparse(self.request.build_absolute_uri()) source = urlparse(source_root) @@ -48,8 +45,8 @@ def get_source_markup(self, url): # CAVEAT: Causes a view request for every resource (img/script/stylesheet) def get_client_markup(self, source_markup): - source = urlparse(settings.PORTAL_BLOG_REMOTE_SOURCE_ROOT) - client_path = settings.PORTAL_BLOG_REMOTE_CLIENT_PATH + source = urlparse(settings.PORTAL_REMOTE_CONTENT_SOURCE_ROOT) + client_path = settings.PORTAL_REMOTE_CONTENT_CLIENT_PATH # FAQ: No markup for bad URL or a resource specific to source wesbite if source_markup: diff --git a/taccsite_cms/custom_app_settings.example.py b/taccsite_cms/custom_app_settings.example.py index fb9165c55..a48ec503a 100644 --- a/taccsite_cms/custom_app_settings.example.py +++ b/taccsite_cms/custom_app_settings.example.py @@ -1,3 +1,3 @@ -CUSTOM_APPS = ['apps.custom_example', 'apps.djangocms_blog_customizations'] +CUSTOM_APPS = ['apps.custom_example', 'apps.remote_content'] CUSTOM_MIDDLEWARE = [] STATICFILES_DIRS = ()