Esempio n. 1
0
def add_player(request,team_id):
    t = get_object_or_404(Team,pk=team_id)
    try:
        p = Player()
        p.first_name = request.POST['first_name']
        p.last_name = request.POST['last_name']
        p.number = request.POST['number']
        p.height = request.POST['height']
    except (KeyError):
        return render_to_response("roster/%d" % team_id, {
                                   'error_message' : "You forgot fields"})
    else:
        p.team = t
        p.save()
        return HttpResponseRedirect(reverse('roster',args=(team_id)))
Esempio n. 2
0
    def init_reader(self, first_time):
        """
        Loop through the spreadsheet and load the data
        """
        player_csv = self.get_google_csv(GOOGLE_KEY, GOOGLE_SHEET)
        already_exists = 0
        start_time = datetime.now()
 
        # Run through the spreadsheet, assigning values to certain fields
        for i, row in enumerate(player_csv):
            number = row['number']
            # Send some fields to functions that clean them
            lastname = row['lastname']
            firstname = row['firstname']
            hand = row['hand']
            position = row['position']
            height = row['height']
            weight = row['weight']
            year = row['year']
            hometown = row['hometown']
            highschool = row['highschool']
            story = row['story']
 
 
            # If the command doesn't use --first, run it this way.
            if first_time is not True:
                # Try and see if this player exists. If so, skip it.
                try:
                    player = Player.objects.get(
                        address=address,
                        name=name)
                    already_exists = already_exists + 1
                    
              #      logger.info('Already exists, skipping it.')
 
                # If the player doesn't exist, create it.
                except Player.DoesNotExist:
                    player = Player(
                        number=number,
                        lastname=lastname,
                        firstname=firstname,
                        hand=hand,
                        position=position,
                        height=height,
                        weight=weight,
                        year=year,
                        hometown=hometown,
                        highschool=highschool,
                        story=story)
                    player.save()
            # If you're running it with --first, save everything.
            else:
                player = Player(
                        number=number,
                        lastname=lastname,
                        firstname=firstname,
                        hand=hand,
                        position=position,
                        height=height,
                        weight=weight,
                        year=year,
                        hometown=hometown,
                        highschool=highschool,
                        story=story)
                player.save()
            #    logger.info("Saved player at %s" % address)
             #   logger.info("Skipped %s so far" % already_exists)
 
        finish_time = datetime.now()
        total_time = finish_time - start_time
Esempio n. 3
0
    def init_reader(self, first_time):
        """
        Loop through the spreadsheet and load the data
        """
        player_csv = self.get_google_csv(GOOGLE_KEY, GOOGLE_SHEET)
        already_exists = 0
        start_time = datetime.now()

        # Run through the spreadsheet, assigning values to certain fields
        for i, row in enumerate(player_csv):
            number = row['number']
            # Send some fields to functions that clean them
            lastname = row['lastname']
            firstname = row['firstname']
            hand = row['hand']
            position = row['position']
            height = row['height']
            weight = row['weight']
            year = row['year']
            hometown = row['hometown']
            highschool = row['highschool']
            story = row['story']

            # If the command doesn't use --first, run it this way.
            if first_time is not True:
                # Try and see if this player exists. If so, skip it.
                try:
                    player = Player.objects.get(address=address, name=name)
                    already_exists = already_exists + 1

            #      logger.info('Already exists, skipping it.')

            # If the player doesn't exist, create it.
                except Player.DoesNotExist:
                    player = Player(number=number,
                                    lastname=lastname,
                                    firstname=firstname,
                                    hand=hand,
                                    position=position,
                                    height=height,
                                    weight=weight,
                                    year=year,
                                    hometown=hometown,
                                    highschool=highschool,
                                    story=story)
                    player.save()
            # If you're running it with --first, save everything.
            else:
                player = Player(number=number,
                                lastname=lastname,
                                firstname=firstname,
                                hand=hand,
                                position=position,
                                height=height,
                                weight=weight,
                                year=year,
                                hometown=hometown,
                                highschool=highschool,
                                story=story)
                player.save()
            #    logger.info("Saved player at %s" % address)
            #   logger.info("Skipped %s so far" % already_exists)

        finish_time = datetime.now()
        total_time = finish_time - start_time