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)
|
||||
manager = models.ForeignKey(User, null=True,on_delete=models.CASCADE)
|
||||
notes = models.CharField(blank=True,null=True,max_length=1000)
|
||||
active = models.BooleanField(default=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
@@ -2207,9 +2208,10 @@ class CourseStandard(models.Model):
|
||||
standardcollection = models.ForeignKey(StandardCollection,on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('name','sex','agemin',
|
||||
'agemax','boatclass','boattype','weightclass','adaptiveclass',
|
||||
'skillclass','standardcollection')
|
||||
unique_together = (
|
||||
('name','standardcollection')
|
||||
)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
@@ -2456,6 +2458,7 @@ class IndoorVirtualRaceForm(ModelForm):
|
||||
self.fields['sessionunit'].initial = 'm'
|
||||
if timezone:
|
||||
self.fields['timezone'].initial = timezone
|
||||
self.fields['coursestandards'].queryset = StandardCollection.objects.filter(active=True)
|
||||
|
||||
def clean(self):
|
||||
cd = self.cleaned_data
|
||||
@@ -2583,6 +2586,7 @@ class VirtualRaceForm(ModelForm):
|
||||
def __init__(self,*args,**kwargs):
|
||||
super(VirtualRaceForm, self).__init__(*args, **kwargs)
|
||||
self.fields['course'].queryset = GeoCourse.objects.all().order_by("country","name")
|
||||
self.fields['coursestandards'].queryset = StandardCollection.objects.filter(active=True)
|
||||
|
||||
|
||||
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 arrow
|
||||
@@ -10,7 +10,8 @@ def save_scoring(name,user,filename,id=0,notes=""):
|
||||
collection.save()
|
||||
standards = CourseStandard.objects.filter(standardcollection=collection)
|
||||
for standard in standards:
|
||||
standard.delete()
|
||||
standards.delete()
|
||||
|
||||
else:
|
||||
try:
|
||||
collection = StandardCollection.objects.get(id=id)
|
||||
@@ -19,8 +20,11 @@ def save_scoring(name,user,filename,id=0,notes=""):
|
||||
collection.save()
|
||||
standards = CourseStandard.objects.filter(standardcollection=collection)
|
||||
for standard in standards:
|
||||
print(standard,collection)
|
||||
standard.delete()
|
||||
records1 = VirtualRaceResult.objects.filter(entrycategory=standard)
|
||||
records2 = IndoorVirtualRaceResult.objects.filter(entrycategory=standard)
|
||||
if records1.count()+records2.count() == 0:
|
||||
standard.delete()
|
||||
|
||||
|
||||
except StandardCollection.DoesNotExist:
|
||||
return 0
|
||||
@@ -30,6 +34,22 @@ def save_scoring(name,user,filename,id=0,notes=""):
|
||||
except:
|
||||
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'])
|
||||
|
||||
for index, row in df.iterrows():
|
||||
@@ -60,9 +80,9 @@ def save_scoring(name,user,filename,id=0,notes=""):
|
||||
|
||||
try:
|
||||
boatclass = row['BoatClass']
|
||||
if boatclass.lower() in ['standard','olympic','normal']:
|
||||
if boatclass.lower() in ['standard','olympic','normal','water']:
|
||||
boatclass = 'water'
|
||||
elif boatclass.lower() in ['erg','c2','concept','static']:
|
||||
elif boatclass.lower() in ['erg','c2','concept','static','rower']:
|
||||
boatclass = 'rower'
|
||||
elif boatclass.lower() in ['dynamic']:
|
||||
boatclass = 'dynamic'
|
||||
@@ -115,23 +135,43 @@ def save_scoring(name,user,filename,id=0,notes=""):
|
||||
except KeyError:
|
||||
skillclass = 'Open'
|
||||
|
||||
# some testing
|
||||
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,
|
||||
)
|
||||
# finding existing standard
|
||||
existingstandards = CourseStandard.objects.filter(name=name,standardcollection=collection)
|
||||
#print(existingstandards,collection)
|
||||
if existingstandards:
|
||||
existingstandards.update(
|
||||
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,
|
||||
)
|
||||
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
|
||||
|
||||
@@ -21,7 +21,18 @@
|
||||
<ul class="main-content">
|
||||
<li class="grid_4">
|
||||
<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 id="id_drop-files" class="grid_12 alpha drop-files">
|
||||
<form id="file_form" enctype="multipart/form-data" method="post">
|
||||
|
||||
@@ -33,7 +33,11 @@
|
||||
</table>
|
||||
</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 class="grid_4">
|
||||
<h2>Standard Times</h2>
|
||||
|
||||
@@ -756,6 +756,10 @@ urlpatterns = [
|
||||
name='course_replace_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+)/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'),
|
||||
# URLS to be created
|
||||
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):
|
||||
r = getrower(request.user)
|
||||
|
||||
standards = StandardCollection.objects.all().order_by("name")
|
||||
standards = StandardCollection.objects.filter(active=True).order_by("name")
|
||||
|
||||
# add search processing
|
||||
query = request.GET.get('q')
|
||||
@@ -521,11 +521,57 @@ def course_upload_view(request):
|
||||
else:
|
||||
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
|
||||
@login_required()
|
||||
def standards_upload_view(request,id=0):
|
||||
is_ajax = False
|
||||
print(id,'aap')
|
||||
if request.is_ajax():
|
||||
is_ajax = True
|
||||
r = getrower(request.user)
|
||||
|
||||
Reference in New Issue
Block a user