'How can I push events into someone's google calendar from pythyon/django?

I want the easiest and simplest way to push events into user's Google Calendars from Python Django. I don't want to read their events or do anything else, just push the events they create in my application to their Google calendar once.

Secondary is to possibly delete events in their google calendar (if the event I push into it is deleted).



Solution 1:[1]

This a snippet to do it :

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>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Armance