diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 655e7f37..2da87b2d 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -247,19 +247,18 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type'): durations = [] for w in workouts: - if w.privacy == 'visible': - dd = w.date.strftime('%m/%d') - dd2 = w.date.strftime('%Y/%m/%d') - du = w.duration.hour*60+w.duration.minute - dates.append(dd) - dates_sorting.append(dd2) - durations.append(du) - - types.append(w.workouttype) - try: - rowers.append(w.user.user.first_name[0]+w.user.user.last_name[0]) - except IndexError: - rowers.append(str(w.user)) + dd = w.date.strftime('%m/%d') + dd2 = w.date.strftime('%Y/%m/%d') + du = w.duration.hour*60+w.duration.minute + dates.append(dd) + dates_sorting.append(dd2) + durations.append(du) + + types.append(w.workouttype) + try: + rowers.append(w.user.user.first_name[0]+w.user.user.last_name[0]) + except IndexError: + rowers.append(str(w.user)) try: d = utc.localize(startdate) diff --git a/rowers/models.py b/rowers/models.py index f45fea10..67cb73c1 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -837,7 +837,7 @@ def checkworkoutuser(user,workout): return True elif teams: for team in teams: - if user == team.manager: + if user == team.manager and workout.privacy == 'visible': return True else: return False diff --git a/rowers/views.py b/rowers/views.py index 6efd954c..3c59cf5f 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -6692,29 +6692,52 @@ def workouts_view(request,message='',successmessage='', raise Http404("Team doesn't exist") if theteam.viewing == 'allmembers' or theteam.manager == request.user: - workouts = Workout.objects.filter(team=theteam, - startdatetime__gte=startdate, - startdatetime__lte=enddate).order_by("-date","-starttime") - g_workouts = Workout.objects.filter(team=theteam, - startdatetime__gte=activity_startdate, - startdatetime__lte=activity_enddate).order_by("-date", "-starttime") + workouts = Workout.objects.filter( + team=theteam, + startdatetime__gte=startdate, + startdatetime__lte=enddate, + privacy='visible').order_by("-date","-starttime") + g_workouts = Workout.objects.filter( + team=theteam, + startdatetime__gte=activity_startdate, + startdatetime__lte=activity_enddate, + privacy='visible').order_by("-date", "-starttime") elif theteam.viewing == 'coachonly': - workouts = Workout.objects.filter(team=theteam,user=r, - startdatetime__gte=startdate, - startdatetime__lte=enddate).order_by("-startdatetime") - g_workouts = Workout.objects.filter(team=theteam,user=r, - startdatetime__gte=activity_startdate, - enddatetime__lte=activity_enddate).order_by("-startdatetime") + workouts = Workout.objects.filter( + team=theteam,user=r, + startdatetime__gte=startdate, + startdatetime__lte=enddate, + privacy='visible').order_by("-startdatetime") + g_workouts = Workout.objects.filter( + team=theteam,user=r, + startdatetime__gte=activity_startdate, + enddatetime__lte=activity_enddate, + privacy='visible').order_by("-startdatetime") - else: + elif request.user != r.user: + theteam = None - workouts = Workout.objects.filter(user=r, - startdatetime__gte=startdate, - startdatetime__lte=enddate).order_by("-date", "-starttime") - g_workouts = Workout.objects.filter(user=r, - startdatetime__gte=activity_startdate, - startdatetime__lte=activity_enddate).order_by("-startdatetime") + workouts = Workout.objects.filter( + user=r, + startdatetime__gte=startdate, + startdatetime__lte=enddate, + privacy='visible').order_by("-date", "-starttime") + g_workouts = Workout.objects.filter( + user=r, + startdatetime__gte=activity_startdate, + startdatetime__lte=activity_enddate, + privacy='visible').order_by("-startdatetime") + else: + theteam = None + workouts = Workout.objects.filter( + user=r, + startdatetime__gte=startdate, + startdatetime__lte=enddate).order_by("-date", "-starttime") + g_workouts = Workout.objects.filter( + user=r, + startdatetime__gte=activity_startdate, + startdatetime__lte=activity_enddate).order_by("-startdatetime") if rankingonly: workouts = [w for w in workouts if w.rankingpiece] @@ -7036,7 +7059,7 @@ def workout_view(request,id=0): }, { 'url':reverse(workout_view,kwargs={'id':id}), - 'name': id, + 'name': row.name, } ] @@ -14623,14 +14646,6 @@ def plannedsessions_view(request, r = getrequestrower(request,userid=userid) - when = request.GET.get('when') - if when: - timeperiod = when - else: - timeperiod = 'thisweek' - - startdate,enddate = get_dates_timeperiod(timeperiod) - if startdatestring: try: startdate = iso8601.parse_date(startdatestring) @@ -14643,6 +14658,21 @@ def plannedsessions_view(request, except ParseError: pass + + when = request.GET.get('when') + if when: + timeperiod = when + startdate,enddate = get_dates_timeperiod(timeperiod) + else: + timeperiod = 'thisweek' + startdate1,enddate1 = get_dates_timeperiod(timeperiod) + + if not startdatestring: + startdate = startdate1 + + if not enddatestring: + enddate = enddate1 + try: trainingplan = TrainingPlan.objects.filter( startdate__lte = startdate, @@ -16982,7 +17012,7 @@ class TrainingTargetUpdate(UpdateView): def allsundays(startdate,enddate): d = startdate d += timedelta(days = 6 - d.weekday()) # first Sunday - while d cycle.startdate: + for i in range(len(sundays)): + if i==0: monday = cycle.startdate - if nextsunday < cycle.enddate and i == len(sundays)-2: - nextsunday = cycle.enddate + else: + monday = sundays[i]-timedelta(days=6) + if monday < cycle.startdate: + monday = cycle.startdate + + nextsunday = sundays[i] micro = TrainingMicroCycle(startdate = monday, enddate = nextsunday, plan = cycle, - name = 'Week %s' % sundays[i+1].isocalendar()[1], + name = 'Week %s' % monday.isocalendar()[1], type = 'userdefined') micro.save()