Private
Public Access
1
0

adding calendar to all team members sending funct

This commit is contained in:
Sander Roosendaal
2019-07-31 14:12:06 +02:00
parent bdeed4c277
commit fca58e740f
8 changed files with 141 additions and 3 deletions

View File

@@ -1321,6 +1321,44 @@ def handle_sendemailcsv(first_name, last_name, email, csvfile,**kwargs):
return 1
@app.task
def handle_sendemail_ical(first_name, last_name, email, url, icsfile, **kwargs):
# send email with attachment
fullemail = first_name + " " + last_name + " " + "<" + email + ">"
subject = "Calendar File for your sessions from Rowsandall.com"
if 'debug' in kwargs:
debug = kwargs['debug']
else:
debug = False
siteurl = SITE_URL
if debug:
progressurl = SITE_URL_DEV
siteurl = SITE_URL_DEV
d = {'first_name':first_name,
'siteurl':siteurl,
'url':url,
}
from_email = 'Rowsandall <info@rowsandall.com>'
res = send_template_email(from_email,[fullemail],
subject,'icsemail.html',d,
attach_file=icsfile,**kwargs)
try:
os.remove(csvfile)
except:
pass
return 1
@app.task
def handle_sendemailfile(first_name, last_name, email, csvfile,**kwargs):

View File

@@ -171,6 +171,13 @@ def remove_coach(coach,rower):
return (1,'Coach removed')
def rower_get_managers(rower):
managers = []
for team in rower.team.all():
managers.append(team.manager.rower)
return managers
def rower_get_coaches(rower):
coaches = []
for group in rower.coachinggroups.all():

View File

@@ -4,10 +4,14 @@
<p>Dear <strong>{{ first_name }}</strong>,</p>
<p>
Please find attached the requested ICS Calendar file. You can import
Please find attached the ICS Calendar file for your training sessions. You can import
this file to your calendar app.
</p>
<p>
You can see the training plan here: <a href="{{ siteurl }}{{ url }}">{{ siteurl }}{{ url }}</a>
</p>
<p>
Best Regards, the Rowsandall Team
</p>

View File

@@ -6,9 +6,9 @@
{% block main %}
{% if theteam %}
<h1>Coach Overview. Team {{ theteam.name }}</h1>
<h1>Group Overview. Team {{ theteam.name }}</h1>
{% else %}
<h1>Coach Overview</h1>
<h1>Group Overview</h1>
{% endif %}
<ul class="main-content">
@@ -83,6 +83,17 @@
{% endfor %}
</tbody>
</table>
<p>
<a href="/rowers/sessions/sendcalendar/user/{{ rower.user.id }}/?when={{ timeperiod }}">
Get Calendar File</a>
</p>
{% if rower|is_coach:rowers %}
<p>
<a href="/rowers/sessions/coach/sendcalendar/user/{{ rower.user.id }}/?when={{ timeperiod }}">
Send Calendar File to all rowers
</a>
</p>
{% endif %}
</li>
{% if unmatchedworkouts %}

View File

@@ -66,6 +66,17 @@ def strfdelta(tdelta):
return res
from rowers.teams import rower_get_managers
@register.filter
def is_coach(rower,rowers):
for r in rowers:
if rower not in rower_get_managers(r):
print(r,rower)
return False
return True
def strfdeltah(tdelta):
hours, rest = divmod(tdelta.seconds,3600)
minutes,seconds = divmod(rest,60)

View File

@@ -673,6 +673,9 @@ urlpatterns = [
name='plannedsessions_coach_view'),
re_path(r'^sessions/coach/user/(?P<userid>\d+)/$',views.plannedsessions_coach_view,
name='plannedsessions_coach_view'),
re_path(r'^sessions/coach/sendcalendar/user/(?P<userid>\d+)/$',
views.plannedsessions_coach_icsemail_view,
name='plannedsessions_coach_icsemail_view'),
re_path(r'^sessions/print/?/$',views.plannedsessions_print_view,
name='plannedsessions_print_view'),
re_path(r'^sessions/(?P<id>\d+)/comments/user/(?P<userid>\d+)/$',views.plannedsession_comment_view,

View File

@@ -71,6 +71,69 @@ def plannedsessions_icsemail_view(request,userid=0):
return response
@login_required()
def plannedsessions_coach_icsemail_view(request,userid=0):
therower = getrequestplanrower(request,userid=userid)
startdate,enddate = get_dates_timeperiod(request)
if 'coach' in request.user.rower.rowerplan:
sps = get_sessions_manager(request.user,teamid=0,
enddate=enddate,
startdate=startdate)
else:
rteams = therower.team.filter(viewing='allmembers')
sps = get_sessions(therower,startdate=startdate,enddate=enddate)
if therower.rowerplan != 'freecoach':
rowers = [therower]
else:
rowers = []
rowers = list(set(rowers))
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)
icalstring = cal.to_ical()
fname = "media/training_plan_{d1}_{d2}".format(
d1 = startdate.strftime("%Y%m%d"),
d2 = enddate.strftime("%Y%m%d"),
)
url = reverse('plannedsessions_coach_view')+'?when={d1}/{d2}'.format(
d1 = startdate.strftime("%Y-%m-%d"),
d2 = enddate.strftime("%Y-%m-%d"),
)
for rower in rowers:
fname2 = fname+"_{u}.ics".format(u=rower.id)
with open(fname2,'wb') as fop:
fop.write(icalstring)
job = myqueue(queue,handle_sendemail_ical,
rower.user.first_name,
rower.user.last_name,
rower.user.email,
url,
fname2,debug=False)
return HttpResponseRedirect(url)
@login_required()
def course_kmldownload_view(request,id=0):

View File

@@ -183,6 +183,7 @@ from rowers.tasks import (
handle_sendemail_userdeleted,
handle_sendemail_raceregistration,
handle_sendemail_racesubmission,
handle_sendemail_ical,
)
from scipy.signal import savgol_filter