From 80d295ca28b5d8e8e3bb6f1b9f49ca6ccef248e5 Mon Sep 17 00:00:00 2001 From: zediious Date: Mon, 6 Nov 2023 11:00:24 -0500 Subject: [PATCH 1/5] Correct duplicated URL on og_image --- raptorWeb/raptormc/routes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/raptorWeb/raptormc/routes.py b/raptorWeb/raptormc/routes.py index 56cc7af4..5472777a 100644 --- a/raptorWeb/raptormc/routes.py +++ b/raptorWeb/raptormc/routes.py @@ -83,7 +83,7 @@ def _get_page_routes(): return { "og_color": site_info.main_color, "og_url": f"{WEB_PROTO}://{DOMAIN_NAME}", - "og_image": f"{WEB_PROTO}://{DOMAIN_NAME}/{site_avatar_url}", + "og_image": f"{site_avatar_url}", "og_title": f"{site_info.brand_name} | Home", "og_desc": site_info.meta_description } @@ -125,7 +125,7 @@ def _get_page_routes(): "og_page": route.page, "og_color": site_info.main_color, "og_url": f"{WEB_PROTO}://{DOMAIN_NAME}/{route.page.get_absolute_url()}", - "og_image": f"{WEB_PROTO}://{DOMAIN_NAME}/{site_avatar_url}", + "og_image": f"{site_avatar_url}", "og_title": f"{site_info.brand_name} | {route.page.name}", "og_desc": route.page.meta_description } @@ -143,7 +143,7 @@ def _get_page_routes(): return { "og_color": site_info.main_color, "og_url": f"{WEB_PROTO}://{DOMAIN_NAME}/{path}", - "og_image": f"{WEB_PROTO}://{DOMAIN_NAME}/{site_avatar_url}", + "og_image": f"{site_avatar_url}", "og_title": f"{site_info.brand_name} | {path.title()}", "og_desc": text_content } From ef97ddd50c24a097ae1a82e4bb77c237e2b9028b Mon Sep 17 00:00:00 2001 From: zediious Date: Mon, 6 Nov 2023 11:54:40 -0500 Subject: [PATCH 2/5] Remove extra / from og_image This was not preventing the request from resolving, but is incorrect. Also out of scope, but was just seen. --- raptorWeb/raptormc/routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raptorWeb/raptormc/routes.py b/raptorWeb/raptormc/routes.py index 5472777a..ba1ce76e 100644 --- a/raptorWeb/raptormc/routes.py +++ b/raptorWeb/raptormc/routes.py @@ -75,7 +75,7 @@ def _get_page_routes(): current_routes: list = [] try: - site_avatar_url = f"{WEB_PROTO}://{DOMAIN_NAME}/{site_info.avatar_image.url}" + site_avatar_url = f"{WEB_PROTO}://{DOMAIN_NAME}{site_info.avatar_image.url}" except ValueError: site_avatar_url = f"{WEB_PROTO}://{DOMAIN_NAME}/static/image/no_user.webp" From c0ffbb3acbda071c3b71d2f2cf740e9277a05b24 Mon Sep 17 00:00:00 2001 From: zediious Date: Mon, 6 Nov 2023 12:22:39 -0500 Subject: [PATCH 3/5] Prev commit append Also needs to be corrected for this check when user does not have profile picture. --- raptorWeb/raptormc/routes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/raptorWeb/raptormc/routes.py b/raptorWeb/raptormc/routes.py index ba1ce76e..73bd9982 100644 --- a/raptorWeb/raptormc/routes.py +++ b/raptorWeb/raptormc/routes.py @@ -107,7 +107,7 @@ def _get_page_routes(): if route.user != None: try: - user_avatar = route.user.user_profile_info.profile_picture.url + user_avatar = f"{WEB_PROTO}://{DOMAIN_NAME}{route.user.user_profile_info.profile_picture.url}" except ValueError: user_avatar = site_avatar_url @@ -115,7 +115,7 @@ def _get_page_routes(): "og_user": route.user, "og_color": site_info.main_color, "og_url": f"{WEB_PROTO}://{DOMAIN_NAME}/{BASE_USER_URL}/{route.user.user_slug}", - "og_image": f"{WEB_PROTO}://{DOMAIN_NAME}/{user_avatar}", + "og_image": f"{user_avatar}", "og_title": f"{site_info.brand_name} | {route.user.username}", "og_desc": f"User Profile for {route.user.username}" } From e5dafa2496f3175ecade8fd4a62bcef19e150ba0 Mon Sep 17 00:00:00 2001 From: zediious Date: Mon, 6 Nov 2023 12:27:11 -0500 Subject: [PATCH 4/5] Check for informative text when making routes informative_text has been added as a class attribute to Route, and will be filled with the informative text object associated with a route. This is checked using the "name" attribute of the URLPattern, capitalizing it and appending " Information" to find an informative text. If it does exist, the route will be identifed as a route using an informative text. Then, the check will use it properly when returning context. This provides a way to define which pages should be checked for informative texts. I've also moved the getting of "main routes" to it's own sub-function. The main function body is only checking for the routes against the path after running the "get" sub-functions --- raptorWeb/raptormc/routes.py | 69 ++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/raptorWeb/raptormc/routes.py b/raptorWeb/raptormc/routes.py index 73bd9982..3a31f145 100644 --- a/raptorWeb/raptormc/routes.py +++ b/raptorWeb/raptormc/routes.py @@ -15,9 +15,10 @@ class Route: - def __init__(self, name, route_type, user=None, page=None) -> None: + def __init__(self, name, route_type, informative_text=None, user=None, page=None) -> None: self.name: str = name self.route_type: str = route_type + self.informative_text = informative_text self.user: RaptorUser = user self.page: Page = page @@ -27,7 +28,8 @@ def __str__(self) -> str: def check_route(request): """ Check all baked-in URLPatterns as well as - variations for created objects. Return True + variations for created objects. Return context + with OpenGraph information about the route if the route exists, False if it does not. """ def _get_user_routes(): @@ -70,15 +72,41 @@ def _get_page_routes(): ) ) + def _get_main_routes(): + """ + Iterate current URLPatterns and create + Routes for each. If the URLPattern name + matches an Informative Text, attach that + Informative Text to the route. + """ + informative_texts = InformativeText.objects.all() + + for pattern in CURRENT_URLPATTERNS[0]: + gathered_text = informative_texts.filter(name=f'{str(pattern.name).title()} Information') + if gathered_text is not None: + current_routes.append( + Route( + name=pattern.name, + route_type="main_with_text", + informative_text=gathered_text.first() + ) + ) + else: + current_routes.append( + Route( + name=pattern.name, + route_type="main" + ) + ) + site_info: SiteInformation.objects = SiteInformation.objects.get_or_create(pk=1)[0] - - current_routes: list = [] try: site_avatar_url = f"{WEB_PROTO}://{DOMAIN_NAME}{site_info.avatar_image.url}" except ValueError: site_avatar_url = f"{WEB_PROTO}://{DOMAIN_NAME}/static/image/no_user.webp" - + + # If request is to root path, we do not need to check routes if request.path == '/': return { "og_color": site_info.main_color, @@ -87,15 +115,10 @@ def _get_page_routes(): "og_title": f"{site_info.brand_name} | Home", "og_desc": site_info.meta_description } + + current_routes: list = [] - for pattern in CURRENT_URLPATTERNS[0]: - current_routes.append( - Route( - name=pattern.name, - route_type="main" - ) - ) - + _get_main_routes() _get_user_routes() _get_page_routes() @@ -130,22 +153,22 @@ def _get_page_routes(): "og_desc": route.page.meta_description } - try: - text_content = strip_tags( - InformativeText.objects.get( - name=f"{path.title()} Information" - ).content - ) - except InformativeText.DoesNotExist: - LOGGER.error(f"Informative Text not found for following path: {path}") - text_content = "Placeholder" + if route.informative_text != None: + return { + "og_color": site_info.main_color, + "og_url": f"{WEB_PROTO}://{DOMAIN_NAME}/{path}", + "og_image": f"{site_avatar_url}", + "og_title": f"{site_info.brand_name} | {path.title()}", + "og_desc": strip_tags(route.informative_text.content) + } return { "og_color": site_info.main_color, "og_url": f"{WEB_PROTO}://{DOMAIN_NAME}/{path}", "og_image": f"{site_avatar_url}", "og_title": f"{site_info.brand_name} | {path.title()}", - "og_desc": text_content + "og_desc": site_info.meta_description } + return False \ No newline at end of file From 0d3d545f4f4c8a529d896dc84f5f25cdb03b5fab Mon Sep 17 00:00:00 2001 From: zediious Date: Mon, 6 Nov 2023 12:42:57 -0500 Subject: [PATCH 5/5] Correct overflowing elements on howtojoin page This was caused by the odd choices here being exacerbated by changes in master templates. Removed col and container classes from inner elements, and applied container to joinBoxes element. --- .../raptormc/defaultpages/joining.html | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/raptorWeb/templates/raptormc/defaultpages/joining.html b/raptorWeb/templates/raptormc/defaultpages/joining.html index a6f93282..29747899 100644 --- a/raptorWeb/templates/raptormc/defaultpages/joining.html +++ b/raptorWeb/templates/raptormc/defaultpages/joining.html @@ -18,39 +18,33 @@