Private
Public Access
1
0

processes files > 1 MB offline

This commit is contained in:
Sander Roosendaal
2017-11-02 15:53:54 +01:00
parent c871d69097
commit c974927192
6 changed files with 129 additions and 29 deletions

View File

@@ -53,7 +53,7 @@ import sys
import utils import utils
import datautils import datautils
from utils import lbstoN from utils import lbstoN,myqueue
from timezonefinder import TimezoneFinder from timezonefinder import TimezoneFinder
@@ -975,17 +975,12 @@ def new_workout_from_file(r, f2,
if len(fileformat) == 3 and fileformat[0] == 'zip': if len(fileformat) == 3 and fileformat[0] == 'zip':
f_to_be_deleted = f2 f_to_be_deleted = f2
title = os.path.basename(f2) title = os.path.basename(f2)
if settings.DEBUG: res = myqueue(
res = handle_zip_file.delay( queuelow,
r.user.email, title, f2 handle_zip_file,
) r.user.email,
title,
else: f2
res = queuelow.enqueue(
handle_zip_file,
r.user.email,
title,
f2
) )
return -1, message, f2 return -1, message, f2

View File

@@ -57,8 +57,15 @@ class DocumentsForm(forms.Form):
notes = forms.CharField(required=False, notes = forms.CharField(required=False,
widget=forms.Textarea) widget=forms.Textarea)
offline = forms.BooleanField(initial=False,required=False,
label='Process in Background')
class Meta: 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 ( from utils import (
workflowleftpanel,workflowmiddlepanel, workflowleftpanel,workflowmiddlepanel,

View File

@@ -4,8 +4,35 @@
{% block title %}File loading{% endblock %} {% 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 %} {% 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"> <div id="left" class="grid_6 alpha">
<h1>Upload Workout File</h1> <h1>Upload Workout File</h1>
{% if user.is_authenticated and user|is_manager %} {% if user.is_authenticated and user|is_manager %}

View File

@@ -3,6 +3,33 @@
{% block title %}File loading{% endblock %} {% 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 %} {% block content %}
<form enctype="multipart/form-data" action="{{ formloc }}" method="post"> <form enctype="multipart/form-data" action="{{ formloc }}" method="post">
<div id="left" class="grid_6 alpha"> <div id="left" class="grid_6 alpha">

View File

@@ -101,7 +101,8 @@ 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_sendemailnewresponse, handle_updatedps, 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 from scipy.signal import savgol_filter
@@ -8244,6 +8245,7 @@ def workout_upload_view(request,
} }
notes = form.cleaned_data['notes'] notes = form.cleaned_data['notes']
offline = form.cleaned_data['offline']
if optionsform.is_valid(): if optionsform.is_valid():
make_plot = optionsform.cleaned_data['make_plot'] make_plot = optionsform.cleaned_data['make_plot']
@@ -8276,12 +8278,29 @@ def workout_upload_view(request,
f1 = res[0] # file name f1 = res[0] # file name
f2 = res[1] # file name incl media directory f2 = res[1] # file name incl media directory
if not offline:
id,message,f2 = dataprep.new_workout_from_file(r,f2, id,message,f2 = dataprep.new_workout_from_file(
workouttype=workouttype, r,f2,
makeprivate=makeprivate, workouttype=workouttype,
title = t, makeprivate=makeprivate,
notes='') 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
if not id: if not id:
messages.error(request,message) messages.error(request,message)
url = reverse(workout_upload_view) url = reverse(workout_upload_view)
@@ -8450,6 +8469,7 @@ def team_workout_upload_view(request,message="",
f = request.FILES['file'] f = request.FILES['file']
res = handle_uploaded_file(f) res = handle_uploaded_file(f)
t = form.cleaned_data['title'] t = form.cleaned_data['title']
offline = form.cleaned_data['offline']
if rowerform.is_valid(): if rowerform.is_valid():
u = rowerform.cleaned_data['user'] u = rowerform.cleaned_data['user']
if u: if u:
@@ -8490,11 +8510,33 @@ def team_workout_upload_view(request,message="",
f2 = res[1] # file name incl media directory f2 = res[1] # file name incl media directory
id,message,f2 = dataprep.new_workout_from_file(r,f2, if not offline:
workouttype=workouttype, id,message,f2 = dataprep.new_workout_from_file(
makeprivate=False, r,f2,
title = t, workouttype=workouttype,
notes='') 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: if not id:
messages.error(request,message) messages.error(request,message)
url = reverse(team_workout_upload_view) url = reverse(team_workout_upload_view)

View File

@@ -226,7 +226,7 @@ var current = null;
<div class="clear"></div> <div class="clear"></div>
<div class="grid_12"> <div id="messaging" class="grid_12">
{% if messages %} {% if messages %}
{% for message in messages %} {% for message in messages %}
{% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %} {% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %}
@@ -241,14 +241,16 @@ var current = null;
{% block message %} {% block message %}
{% if message %} {% if message %}
<p class="message"> <p class="message">
{{ message }} <span>{{ message }}</span>
</p> </p>
{% endif %} {% endif %}
{% if successmessage %} {% if successmessage %}
<p class="successmessage"> <p class="successmessage">
{{ successmessage }} <span>{{ successmessage }}</span>
</p> </p>
{% endif %} {% endif %}
<div id="extra_message">
</div>
{% endblock %} {% endblock %}
</div> </div>
<div class="grid_12"> <div class="grid_12">