Private
Public Access
1
0

TP fix maybe, and form to message racers

This commit is contained in:
Sander Roosendaal
2020-06-06 17:43:16 +02:00
parent 55ad7ce2d9
commit 5aa6d89891
10 changed files with 174 additions and 4 deletions

View File

@@ -122,7 +122,9 @@ class EmailForm(forms.Form):
lastname = forms.CharField(max_length=255) lastname = forms.CharField(max_length=255)
email = forms.EmailField() email = forms.EmailField()
subject = forms.CharField(max_length=255) subject = forms.CharField(max_length=255)
message = forms.CharField() message = forms.CharField(widget=forms.Textarea())
disqualificationreasons = ( disqualificationreasons = (
('noimage','No monitor screenshot or data evidence was included'), ('noimage','No monitor screenshot or data evidence was included'),

View File

@@ -2353,6 +2353,23 @@ class PlannedSessionForm(ModelForm):
self.fields['course'].queryset = GeoCourse.objects.all().order_by("country","name") self.fields['course'].queryset = GeoCourse.objects.all().order_by("country","name")
self.fields['sessiontype'].choices = regularsessiontypechoices 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): class PlannedSessionTemplateForm(ModelForm):

View File

@@ -2333,6 +2333,18 @@ def handle_sendemailnewcomment(first_name,
return 1 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 @app.task
def handle_sendemail_message(email,fromemail,rowername,message,teamname,managername, def handle_sendemail_message(email,fromemail,rowername,message,teamname,managername,
debug=False,**kwargs): debug=False,**kwargs):

View 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 %}

View File

@@ -383,14 +383,21 @@
{% endif %} {% endif %}
</p> </p>
{% if race.manager == request.user %} {% if race.manager == request.user %}
<p>
<a href="/rowers/virtualevent/{{ race.id }}/download" <a href="/rowers/virtualevent/{{ race.id }}/download"
title="Download Results">Download Results</a> title="Download Results">Download Results</a>
</p>
{% endif %} {% endif %}
{% else %} {% else %}
<p> <p>
No results yet No results yet
</p> </p>
{% endif %} {% endif %}
{% if race.manager == request.user %}
<p>
<a href="/rowers/sessions/{{ race.id }}/message/">Message to participant(s)</a>
</p>
{% endif %}
</div> </div>
</li> </li>
{% if form %} {% if form %}

View File

@@ -0,0 +1,10 @@
{% extends "emailbase.html" %}
{% block body %}
<p>Dear <strong>{{ rowername }}</strong>,</p>
<p>
{{ message }}
</p>
{% endblock %}

View File

@@ -69,7 +69,7 @@ def get_token(code):
response = requests.post( response = requests.post(
"https://oauth.trainingpeaks.com/oauth/token", "https://oauth.trainingpeaks.com/oauth/token",
data=post_data data=post_data,verify=False,
) )

View File

@@ -735,6 +735,8 @@ urlpatterns = [
name='plannedsession_comment_view'), name='plannedsession_comment_view'),
re_path(r'^sessions/print/user/(?P<userid>\d+)/$',views.plannedsessions_print_view, re_path(r'^sessions/print/user/(?P<userid>\d+)/$',views.plannedsessions_print_view,
name='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, 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'), name='plannedsessions_print_view'),
re_path(r'^sessions/sendcalendar/$',views.plannedsessions_icsemail_view, re_path(r'^sessions/sendcalendar/$',views.plannedsessions_icsemail_view,

View File

@@ -172,6 +172,87 @@ def plannedsession_comment_view(request,id=0,userid=0):
'form':form, '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 # Cloning sessions
@user_passes_test(can_plan,login_url="/rowers/paidplans/", @user_passes_test(can_plan,login_url="/rowers/paidplans/",
message="This functionality requires a Coach or Self-Coach plan", message="This functionality requires a Coach or Self-Coach plan",

View File

@@ -131,7 +131,7 @@ from rowers.models import (
IndoorVirtualRaceResultForm,IndoorVirtualRaceResult, IndoorVirtualRaceResultForm,IndoorVirtualRaceResult,
IndoorVirtualRaceForm,PlannedSessionCommentForm, IndoorVirtualRaceForm,PlannedSessionCommentForm,
Alert, Condition, StaticChartRowerForm, Alert, Condition, StaticChartRowerForm,
FollowerForm, FollowerForm,VirtualRaceAthleteForm,
) )
from rowers.models import ( from rowers.models import (
FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement,BasePlannedSessionFormSet, FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement,BasePlannedSessionFormSet,
@@ -198,6 +198,7 @@ from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,
from rowers.tasks import ( from rowers.tasks import (
handle_sendemail_unrecognized,handle_sendemailnewcomment, handle_sendemail_unrecognized,handle_sendemailnewcomment,
handle_sendemailsummary, handle_sendemailsummary,
handle_send_template_email,
handle_send_disqualification_email, handle_send_disqualification_email,
handle_send_withdraw_email, handle_send_withdraw_email,
handle_sendemailfile, handle_sendemailfile,