From 8ea488123a62d6972ac5a7df76be4438528d475b Mon Sep 17 00:00:00 2001 From: humanauction Date: Tue, 21 Oct 2025 18:36:12 +0100 Subject: [PATCH] Add: fix bug: URL routing: use RedirectView; Add: event detail, events templates; Add: fix bug: HTML structure in calendar partials. --- config/urls.py | 12 +- home/templates/home/event_detail.html | 26 ++-- home/templates/home/events.html | 80 ++++-------- .../home/partials/_events_calendar.html | 117 ++++++++---------- 4 files changed, 102 insertions(+), 133 deletions(-) diff --git a/config/urls.py b/config/urls.py index 2215cb7..67ffa2e 100644 --- a/config/urls.py +++ b/config/urls.py @@ -17,12 +17,16 @@ from django.contrib import admin from django.urls import path, include from django.conf import settings -from django.views.generic import TemplateView +from django.views.generic import RedirectView from django.conf.urls.static import static urlpatterns = [ path('admin/', admin.site.urls), - path('', TemplateView.as_view(template_name='index.html'), name='index'), + path( + '', + RedirectView.as_view(url='/home/', permanent=False), + name='index' + ), path('map/', include('map.urls')), path('home/', include('home.urls')), ] @@ -32,4 +36,6 @@ path("__reload__/", include("django_browser_reload.urls")), ] # media files serving in development - urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ No newline at end of file + urlpatterns += static( + settings.MEDIA_URL, document_root=settings.MEDIA_ROOT + ) diff --git a/home/templates/home/event_detail.html b/home/templates/home/event_detail.html index 095d090..f1fb930 100644 --- a/home/templates/home/event_detail.html +++ b/home/templates/home/event_detail.html @@ -16,13 +16,12 @@

{{ event.title }}

Date & Time

- {{ event.start_time|date:"D, d M Y" }} at {{ - event.start_time|time:"g:i A" }} {% if - event.end_time|date:"D, d M Y" == - event.start_time|date:"D, d M Y" %} - {{ - event.end_time|time:"g:i A" }} {% else %} to {{ - event.end_time|date:"D, d M Y" }} at {{ - event.end_time|time:"g:i A" }} {% endif %} + {{ event.start_time|date:"D, d M Y" }} at {{ event.start_time|time:"g:i A" }} + {% if event.end_time|date:"D, d M Y" == event.start_time|date:"D, d M Y" %} + - {{ event.end_time|time:"g:i A" }} + {% else %} + to {{ event.end_time|date:"D, d M Y" }} at {{ event.end_time|time:"g:i A" }} + {% endif %}

@@ -30,11 +29,14 @@

{{ event.title }}

Location

- {% if event.church %} {{ event.church.name }} {% if - event.church.address %}
{{ event.church.address - }}{% endif %} {% if event.church.postcode %}, {{ - event.church.postcode }}{% endif %} {% else %} {{ - event.location }} {% endif %} + {% if event.church %} + {{ event.church.name }} + {% if event.church.address %} +
{{ event.church.address }}, {{ event.church.postcode }} + {% endif %} + {% else %} + {{ event.location }} + {% endif %}

diff --git a/home/templates/home/events.html b/home/templates/home/events.html index 35d410c..b2fcf07 100644 --- a/home/templates/home/events.html +++ b/home/templates/home/events.html @@ -1,5 +1,8 @@ -{% extends "base.html" %} {% load static %} {% block content %} +{% extends "base.html" %} +{% load static %} + +{% block content %}

Church Events

@@ -19,39 +22,25 @@

Featured Events

{% if event.image %}
- {{ event.title }} + {{ event.title }}
{% else %} -
- +
+
{% endif %}

{{ event.title }}

- {{ event.start_time|date:"D, d M Y" }} at {{ - event.start_time|time:"g:i A" }} + {{ event.start_time|date:"D, d M Y" }} at {{ event.start_time|time:"g:i A" }}

- {% if event.church %}{{ event.church.name }}{% else %}{{ - event.location }}{% endif %} + {% if event.church %}{{ event.church.name }}{% else %}{{ event.location }}{% endif %}

@@ -80,53 +69,38 @@

Upcoming Events

{{ event.title }}
{% if event.is_featured %} - Featured + Featured {% endif %} - {{ event.start_time|date:"D, d M Y" }}
+ {{ event.start_time|date:"D, d M Y" }}
- {{ event.start_time|time:"g:i A" }} - {{ - event.end_time|time:"g:i A" }} + {{ event.start_time|time:"g:i A" }} - {{ event.end_time|time:"g:i A" }} - {% if event.church %} {{ event.church.name }} {% - else %} {{ event.location }} {% endif %} + {% if event.church %} + {{ event.church.name }} + {% else %} + {{ event.location }} + {% endif %}
- + Details {% if user.is_authenticated %} - - {% endif %} {% if user.is_staff or - user.is_superuser %} - Edit - Delete + {% endif %} + {% if user.is_staff or user.is_superuser %} + Edit + Delete {% endif %}
diff --git a/home/templates/home/partials/_events_calendar.html b/home/templates/home/partials/_events_calendar.html index bc2d1cd..906c0bd 100644 --- a/home/templates/home/partials/_events_calendar.html +++ b/home/templates/home/partials/_events_calendar.html @@ -21,13 +21,11 @@

Featured Events

{{ event.title }}

- {{ event.start_time|date:"D, d M Y" }} at {{ - event.start_time|time:"g:i A" }} + {{ event.start_time|date:"D, d M Y" }} at {{ event.start_time|time:"g:i A" }}

- {% if event.church %}{{ event.church.name }}{% else %}{{ - event.location }}{% endif %} + {% if event.church %}{{ event.church.name }}{% else %}{{ event.location }}{% endif %}

{{ event.title }}
{{ event.title }}
{% if event.is_featured %} - Featured + Featured {% endif %} {{ event.start_time|date:"D, d M Y" }}
- {{ event.start_time|time:"g:i A" }} - {{ - event.end_time|time:"g:i A" }} + {{ event.start_time|time:"g:i A" }} - {{ event.end_time|time:"g:i A" }} - {% if event.church %} {{ event.church.name }} {% else %} - {{ event.location }} {% endif %} + {% if event.church %} + {{ event.church.name }} + {% else %} + {{ event.location }} + {% endif %}
@@ -104,12 +102,11 @@

{{ event.title }}

title="Mark as interested" > - + - {% endif %} {% if user.is_staff or user.is_superuser - %} + {% endif %} + + {% if user.is_staff or user.is_superuser %}
{{ event.title }}
- +

No upcoming events scheduled. Check back soon!

- {% endfor %} {% if user.is_staff or user.is_superuser %} + {% endfor %} + + {% if user.is_staff or user.is_superuser %} -
+ Add New Event @@ -164,29 +158,24 @@

{{ event.title }}

const fullUrl = window.location.origin + url; if (navigator.share) { - navigator - .share({ - title: title, - url: fullUrl, - }) - .catch((err) => console.error("Share failed:", err)); + navigator.share({ + title: title, + url: fullUrl, + }).catch((err) => console.error("Share failed:", err)); } else { // Fallback: copy to clipboard - navigator.clipboard - .writeText(fullUrl) - .then(() => { - alert("Link copied to clipboard!"); - }) - .catch((err) => { - // Older fallback - const tempInput = document.createElement("input"); - document.body.appendChild(tempInput); - tempInput.value = fullUrl; - tempInput.select(); - document.execCommand("copy"); - document.body.removeChild(tempInput); - alert("Link copied to clipboard!"); - }); + navigator.clipboard.writeText(fullUrl).then(() => { + alert("Link copied to clipboard!"); + }).catch((err) => { + // Older fallback + const tempInput = document.createElement("input"); + document.body.appendChild(tempInput); + tempInput.value = fullUrl; + tempInput.select(); + document.execCommand("copy"); + document.body.removeChild(tempInput); + alert("Link copied to clipboard!"); + }); } } @@ -198,32 +187,32 @@

{{ event.title }}

button.addEventListener("click", function () { const eventId = this.dataset.eventId; - fetch(`/events/${eventId}/like/`, { + fetch(`/home/events/${eventId}/like/`, { method: "POST", headers: { "X-CSRFToken": getCookie("csrftoken"), "Content-Type": "application/json", }, }) - .then((response) => response.json()) - .then((data) => { - if (data.status === "success") { - const likeCount = this.querySelector(".like-count"); - likeCount.textContent = data.likes; + .then((response) => response.json()) + .then((data) => { + if (data.status === "success") { + const likeCount = this.querySelector(".like-count"); + likeCount.textContent = data.likes; - if (data.liked) { - this.classList.add("btn-error"); - } else { - this.classList.remove("btn-error"); - } + if (data.liked) { + this.classList.add("btn-error"); } else { - alert("Please log in to like events"); + this.classList.remove("btn-error"); } - }) - .catch((error) => { - console.error("Error:", error); - alert("An error occurred. Please try again."); - }); + } else { + alert("Please log in to like events"); + } + }) + .catch((error) => { + console.error("Error:", error); + alert("An error occurred. Please try again."); + }); }); }); }); @@ -236,9 +225,7 @@

{{ event.title }}

for (let i = 0; i < cookies.length; i++) { const cookie = cookies[i].trim(); if (cookie.substring(0, name.length + 1) === name + "=") { - cookieValue = decodeURIComponent( - cookie.substring(name.length + 1) - ); + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } }