Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix url
Browse files Browse the repository at this point in the history
AlexandreJunod committed Nov 22, 2023
1 parent 683ba47 commit 0c3b99e
Showing 5 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion geocity/apps/agenda/templates/agenda/agenda.html
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
</style>

<!-- Render the component -->
<agenda-embed api-base-url="http://localhost:9095/rest"></agenda-embed>
<agenda-embed api-base-url="{{ api_root }}"></agenda-embed>

<!-- Initialize the component -->
<script type="module" src="https://cdn.jsdelivr.net/npm/@geocity/agenda-embed"></script>
2 changes: 1 addition & 1 deletion geocity/apps/agenda/templates/agenda/agenda_culture.html
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
</style>

<!-- Render the component -->
<agenda-embed domain="culture" api-base-url="http://localhost:9095/rest"></agenda-embed>
<agenda-embed domain="culture" api-base-url="{{ api_root }}"></agenda-embed>

<!-- Initialize the component -->
<script type="module" src="https://cdn.jsdelivr.net/npm/@geocity/agenda-embed"></script>
2 changes: 1 addition & 1 deletion geocity/apps/agenda/templates/agenda/agenda_sports.html
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
</style>

<!-- Render the component -->
<agenda-embed domain="sports" api-base-url="http://localhost:9095/rest"></agenda-embed>
<agenda-embed domain="sports" api-base-url="{{ api_root }}"></agenda-embed>

<!-- Initialize the component -->
<script type="module" src="https://cdn.jsdelivr.net/npm/@geocity/agenda-embed"></script>
22 changes: 19 additions & 3 deletions geocity/apps/agenda/views.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
from django.shortcuts import render
from django.urls import reverse


def agenda(request):
api_root = reverse("api-root")[:-1]
context = {
"api_root": api_root,
}

return render(
request,
"agenda/agenda.html",
{},
context,
)


def agenda_sports(request):
api_root = reverse("api-root")[:-1]
context = {
"api_root": api_root,
}

return render(
request,
"agenda/agenda_sports.html",
{},
context,
)


def agenda_culture(request):
api_root = reverse("api-root")[:-1]
context = {
"api_root": api_root,
}

return render(
request,
"agenda/agenda_culture.html",
{},
context,
)
29 changes: 18 additions & 11 deletions geocity/apps/submissions/models.py
Original file line number Diff line number Diff line change
@@ -494,6 +494,19 @@ def set_dates_for_renewable_forms(self):
ends_at=today + timedelta(days=permit_duration_max)
)

@staticmethod
def get_submission_site_domain(url_split):
if "submissions" in url_split:
submission_id_index = url_split.index("submissions") + 1
elif "thumbor" in url_split:
submission_id_index = url_split.index("thumbor") + 1
else:
return None

submission_id = url_split[submission_id_index]
submission = Submission.objects.get(id=submission_id)
return submission.get_site(use_default=False)

@staticmethod
def get_absolute_url(relative_url):
protocol = "https" if settings.SITE_HTTPS else "http"
@@ -503,18 +516,12 @@ def get_absolute_url(relative_url):
else ""
)

if settings.SITE_DOMAIN:
site_domain = settings.SITE_DOMAIN
url_split = relative_url.split("/")
submission_site = Submission.get_submission_site_domain(url_split)
if submission_site:
site_domain = submission_site
else:
url_split = relative_url.split("/")
if "submissions" in url_split:
submission_id_index = url_split.index("submissions") + 1
elif "thumbor" in url_split:
submission_id_index = url_split.index("thumbor") + 1

submission_id = url_split[submission_id_index]
submission = Submission.objects.get(id=submission_id)
site_domain = submission.get_site(use_default=False)
site_domain = settings.SITE_DOMAIN

return f"{protocol}://{site_domain}{port}{relative_url}"

0 comments on commit 0c3b99e

Please sign in to comment.