diff --git a/rowers/forms.py b/rowers/forms.py index 744c47a3..bad60f81 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -49,8 +49,9 @@ class StrokeDataForm(forms.Form): # The form used for uploading files class DocumentsForm(forms.Form): title = forms.CharField(required=False) - file = forms.FileField(required=True, + file = forms.FileField(required=False, validators=[validate_file_extension]) + workouttype = forms.ChoiceField(required=True, choices=Workout.workouttypes) # initial='rower') diff --git a/rowers/mailprocessing.py b/rowers/mailprocessing.py index bc478527..98180c61 100644 --- a/rowers/mailprocessing.py +++ b/rowers/mailprocessing.py @@ -3,7 +3,10 @@ import shutil import time from django.conf import settings -from rowers.tasks import handle_sendemail_unrecognized +from rowers.tasks import ( + handle_sendemail_unrecognized, + handle_sendemail_unrecognizedowner + ) from django_mailbox.models import Message, MessageAttachment from rowers.models import User, Rower, RowerForm diff --git a/rowers/templates/document_form.html b/rowers/templates/document_form.html index 3c02acee..c5b03d79 100644 --- a/rowers/templates/document_form.html +++ b/rowers/templates/document_form.html @@ -5,50 +5,52 @@ {% block title %}File loading{% endblock %} {% block meta %} - - - + + + {% endblock %} -{% block content %} + {% block content %} +

Upload Workout File

@@ -85,10 +87,148 @@ If you check "make private", this workout will not be visible to your followers and will not show up in your teams' workouts list. With the Landing Page option, you can select to which (workout related) page you will be taken after a successfull upload.

+

Select Files with the File button or drag them on the marked area

-
+ +
{% endblock %} + + {% block scripts %} + + + + {% endblock %} diff --git a/rowers/views.py b/rowers/views.py index 11cbea23..5f6c87a8 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -1671,6 +1671,7 @@ def workout_csvtoadmin_view(request,id=0): # Send workout to TP @login_required() def workout_tp_upload_view(request,id=0): + message = "" r = getrower(request.user) res = -1 @@ -8414,6 +8415,10 @@ def workout_upload_view(request, 'workouttype':'rower', }): + is_ajax = False + if request.is_ajax(): + is_ajax = True + r = getrower(request.user) if 'uploadoptions' in request.session: @@ -8489,8 +8494,10 @@ def workout_upload_view(request, if request.method == 'POST': form = DocumentsForm(request.POST,request.FILES) optionsform = UploadOptionsForm(request.POST) + if form.is_valid(): f = request.FILES['file'] + res = handle_uploaded_file(f) t = form.cleaned_data['title'] workouttype = form.cleaned_data['workouttype'] @@ -8552,20 +8559,29 @@ def workout_upload_view(request, 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 is_ajax: + return JSONResponse({'result':1,'url':url}) + else: + response = HttpResponseRedirect(url) + return response if not id: messages.error(request,message) url = reverse(workout_upload_view) - response = HttpResponseRedirect(url) - return response + if is_ajax: + return JSONResponse({'result':0,'url':url}) + else: + response = HttpResponseRedirect(url) + return response elif id == -1: message = 'The zip archive will be processed in the background. The files in the archive will only be uploaded without the extra actions. You will receive email when the workouts are ready.' messages.info(request,message) url = reverse(workout_upload_view) - response = HttpResponseRedirect(url) - return response + if is_ajax: + return JSONResponse({'result':1,'url':url}) + else: + response = HttpResponseRedirect(url) + return response else: if message: messages.error(request,message) @@ -8574,8 +8590,12 @@ def workout_upload_view(request, kwargs = { 'id':int(id), }) - - response = HttpResponseRedirect(url) + + if is_ajax: + response = {'result': 1,'url':url} + else: + response = HttpResponseRedirect(url) + w = Workout.objects.get(id=id) r = getrower(request.user) @@ -8671,26 +8691,38 @@ def workout_upload_view(request, }) else: url = reverse(landingpage) - - return HttpResponseRedirect(url) + + if is_ajax: + response = {'result':1,'url':url} + else: + response = HttpResponseRedirect(url) else: - response = render(request, - 'document_form.html', - {'form':form, - 'teams':get_my_teams(request.user), - 'optionsform': optionsform, - }) + if not is_ajax: + response = render(request, + 'document_form.html', + {'form':form, + 'teams':get_my_teams(request.user), + 'optionsform': optionsform, + }) - return response + + if is_ajax: + return JSONResponse(response) + else: + return response else: - form = DocumentsForm(initial=docformoptions) - optionsform = UploadOptionsForm(initial=uploadoptions) - return render(request, 'document_form.html', - {'form':form, - 'teams':get_my_teams(request.user), - 'optionsform': optionsform, - }) + if not is_ajax: + form = DocumentsForm(initial=docformoptions) + optionsform = UploadOptionsForm(initial=uploadoptions) + return render(request, 'document_form.html', + {'form':form, + 'teams':get_my_teams(request.user), + 'optionsform': optionsform, + }) + else: + return {'result':0} + # This is the main view for processing uploaded files @user_passes_test(iscoachmember,login_url="/",redirect_field_name=None) def team_workout_upload_view(request,message="", diff --git a/static/css/rowsandall.css b/static/css/rowsandall.css index 0188e56f..fe739c64 100644 --- a/static/css/rowsandall.css +++ b/static/css/rowsandall.css @@ -790,3 +790,9 @@ a.wh:hover { -webkit-margin-before: 0em; -webkit-margin-after: 0em; } + +.drop-files { + border: 1px solid #000; + color: #000; + +}