Exemple #1
0
 def get_queryset(self):
     """Coaches can view all splits from sessions they create. Athletes
     can view all of their own splits. Anonymous users have read
     access to all splits belonging to public sessions.
     """
     user = self.request.user
     if is_athlete(user):
         return Split.objects.filter(athlete__user=user).distinct()
     elif is_coach(user):
         return Split.objects.filter(timingsession__coach=user.coach)
     else:
         return Split.objects.filter(timingsession__private=False)
Exemple #2
0
    def filter_registered_athletes(self, queryset):
        """Only show athletes belonging to the current coach."""
        if 'request' in self.context:
            user = self.context['request'].user

            if is_coach(user):
                queryset = queryset.filter(team__in=user.coach.team_set.all(),
                                           team__isnull=False)
            elif is_athlete(user):
                queryset = queryset.filter(user=user)
            else:
                queryset = queryset.none()

        return queryset
Exemple #3
0
    def filter_team(self, queryset):
        # Only allow teams owned by the current user. Note that this
        # is for validation only.
        if 'request' in self.context:
            user = self.context['request'].user

            if is_coach(user):
                queryset = queryset.filter(coach__user=user)
            elif is_athlete(user):
                queryset = queryset.filter(athlete__user=user)
            else:
                queryset = queryset.none()

        return queryset
Exemple #4
0
    def get_queryset(self):
        """Filter teams based on current user.

        A coach can see all of the teams he owns, an athlete can see
        all of the teams he belongs to, an anonymous user can see
        teams that are designated public and primary.
        """
        user = self.request.user

        if is_coach(user):
            return user.coach.team_set.all()
        elif is_athlete(user):
            return Team.objects.filter(athlete__in=[user.athlete.pk],
                                       primary_team=True)
        else:
            return Team.objects.filter(public_team=True, primary_team=True)
Exemple #5
0
    def filter_athlete(self, queryset):
        """Only show athletes belonging to the current coach."""
        if 'request' in self.context:
            user = self.context['request'].user

            if is_coach(user):
                athletes = Athlete.objects.filter(
                    team__in=user.coach.team_set.all())
                queryset = queryset.filter(
                    pk__in=[athlete.pk for athlete in athletes])
            elif is_athlete(user):
                queryset = queryset.filter(pk=user.athlete.id)
            else:
                queryset = queryset.none()

        return queryset
Exemple #6
0
    def get_queryset(self):
        """Filter sessions by user.

        If the user is an athlete, list the sessions he has
        completed. If the user is a coach, list the sessions he owns.
        Otherwise, list all public sessions.
        """
        user = self.request.user

        if is_athlete(user):
            return TimingSession.objects.filter(
                splits__athlete=user.athlete).distinct()
        elif is_coach(user):
            return TimingSession.objects.filter(coach=user.coach)
        else:
            return TimingSession.objects.filter(private=False)
Exemple #7
0
    def get_queryset(self):
        """
        Get athletes associated with a coach.
        """
        user = self.request.user

        if is_coach(user):
            coach = Coach.objects.get(user=user)
            return Athlete.objects.filter(team__in=coach.team_set.all())

        elif is_athlete(user):
            return Athlete.objects.filter(user=user)

        else:
            return Athlete.objects.filter(
                Q(split__timingsession__private=False)
                | Q(timingsession__private=False)).distinct()
Exemple #8
0
    def get_queryset(self):
        """Filter tags by requesting user.

        Athletes can see the tags assigned to them, coaches can see
        all tags owned by their athletes, anonymous users cannot
        see any tags.
        """
        user = self.request.user

        if is_athlete(user):
            tags = Tag.objects.filter(athlete_id=user.athlete.id)
        elif is_coach(user):
            tags = Tag.objects.filter(
                athlete__team__in=user.coach.team_set.all())
        else:
            tags = Tag.objects.none()

        return tags
Exemple #9
0
def VO2Max(request):
    """
    TODO: Fix
    """
    user = request.user
    if is_coach(user):
        result = []
        cp = Coach.objects.get(user=user)
        for athlete in cp.athletes.all():
            sum_VO2 = 0
            count = 0
            for entry in athlete.performancerecord_set.all():
                sum_VO2 += entry.VO2
                count += 1
            try:
                avg_VO2 = sum_VO2 / count
                if entry.interval == 'i':
                    avg_VO2 = avg_VO2 / .9
                else:
                    avg_VO2 = avg_VO2 / .8
                avg_VO2 = int(avg_VO2)
                vVO2 = 2.8859 + .0686 * (avg_VO2 - 29)
                vVO2 = vVO2 / .9
            except:
                avg_VO2 = 'None'
                vVO2 = 1
            #print athlete
            #print 'VO2: ' + str(avg_VO2)
            #print 'vVO2: ' + str(vVO2)
            #print '100m: ' + str(100/vVO2)
            #print '200m: ' + str(200/vVO2)
            #print '400m: ' + str(400/vVO2)
            #print '800m: ' + str(800/vVO2)
            #print '1000m: ' + str(1000/vVO2)
            #print '1500m: ' + str(1500/vVO2)
            #print '1600m: ' + str(1609/vVO2)
            #print '3000m: ' + str(3000/vVO2)
            #print '5000m: ' + str(5000/vVO2)
            #print '10000m: ' + str(10000/vVO2)
    elif is_athlete(user):
        ap = Athlete.objects.get(user=user)

    return HttpResponse(status.HTTP_200_OK)