예제 #1
0
    def test_team_manager_roster_upload_error(self):
        """
        An error message is displayed if swimmers can't be uploaded, or files can't
        be found.
        """
        with open(
                '/Users/hgridley/Documents/Code/projects/CoachMate/teams/tests/test_files/NUSC-NE-Roster003_bad.zip'
        ) as f:
            tm = TeamManager(team=self.team, zip_file=f)
            msg = tm.load_roster()
            self.assertEqual(msg[0], ('error', 'Couldn\'t import swimmer(s)'))

        with open(
                '/Users/hgridley/Documents/Code/projects/CoachMate/teams/tests/test_files/fftlighttest-Roster.zip'
        ) as f:
            tm = TeamManager(team=self.team, zip_file=f)
            msg = tm.load_roster()
            self.assertEqual(
                msg[0],
                ('error', 'Couldn\'t find .CL2 or .HY3 file in zip file'))
예제 #2
0
    def test_team_manager_load_roster_hy3(self):
        """
        Loads a team roster from the .HY3 file in the zip file.
        """
        with open(
                '/Users/hgridley/Documents/Code/projects/CoachMate/teams/tests/test_files/NUSC-NE-Roster004.zip',
                'r') as f:
            tm = TeamManager(team=self.team, zip_file=f)
            msg = tm.load_roster()
            self.assertEqual(msg[0], ('success', 'Roster imported'))

        new_swimmers = []
        for swimmer in self.team.swimmer_set.all():
            new_swimmers.append('<Swimmer: ' + swimmer.l_name + '>')
        self.assertEqual(new_swimmers, self.swimmers)
예제 #3
0
    def test_team_manager_load_roster_and_results(self):
        """
        Loads a team roster from a zip file then loads meet results for that team
        from a different zip file.
        """
        with open(
                '/Users/hgridley/Documents/Code/projects/CoachMate/teams/tests/test_files/NUSC-NE-Roster003.zip',
                'r') as f:
            tm = TeamManager(team=self.team, zip_file=f)
            msg = tm.load_roster()
            self.assertEqual(msg[0], ('success', 'Roster imported'))

        with open(
                '/Users/hgridley/Documents/Code/projects/CoachMate/teams/tests/test_files/RED-NE-Results005.zip',
                'r') as f:
            tm = TeamManager(team=self.team, zip_file=f)
            msg = tm.load_results()
            self.assertEqual(msg[0], ('success', 'Results imported'))

        events = Event.objects.all()
        self.assertEqual(len(events), 113)
예제 #4
0
def swimmerList(request, abbr):
    team = get_object_or_404(Team, Q(user=request.user), abbr=abbr)
    if request.method == 'POST':
        if 'swimmer_create' in request.POST:
            swimmer_form = SwimmerForm(request.POST, team=team)
            if swimmer_form.is_valid():
                last_name = swimmer_form.cleaned_data['l_name']
                first_name = swimmer_form.cleaned_data['f_name']
                try:
                    # do nothing if swimmer already exists
                    swimmer = Swimmer.objects.filter(team=team).filter(
                        l_name=last_name).get(f_name=first_name)
                except:
                    # else create new swimmer
                    new_swimmer = swimmer_form.save()
                    return redirect('teams:swimmerList', abbr=team.abbr)
            else:
                team_form = TeamForm(instance=team)
                upload_form = UploadZipForm()

        elif 'team_edit' in request.POST:
            team_form = TeamForm(request.POST, instance=team, user=request.user)
            if team_form.is_valid():
                team_form.save()
                return redirect('teams:swimmerList', abbr=team.abbr)
            else:
                swimmer_form = SwimmerForm()
                upload_form = UploadZipForm()

        # upload team rosters and meet results
        elif 'upload' in request.POST:
            upload_form = UploadZipForm(request.POST, request.FILES)
            if upload_form.is_valid():
                zip_file = request.FILES['zip_file']
                tm = TeamManager(team=team, zip_file=zip_file) # team manager object
                # msgs contains error or success messages
                if 'Roster' in zip_file.name:
                    msgs = tm.load_roster()
                elif 'Results' in zip_file.name:
                    msgs = tm.load_results()
                else:
                    msgs = ('error', 'Invalid file')

                for message in msgs:
                    if message[0] == 'success':
                        messages.success(request, message[1])
                    else:
                        messages.error(request, message[1])
                return redirect('teams:swimmerList', abbr=team.abbr)
            else:
                team_form = TeamForm(instance=team)
                swimmer_form = SwimmerForm()
    else:
        swimmer_form = SwimmerForm()
        team_form = TeamForm(instance=team)
        upload_form = UploadZipForm()

    swimmer_list  = Swimmer.objects.filter(team=team)
    context = {
        'team': team,
        'team_form': team_form,
        'swimmer_list': swimmer_list,
        'swimmer_form': swimmer_form,
        'upload_form': upload_form,
    }

    if DEBUG == True:
        return render(request, 'teams/swimmer_list.html', context)
    else:
        return render(request, 'teams/swimmer_list.min.html', context)