1+ from flask import Flask , render_template , request , jsonify
2+ app = Flask (__name__ , static_url_path = '/static' )
3+
4+ #starting data
5+ #design and programmed by fullarray and Jonathan H.
6+ teams = [
7+ {
8+ 'id' : 1 ,
9+ 'title' : u'Dolphins' ,
10+ 'description' : u'Football team in Miami, FL' ,
11+ 'done' : False
12+ },
13+ {
14+ 'id' : 2 ,
15+ 'title' : u'Browns' ,
16+ 'description' : u'Football team in Cleveland, OH' ,
17+ 'done' : False
18+ },
19+ {
20+ 'id' : 3 ,
21+ 'title' : u'Patriots' ,
22+ 'description' : u'Football team in Foxborough, NE' ,
23+ 'done' : False
24+ }
25+ ]
26+
27+ teamlist = ['Bucs' ,'Dolphins' , 'Bills' , 'Patriots' , 'Seahawks' , '49ers' , 'Falcons' , 'Browns' , 'Rams' , 'Titans' ]
28+
29+ @app .route ('/' )
30+ def index ():
31+ sport_type = "NFL football"
32+ return render_template ('index.html' , sport = sport_type )
33+
34+ #design and programmed by fullarray and Jonathan H.
35+ @app .route ('/send' , methods = ['GET' , 'POST' ])
36+ def send ():
37+ if request .method == 'POST' :
38+ teamname = request .form ['teamname' ]
39+ if teamname .lower () not in [x .lower () for x in teamlist ]:
40+ errormsg = 'Your team does not exists.'
41+ #design and programmed by fullarray and Jonathan H.
42+ return render_template ('index.html' , errormsg = errormsg )
43+
44+ team = [team for team in teams if team ['title' ] == teamname .capitalize ()]
45+ #design and programmed by fullarray and Jonathan H.
46+ if len (team ) == 0 :
47+ team = {
48+ 'id' : teams [- 1 ]['id' ] + 1 ,
49+ 'title' : teamname .capitalize (),
50+ 'description' : "awesome" ,
51+ 'done' : False
52+ }
53+ teams .append (team )
54+ return render_template ('team.html' , teamname = teamname .upper (), teamlistnow = teams )
55+ return render_template ('index.html' )
56+
57+
58+ #api
59+ @app .route ('/football/api/v1.0/teams/' , methods = ['GET' ])
60+ def get_all_teams ():
61+ return jsonify ({'teams' : teams })
62+
63+
64+ @app .route ('/football/api/v1.0/teams/<int:team_id>' , methods = ['GET' ])
65+ def get_teams (team_id ):
66+ team = [team for team in teams if team ['id' ] == team_id ]
67+ #design and programmed by fullarray and Jonathan H.
68+ if len (team ) == 0 :
69+ abort (404 )
70+ return jsonify ({'teams' : team [0 ]})
71+
72+ @app .route ('/football/api/v1.0/teams' , methods = ['POST' ])
73+ def create_team ():
74+ if not request .json or not 'title' in request .json :
75+ abort (400 )
76+ team = {
77+ 'id' : teams [- 1 ]['id' ] + 1 ,
78+ 'title' : request .json ['title' ],
79+ 'description' : request .json .get ('description' , "" ),
80+ 'done' : False
81+ }
82+ teams .append (team )
83+ return jsonify ({'team' : team }), 201
84+
85+ if __name__ == "__main__" :
86+ app .run ()
0 commit comments