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 news on other sites #868

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
17640a4
refactor: CMD-97 breadcrumbs for news via 1 template
wesleyboar Jul 16, 2024
55dc431
idea: TUP-706 4.a.i change RSS feed render ⚠️
wesleyboar Jul 19, 2024
de81256
refactor: TUP-706 rename and document blog block
wesleyboar Jul 22, 2024
463871f
feat: TUP-706 render page with only (*_)content
wesleyboar Jul 22, 2024
8038de7
fix: TUP-706 disable failed djangocms_blog_c… url
wesleyboar Jul 22, 2024
89a160c
idea!: TUP-706 render blog base via custom app
wesleyboar Jul 22, 2024
db234df
feat!: TUP-706 render remote url content
wesleyboar Jul 22, 2024
d7f10ae
chore: TUP-706 move an import higher in file
wesleyboar Jul 22, 2024
ec10c85
feat: TUP-706 render remote url via setting
wesleyboar Jul 22, 2024
223b72a
fix: TUP-706 render blog customizations
wesleyboar Jul 22, 2024
aaa971e
Merge branch 'main' into feat/tup-706-news-on-other-sites
wesleyboar Jul 22, 2024
646b26d
fix: TUP-706 render feed ⚠️
wesleyboar Jul 22, 2024
aa709fd
docs: TUP-706 describe each URL's problem
wesleyboar Jul 22, 2024
26a9412
docs: TUP-706 describe each URL goal and status
wesleyboar Jul 22, 2024
4e78038
feat: TUP-706 A.1+3.c remote markup via template
wesleyboar Jul 22, 2024
17380fb
Merge branch 'main' into feat/tup-706-news-on-other-sites
wesleyboar Jul 23, 2024
a461693
feat: TUP-706 A.1.a. support BLOG_MULTISITE
wesleyboar Jul 23, 2024
6bece39
fix: TUP-706 A.1.a. cannot login to site 2
wesleyboar Jul 23, 2024
e6bdbbf
Revert "fix: TUP-706 A.1.a. cannot login to site 2"
wesleyboar Jul 23, 2024
4f9888b
Merge branch 'main' into feat/tup-706-news-on-other-sites
wesleyboar Sep 10, 2024
104fe71
docs: TUP-706 feed status (ineffectual)
wesleyboar Sep 10, 2024
dfc9fa4
docs: tup-706 urls for local and remote
wesleyboar Sep 10, 2024
cd59bf9
feat(poc): TUP-706 get news from remote url
wesleyboar Sep 11, 2024
6995c44
chore: remove test print statements from feeds
wesleyboar Sep 11, 2024
db79397
core: clean up views
wesleyboar Sep 11, 2024
a6d8551
core: clean up views more
wesleyboar Sep 11, 2024
82027fe
refactor: switch order of methods in view class
wesleyboar Sep 11, 2024
0c94401
feat: TUP-706 edit links via get_client_markup()
wesleyboar Sep 11, 2024
49edd04
fix: TUP-706 broken links
wesleyboar Sep 12, 2024
22c6ac3
Merge branch 'main' into feat/tup-706-news-on-other-sites
wesleyboar Sep 13, 2024
c1659f2
chore: remove SITE_ID middleware
wesleyboar Sep 13, 2024
6cd5a77
chore: delete cruft from messy merge
wesleyboar Sep 13, 2024
7d56f8d
refactor: djangocms_blog_custom… → remote_content
wesleyboar Sep 13, 2024
06304c9
Merge branch 'main' into feat/tup-706-news-on-other-sites
wesleyboar Sep 13, 2024
92ed5de
fix: load raw markup from remote site
wesleyboar Sep 18, 2024
2fc6f36
fix: load raw markup from remote site
wesleyboar Sep 18, 2024
98b13e7
style: move parameter
wesleyboar Sep 18, 2024
fef2cb3
feat!: change mage source not article link
wesleyboar Sep 18, 2024
deffe74
fix: links to articles should open on source
wesleyboar Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added apps/remote_content/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions apps/remote_content/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.apps import AppConfig

class remoteContentAppConfig(AppConfig):
name = 'apps.remote_content'
1 change: 1 addition & 0 deletions apps/remote_content/templates/remote_content/markup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ markup|safe }}
17 changes: 17 additions & 0 deletions apps/remote_content/urls.py
Original file line number Diff line number Diff line change
@@ -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'),
]
72 changes: 72 additions & 0 deletions apps/remote_content/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import requests

from urllib.parse import urlparse, urlencode, parse_qsl

from django.conf import settings
from django.template import Template, Context
from django.shortcuts import render
from django.views.generic.base import TemplateView

class RemoteMarkup(TemplateView):
template_name = 'remote_content/markup.html'

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
source_url = self.get_source_url()
source_markup = self.get_source_markup(source_url)
client_markup = self.get_client_markup(source_markup)

context['markup'] = client_markup

return context

def get_source_url(self):
source_root = settings.PORTAL_REMOTE_CONTENT_SOURCE_ROOT
client = urlparse(self.request.build_absolute_uri())
source = urlparse(source_root)

client_path = settings.PORTAL_REMOTE_CONTENT_CLIENT_PATH
source_path = source.path + client.path.replace(client_path, '')

source_url = client._replace(
scheme=source.scheme,
netloc=source.netloc,
path=source_path,
).geturl()
source_url = add_query_params(source_url, {'raw':''})

return source_url

def get_source_markup(self, url):
response = requests.get(url)

if response.status_code == 200:
return response.text
else:
return None

# CAVEAT: Causes a view request for every resource (img/script/stylesheet)
def get_client_markup(self, source_markup):
client_markup = None

source = urlparse(settings.PORTAL_REMOTE_CONTENT_SOURCE_ROOT)
source_site = source.scheme + '://' + source.netloc

# FAQ: No markup for bad URL or a resource specific to source wesbite
if source_markup:
client_markup = source_markup.replace(
'src="',
'crossorigin="anonymous" src="' + source_site
).replace(
'href="' + source.path,
'target="_blank" href="' + source_site + source.path
)

return client_markup

def add_query_params(url, params):
request = requests.PreparedRequest()

request.prepare_url(url, params)

return request.url
2 changes: 1 addition & 1 deletion taccsite_cms/custom_app_settings.example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CUSTOM_APPS = ['apps.custom_example']
CUSTOM_APPS = ['apps.custom_example', 'apps.remote_content']
CUSTOM_MIDDLEWARE = []
STATICFILES_DIRS = ()