Skip to content

Commit

Permalink
updated upcoming events to work with api changes, fixed fallback even…
Browse files Browse the repository at this point in the history
…t image
  • Loading branch information
CheeseLad committed Oct 2, 2024
1 parent 2aee493 commit 6ab1149
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
35 changes: 21 additions & 14 deletions mps_site/templates/components/home/upcoming_events.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,41 @@ <h1>Upcoming Events</h1>
<h5><i>You won't want to miss them!</i></h5>
<div class="row justify-content-center">
<div class="col-md-12 custom-box shadow-lg p-3 mb-5 bg-body">
{% if events.events.items|length == 0 %}
{% if events|length == 0 %}
<h3 style="justify-content: center; padding-top: 10px;">No events at the
moment, check back later!</h3>
{% else %}
<div class="container mt-4">
<div class="row">

{% for event_key, event in events.events.items %}
{% for event in events %}
<div class="col-md-4">
<div class="committee-member"
style="border-radius: 25px; padding-top: 20px; padding-bottom: 20px; background-color: #202E4E;">
<img src="{{ event.image }}" alt="Event Image" width="300px"
height="300px">
<img src="{{ event.image|default:'/static/assets/img/other/upcoming_event.png' }}" alt="Event Image" width="300px" height="300px">

<h3>{{ event.name }}</h3>
<h5><strong>Starts:</strong> {{ event.start }}</h5>
<h5><strong>Ends:</strong> {{ event.end }}</h5>
<h5><strong>Location:</strong> <a href="{{ event.location }}"
target="_blank">Join Here</a></h5>

<h5>
<strong>Starts:</strong> {{ event.formatted_start }}
</h5>
<h5>
<strong>Ends:</strong> {{ event.formatted_end }}
</h5>

<h5><strong>Location:</strong> {{ event.location }}</h5>
<button type="button" class="btn btn-primary" data-toggle="modal"
data-target="#moreInfoModal_{{ forloop.counter }}"
style="background-color: #9791FF;">
Description
</button>
<a href="https://dcuclubsandsocs.ie/society/media-production#events" target="_blank"><button type="button" class="btn btn-primary"
style="background-color: #9791FF;">
View Event
</button></a>
<a
href="https://dcuclubsandsocs.ie/society/media-production#events"
target="_blank">
<button type="button" class="btn btn-primary"
style="background-color: #9791FF;">
View Event
</button>
</a>

<div class="modal fade" id="moreInfoModal_{{ forloop.counter }}"
tabindex="-1" role="dialog"
Expand Down Expand Up @@ -63,7 +71,6 @@ <h5><strong>Location:</strong> <a href="{{ event.location }}"
</div>
</div>
{% endfor %}

</div>
</div>
{% endif %}
Expand Down
16 changes: 16 additions & 0 deletions mps_site/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,28 @@
from .data.thecollegeview import *
from .data.committee import *

def ordinal(n):
if 10 <= n % 100 <= 20:
suffix = 'th'
else:
suffix = {1: 'st', 2: 'nd', 3: 'rd'}.get(n % 10, 'th')
return f"{n}{suffix}"

def format_event_date(date_str):
date_obj = datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%S")
day = ordinal(date_obj.day)
return date_obj.strftime(f"%a {day} %b at %H:%M")

def index(request):
video = get_latest_video_id("https://www.youtube.com/feeds/videos.xml?channel_id=UCEnLsvcq1eFkSFFAIqBDgUw")
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")
previous, current, next_show = get_date_time()
events = requests.get("https://clubsandsocs.jakefarrell.ie/dcuclubsandsocs.ie/society/media-production/events").json()

for event in events:
event['formatted_start'] = format_event_date(event['start'])
event['formatted_end'] = format_event_date(event['end'])

return render(request, 'index.html',
{'stats_data': homepage_stats_data,
'subgroups_data': homepage_subgroups,
Expand Down

0 comments on commit 6ab1149

Please sign in to comment.