Skip to content

Commit 193bea1

Browse files
authored
Merge pull request #414 from CrisKrus/361-add-google-calendar-link
#361 add google calendar link
2 parents 54b9a07 + c1fa59c commit 193bea1

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

apps/events/models.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ class Meta:
7979
def slug(self):
8080
return self.hashtag.lower()
8181

82+
def end_datetime(self):
83+
try:
84+
return self.schedule.order_by('end').last().end
85+
except AttributeError:
86+
end_time = datetime.time(
87+
23, 59, 59, tzinfo=timezone.get_current_timezone())
88+
return datetime.datetime.combine(self.start_date, end_time)
89+
90+
def get_google_calendar_url(self):
91+
start_datetime = self.start_datetime().strftime('%Y%m%dT%H%M%S%Z')
92+
end_datetime = self.end_datetime().strftime('%Y%m%dT%H%M%S%Z')
93+
return f"https://www.google.com/calendar/render?action=TEMPLATE&text={self.name}&details={self.description}&location={self.venue}&dates={start_datetime}%2F{end_datetime}"
94+
8295
@classmethod
8396
def get_by_slug(cls, slug):
8497
return cls.objects.get(hashtag__iexact=slug)

apps/events/templates/events/event.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ <h1 class="title section-title dyn-anchor-heading">
114114
<a class="dyn-anchor-link" href="#schedule"><i class="fas fa-link"></i></a>
115115
</p>
116116
<p class="section-detail"><i class="far fa-calendar-alt"></i> {{ event.start_date|as_date }}</p>
117+
<a target="_blank" href="{{ event.get_google_calendar_url }}">Añadir a Google Calendar</a>
117118
{% if event.schedule_for_display and not event.closed_schedule %}
118119
<span class="tag is-warning is-medium not-closed-schedule">
119120
<i class="fas fa-info-circle"></i>

apps/events/templates/events/includes/event-section.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ <h1 class="title is-3">
2020
</h1>
2121
<div class="event-date">
2222
<i class="far fa-calendar-alt"></i> {{ event.start_date|as_date }}
23+
<a target="_blank" href="{{ event.get_google_calendar_url }}">Añadir a Google Calendar</a>
2324
</div>
2425
{% if event.venue %}
2526
<div class="event-location">

0 commit comments

Comments
 (0)