Ejemplo n.º 1
0
def show_status(data):
    prog = TeamModel(
        name='', time_stamp='', gate=1,
        inout='')  # data = {groupName:gpName, gate:'', inout:'in'};
    ret = prog.find_interval()
    if ret:
        emit('status', {'data': ret})
Ejemplo n.º 2
0
def show_records(data):
    prog = TeamModel(
        name=data['group'], time_stamp='', gate=data['gate'],
        inout='')  # data = {groupName:gpName, gate:'', inout:'in'};
    ret = prog.find_records(name=data['group'], gate=data['gate'])
    if ret:
        emit('allRecords', {'data': ret})
Ejemplo n.º 3
0
def delete_all_records():
    prog = TeamModel(
        name='', time_stamp='', gate=1,
        inout='')  # data = {groupName:gpName, gate:'', inout:'in'};
    ret = prog.delete_from_db()
    if ret:
        emit('deletedOK', {'data': 'records deleted'})
    else:
        emit('deletedOK', {'data': 'delete failed'})
Ejemplo n.º 4
0
 def get(self, business_name):
     team = TeamModel.find_by_business_name(business_name)
     if team:
         return team.json()
         # Serialize the data for the response
         # team_schema = TeamSchema(many=True)
         # return team_schema.dump(team).data
     return {'message': 'team not found'}, 404
Ejemplo n.º 5
0
def check_in(data):
    server_data = {
        'groupName': data['groupName'],
        'time_stamp': datetime.datetime.now(),
        'gate': data['gate'],
        'inout': data['inout']
    }
    prog = TeamModel(name=server_data['groupName'],
                     time_stamp=server_data['time_stamp'],
                     gate=server_data['gate'],
                     inout=server_data['inout']
                     )  # data = {groupName:gpName, gate:'', inout:'in'};
    prog.save_to_db()

    server_data['time_stamp'] = datetime.datetime.strftime(
        server_data['time_stamp'], '%c')
    socketio.emit('reply', server_data)
    ret = prog.find_interval()
    if ret:
        emit('status', {'data': ret}, broadcast=True)
Ejemplo n.º 6
0
    def delete(self, name):
        data = Player.parser.parse_args()
        team = TeamModel.find_by_name(data['team_name'])
        if team is None:
            return {"message": "Team does not exist"}

        player = PlayerModel.find_player_in_team(name, team.id,
                                                 data['back_number'])
        if player:
            player.delete_from_db()
        return {"message": "Player deleted"}
Ejemplo n.º 7
0
    def get(self, team_name=None, division=None):
        if team_name is None and division is None:
            players = PlayerModel.query.all()
        else:
            team = TeamModel.find_by_name(team_name)
            if team:
                players = PlayerModel.find_by_team_id(team.id)
            else:
                players = PlayerModel.find_by_division(division)

        return {"players": [player.json() for player in players]}
Ejemplo n.º 8
0
 def post(self, team_id):
     if TeamModel.find_by_id(team_id):
         return {"msg": "Team already exist"}, 400
     data = self.parser.parse_args()
     new_team = TeamModel(team_id, **data)
     new_team.save_to_db()
     return new_team.json(), 201
Ejemplo n.º 9
0
    def put(self, business_name):
        data = Team.parser.parse_args()

        team = TeamModel.find_by_business_name(business_name)

        if team is None:
            # team = TeamModel(name, data['price'], data['storebusiness_name'])
            team = TeamModel(**data)
        else:
            team.business_name = business_name
            team.location = data['location']

        team.save_to_db()
        return team.json()
Ejemplo n.º 10
0
    def post(self, name):
        data = Player.parser.parse_args()
        team = TeamModel.find_by_name(data['team_name'])
        if team is None:
            return {"message": "Team does not exist"}

        if PlayerModel.find_by_back_number_in_team(data['back_number'],
                                                   team.id):
            return {"message": "Back number is already taken."}

        player = PlayerModel(name, data['back_number'], team.id)
        player.save_to_db()
        return player.json()
Ejemplo n.º 11
0
 def delete(self, name):
     # data = Team.parser.parse_args()
     #
     # if data['division'] is None:
     #     return {"division": "This field can not be blank"}
     #
     # team = TeamModel.find_by_name_division(name,data['division'])
     # if team:
     #     team.delete_from_db()
     # return {"message": "Team deleted"}
     team = TeamModel.find_by_name(name)
     if team:
         team.delete_from_db()
     return {"message": "Team deleted"}
Ejemplo n.º 12
0
 def get(self, name, division=None, team_name=None):
     if team_name is None and division is None:
         players = PlayerModel.find_by_name(name)
         if players.count() > 0:
             return {"players": [player.json() for player in players]}
     elif team_name is None:
         print(division)
     else:
         team = TeamModel.find_by_name_division(team_name, division)
         if team:
             players = PlayerModel.find_by_team_id(team.id)
             if players.count() > 0:
                 return {"players": [player.json() for player in players]}
     return {"message": "Player does not exists"}
Ejemplo n.º 13
0
    def put(self, name):
        data = Team.parser.parse_args()

        team = TeamModel.find_by_name(name)

        if team is None:
            team = TeamModel(name, data['division'])
        else:
            team.division = data['division']

        team.save_to_db()

        return team.json()
Ejemplo n.º 14
0
    def put(self, team_id):
        data = self.parser.parse_args()

        team = TeamModel.find_by_id(team_id)

        if team is None:
            team = TeamModel(team_id, **data)

        else:
            team.team_name = data["team_name"]

        team.save_to_db()
        return team.json()
Ejemplo n.º 15
0
def sample_data(app, db):
    admin = UserModel(email='*****@*****.**', password='******')
    guest = UserModel(email='*****@*****.**', password='******')
    db.session.add(admin)
    db.session.add(guest)

    team1 = TeamModel(name='England')
    team2 = TeamModel(name='Australia')

    db.session.add(team1)
    db.session.add(team2)
    db.session.commit()

    player1a = PlayerModel(name='Jack', team_id=team1.id)
    player1b = PlayerModel(name='Jill', team_id=team1.id)
    db.session.add(player1a)
    db.session.add(player1b)

    player2a = PlayerModel(name='Jamie', team_id=team2.id)
    player2b = PlayerModel(name='James', team_id=team2.id)
    db.session.add(player2a)
    db.session.add(player2b)

    db.session.commit()
Ejemplo n.º 16
0
    def get(self, team_name):

        try:
            team_list = TeamModel.find_by_team(team_name)

            if team_list:
                return {'results': team_list}, 200

            else:
                return {
                    'message': '{} is not a valid team name'.format(team_name)
                }
        except:
            return {
                "message": "An error occurred retrieving the team list."
            }, 500  # internal server error
Ejemplo n.º 17
0
    def post(self, business_name):
        if TeamModel.find_by_business_name(business_name):
            return {'message': "That team already exists!"}

        data = Team.parser.parse_args()
        print(data['location'])
        new_team = TeamModel(business_name, data['location'])

        new_team.save_to_db()

        return new_team.json(), 201  # 201 status code means created
Ejemplo n.º 18
0
 def get(self, name):
     '''
     data = Team.parser.parse_args()
     if data['division']:
         team = TeamModel.find_by_name_division(name, data['division'])
         if team:
             return {"team": team.json()}
     else:
         teams = TeamModel.find_by_name(name)
         if teams.count() > 0:
             return {"teams": [team.json() for team in teams]}
     return {"message" : "Team not found"}, 404
     '''
     team = TeamModel.find_by_name(name)
     if team:
         return {"teams": team.json()}
     return {"message": "Team not found"}, 404
Ejemplo n.º 19
0
    def post(self, name):
        if TeamModel.lookup(name):
            return {
                'message': "A team with name '{}' already exists.".format(name)
            }, 400

        team = TeamModel(name)
        try:
            team.save()
        except:
            return {"message": "An error occurred creating the team."}, 500

        return team.json(), 201
Ejemplo n.º 20
0
    def post(self, name, division=None):
        data = Team.parser.parse_args()

        if TeamModel.find_by_name(name):
            return {"message": "{} already exists".format(name)}
        team = TeamModel(name, data['division'])
        try:
            team.save_to_db()
        except:
            return {
                "message": "An error occured while creating the team."
            }, 500

        return team.json()
Ejemplo n.º 21
0
    def put(self, name):
        data = Player.parser.parse_args()

        team = TeamModel.find_by_name(data['team_name'])
        if team is None:
            return {"message": "Team does not exist"}

        if PlayerModel.find_by_back_number_in_team(data['new_back_number'],
                                                   team.id):
            return {"message": "Back number is already taken."}

        player = PlayerModel.find_player_in_team(name, team.id,
                                                 data['back_number'])

        if player is None:
            return {"message": "Player doesn not exist"}
        else:
            if data['new_back_number'] is None:
                return {"message": "New Back Number is missing"}
            player.back_number = data['new_back_number']

        player.save_to_db()

        return player.json()
Ejemplo n.º 22
0
 def get(self, name):
     team = TeamModel.find_by_name(name)
     if team:
         return team.json()
     return {'message': 'Store not found'}, 404
Ejemplo n.º 23
0
 def get(self):
     return TeamModel.get_all_teams_list()
Ejemplo n.º 24
0
 def delete(self, team_id):
     team = TeamModel.find_by_id(team_id)
     if team:
         team.delete_from_db()
         return {"msg": "Team Deleted"}, 200
     return {"msg": "Team Not Found"}, 404
Ejemplo n.º 25
0
 def get(self, division=None):
     if division:
         teams = TeamModel.find_by_division(division)
     else:
         teams = TeamModel.query.all()
     return {"teams": [team.json() for team in teams]}
Ejemplo n.º 26
0
 def __init__(self, name, back_number, team_id):
     self.name = name
     self.back_number = back_number
     self.team_id = team_id
     self.division = TeamModel.find_by_id(team_id).division
Ejemplo n.º 27
0
    def delete(self, name):
        team = TeamModel.lookup(name)
        if team:
            team.delete()

        return {'message': 'Team deleted'}
Ejemplo n.º 28
0
 def get(self, name):
     team = TeamModel.lookup(name)
     if team:
         return team.json()
     return {'message': 'Team not found'}, 404
Ejemplo n.º 29
0
 def get(self, team_id):
     team = TeamModel.find_by_id(team_id)
     if team:
         return team.json(), 200
     return {"msg": "Team Not Found"}, 404
Ejemplo n.º 30
0
    def delete(self, business_name):
        team = TeamModel.find_by_business_name(business_name)
        if team:
            team.delete_from_db()

        return {'message': 'team deleted'}