implemented ics export by email
This commit is contained in:
@@ -873,6 +873,28 @@ def handle_sendemail_unrecognizedowner(useremail, userfirstname,
|
||||
|
||||
return 1
|
||||
|
||||
@app.task
|
||||
def handle_sendemailics(first_name, last_name, email, icsfile, **kwargs):
|
||||
# send email with attachment
|
||||
fullemail = first_name + " " + last_name + " " + "<" + email + ">"
|
||||
subject = "Calendar File from Rowsandall.com"
|
||||
|
||||
|
||||
d = {'first_name':first_name,
|
||||
'siteurl':siteurl,
|
||||
}
|
||||
|
||||
from_email = 'Rowsandall <info@rowsandall.com>'
|
||||
|
||||
|
||||
res = send_template_email(from_email,[fullemail],
|
||||
subject,'icsemail.html',d,
|
||||
attach_file=icsfile,**kwargs)
|
||||
|
||||
os.remove(icsfile)
|
||||
return 1
|
||||
|
||||
|
||||
@app.task
|
||||
def handle_sendemailkml(first_name, last_name, email, kmlfile,**kwargs):
|
||||
|
||||
|
||||
14
rowers/templates/icsemail.html
Normal file
14
rowers/templates/icsemail.html
Normal file
@@ -0,0 +1,14 @@
|
||||
{% extends "emailbase.html" %}
|
||||
|
||||
{% block body %}
|
||||
<p>Dear <strong>{{ first_name }}</strong>,</p>
|
||||
|
||||
<p>
|
||||
Please find attached the requested ICS Calendar file. You can import
|
||||
this file to your calendar app.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Best Regards, the Rowsandall Team
|
||||
</p>
|
||||
{% endblock %}
|
||||
@@ -129,7 +129,12 @@
|
||||
<a
|
||||
href="/rowers/sessions/print/user/{{ rower.user.id }}/?when={{ timeperiod }}">
|
||||
Print View</a>
|
||||
|
||||
<a
|
||||
href="/rowers/sessions/sendcalendar/user/{{ rower.user.id }}/?when={{ timeperiod }}">
|
||||
Get Calendar File</a>
|
||||
</p>
|
||||
|
||||
</li>
|
||||
<li class="grid_4">
|
||||
{% if unmatchedworkouts %}
|
||||
|
||||
@@ -507,6 +507,8 @@ urlpatterns = [
|
||||
url(r'^sessions/coach/user/\d+/$',views.plannedsessions_coach_view),
|
||||
url(r'^sessions/print/?$',views.plannedsessions_print_view),
|
||||
url(r'^sessions/print/user/(?P<userid>\d+)/$',views.plannedsessions_print_view),
|
||||
url(r'^sessions/sendcalendar/$',views.plannedsessions_icsemail_view),
|
||||
url(r'^sessions/sendcalendar/user/(?P<userid>\d+)/$',views.plannedsessions_icsemail_view),
|
||||
url(r'^sessions/$',views.plannedsessions_view),
|
||||
url(r'^sessions/user/(?P<userid>\d+)$',views.plannedsessions_view),
|
||||
url(r'^sessions/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)$',
|
||||
|
||||
@@ -27,7 +27,7 @@ import codecs
|
||||
import isodate
|
||||
import re
|
||||
import cgi
|
||||
|
||||
from icalendar import Calendar, Event
|
||||
|
||||
from django.shortcuts import render
|
||||
from django.template.loader import render_to_string
|
||||
@@ -160,6 +160,7 @@ from rowers.tasks import (
|
||||
handle_zip_file,handle_getagegrouprecords,
|
||||
handle_updatefitnessmetric,
|
||||
handle_update_empower,
|
||||
handle_sendemailics,
|
||||
handle_sendemail_userdeleted,
|
||||
)
|
||||
|
||||
@@ -1431,6 +1432,60 @@ def workout_tcxemail_view(request,id=0):
|
||||
|
||||
return response
|
||||
|
||||
@login_required()
|
||||
def plannedsessions_icsemail_view(request,userid=0):
|
||||
r = getrequestrower(request,userid=userid)
|
||||
startdate,enddate = get_dates_timeperiod(request)
|
||||
|
||||
sps = get_sessions(r,startdate=startdate,enddate=enddate)
|
||||
|
||||
cal = Calendar()
|
||||
cal.add('prodid','rowsandall')
|
||||
cal.add('version','1.0')
|
||||
|
||||
for ps in sps:
|
||||
event = Event()
|
||||
comment = '{d} {u} {c}'.format(
|
||||
d=ps.sessionvalue,
|
||||
u = ps.sessionunit,
|
||||
c = ps.criterium)
|
||||
event.add('summary',ps.name)
|
||||
event.add('dtstart',ps.preferreddate)
|
||||
event.add('dtend',ps.preferreddate)
|
||||
event['uid'] = 'plannedsession_'+str(ps.id)
|
||||
event.add('description',ps.comment)
|
||||
event.add('comment',comment)
|
||||
cal.add_component(event)
|
||||
|
||||
icsfilename = 'calendar_{id}.ics'.format(id=request.user.id)
|
||||
|
||||
with open(icsfilename,'wb') as f:
|
||||
f.write(cal.to_ical())
|
||||
|
||||
res = myqueue(queuehigh,handle_sendemailics,
|
||||
request.user.first_name,
|
||||
request.user.last_name,
|
||||
request.user.email,icsfilename,
|
||||
emailbounced = r.emailbounced
|
||||
)
|
||||
|
||||
|
||||
successmessage = "The calendar file was sent to you per email"
|
||||
messages.info(request,successmessage)
|
||||
url = reverse(plannedsessions_view,
|
||||
kwargs = {
|
||||
'userid':r.user.id,
|
||||
})
|
||||
startdatestring = startdate.strftime('%Y-%m-%d')
|
||||
enddatestring = enddate.strftime('%Y-%m-%d')
|
||||
url+='?when='+startdatestring+'/'+enddatestring
|
||||
|
||||
|
||||
response = HttpResponseRedirect(url)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
@login_required()
|
||||
def course_kmlemail_view(request,id=0):
|
||||
r = getrower(request.user)
|
||||
@@ -14542,7 +14597,6 @@ def plannedsession_teamedit_view(request,
|
||||
r = getrequestrower(request,userid=userid)
|
||||
|
||||
|
||||
|
||||
try:
|
||||
ps = PlannedSession.objects.get(id=sessionid)
|
||||
except PlannedSession.DoesNotExist:
|
||||
@@ -14576,7 +14630,7 @@ def plannedsession_teamedit_view(request,
|
||||
|
||||
|
||||
sps = list(set(sps))
|
||||
ids = [ps.id for ps in sps]
|
||||
ids = [pps.id for pps in sps]
|
||||
sps = PlannedSession.objects.filter(id__in=ids).order_by(
|
||||
"preferreddate","startdate","enddate")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user