processes files > 1 MB offline
This commit is contained in:
@@ -53,7 +53,7 @@ import sys
|
||||
|
||||
import utils
|
||||
import datautils
|
||||
from utils import lbstoN
|
||||
from utils import lbstoN,myqueue
|
||||
|
||||
from timezonefinder import TimezoneFinder
|
||||
|
||||
@@ -975,17 +975,12 @@ def new_workout_from_file(r, f2,
|
||||
if len(fileformat) == 3 and fileformat[0] == 'zip':
|
||||
f_to_be_deleted = f2
|
||||
title = os.path.basename(f2)
|
||||
if settings.DEBUG:
|
||||
res = handle_zip_file.delay(
|
||||
r.user.email, title, f2
|
||||
)
|
||||
|
||||
else:
|
||||
res = queuelow.enqueue(
|
||||
handle_zip_file,
|
||||
r.user.email,
|
||||
title,
|
||||
f2
|
||||
res = myqueue(
|
||||
queuelow,
|
||||
handle_zip_file,
|
||||
r.user.email,
|
||||
title,
|
||||
f2
|
||||
)
|
||||
|
||||
return -1, message, f2
|
||||
|
||||
@@ -57,8 +57,15 @@ class DocumentsForm(forms.Form):
|
||||
notes = forms.CharField(required=False,
|
||||
widget=forms.Textarea)
|
||||
|
||||
offline = forms.BooleanField(initial=False,required=False,
|
||||
label='Process in Background')
|
||||
class Meta:
|
||||
fields = ['title','file','workouttype','fileformat']
|
||||
fields = ['title','file','workouttype','fileformat','offline']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
from django.forms.widgets import HiddenInput
|
||||
super(DocumentsForm, self).__init__(*args, **kwargs)
|
||||
self.fields['offline'].widget = HiddenInput()
|
||||
|
||||
from utils import (
|
||||
workflowleftpanel,workflowmiddlepanel,
|
||||
|
||||
@@ -4,8 +4,35 @@
|
||||
|
||||
{% 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='http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js'>
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#id_file').on('change', function(evt) {
|
||||
var f = this.files[0];
|
||||
console.log(f);
|
||||
if (f.size > 4194304) {
|
||||
alert("File Size must be smaller than 4 MB");
|
||||
this.value = null;
|
||||
}
|
||||
if (f.size > 1048576) {
|
||||
$('#id_offline').val('True');
|
||||
console.log("Set offline to True");
|
||||
$('#extra_message').text('Because of the large size, the file will be processed offline. You will receive email when it is done. The extra actions will not be performed.');
|
||||
$('#extra_message').addClass('message');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
|
||||
<form id="file_form" enctype="multipart/form-data" action="{{ formloc }}" method="post">
|
||||
<div id="left" class="grid_6 alpha">
|
||||
<h1>Upload Workout File</h1>
|
||||
{% if user.is_authenticated and user|is_manager %}
|
||||
|
||||
@@ -3,6 +3,33 @@
|
||||
|
||||
{% 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='http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js'>
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#id_file').on('change', function(evt) {
|
||||
var f = this.files[0];
|
||||
console.log(f);
|
||||
if (f.size > 4194304) {
|
||||
alert("File Size must be smaller than 4 MB");
|
||||
this.value = null;
|
||||
}
|
||||
if (f.size > 1048576) {
|
||||
$('#id_offline').val('True');
|
||||
console.log("Set offline to True");
|
||||
$('#extra_message').text('Because of the large size, the file will be processed offline. You will receive email when it is done. The extra actions will not be performed.');
|
||||
$('#extra_message').addClass('message');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
|
||||
<div id="left" class="grid_6 alpha">
|
||||
|
||||
@@ -101,7 +101,8 @@ from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,
|
||||
from rowers.tasks import (
|
||||
handle_sendemail_unrecognized,handle_sendemailnewcomment,
|
||||
handle_sendemailnewresponse, handle_updatedps,
|
||||
handle_updatecp,long_test_task,long_test_task2
|
||||
handle_updatecp,long_test_task,long_test_task2,
|
||||
handle_zip_file
|
||||
)
|
||||
|
||||
from scipy.signal import savgol_filter
|
||||
@@ -8244,6 +8245,7 @@ def workout_upload_view(request,
|
||||
}
|
||||
|
||||
notes = form.cleaned_data['notes']
|
||||
offline = form.cleaned_data['offline']
|
||||
|
||||
if optionsform.is_valid():
|
||||
make_plot = optionsform.cleaned_data['make_plot']
|
||||
@@ -8276,12 +8278,29 @@ def workout_upload_view(request,
|
||||
f1 = res[0] # file name
|
||||
f2 = res[1] # file name incl media directory
|
||||
|
||||
if not offline:
|
||||
id,message,f2 = dataprep.new_workout_from_file(
|
||||
r,f2,
|
||||
workouttype=workouttype,
|
||||
makeprivate=makeprivate,
|
||||
title = t,
|
||||
notes=''
|
||||
)
|
||||
else:
|
||||
job = myqueue(
|
||||
queuehigh,
|
||||
handle_zip_file,
|
||||
r.user.email,
|
||||
t,
|
||||
f2)
|
||||
|
||||
messages.info(
|
||||
request,
|
||||
"The file was too large to process in real time. It will be processed in a background process. You will receive an email when it is ready")
|
||||
url = reverse(workout_upload_view)
|
||||
response = HttpResponseRedirect(url)
|
||||
return response
|
||||
|
||||
id,message,f2 = dataprep.new_workout_from_file(r,f2,
|
||||
workouttype=workouttype,
|
||||
makeprivate=makeprivate,
|
||||
title = t,
|
||||
notes='')
|
||||
if not id:
|
||||
messages.error(request,message)
|
||||
url = reverse(workout_upload_view)
|
||||
@@ -8450,6 +8469,7 @@ def team_workout_upload_view(request,message="",
|
||||
f = request.FILES['file']
|
||||
res = handle_uploaded_file(f)
|
||||
t = form.cleaned_data['title']
|
||||
offline = form.cleaned_data['offline']
|
||||
if rowerform.is_valid():
|
||||
u = rowerform.cleaned_data['user']
|
||||
if u:
|
||||
@@ -8490,11 +8510,33 @@ def team_workout_upload_view(request,message="",
|
||||
f2 = res[1] # file name incl media directory
|
||||
|
||||
|
||||
id,message,f2 = dataprep.new_workout_from_file(r,f2,
|
||||
workouttype=workouttype,
|
||||
makeprivate=False,
|
||||
title = t,
|
||||
notes='')
|
||||
if not offline:
|
||||
id,message,f2 = dataprep.new_workout_from_file(
|
||||
r,f2,
|
||||
workouttype=workouttype,
|
||||
makeprivate=False,
|
||||
title = t,
|
||||
notes=''
|
||||
)
|
||||
else:
|
||||
job = myqueue(
|
||||
queuehigh,
|
||||
handle_zip_file,
|
||||
r.user.email,
|
||||
t,
|
||||
f2)
|
||||
|
||||
messages.info(
|
||||
request,
|
||||
"The file was too large to process in real time. It will be processed in a background process. The user will receive an email when it is ready"
|
||||
)
|
||||
|
||||
|
||||
url = reverse(team_workout_upload_view)
|
||||
response = HttpResponseRedirect(url)
|
||||
return response
|
||||
|
||||
|
||||
if not id:
|
||||
messages.error(request,message)
|
||||
url = reverse(team_workout_upload_view)
|
||||
|
||||
@@ -226,7 +226,7 @@ var current = null;
|
||||
|
||||
|
||||
<div class="clear"></div>
|
||||
<div class="grid_12">
|
||||
<div id="messaging" class="grid_12">
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
{% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %}
|
||||
@@ -241,14 +241,16 @@ var current = null;
|
||||
{% block message %}
|
||||
{% if message %}
|
||||
<p class="message">
|
||||
{{ message }}
|
||||
<span>{{ message }}</span>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if successmessage %}
|
||||
<p class="successmessage">
|
||||
{{ successmessage }}
|
||||
<span>{{ successmessage }}</span>
|
||||
</p>
|
||||
{% endif %}
|
||||
<div id="extra_message">
|
||||
</div>
|
||||
{% endblock %}
|
||||
</div>
|
||||
<div class="grid_12">
|
||||
|
||||
Reference in New Issue
Block a user