Course Times Standards CSV v1 working
This commit is contained in:
@@ -212,6 +212,18 @@ class CourseForm(forms.Form):
|
||||
from django.forms.widgets import HiddenInput
|
||||
super(CourseForm, self).__init__(*args, **kwargs)
|
||||
|
||||
# The form used for uploading images
|
||||
class StandardsForm(forms.Form):
|
||||
name = forms.CharField(max_length=150,label='Course Name')
|
||||
file = forms.FileField(required=False,
|
||||
validators=[must_be_csv])
|
||||
notes = forms.CharField(required=False,
|
||||
max_length=200,label='Course Notes',
|
||||
widget=forms.Textarea)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
from django.forms.widgets import HiddenInput
|
||||
super(StandardsForm, self).__init__(*args, **kwargs)
|
||||
|
||||
# The form used for uploading files
|
||||
class DocumentsForm(forms.Form):
|
||||
|
||||
@@ -5,6 +5,7 @@ import arrow
|
||||
import datetime
|
||||
|
||||
def save_scoring(name,user,filename,id=0,notes=""):
|
||||
print(notes)
|
||||
if id==0:
|
||||
collection = StandardCollection(name=name,manager=user,notes=notes)
|
||||
collection.save()
|
||||
@@ -102,3 +103,5 @@ def save_scoring(name,user,filename,id=0,notes=""):
|
||||
)
|
||||
|
||||
standard.save()
|
||||
|
||||
return collection.id
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
Please correct the error{{ form.errors|pluralize }} below.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
@@ -71,13 +71,13 @@
|
||||
if (!formdatasetok) {
|
||||
$("#id_dropregion").remove();
|
||||
}
|
||||
|
||||
|
||||
if (formdatasetok) {
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
|
||||
console.log("CSRF token",csrftoken);
|
||||
|
||||
|
||||
function csrfSafeMethod(method) {
|
||||
// these HTTP methods do not require CSRF protection
|
||||
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
|
||||
@@ -95,11 +95,11 @@
|
||||
$(window).on('dragenter', function() {
|
||||
$("#id_drop-files").css("background-color","#E9E9E4");
|
||||
$("#id_dropregion").addClass("watermark").removeClass("invisible");})
|
||||
|
||||
|
||||
$(window).on('dragleave', function() {
|
||||
$("#id_drop-files").css("background-color","#FFFFFF");
|
||||
$("#id_dropregion").removeClass("watermark").addClass("invisible");})
|
||||
|
||||
|
||||
var frm = $("#file_form");
|
||||
|
||||
if( window.FormData === undefined ) {
|
||||
@@ -108,7 +108,7 @@
|
||||
} else {
|
||||
console.log('we have formdata');
|
||||
}
|
||||
|
||||
|
||||
var data = new FormData(frm[0]);
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
$('input').each(function( i ) {
|
||||
$(this).change(function() {
|
||||
@@ -159,7 +159,14 @@
|
||||
console.log($(this).attr('name'),$(this).val());
|
||||
};
|
||||
});});
|
||||
|
||||
|
||||
$('textarea').each(function( i ) {
|
||||
$(this).change(function() {
|
||||
data.set($(this).attr('name'),$(this).val());
|
||||
console.log($(this).attr('name'),$(this).val());
|
||||
});
|
||||
});
|
||||
|
||||
$('select').each(function( i ) {
|
||||
console.log($(this).attr('name'),$(this).val());
|
||||
$(this).change(function() {
|
||||
@@ -200,7 +207,7 @@
|
||||
console.log(result," reloading");
|
||||
location.reload();
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
@@ -236,7 +243,7 @@
|
||||
$("#id_file").value = 0;
|
||||
return false;
|
||||
}
|
||||
data.set("file",f);
|
||||
data.set("file",f);
|
||||
// data.append("file",f);
|
||||
|
||||
$("#id_file").replaceWith('<div id="id_file">'+files[0].name+' <a class="remove" href="javascript:void(0);"><b><font color="red">X</font></b></a></div>');
|
||||
|
||||
265
rowers/templates/standard_form.html
Normal file
265
rowers/templates/standard_form.html
Normal file
@@ -0,0 +1,265 @@
|
||||
{% extends "newbase.html" %}
|
||||
{% load staticfiles %}
|
||||
{% load rowerfilters %}
|
||||
|
||||
{% block title %}File loading{% endblock %}
|
||||
|
||||
{% block meta %}
|
||||
<script type='text/javascript'
|
||||
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
|
||||
</script>
|
||||
<script type='text/javascript'
|
||||
src='https://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js'>
|
||||
</script>
|
||||
<script>
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<h1>Upload Course Standard Times File</h1>
|
||||
|
||||
<ul class="main-content">
|
||||
<li class="grid_4">
|
||||
<div id="id_dropregion watermark invisible">
|
||||
<p>Drag and drop files here </p>
|
||||
</div>
|
||||
<div id="id_drop-files" class="grid_12 alpha drop-files">
|
||||
<form id="file_form" enctype="multipart/form-data" method="post">
|
||||
{% if form.errors %}
|
||||
<p style="color: red;">
|
||||
Please correct the error{{ form.errors|pluralize }} below.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
{% csrf_token %}
|
||||
<p>
|
||||
<input type="submit" value="Submit">
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block sidebar %}
|
||||
{% include 'menu_racing.html' %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block scripts %}
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||
<script>
|
||||
var td = new FormData();
|
||||
var formdatasetok = false;
|
||||
try {
|
||||
td.set('aap','noot');
|
||||
formdatasetok = true;
|
||||
console.log('FormData.set OK');
|
||||
}
|
||||
catch(err) {
|
||||
console.log('FormData.set not OK');
|
||||
formdatasetok = false;
|
||||
}
|
||||
|
||||
if (!formdatasetok) {
|
||||
$("#id_dropregion").remove();
|
||||
}
|
||||
|
||||
if (formdatasetok) {
|
||||
|
||||
$(document).ready(function() {
|
||||
var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
|
||||
console.log("CSRF token",csrftoken);
|
||||
|
||||
function csrfSafeMethod(method) {
|
||||
// these HTTP methods do not require CSRF protection
|
||||
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
|
||||
}
|
||||
$.ajaxSetup({
|
||||
beforeSend: function(xhr, settings) {
|
||||
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
|
||||
xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log("Loading dropper");
|
||||
jQuery.event.props.push('dataTransfer');
|
||||
|
||||
$(window).on('dragenter', function() {
|
||||
$("#id_drop-files").css("background-color","#E9E9E4");
|
||||
$("#id_dropregion").addClass("watermark").removeClass("invisible");})
|
||||
|
||||
$(window).on('dragleave', function() {
|
||||
$("#id_drop-files").css("background-color","#FFFFFF");
|
||||
$("#id_dropregion").removeClass("watermark").addClass("invisible");})
|
||||
|
||||
var frm = $("#file_form");
|
||||
|
||||
if( window.FormData === undefined ) {
|
||||
console.log('no formdata');
|
||||
alert("No FormData");
|
||||
} else {
|
||||
console.log('we have formdata');
|
||||
}
|
||||
|
||||
var data = new FormData(frm[0]);
|
||||
|
||||
|
||||
$('#id_file').on('change', function(evt) {
|
||||
var f = this.files[0];
|
||||
console.log(f);
|
||||
var istcx = false;
|
||||
var isgzip = false;
|
||||
var size1 = 10485760;
|
||||
var size2 = 1048576;
|
||||
if ((/\.(tcx|TCX)/i).test(f.name)) {
|
||||
istcx = true;
|
||||
console.log('tcx');
|
||||
if ((/\.(gz|GZ)/i).test(f.name)) {
|
||||
isgzip = true;
|
||||
console.log('gzip');
|
||||
size1 /= 5;
|
||||
size2 /= 5;
|
||||
}
|
||||
}
|
||||
console.log(size1)
|
||||
console.log(size2)
|
||||
if (f.size > size1) {
|
||||
alert("File Size must be smaller than 10 MB");
|
||||
this.value = null;
|
||||
} else {
|
||||
|
||||
if (f.size > size2) {
|
||||
$('#id_offline').val('True');
|
||||
$('#id_offline').prop('checked','True');
|
||||
data.set($('#id_offline').attr('name'),$('#id_offline').prop('checked'));
|
||||
console.log("Set offline to True");
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$('input').each(function( i ) {
|
||||
$(this).change(function() {
|
||||
if ($(this).attr('type') == 'checkbox') {
|
||||
data.set($(this).attr('name'),$(this).prop('checked'));
|
||||
console.log($(this).attr('id'),$(this).attr('name'),$(this).attr('notes'),$(this).prop('checked'));
|
||||
} else {
|
||||
data.set($(this).attr('name'),$(this).val());
|
||||
if ($(this).attr('id') == 'id_file') {
|
||||
data.set("file",this.files[0]);
|
||||
}
|
||||
console.log($(this).attr('name'),$(this).val());
|
||||
};
|
||||
});});
|
||||
|
||||
$('textarea').each(function( i ) {
|
||||
$(this).change(function() {
|
||||
data.set($(this).attr('name'),$(this).val());
|
||||
console.log($(this).attr('name'),$(this).val());
|
||||
});
|
||||
});
|
||||
|
||||
$('select').each(function( i ) {
|
||||
console.log($(this).attr('name'),$(this).val());
|
||||
$(this).change(function() {
|
||||
data.set($(this).attr('name'),$(this).val());
|
||||
console.log($(this).attr('id'),$(this).attr('name'),$(this).val());
|
||||
});
|
||||
});
|
||||
|
||||
frm.submit(function() {
|
||||
console.log("Form submission");
|
||||
$(data.values()).each(function(value) {
|
||||
console.log(value);
|
||||
});
|
||||
|
||||
$("#id_drop-files").replaceWith(
|
||||
'<div id="id_waiting"><img src="/static/img/rowingtimer.gif" width="60" height="50" style="width:60px">'
|
||||
);
|
||||
$.ajax({
|
||||
data: data,
|
||||
type: $(this).attr('method'),
|
||||
url: '/rowers/standards/upload/',
|
||||
contentType: false,
|
||||
processData: false,
|
||||
error: function(result) {
|
||||
$("#id_waiting").replaceWith(
|
||||
'<div id="id_failed" class="grid_12 alpha message">Your upload failed</div>'
|
||||
);
|
||||
setTimeout(function() {
|
||||
location.reload();
|
||||
},1000);
|
||||
},
|
||||
success: function(result) {
|
||||
console.log('got something back');
|
||||
console.log(result);
|
||||
if (result.result == 1) {
|
||||
window.location.href = result.url;
|
||||
} else {
|
||||
console.log(result," reloading");
|
||||
location.reload();
|
||||
};
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
$('#id_drop-files').bind({
|
||||
drop: function(e) {
|
||||
e.preventDefault();
|
||||
console.log("you dropped something");
|
||||
var files = e.dataTransfer.files;
|
||||
console.log(files[0]);
|
||||
|
||||
var f = files[0];
|
||||
var istcx = false;
|
||||
var isgzip = false;
|
||||
var size1 = 10485760;
|
||||
var size2 = 1048576;
|
||||
if ((/\.(tcx|TCX)/i).test(f.name)) {
|
||||
istcx = true;
|
||||
console.log('tcx');
|
||||
if ((/\.(gz|GZ)/i).test(f.name)) {
|
||||
isgzip = true;
|
||||
console.log('gzip');
|
||||
size1 /= 5;
|
||||
size2 /= 5;
|
||||
}
|
||||
}
|
||||
console.log(f);
|
||||
console.log(size1)
|
||||
console.log(size2)
|
||||
if (f.size > size1) {
|
||||
alert("File Size must be smaller than 10 MB");
|
||||
$("#id_file").value = 0;
|
||||
return false;
|
||||
}
|
||||
data.set("file",f);
|
||||
// data.append("file",f);
|
||||
|
||||
$("#id_file").replaceWith('<div id="id_file">'+files[0].name+' <a class="remove" href="javascript:void(0);"><b><font color="red">X</font></b></a></div>');
|
||||
},
|
||||
mouseenter:function(){$("#id_drop-files").css("background-color","#E9E9E4");},
|
||||
mouseleave:function(){$("#id_drop-files").css("background-color","#FFFFFF");},
|
||||
dragover:function(e){
|
||||
e.preventDefault();
|
||||
$("#id_drop-files").css("background-color","#E9E9E4");},
|
||||
dragleave:function(e){ e.preventDefault();},
|
||||
});
|
||||
$(document).on("click", "a.remove", function() {
|
||||
$(this).parent().replaceWith('<td><input id="id_file" name="file" type="file" /></td>');
|
||||
});
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
@@ -203,6 +203,7 @@ urlpatterns = [
|
||||
re_path(r'^list-courses/$',views.courses_view,name='courses_view'),
|
||||
re_path(r'^list-standards/$',views.standards_view,name='standards_view'),
|
||||
re_path(r'^courses/upload/$',views.course_upload_view,name='course_upload_view'),
|
||||
re_path(r'^standards/upload/$',views.standards_upload_view,name='standards_upload_view'),
|
||||
re_path(r'^workout/addmanual/(?P<raceid>\d+)$',views.addmanual_view,name='addmanual_view'),
|
||||
re_path(r'^workout/addmanual/$',views.addmanual_view,name='addmanual_view'),
|
||||
re_path(r'^team-compare-select/workout/(?P<id>\d+)/team/(?P<teamid>\d+)/user/(?P<userid>\d+)/$',views.team_comparison_select,name='team_comparison_select'),
|
||||
|
||||
@@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from rowers.views.statements import *
|
||||
from rowsandall_app.settings import SITE_URL
|
||||
from rowers.scoring import *
|
||||
|
||||
# List Courses
|
||||
def courses_view(request):
|
||||
@@ -40,7 +41,6 @@ def standards_view(request):
|
||||
r = getrower(request.user)
|
||||
|
||||
standards = StandardCollection.objects.all().order_by("name")
|
||||
print(standards)
|
||||
|
||||
# add search processing
|
||||
query = request.GET.get('q')
|
||||
@@ -49,8 +49,6 @@ def standards_view(request):
|
||||
standards = StandardCollection.objects.filter(
|
||||
reduce(operator.and_,
|
||||
(Q(name__icontains=q) for q in query_list)) |
|
||||
reduce(operator.and_,
|
||||
(Q(country__icontains=q) for q in query_list)) |
|
||||
reduce(operator.and_,
|
||||
(Q(notes__icontains=q) for q in query_list))
|
||||
)
|
||||
@@ -58,7 +56,6 @@ def standards_view(request):
|
||||
else:
|
||||
searchform = SearchForm()
|
||||
|
||||
print(standards)
|
||||
|
||||
return render(request,'list_standards.html',
|
||||
{'standards':standards,
|
||||
@@ -464,7 +461,7 @@ def virtualevent_uploadimage_view(request,id=0):
|
||||
})
|
||||
|
||||
|
||||
# Image upload
|
||||
# Course upload
|
||||
@login_required()
|
||||
def course_upload_view(request):
|
||||
is_ajax = False
|
||||
@@ -524,6 +521,66 @@ def course_upload_view(request):
|
||||
else:
|
||||
return {'result':0}
|
||||
|
||||
# Standards upload
|
||||
@login_required()
|
||||
def standards_upload_view(request,id=0):
|
||||
is_ajax = False
|
||||
if request.is_ajax():
|
||||
is_ajax = True
|
||||
r = getrower(request.user)
|
||||
|
||||
|
||||
if request.method == 'POST':
|
||||
print(request.POST)
|
||||
form = StandardsForm(request.POST,request.FILES)
|
||||
|
||||
if form.is_valid():
|
||||
f = form.cleaned_data['file']
|
||||
name = form.cleaned_data['name']
|
||||
notes = form.cleaned_data['notes']
|
||||
if f is not None:
|
||||
filename,path_and_filename = handle_uploaded_file(f)
|
||||
|
||||
id = save_scoring(name,request.user,path_and_filename,notes=notes,id=id)
|
||||
print(notes)
|
||||
|
||||
os.remove(path_and_filename)
|
||||
|
||||
|
||||
|
||||
if id==0:
|
||||
url = reverse(standards_view)
|
||||
else:
|
||||
url = reverse(standard_view,kwargs={'id':id})
|
||||
|
||||
if is_ajax:
|
||||
return JSONResponse({'result':1,'url':url})
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
else:
|
||||
messages.error(request,'Something went wrong - no file attached')
|
||||
url = reverse(standards_upload_view)
|
||||
if is_ajax:
|
||||
return JSONResponse({'result':0,'url':0})
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
else:
|
||||
messages.error(request,'Form is not valid')
|
||||
print(form.errors)
|
||||
return render(request,'standard_form.html',
|
||||
{'form':form,
|
||||
})
|
||||
|
||||
else:
|
||||
if not is_ajax:
|
||||
form = StandardsForm()
|
||||
return render(request,'standard_form.html',
|
||||
{'form':form,
|
||||
'active':'nav-racing',
|
||||
})
|
||||
return {'result':0}
|
||||
|
||||
|
||||
def virtualevents_view(request):
|
||||
is_ajax = False
|
||||
|
||||
@@ -93,7 +93,7 @@ from rowers.forms import (
|
||||
FitnessMetricForm,PredictedPieceFormNoDistance,
|
||||
EmailForm, RegistrationForm, RegistrationFormTermsOfService,
|
||||
RegistrationFormUniqueEmail,RegistrationFormSex,
|
||||
CNsummaryForm,UpdateWindForm,
|
||||
CNsummaryForm,UpdateWindForm,StandardsForm,
|
||||
UpdateStreamForm,WorkoutMultipleCompareForm,ChartParamChoiceForm,
|
||||
FusionMetricChoiceForm,BoxPlotChoiceForm,MultiFlexChoiceForm,
|
||||
TrendFlexModalForm,WorkoutSplitForm,WorkoutJoinParamForm,
|
||||
|
||||
Reference in New Issue
Block a user