Generate Google Calendar links from django-event-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. Generate ICalendar Files with django-events by ElfSternberg 2 years, 8 months ago
  2. Extend simplejson to understand closures, functors, generators and iterators by ElfSternberg 4 years, 1 month ago
  3. Ensure submitted slugs do not conflict with existing resolvable URLs by ElfSternberg 3 years, 11 months ago
  4. email_links by sansmojo 6 years ago
  5. Ensure ugettext is available absolutely everywhere by ElfSternberg 3 years, 11 months ago

Comments

(Forgotten your password?)