Skip to content

Commit 6ab1149

Browse files
committed
updated upcoming events to work with api changes, fixed fallback event image
1 parent 2aee493 commit 6ab1149

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

mps_site/templates/components/home/upcoming_events.html

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,41 @@ <h1>Upcoming Events</h1>
33
<h5><i>You won't want to miss them!</i></h5>
44
<div class="row justify-content-center">
55
<div class="col-md-12 custom-box shadow-lg p-3 mb-5 bg-body">
6-
{% if events.events.items|length == 0 %}
6+
{% if events|length == 0 %}
77
<h3 style="justify-content: center; padding-top: 10px;">No events at the
88
moment, check back later!</h3>
99
{% else %}
1010
<div class="container mt-4">
1111
<div class="row">
12-
13-
{% for event_key, event in events.events.items %}
12+
{% for event in events %}
1413
<div class="col-md-4">
1514
<div class="committee-member"
1615
style="border-radius: 25px; padding-top: 20px; padding-bottom: 20px; background-color: #202E4E;">
17-
<img src="{{ event.image }}" alt="Event Image" width="300px"
18-
height="300px">
16+
<img src="{{ event.image|default:'/static/assets/img/other/upcoming_event.png' }}" alt="Event Image" width="300px" height="300px">
17+
1918
<h3>{{ event.name }}</h3>
20-
<h5><strong>Starts:</strong> {{ event.start }}</h5>
21-
<h5><strong>Ends:</strong> {{ event.end }}</h5>
22-
<h5><strong>Location:</strong> <a href="{{ event.location }}"
23-
target="_blank">Join Here</a></h5>
19+
20+
<h5>
21+
<strong>Starts:</strong> {{ event.formatted_start }}
22+
</h5>
23+
<h5>
24+
<strong>Ends:</strong> {{ event.formatted_end }}
25+
</h5>
26+
27+
<h5><strong>Location:</strong> {{ event.location }}</h5>
2428
<button type="button" class="btn btn-primary" data-toggle="modal"
2529
data-target="#moreInfoModal_{{ forloop.counter }}"
2630
style="background-color: #9791FF;">
2731
Description
2832
</button>
29-
<a href="https://dcuclubsandsocs.ie/society/media-production#events" target="_blank"><button type="button" class="btn btn-primary"
30-
style="background-color: #9791FF;">
31-
View Event
32-
</button></a>
33+
<a
34+
href="https://dcuclubsandsocs.ie/society/media-production#events"
35+
target="_blank">
36+
<button type="button" class="btn btn-primary"
37+
style="background-color: #9791FF;">
38+
View Event
39+
</button>
40+
</a>
3341

3442
<div class="modal fade" id="moreInfoModal_{{ forloop.counter }}"
3543
tabindex="-1" role="dialog"
@@ -63,7 +71,6 @@ <h5><strong>Location:</strong> <a href="{{ event.location }}"
6371
</div>
6472
</div>
6573
{% endfor %}
66-
6774
</div>
6875
</div>
6976
{% endif %}

mps_site/views.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,28 @@
1313
from .data.thecollegeview import *
1414
from .data.committee import *
1515

16+
def ordinal(n):
17+
if 10 <= n % 100 <= 20:
18+
suffix = 'th'
19+
else:
20+
suffix = {1: 'st', 2: 'nd', 3: 'rd'}.get(n % 10, 'th')
21+
return f"{n}{suffix}"
22+
23+
def format_event_date(date_str):
24+
date_obj = datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%S")
25+
day = ordinal(date_obj.day)
26+
return date_obj.strftime(f"%a {day} %b at %H:%M")
27+
1628
def index(request):
1729
video = get_latest_video_id("https://www.youtube.com/feeds/videos.xml?channel_id=UCEnLsvcq1eFkSFFAIqBDgUw")
1830
posts = tcv_posts("https://thecollegeview.ie/wp-json/wp/v2/posts?per_page=3&orderby=date&_fields=id,date,title,content,link,author,featured_media")
1931
previous, current, next_show = get_date_time()
2032
events = requests.get("https://clubsandsocs.jakefarrell.ie/dcuclubsandsocs.ie/society/media-production/events").json()
2133

34+
for event in events:
35+
event['formatted_start'] = format_event_date(event['start'])
36+
event['formatted_end'] = format_event_date(event['end'])
37+
2238
return render(request, 'index.html',
2339
{'stats_data': homepage_stats_data,
2440
'subgroups_data': homepage_subgroups,

0 commit comments

Comments
 (0)