added navionics (needs to be tested on production)
This commit is contained in:
169
rowers/views.py
169
rowers/views.py
@@ -6405,6 +6405,175 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# The basic edit page
|
||||
@login_required()
|
||||
def workout_edit_view_navionics(request,id=0,message="",successmessage=""):
|
||||
request.session[translation.LANGUAGE_SESSION_KEY] = USER_LANGUAGE
|
||||
request.session['referer'] = absolute(request)['PATH']
|
||||
|
||||
|
||||
try:
|
||||
# check if valid ID exists (workout exists)
|
||||
row = Workout.objects.get(id=id)
|
||||
form = WorkoutForm(instance=row)
|
||||
except Workout.DoesNotExist:
|
||||
raise Http404("Workout doesn't exist")
|
||||
|
||||
if request.method == 'POST':
|
||||
# Form was submitted
|
||||
form = WorkoutForm(request.POST)
|
||||
if form.is_valid():
|
||||
# Get values from form
|
||||
name = form.cleaned_data['name']
|
||||
date = form.cleaned_data['date']
|
||||
starttime = form.cleaned_data['starttime']
|
||||
workouttype = form.cleaned_data['workouttype']
|
||||
duration = form.cleaned_data['duration']
|
||||
distance = form.cleaned_data['distance']
|
||||
notes = form.cleaned_data['notes']
|
||||
thetimezone = form.cleaned_data['timezone']
|
||||
try:
|
||||
boattype = request.POST['boattype']
|
||||
except KeyError:
|
||||
boattype = Workout.objects.get(id=id).boattype
|
||||
try:
|
||||
privacy = request.POST['privacy']
|
||||
except KeyError:
|
||||
privacy = Workout.objects.get(id=id).privacy
|
||||
try:
|
||||
rankingpiece = form.cleaned_data['rankingpiece']
|
||||
except KeyError:
|
||||
rankingpiece =- Workout.objects.get(id=id).rankingpiece
|
||||
|
||||
startdatetime = (str(date) + ' ' + str(starttime))
|
||||
startdatetime = datetime.datetime.strptime(startdatetime,
|
||||
"%Y-%m-%d %H:%M:%S")
|
||||
startdatetime = timezone.make_aware(startdatetime)
|
||||
startdatetime = startdatetime.astimezone(pytz.timezone(thetimezone))
|
||||
|
||||
|
||||
# check if user is owner of this workout
|
||||
if checkworkoutuser(request.user,row):
|
||||
row.name = name
|
||||
row.date = date
|
||||
row.starttime = starttime
|
||||
row.startdatetime = startdatetime
|
||||
row.workouttype = workouttype
|
||||
row.notes = notes
|
||||
row.duration = duration
|
||||
row.distance = distance
|
||||
row.boattype = boattype
|
||||
row.privacy = privacy
|
||||
row.rankingpiece = rankingpiece
|
||||
row.timezone = thetimezone
|
||||
try:
|
||||
row.save()
|
||||
except IntegrityError:
|
||||
pass
|
||||
# change data in csv file
|
||||
|
||||
r = rdata(row.csvfilename)
|
||||
if r == 0:
|
||||
return HttpResponse("Error: CSV Data File Not Found")
|
||||
r.rowdatetime = startdatetime
|
||||
r.write_csv(row.csvfilename,gzip=True)
|
||||
dataprep.update_strokedata(id,r.df)
|
||||
successmessage = "Changes saved"
|
||||
messages.info(request,successmessage)
|
||||
url = reverse(workout_edit_view,
|
||||
kwargs = {
|
||||
'id':str(row.id),
|
||||
})
|
||||
response = HttpResponseRedirect(url)
|
||||
else:
|
||||
message = "You are not allowed to change this workout"
|
||||
messages.error(request,message)
|
||||
url = reverse(workouts_view)
|
||||
|
||||
response = HttpResponseRedirect(url)
|
||||
|
||||
#else: # form not POSTed
|
||||
form = WorkoutForm(instance=row)
|
||||
|
||||
|
||||
try:
|
||||
row = Workout.objects.get(id=id)
|
||||
except Workout.DoesNotExist:
|
||||
raise Http404("Workout doesn't exist")
|
||||
|
||||
g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime")
|
||||
# check if user is owner of this workout
|
||||
|
||||
comments = WorkoutComment.objects.filter(workout=row)
|
||||
|
||||
aantalcomments = len(comments)
|
||||
|
||||
if (checkworkoutuser(request.user,row)==False):
|
||||
raise Http404("You are not allowed to edit this workout")
|
||||
|
||||
# create interactive plot
|
||||
f1 = row.csvfilename
|
||||
u = row.user.user
|
||||
r = getrower(u)
|
||||
rowdata = rdata(f1)
|
||||
hascoordinates = 1
|
||||
if rowdata != 0:
|
||||
try:
|
||||
latitude = rowdata.df[' latitude']
|
||||
if not latitude.std():
|
||||
hascoordinates = 0
|
||||
except KeyError,AttributeError:
|
||||
hascoordinates = 0
|
||||
|
||||
else:
|
||||
hascoordinates = 0
|
||||
|
||||
|
||||
if hascoordinates:
|
||||
mapscript,mapdiv = leaflet_chart2(rowdata.df[' latitude'],
|
||||
rowdata.df[' longitude'],
|
||||
row.name)
|
||||
|
||||
#res = googlemap_chart(rowdata.df[' latitude'],
|
||||
# rowdata.df[' longitude'],
|
||||
# row.name)
|
||||
#gmscript = res[0]
|
||||
#gmdiv = res[1]
|
||||
|
||||
else:
|
||||
mapscript = ""
|
||||
mapdiv = ""
|
||||
|
||||
|
||||
# render page
|
||||
if (len(g)<=3):
|
||||
return render(request, 'workout_form.html',
|
||||
{'form':form,
|
||||
'workout':row,
|
||||
'teams':get_my_teams(request.user),
|
||||
'graphs1':g[0:3],
|
||||
'mapscript':mapscript,
|
||||
'aantalcomments':aantalcomments,
|
||||
'mapdiv':mapdiv,
|
||||
})
|
||||
|
||||
else:
|
||||
return render(request, 'workout_form.html',
|
||||
{'form':form,
|
||||
'teams':get_my_teams(request.user),
|
||||
'workout':row,
|
||||
'graphs1':g[0:3],
|
||||
'graphs2':g[3:6],
|
||||
'mapscript':mapscript,
|
||||
'aantalcomments':aantalcomments,
|
||||
'mapdiv':mapdiv,
|
||||
})
|
||||
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
|
||||
# Create the chart image with wind corrected pace (OTW)
|
||||
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
||||
def workout_add_otw_powerplot_view(request,id):
|
||||
|
||||
Reference in New Issue
Block a user