TP fix maybe, and form to message racers
This commit is contained in:
@@ -122,7 +122,9 @@ class EmailForm(forms.Form):
|
||||
lastname = forms.CharField(max_length=255)
|
||||
email = forms.EmailField()
|
||||
subject = forms.CharField(max_length=255)
|
||||
message = forms.CharField()
|
||||
message = forms.CharField(widget=forms.Textarea())
|
||||
|
||||
|
||||
|
||||
disqualificationreasons = (
|
||||
('noimage','No monitor screenshot or data evidence was included'),
|
||||
|
||||
@@ -2353,6 +2353,23 @@ class PlannedSessionForm(ModelForm):
|
||||
self.fields['course'].queryset = GeoCourse.objects.all().order_by("country","name")
|
||||
self.fields['sessiontype'].choices = regularsessiontypechoices
|
||||
|
||||
class VirtualRaceAthleteForm(ModelForm):
|
||||
class Meta:
|
||||
model = PlannedSession
|
||||
|
||||
fields = ['rower']
|
||||
|
||||
|
||||
widgets = {
|
||||
'rower':forms.CheckboxSelectMultiple,
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(VirtualRaceAthleteForm, self).__init__(*args, **kwargs)
|
||||
self.fields['rower'].queryset = self.instance.rower.all()
|
||||
self.fields['subject']= forms.CharField(max_length=255)
|
||||
self.fields['message'] = forms.CharField(widget=forms.Textarea())
|
||||
|
||||
|
||||
class PlannedSessionTemplateForm(ModelForm):
|
||||
|
||||
|
||||
@@ -2333,6 +2333,18 @@ def handle_sendemailnewcomment(first_name,
|
||||
|
||||
return 1
|
||||
|
||||
@app.task
|
||||
def handle_send_template_email(template,email,fromemail,rowername,
|
||||
subject,message,debug=False,**kwargs):
|
||||
fullemail = [email]
|
||||
d = {
|
||||
'message':message,
|
||||
'rowername':rowername,
|
||||
}
|
||||
|
||||
res = send_template_email(fromemail,fullemail,subject,
|
||||
template,d,**kwargs)
|
||||
|
||||
@app.task
|
||||
def handle_sendemail_message(email,fromemail,rowername,message,teamname,managername,
|
||||
debug=False,**kwargs):
|
||||
|
||||
38
rowers/templates/plannedsession_message.html
Normal file
38
rowers/templates/plannedsession_message.html
Normal file
@@ -0,0 +1,38 @@
|
||||
{% extends "newbase.html" %}
|
||||
{% load staticfiles %}
|
||||
{% load rowerfilters %}
|
||||
{% load tz %}
|
||||
|
||||
{% block scripts %}
|
||||
{% include "monitorjobs.html" %}
|
||||
{% endblock %}
|
||||
|
||||
{% block title %}Comment Session {% endblock %}
|
||||
|
||||
{% block main %}
|
||||
|
||||
<h1>Messages {{ plannedession.name }}</h1>
|
||||
|
||||
<p>With this form, you can send an email message to selected Challenge participants</p>
|
||||
|
||||
<ul class="main-content">
|
||||
<li class="grid_2">
|
||||
<form enctype="multipart/form-data" method="post">
|
||||
<table width=100%>
|
||||
{{ userform.as_table }}
|
||||
</table>
|
||||
{% csrf_token %}
|
||||
<input type="submit" value="Send">
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block sidebar %}
|
||||
{% if 'racing' in active %}
|
||||
{% include 'menu_racing.html' %}
|
||||
{% else %}
|
||||
{% include 'menu_plan.html' %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@@ -383,14 +383,21 @@
|
||||
{% endif %}
|
||||
</p>
|
||||
{% if race.manager == request.user %}
|
||||
<p>
|
||||
<a href="/rowers/virtualevent/{{ race.id }}/download"
|
||||
title="Download Results">Download Results</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<p>
|
||||
No results yet
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if race.manager == request.user %}
|
||||
<p>
|
||||
<a href="/rowers/sessions/{{ race.id }}/message/">Message to participant(s)</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</li>
|
||||
{% if form %}
|
||||
|
||||
10
rowers/templates/virtualracemessage.html
Normal file
10
rowers/templates/virtualracemessage.html
Normal file
@@ -0,0 +1,10 @@
|
||||
{% extends "emailbase.html" %}
|
||||
{% block body %}
|
||||
<p>Dear <strong>{{ rowername }}</strong>,</p>
|
||||
|
||||
<p>
|
||||
{{ message }}
|
||||
</p>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
@@ -69,7 +69,7 @@ def get_token(code):
|
||||
|
||||
response = requests.post(
|
||||
"https://oauth.trainingpeaks.com/oauth/token",
|
||||
data=post_data
|
||||
data=post_data,verify=False,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -735,6 +735,8 @@ urlpatterns = [
|
||||
name='plannedsession_comment_view'),
|
||||
re_path(r'^sessions/print/user/(?P<userid>\d+)/$',views.plannedsessions_print_view,
|
||||
name='plannedsessions_print_view'),
|
||||
re_path(r'^sessions/(?P<id>\d+)/message/$',views.plannedsession_message_view,
|
||||
name='plannedsession_message_view'),
|
||||
re_path(r'^sessions/print/user/(?P<userid>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\d+-\d+-\d+)/$',views.plannedsessions_print_view,
|
||||
name='plannedsessions_print_view'),
|
||||
re_path(r'^sessions/sendcalendar/$',views.plannedsessions_icsemail_view,
|
||||
|
||||
@@ -172,6 +172,87 @@ def plannedsession_comment_view(request,id=0,userid=0):
|
||||
'form':form,
|
||||
})
|
||||
|
||||
@login_required
|
||||
@permission_required('plannedsession.edit_session',fn=get_session_by_pk,raise_exception=True)
|
||||
def plannedsession_message_view(request,id=0,userid=0):
|
||||
r = getrequestplanrower(request,userid=userid)
|
||||
ps = get_object_or_404(PlannedSession,pk=id)
|
||||
|
||||
userform = VirtualRaceAthleteForm(instance=ps)
|
||||
|
||||
if request.method == 'POST':
|
||||
userform = VirtualRaceAthleteForm(request.POST,instance=ps)
|
||||
if userform.is_valid():
|
||||
subject = userform.cleaned_data['subject']
|
||||
message = userform.cleaned_data['message']
|
||||
rowers = userform.cleaned_data['rower']
|
||||
|
||||
for participant in rowers:
|
||||
rowername = participant.user.first_name
|
||||
fromemail = ps.manager.email
|
||||
|
||||
job = myqueue(
|
||||
queue,
|
||||
handle_send_template_email,
|
||||
'virtualracemessage.html',
|
||||
participant.user.email,
|
||||
fromemail,
|
||||
rowername,
|
||||
subject,
|
||||
message,
|
||||
)
|
||||
|
||||
|
||||
url = reverse('virtualevent_view',kwargs={'id':ps.id})
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
if ps.sessiontype in ['race','indoorrace']:
|
||||
breadcrumbs = [
|
||||
{
|
||||
'url':reverse('virtualevents_view'),
|
||||
'name': 'Races'
|
||||
},
|
||||
{
|
||||
'url': reverse('virtualevent_view',kwargs={'id':ps.id}),
|
||||
'name': ps.name
|
||||
},
|
||||
{
|
||||
'url':reverse('plannedsession_comment_view',kwargs={'id':ps.id}),
|
||||
'name': 'Comments'
|
||||
}
|
||||
]
|
||||
|
||||
active = 'nav-racing'
|
||||
|
||||
else:
|
||||
breadcrumbs = [
|
||||
{
|
||||
'url':reverse('plannedsessions_view'),
|
||||
'name': 'Sessions'
|
||||
},
|
||||
{
|
||||
'url': reverse('plannedsession_view',kwargs={'id':ps.id}),
|
||||
'name': ps.name
|
||||
},
|
||||
{
|
||||
'url':reverse('plannedsession_comment_view',kwargs={'id':ps.id}),
|
||||
'name': 'Comments'
|
||||
}
|
||||
]
|
||||
|
||||
active = 'nav-plan'
|
||||
|
||||
return render(request,
|
||||
'plannedsession_message.html',
|
||||
{'plannedsession':ps,
|
||||
'rower':r,
|
||||
'breadcrumbs':breadcrumbs,
|
||||
'active':active,
|
||||
'userform':userform,
|
||||
})
|
||||
|
||||
|
||||
# Cloning sessions
|
||||
@user_passes_test(can_plan,login_url="/rowers/paidplans/",
|
||||
message="This functionality requires a Coach or Self-Coach plan",
|
||||
|
||||
@@ -131,7 +131,7 @@ from rowers.models import (
|
||||
IndoorVirtualRaceResultForm,IndoorVirtualRaceResult,
|
||||
IndoorVirtualRaceForm,PlannedSessionCommentForm,
|
||||
Alert, Condition, StaticChartRowerForm,
|
||||
FollowerForm,
|
||||
FollowerForm,VirtualRaceAthleteForm,
|
||||
)
|
||||
from rowers.models import (
|
||||
FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement,BasePlannedSessionFormSet,
|
||||
@@ -198,6 +198,7 @@ from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,
|
||||
from rowers.tasks import (
|
||||
handle_sendemail_unrecognized,handle_sendemailnewcomment,
|
||||
handle_sendemailsummary,
|
||||
handle_send_template_email,
|
||||
handle_send_disqualification_email,
|
||||
handle_send_withdraw_email,
|
||||
handle_sendemailfile,
|
||||
|
||||
Reference in New Issue
Block a user