Skip to content

Commit

Permalink
Check if site avatar exists
Browse files Browse the repository at this point in the history
Implement try catch to check if the site avatar exists yet when checking the route. If it doesn't use the no_user image instead.

This was not checked when implemented, and highlights the need for me to write tests.
  • Loading branch information
zediious committed Oct 31, 2023
1 parent a447256 commit 332794e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions raptorWeb/raptormc/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,17 @@ def _get_page_routes():
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.path == '/':
return {
"og_color": site_info.main_color,
"og_url": f"{WEB_PROTO}://{DOMAIN_NAME}",
"og_image": f"{WEB_PROTO}://{DOMAIN_NAME}/{site_info.avatar_image.url}",
"og_image": f"{WEB_PROTO}://{DOMAIN_NAME}/{site_avatar_url}",
"og_title": f"{site_info.brand_name} | Home",
"og_desc": site_info.meta_description
}
Expand All @@ -104,7 +109,7 @@ def _get_page_routes():
try:
user_avatar = route.user.user_profile_info.profile_picture.url
except ValueError:
user_avatar = site_info.avatar_image.url
user_avatar = site_avatar_url

return {
"og_user": route.user,
Expand All @@ -120,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_info.avatar_image.url}",
"og_image": f"{WEB_PROTO}://{DOMAIN_NAME}/{site_avatar_url}",
"og_title": f"{site_info.brand_name} | {route.page.name}",
"og_desc": route.page.meta_description
}
Expand All @@ -138,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_info.avatar_image.url}",
"og_image": f"{WEB_PROTO}://{DOMAIN_NAME}/{site_avatar_url}",
"og_title": f"{site_info.brand_name} | {path.title()}",
"og_desc": text_content
}
Expand Down

0 comments on commit 332794e

Please sign in to comment.