- Author:
- ElfSternberg
- Posted:
- October 6, 2010
- Language:
- Python
- Version:
- Not specified
- 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
- Template tag - list punctuation for a list of items by shapiromatron 8 months, 4 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 9 months ago
- Serializer factory with Django Rest Framework by julio 1 year, 3 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 4 months ago
- Help text hyperlinks by sa2812 1 year, 5 months ago
Comments
Please login first before commenting.