diff --git a/rowers/models.py b/rowers/models.py index e37e35e9..7419ae54 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -479,10 +479,6 @@ class Rower(models.Model): runkeepertoken = models.CharField(default='',max_length=200, blank=True,null=True) -# runkeepertokenexpirydate = models.DateTimeField(blank=True,null=True) -# runkeeperrefreshtoken = models.CharField(default='',max_length=200, -# blank=True,null=True) - # Plan plans = ( ('basic','basic'), @@ -856,6 +852,7 @@ class GraphImage(models.Model): def __str__(self): return self.filename + # delete related file object when image is deleted @receiver(models.signals.post_delete,sender=GraphImage) def auto_delete_image_on_delete(sender,instance, **kwargs): diff --git a/rowers/uploads.py b/rowers/uploads.py index e263b7bf..02ac1837 100644 --- a/rowers/uploads.py +++ b/rowers/uploads.py @@ -280,11 +280,16 @@ def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0): width = 1200 height = 600 - i = GraphImage(workout=w, - creationdatetime=timezone.now(), - filename=fullpathimagename, - width=width,height=height) - i.save() + imgs = GraphImage.objects.filter(workout=w) + if len(imgs) < 7: + i = GraphImage(workout=w, + creationdatetime=timezone.now(), + filename=fullpathimagename, + width=width,height=height) + + i.save() + else: + return 0,'You have reached the maximum number of static images for this workout. Delete an image first' return i.id,job.id diff --git a/rowers/views.py b/rowers/views.py index ca4cc7db..a6d27deb 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -7112,13 +7112,17 @@ def instroke_chart(request,id=0,metric=''): width = 1200 height = 600 - i = GraphImage(workout=w, - creationdatetime=timezone.now(), - filename=fullpathimagename, - width=width,height=height) - - i.save() - print i.id,'aap' + imgs = GraphImage.objects.filter(workout=w) + if len(imgs) < 7: + i = GraphImage(workout=w, + creationdatetime=timezone.now(), + filename=fullpathimagename, + width=width,height=height) + + i.save() + else: + messages.error(request,'You have reached the maximum number of static images for this workout. Delete an image first') + r = getrower(request.user) url = reverse(r.defaultlandingpage, @@ -8855,10 +8859,13 @@ def workout_add_chart_view(request,id,plotnr=1): r,w,f1,w.csvfilename,'timeplot',title,plotnr=plotnr, imagename=imagename ) - try: - request.session['async_tasks'] += [(jobid,'make_plot')] - except KeyError: - request.session['async_tasks'] = [(jobid,'make_plot')] + if res == 0: + messages.error(request,jobid) + else: + try: + request.session['async_tasks'] += [(jobid,'make_plot')] + except KeyError: + request.session['async_tasks'] = [(jobid,'make_plot')] try: url = request.session['referer'] @@ -9739,10 +9746,13 @@ def workout_upload_view(request, r = getrower(request.user) if (make_plot): res,jobid = uploads.make_plot(r,w,f1,f2,plottype,t) - try: - request.session['async_tasks'] += [(jobid,'make_plot')] - except KeyError: - request.session['async_tasks'] = [(jobid,'make_plot')] + if res == 0: + messages.error(request,jobid) + else: + try: + request.session['async_tasks'] += [(jobid,'make_plot')] + except KeyError: + request.session['async_tasks'] = [(jobid,'make_plot')] # upload to C2 if (upload_to_c2): @@ -9988,7 +9998,8 @@ def team_workout_upload_view(request,message="", r = getrower(request.user) if (make_plot): - id = uploads.make_plot(r,w,f1,f2,plottype,t) + id,jobid = uploads.make_plot(r,w,f1,f2,plottype,t) +