Login

Generate Google Calendar links from django-event-calendar

Author:
ElfSternberg
Posted:
October 6, 2010
Language:
Python
Version:
Not specified
Tags:
django events calendar google event
Score:
1 (after 1 ratings)

This very simple templatetag can take event objects from django-event-calendar and create the appropriate URLs to automatically allow users to add events from your website to Google calendar.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from django import template
from django.contrib.sites.models import Site
from django.utils.http import urlquote_plus

register = template.Library()

@register.filter
def google_calendarize(event):
    st = event.start
    en = event.end and event.end or event.start
    tfmt = '%Y%m%dT000000'

    dates = '%s%s%s' % (st.strftime(tfmt), '%2F', en.strftime(tfmt))
    name = urlquote_plus(event.name)

    s = ('http://www.google.com/calendar/event?action=TEMPLATE&' +
         'text=' + name + '&' +
         'dates=' + dates + '&' +
         'sprop=website:' + urlquote_plus(Site.objects.get_current().domain))

    if event.location:
        s = s + '&location=' + urlquote_plus(event.location)

    return s + '&trp=false'

google_calendarize.safe = True



And this code can be invoked via:
{% load project_events_tags %}
...
<a href="{{ event|google_calendarize }}">+ Add to Google Calendar</a>

More like this

  1. Simple Django event calendar template tag by sandinmyjoints_ 3 years, 10 months ago
  2. Generate ICalendar Files with django-events by ElfSternberg 4 years, 6 months ago
  3. Link Models to Google Calendar by JosefK 7 years, 9 months ago
  4. Calendar template-tag by masida 8 years, 1 month ago
  5. Django Jalali Calendar Widget by behrooznobakht 4 years, 10 months ago

Comments

Please login first before commenting.