standards can be downloaded and deactivated
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -2187,6 +2187,7 @@ class StandardCollection(models.Model):
|
|||||||
name = models.CharField(max_length=150)
|
name = models.CharField(max_length=150)
|
||||||
manager = models.ForeignKey(User, null=True,on_delete=models.CASCADE)
|
manager = models.ForeignKey(User, null=True,on_delete=models.CASCADE)
|
||||||
notes = models.CharField(blank=True,null=True,max_length=1000)
|
notes = models.CharField(blank=True,null=True,max_length=1000)
|
||||||
|
active = models.BooleanField(default=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@@ -2207,9 +2208,10 @@ class CourseStandard(models.Model):
|
|||||||
standardcollection = models.ForeignKey(StandardCollection,on_delete=models.CASCADE)
|
standardcollection = models.ForeignKey(StandardCollection,on_delete=models.CASCADE)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ('name','sex','agemin',
|
unique_together = (
|
||||||
'agemax','boatclass','boattype','weightclass','adaptiveclass',
|
('name','standardcollection')
|
||||||
'skillclass','standardcollection')
|
)
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@@ -2456,6 +2458,7 @@ class IndoorVirtualRaceForm(ModelForm):
|
|||||||
self.fields['sessionunit'].initial = 'm'
|
self.fields['sessionunit'].initial = 'm'
|
||||||
if timezone:
|
if timezone:
|
||||||
self.fields['timezone'].initial = timezone
|
self.fields['timezone'].initial = timezone
|
||||||
|
self.fields['coursestandards'].queryset = StandardCollection.objects.filter(active=True)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
cd = self.cleaned_data
|
cd = self.cleaned_data
|
||||||
@@ -2583,6 +2586,7 @@ class VirtualRaceForm(ModelForm):
|
|||||||
def __init__(self,*args,**kwargs):
|
def __init__(self,*args,**kwargs):
|
||||||
super(VirtualRaceForm, self).__init__(*args, **kwargs)
|
super(VirtualRaceForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['course'].queryset = GeoCourse.objects.all().order_by("country","name")
|
self.fields['course'].queryset = GeoCourse.objects.all().order_by("country","name")
|
||||||
|
self.fields['coursestandards'].queryset = StandardCollection.objects.filter(active=True)
|
||||||
|
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from rowers.models import StandardCollection,CourseStandard
|
from rowers.models import StandardCollection,CourseStandard, VirtualRaceResult,IndoorVirtualRaceResult
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import arrow
|
import arrow
|
||||||
@@ -10,7 +10,8 @@ def save_scoring(name,user,filename,id=0,notes=""):
|
|||||||
collection.save()
|
collection.save()
|
||||||
standards = CourseStandard.objects.filter(standardcollection=collection)
|
standards = CourseStandard.objects.filter(standardcollection=collection)
|
||||||
for standard in standards:
|
for standard in standards:
|
||||||
standard.delete()
|
standards.delete()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
collection = StandardCollection.objects.get(id=id)
|
collection = StandardCollection.objects.get(id=id)
|
||||||
@@ -19,8 +20,11 @@ def save_scoring(name,user,filename,id=0,notes=""):
|
|||||||
collection.save()
|
collection.save()
|
||||||
standards = CourseStandard.objects.filter(standardcollection=collection)
|
standards = CourseStandard.objects.filter(standardcollection=collection)
|
||||||
for standard in standards:
|
for standard in standards:
|
||||||
print(standard,collection)
|
records1 = VirtualRaceResult.objects.filter(entrycategory=standard)
|
||||||
standard.delete()
|
records2 = IndoorVirtualRaceResult.objects.filter(entrycategory=standard)
|
||||||
|
if records1.count()+records2.count() == 0:
|
||||||
|
standard.delete()
|
||||||
|
|
||||||
|
|
||||||
except StandardCollection.DoesNotExist:
|
except StandardCollection.DoesNotExist:
|
||||||
return 0
|
return 0
|
||||||
@@ -30,6 +34,22 @@ def save_scoring(name,user,filename,id=0,notes=""):
|
|||||||
except:
|
except:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
df.rename(
|
||||||
|
columns={
|
||||||
|
'name':'Name',
|
||||||
|
'agemax':'MaxAge',
|
||||||
|
'agemin':'MinAge',
|
||||||
|
'adaptiveclass':'AdaptiveClass',
|
||||||
|
'coursedistance':'CourseDistance',
|
||||||
|
'coursetime':'CourseStandard',
|
||||||
|
'boatclass':'BoatClass',
|
||||||
|
'boattype':'BoatType',
|
||||||
|
'sex':'Gender',
|
||||||
|
'weightclass':'WeightClass',
|
||||||
|
'skillclass':'SkillClass',
|
||||||
|
},
|
||||||
|
inplace=True)
|
||||||
|
|
||||||
df = df.drop_duplicates(['Name'])
|
df = df.drop_duplicates(['Name'])
|
||||||
|
|
||||||
for index, row in df.iterrows():
|
for index, row in df.iterrows():
|
||||||
@@ -60,9 +80,9 @@ def save_scoring(name,user,filename,id=0,notes=""):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
boatclass = row['BoatClass']
|
boatclass = row['BoatClass']
|
||||||
if boatclass.lower() in ['standard','olympic','normal']:
|
if boatclass.lower() in ['standard','olympic','normal','water']:
|
||||||
boatclass = 'water'
|
boatclass = 'water'
|
||||||
elif boatclass.lower() in ['erg','c2','concept','static']:
|
elif boatclass.lower() in ['erg','c2','concept','static','rower']:
|
||||||
boatclass = 'rower'
|
boatclass = 'rower'
|
||||||
elif boatclass.lower() in ['dynamic']:
|
elif boatclass.lower() in ['dynamic']:
|
||||||
boatclass = 'dynamic'
|
boatclass = 'dynamic'
|
||||||
@@ -115,23 +135,43 @@ def save_scoring(name,user,filename,id=0,notes=""):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
skillclass = 'Open'
|
skillclass = 'Open'
|
||||||
|
|
||||||
# some testing
|
# finding existing standard
|
||||||
standard = CourseStandard(
|
existingstandards = CourseStandard.objects.filter(name=name,standardcollection=collection)
|
||||||
name=name,
|
#print(existingstandards,collection)
|
||||||
coursedistance=coursedistance,
|
if existingstandards:
|
||||||
referencespeed=referencespeed,
|
existingstandards.update(
|
||||||
coursetime=coursetime,
|
name=name,
|
||||||
agemin=agemin,
|
coursedistance=coursedistance,
|
||||||
agemax=agemax,
|
referencespeed=referencespeed,
|
||||||
boatclass=boatclass,
|
coursetime=coursetime,
|
||||||
boattype=boattype,
|
agemin=agemin,
|
||||||
sex=sex,
|
agemax=agemax,
|
||||||
weightclass=weightclass,
|
boatclass=boatclass,
|
||||||
adaptiveclass=adaptiveclass,
|
boattype=boattype,
|
||||||
skillclass=skillclass,
|
sex=sex,
|
||||||
standardcollection = collection,
|
weightclass=weightclass,
|
||||||
)
|
adaptiveclass=adaptiveclass,
|
||||||
|
skillclass=skillclass,
|
||||||
|
standardcollection = collection,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
#print('not')
|
||||||
|
standard = CourseStandard(
|
||||||
|
name=name,
|
||||||
|
coursedistance=coursedistance,
|
||||||
|
referencespeed=referencespeed,
|
||||||
|
coursetime=coursetime,
|
||||||
|
agemin=agemin,
|
||||||
|
agemax=agemax,
|
||||||
|
boatclass=boatclass,
|
||||||
|
boattype=boattype,
|
||||||
|
sex=sex,
|
||||||
|
weightclass=weightclass,
|
||||||
|
adaptiveclass=adaptiveclass,
|
||||||
|
skillclass=skillclass,
|
||||||
|
standardcollection = collection,
|
||||||
|
)
|
||||||
|
|
||||||
standard.save()
|
standard.save()
|
||||||
|
|
||||||
return collection.id
|
return collection.id
|
||||||
|
|||||||
@@ -21,7 +21,18 @@
|
|||||||
<ul class="main-content">
|
<ul class="main-content">
|
||||||
<li class="grid_4">
|
<li class="grid_4">
|
||||||
<div id="id_dropregion watermark invisible">
|
<div id="id_dropregion watermark invisible">
|
||||||
<p>Drag and drop files here </p>
|
<p>Drag and drop files here.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
If you're updating an existing set of standard times,
|
||||||
|
existing groups with challenge entries will be updated. New
|
||||||
|
groups will be created. All groups with challenge entries will
|
||||||
|
remain, even if you delete them from the CSV file. So, it
|
||||||
|
is not possible to remove groups if there have been starts in this group.</p>
|
||||||
|
<p>
|
||||||
|
If you want to still remove those groups, it is better to set the
|
||||||
|
existing set of standard times to inactive and upload a new one.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div id="id_drop-files" class="grid_12 alpha drop-files">
|
<div id="id_drop-files" class="grid_12 alpha drop-files">
|
||||||
<form id="file_form" enctype="multipart/form-data" method="post">
|
<form id="file_form" enctype="multipart/form-data" method="post">
|
||||||
|
|||||||
@@ -33,7 +33,11 @@
|
|||||||
</table>
|
</table>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p><a href="/rowers/standards/upload/{{ collection.id }}/">Update these Standard Times</a>
|
{% if request.user == collection.manager %}
|
||||||
|
<p><a href="/rowers/standards/upload/{{ collection.id }}/">Update these Standard Times</a></p>
|
||||||
|
<p><a href="/rowers/standards/{{ collection.id }}/deactivate/">Deactivate this standard</a></p>
|
||||||
|
{% endif %}
|
||||||
|
<p><a href="/rowers/standards/{{ collection.id }}/download/">Download as CSV file</a></p>
|
||||||
</li>
|
</li>
|
||||||
<li class="grid_4">
|
<li class="grid_4">
|
||||||
<h2>Standard Times</h2>
|
<h2>Standard Times</h2>
|
||||||
|
|||||||
@@ -756,6 +756,10 @@ urlpatterns = [
|
|||||||
name='course_replace_view'),
|
name='course_replace_view'),
|
||||||
re_path(r'^courses/(?P<id>\d+)/$',views.course_view,name='course_view'),
|
re_path(r'^courses/(?P<id>\d+)/$',views.course_view,name='course_view'),
|
||||||
re_path(r'^standards/(?P<id>\d+)/$',views.standard_view,name='standard_view'),
|
re_path(r'^standards/(?P<id>\d+)/$',views.standard_view,name='standard_view'),
|
||||||
|
re_path(r'^standards/(?P<id>\d+)/download/$',views.standards_download_view,
|
||||||
|
name='standards_download_view'),
|
||||||
|
re_path(r'^standards/(?P<id>\d+)/deactivate/$',views.standard_deactivate_view,
|
||||||
|
name='standard_decativate_view'),
|
||||||
re_path(r'^courses/(?P<id>\d+)/map/$',views.course_map_view,name='course_map_view'),
|
re_path(r'^courses/(?P<id>\d+)/map/$',views.course_map_view,name='course_map_view'),
|
||||||
# URLS to be created
|
# URLS to be created
|
||||||
re_path(r'^help/$',TemplateView.as_view(template_name='help.html'), name='help'),
|
re_path(r'^help/$',TemplateView.as_view(template_name='help.html'), name='help'),
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ def courses_view(request):
|
|||||||
def standards_view(request):
|
def standards_view(request):
|
||||||
r = getrower(request.user)
|
r = getrower(request.user)
|
||||||
|
|
||||||
standards = StandardCollection.objects.all().order_by("name")
|
standards = StandardCollection.objects.filter(active=True).order_by("name")
|
||||||
|
|
||||||
# add search processing
|
# add search processing
|
||||||
query = request.GET.get('q')
|
query = request.GET.get('q')
|
||||||
@@ -521,11 +521,57 @@ def course_upload_view(request):
|
|||||||
else:
|
else:
|
||||||
return {'result':0}
|
return {'result':0}
|
||||||
|
|
||||||
|
# Standards deactivate
|
||||||
|
@login_required()
|
||||||
|
def standard_deactivate_view(request,id=0):
|
||||||
|
is_ajax = False
|
||||||
|
if request.is_ajax():
|
||||||
|
is_ajax = True
|
||||||
|
|
||||||
|
r = getrower(request.user)
|
||||||
|
|
||||||
|
try:
|
||||||
|
collection = StandardCollection.objects.get(id=id)
|
||||||
|
except StandardCollection.DoesNotExist:
|
||||||
|
raise Http404("Does not exist")
|
||||||
|
|
||||||
|
if request.user != collection.manager:
|
||||||
|
raise PermissionDenied("You cannot change this set of time standards")
|
||||||
|
|
||||||
|
collection.active = False
|
||||||
|
collection.save()
|
||||||
|
|
||||||
|
url = reverse(standards_view)
|
||||||
|
|
||||||
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
def standards_download_view(request,id=0):
|
||||||
|
try:
|
||||||
|
collection = StandardCollection.objects.get(id=id)
|
||||||
|
except StandardCollection.DoesNotExist:
|
||||||
|
raise Http404("Does not exist")
|
||||||
|
|
||||||
|
filename = 'Standard Times {name} {id} {date}.csv'.format(
|
||||||
|
id=id,
|
||||||
|
name=collection.name,
|
||||||
|
date=timezone.now().strftime("%Y-%m-%d %H:%M:%S %Z")
|
||||||
|
)
|
||||||
|
|
||||||
|
standards = CourseStandard.objects.filter(standardcollection=collection)
|
||||||
|
df = pd.DataFrame.from_records(standards.values())
|
||||||
|
|
||||||
|
response = HttpResponse(df.to_csv())
|
||||||
|
|
||||||
|
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
|
||||||
|
response['Content-Type'] = 'application/octet-stream'
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
# Standards upload
|
# Standards upload
|
||||||
@login_required()
|
@login_required()
|
||||||
def standards_upload_view(request,id=0):
|
def standards_upload_view(request,id=0):
|
||||||
is_ajax = False
|
is_ajax = False
|
||||||
print(id,'aap')
|
|
||||||
if request.is_ajax():
|
if request.is_ajax():
|
||||||
is_ajax = True
|
is_ajax = True
|
||||||
r = getrower(request.user)
|
r = getrower(request.user)
|
||||||
|
|||||||
Reference in New Issue
Block a user