Skip to content

Pine: Karina & Roslyn#10

Open
roslynm wants to merge 23 commits intoAda-C16:mainfrom
roslynm:main
Open

Pine: Karina & Roslyn#10
roslynm wants to merge 23 commits intoAda-C16:mainfrom
roslynm:main

Conversation

@roslynm
Copy link
Copy Markdown

@roslynm roslynm commented Oct 18, 2021

We had some extra time so we added an html template to render the planet images.

Copy link
Copy Markdown

@jbieniosek jbieniosek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this project, fantastic extensions! This project is green.

Comment thread app/routes.py Outdated
Comment on lines +51 to +69
@planets_bp.route("/picture/<planet_id>", methods=["GET"])
def handle_planet_picture(planet_id):
for planet in planets:
if planet.id == int(planet_id):
return render_template('planet_picture.html', url=planet.picture)

@planets_bp.route("/picturesummary/<planet_id>", methods=["GET"])
def handle_planet_summary(planet_id):
for planet in planets:
if planet.id == int(planet_id):
if planet.moon == True:
moon = "Yes"
else:
moon = "No"
return render_template('planet_summary.html',
url=planet.picture,
title=planet.title,
diameter=planet.description,
moon=moon)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic!

Comment on lines +1 to +15
<html>
<head>
</head>

<body>
<h1>{{title}}</h1>
<br>
<i>{{diameter}}</i>
<br>
<i>Moon: {{moon}}</i>
<br>
<img src="{{ url }}">
</body>

</html> No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Comment thread app/routes.py Outdated
Comment on lines +43 to +49
return {
"id": planet.id,
"title": planet.title,
"description": planet.description,
"moon":planet.moon,
"picture": planet.picture
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend adding ‘jsonify’ to the return even in the case where the Flask default behavior is doing the same thing. Using ‘jsonify’ adds a layer of error protection and also makes it clear that json is the intended behavior.

Suggested change
return {
"id": planet.id,
"title": planet.title,
"description": planet.description,
"moon":planet.moon,
"picture": planet.picture
}
return jsonify({
"id": planet.id,
"title": planet.title,
"description": planet.description,
"moon":planet.moon,
"picture": planet.picture
})

Copy link
Copy Markdown

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done Karina & Roslyn, you hit the learning goals here. Well done.

Comment thread app/__init__.py
Comment on lines +14 to +22
if not test_config:
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get(
"SQLALCHEMY_DATABASE_URI")
else:
app.config["TESTING"] = True
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get(
"SQLALCHEMY_TEST_DATABASE_URI")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of env variables!

Comment thread app/models/planet.py
moons = db.Column(db.Boolean)
picture = db.Column(db.String)

def to_dict(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good helper method!

Comment thread app/routes.py
Comment on lines +9 to +10
@planets_bp.route("", methods = ["GET"])
def handle_planets():
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Like the Query params

Comment thread app/routes.py
@planets_bp.route("/<planet_id>", methods=["GET", "PATCH", "PUT", "DELETE"])
def handle_planet(planet_id):
if not planet_id.isnumeric():
return { "Error": f"{planet_id} must be numeric."}, 404
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An argument can be made for this to be a 400 error as opposed to 404.

Comment thread app/routes.py
for name, val_type in data_types.items():
try:
assert val_type==type(input_data[name])
print(name,type(input_data[name]))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print isn't needed

Suggested change
print(name,type(input_data[name]))

Comment thread app/routes.py
Comment on lines +120 to +124
return render_template('planet_summary.html',
url=planet.picture,
title=planet.name,
diameter=planet.diameter,
moon=moon)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh well!

Comment thread app/routes.py
Comment on lines +97 to +98
@planets_bp.route("/picturesummary", methods=["GET"])
def handle_planet_summary_params():
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice custom route and use of render_template

Comment thread tests/test_routes.py
assert saturn in response_body
assert jupiter in response_body

def test_post_one_planet(client):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Another good set of tests for failure cases as well would be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants