image upload working
This commit is contained in:
@@ -27,7 +27,7 @@ from django.http import (
|
||||
)
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from rowers.forms import (
|
||||
LoginForm,DocumentsForm,UploadOptionsForm,
|
||||
LoginForm,DocumentsForm,UploadOptionsForm,ImageForm,
|
||||
TeamUploadOptionsForm,WorkFlowLeftPanelForm,WorkFlowMiddlePanelForm,
|
||||
WorkFlowLeftPanelElement,WorkFlowMiddlePanelElement,
|
||||
LandingPageForm,
|
||||
@@ -103,7 +103,7 @@ import requests
|
||||
import json
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
from rest_framework.parsers import JSONParser
|
||||
from rowers.rows import handle_uploaded_file
|
||||
from rowers.rows import handle_uploaded_file,handle_uploaded_image
|
||||
from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,handle_sendemailcsv
|
||||
from rowers.tasks import (
|
||||
handle_sendemail_unrecognized,handle_sendemailnewcomment,
|
||||
@@ -116,7 +116,7 @@ from rowers.tasks import (
|
||||
from scipy.signal import savgol_filter
|
||||
from django.shortcuts import render_to_response
|
||||
from Cookie import SimpleCookie
|
||||
from shutil import copyfile
|
||||
from shutil import copyfile,move
|
||||
import types
|
||||
from rowingdata import rower as rrower
|
||||
from rowingdata import main as rmain
|
||||
@@ -8836,6 +8836,92 @@ def workout_edit_view_navionics(request,id=0,message="",successmessage=""):
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# Image upload
|
||||
@login_required()
|
||||
def workout_uploadimage_view(request,id):
|
||||
is_ajax = False
|
||||
if request.is_ajax():
|
||||
is_ajax = True
|
||||
|
||||
r = getrower(request.user)
|
||||
|
||||
try:
|
||||
w = Workout.objects.get(id=id)
|
||||
except Workout.DoesNotExist:
|
||||
raise Http404("Workout doesn't exist")
|
||||
|
||||
if not checkworkoutuser(request.user,w):
|
||||
raise PermissionDenied("You are not allowed to edit this workout")
|
||||
|
||||
images = GraphImage.objects.filter(workout=w)
|
||||
|
||||
|
||||
if len(images) >= 6:
|
||||
message = "You have reached the maximum number of static images for this workout"
|
||||
messages.error(request,message)
|
||||
url = reverse(r.defaultlandingpage,
|
||||
kwargs = {
|
||||
'id':int(id),
|
||||
})
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
if request.method == 'POST':
|
||||
form = ImageForm(request.POST,request.FILES)
|
||||
|
||||
if form.is_valid():
|
||||
f = form.cleaned_data['file']
|
||||
|
||||
if f is not None:
|
||||
filename,path_and_filename = handle_uploaded_image(f)
|
||||
print path_and_filename,'aap'
|
||||
try:
|
||||
width,height = Image.open(path_and_filename).size
|
||||
except:
|
||||
message = "Not a valid image"
|
||||
messages.error(request,message)
|
||||
os.remove(path_and_filename)
|
||||
url = reverse(workout_uploadimage_view,
|
||||
kwargs = {'id':id})
|
||||
|
||||
if is_ajax:
|
||||
return JSONResponse({'result':0,'url':0})
|
||||
else:
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
i = GraphImage(workout=w,
|
||||
creationdatetime=timezone.now(),
|
||||
filename = path_and_filename,
|
||||
width=width,height=height)
|
||||
i.save()
|
||||
url = reverse(r.defaultlandingpage,
|
||||
kwargs = {'id':id})
|
||||
return HttpResponseRedirect(url)
|
||||
else:
|
||||
messages.error(request,'Something went wrong - no file attached')
|
||||
url = reverse(workout_uploadimage_view,
|
||||
kwargs = {'id':id})
|
||||
|
||||
if is_ajax:
|
||||
return JSONResponse({'result':0,'url':0})
|
||||
else:
|
||||
return HttpResponseRedirect(url)
|
||||
else:
|
||||
return HttpResponse("Form is not valid")
|
||||
|
||||
else:
|
||||
if not is_ajax:
|
||||
form = ImageForm()
|
||||
return render(request,'image_form.html',
|
||||
{'form':form,
|
||||
'teams':get_my_teams(request.user),
|
||||
'workout': w,
|
||||
})
|
||||
else:
|
||||
return {'result':0}
|
||||
|
||||
|
||||
|
||||
# Generic chart creation
|
||||
@login_required()
|
||||
def workout_add_chart_view(request,id,plotnr=1):
|
||||
@@ -9508,8 +9594,7 @@ def workout_toggle_ranking(request,id=0):
|
||||
raise Http404("Workout doesn't exist")
|
||||
|
||||
if not checkworkoutuser(request.user,row):
|
||||
message = "You are not allowed to change this workout"
|
||||
messages.error(request,message)
|
||||
raise PermissionDenied("You are not allowed to change this workout")
|
||||
|
||||
# we are still here - we own the workout
|
||||
row.rankingpiece = not row.rankingpiece
|
||||
|
||||
Reference in New Issue
Block a user