Skip to content

Commit fd12509

Browse files
authored
Merge branch 'master' into fixing-learnpack-and-readme
2 parents b2dc9a5 + 5a445c0 commit fd12509

File tree

13 files changed

+101
-180
lines changed

13 files changed

+101
-180
lines changed

.devcontainer/devcontainer.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/python
3+
{
4+
"name": "Python 3",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"image": "mcr.microsoft.com/devcontainers/python:0-3.10",
7+
"features": {
8+
"ghcr.io/devcontainers/features/node:1": {
9+
"nodeGypDependencies": true,
10+
"version": "16"
11+
}
12+
},
13+
"customizations": {
14+
"vscode": {
15+
"settings": {
16+
"editor.defaultFormatter": "esbenp.prettier-vscode",
17+
"workbench.editorAssociations": {
18+
"*.md": "vscode.markdown.preview.editor"
19+
}
20+
},
21+
"extensions": ["learn-pack.learnpack-vscode"]
22+
}
23+
},
24+
"onCreateCommand": "pip3 install pytest==4.4.2 mock pytest-testdox toml && npm i @learnpack/[email protected] -g && learnpack plugins:install @learnpack/[email protected]"
25+
26+
// Features to add to the dev container. More info: https://containers.dev/features.
27+
// "features": {},
28+
29+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
30+
// "forwardPorts": [],
31+
32+
// Use 'postCreateCommand' to run commands after the container is created.
33+
// "postCreateCommand": "pip3 install --user -r requirements.txt",
34+
35+
// Configure tool-specific properties.
36+
// "customizations": {},
37+
38+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
39+
// "remoteUser": "root"
40+
}

.learn/exercises/02-pipenv-installation/README.es.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Cada proyecto de python debe estar envuelto en un "ambiente virtual" para asegur
1111
1. Ejecuta el siguiente comando para crear un nuevo entorno virtual con Python 3:
1212

1313
```bash
14-
$ pipenv --three
14+
$ pipenv install --python 3
1515
```
1616

1717
Deberías ver un **PipFile** en la raíz de tu proyecto y dentro debería tener **[requires]** en la versión de Python 3+ similar a este (pero quizás con una diferente versión de Python 3).

.learn/exercises/02-pipenv-installation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Every python project should be wrapped in a "virtual environment" to ensure that
1111
1. Run the following command to create a new virtual environment with python 3 on it:
1212

1313
```bash
14-
$ pipenv --three
14+
$ pipenv install --python 3
1515
```
1616

1717
You should see a **PipFile** on the root of your project and it should have a **[requires]** inside of it for python version 3+: similar to this one (but maybe with a different python 3 version).

.learn/exercises/02-pipenv-installation/test.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

.learn/exercises/02.1-flask-installation/test.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
def test_pipfile_exists():
55
assert os.path.isfile("Pipfile")
66

7-
@pytest.mark.it("Python version on Pipfile must be 3+")
8-
def test_pipfile_contains_python_version():
9-
with open("Pipfile", "r") as f:
10-
toml_content = f.read()
11-
parsed_toml = toml.loads(toml_content)
12-
assert parsed_toml["requires"]["python_version"][0:2] == "3."
13-
147
@pytest.mark.it("Flask must exist on the pipfile dependency [packages]")
158
def test_pipfile_contains_flask():
169
with open("Pipfile", "r") as f:

.learn/exercises/03.3-your-first-route/README.es.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def hello_world():
1414

1515
+ La primera línea también especifica el método que se usará con esa URL, en este caso es el método `GET` (para obtener info).
1616

17-
+ La segunda línea define una función que será llamada por Flask cuando ese endpoint sea llamado por el usuario (cuando el usuario use `/hello`).
17+
+ La segunda línea define una función que será llamada por Flask cuando ese endpoint sea llamado por el usuario (cuando el usuario use `/blabla`).
1818

1919
+ La tercera línea retorna el texto: `Hello World` al cliente o navegador que lo solicite.
2020

.learn/exercises/03.3-your-first-route/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def hello_world():
1414

1515
+ The first line also specifies the methods that will be used with that URL. In this case, the `GET` method (for reading data).
1616

17-
+ The second line defines a function that will be called by Flask when that endpoint is called by the user (when the user requests `/hello`).
17+
+ The second line defines a function that will be called by Flask when that endpoint is called by the user (when the user requests `/blabla`).
1818

1919
+ The third line defines our function execution and in this case, returns the text "Hello World" to the requesting client or browser.
2020

.learn/exercises/05-returning-json/README.es.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ Las REST APIs tienen que retornar datos en formato JSON, no en formato HTML.
55
Puedes usar la función [flask jsonify](https://flask.palletsprojects.com/en/1.1.x/api/#flask.json.jsonify) para convertir con facilidad cualquier tipo de datos básico a JSON de esta forma:
66

77
```python
8-
def hello_world():
9-
# supongamos que tienes some_data (cierta información) en una variable json
8+
# añade el método jsonify a tu importación de Flask
9+
from flask import Flask, jsonify
10+
11+
# supongamos que tienes tus datos en la variable some_data
1012
some_data = { "name": "Bobby", "lastname": "Rixer" }
1113

12-
# puedes convertir esa variable en un string json así
14+
@app.route('/blahblah', methods=['GET'])
15+
def hello_world():
16+
# puedes convertir esa variable en una cadena json de la siguiente manera
1317
json_text = jsonify(some_data)
1418

15-
# y luego puedes retornarla (return) en el response body así:
19+
# y luego puedes devolverlo al front-end en el cuerpo de la respuesta de la siguiente manera
1620
return json_text
1721
```
1822

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
# `07.2` Finish the POST /todos
22

3-
Ahora, si queremos terminar el `post` tenemos que hacer dos acciones específicas:
3+
Ahora... si queremos terminar el post, tenemos que realizar estas acciones específicas:
44

5-
+ Decodificar el request.data para convertirlo a un diccionario de python.
5+
+ Primero asegúrate de convertir el cuerpo de la solicitud en una estructura de datos real de Python, como un diccionario. Ya usamos `request.json` para eso, ya que sabemos que la solicitud estará en formato application/json. Si eso no se conoce, es posible que desee usar `request.get_json(force=True)` para ignorar el tipo de contenido y tratarlo como json.
66

7-
+ Añadir el diccionario a la lista de todos.
7+
+ Agrega el diccionario a la lista de `todos`.
88

9-
+ Retornar la nueva lista de todos.
9+
+ Devuelve la nueva lista de `todos`.
1010

11-
Para decodificar cualquier string json y convertirlo a un objeto de python podemos usar esta función:
11+
Tu código debería verse así ahora:
1212

1313
```python
14-
import json
15-
decoded_object = json.loads(original_string)
14+
15+
@app.route('/todos', methods=['POST'])
16+
def add_new_todo():
17+
request_body = request.json
18+
print("Incoming request with the following body", request_body)
19+
return 'Response for the POST todo'
20+
1621
```
1722

23+
Obviamente, este punto final actualmente no agrega nada nuevo a nuestra 'base de datos' (la lista `todo`).
24+
25+
Completemos el código para que el punto final pueda hacer tu trabajo: agregar una nueva tarea a los `todos`.
26+
1827
## 📝 Instrucciones:
1928

20-
1. Usa la función json.loads para decodificar el `request.data`
29+
1. Agrega el contenido del cuerpo de la solicitud decodificada a la lista `todos`.
2130

22-
2. Añade el objeto decodificado a la lista de `todos`.
31+
2. Devuelve la lista actualizada `todos` al front end.
2332

24-
3. Retorna la lista jsonify de los `todos` actualizados.
33+
3. No olvide `jsonify` su devolución. ¿Por qué es esto necesario? Discuta con la clase.

Pipfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@ name = "pypi"
77
flask = "*"
88

99
[dev-packages]
10-
11-
[requires]
12-
python_version = "3.8"

0 commit comments

Comments
 (0)