You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tasks.md
+22-6
Original file line number
Diff line number
Diff line change
@@ -62,7 +62,8 @@ You can preview your work by running `flask run` in the root of your fork. Then
62
62
63
63
## 1.4 - Create Index Template
64
64
65
-
@pytest.mark.index-template In the root of the `templates` folder, create a file called `index.html`. Add a single line to the file:
65
+
@pytest.mark.index-template In the root of the `templates` folder, create a file called `index.html`. Add a single line to the file:
66
+
66
67
-`<h1>Jobs</h1>`
67
68
68
69
## 1.5 - Index Route Function
@@ -77,6 +78,7 @@ For now let’s setup a basic route that displays our simplified `index.html` te
77
78
## 1.6 - Route Decorators
78
79
79
80
@pytest.mark.app-route-decoractors Still in `app.py`:
81
+
80
82
- Attach a `route()` decorator with the URL of `/` to the `jobs` function.
81
83
- Attach an additional route decorator of `/jobs`. **Note: The `jobs` function can now be reached at `/` and `/jobs`**
82
84
@@ -108,7 +110,7 @@ For the `href` use the mustache template markup `{{}}` and the flask `url_for()`
108
110
109
111
## 2.3 - Add Custom CSS
110
112
111
-
@pytest.mark.add-custom-css For the second `<link>` tag in `layout.html` construct an `href` for the file `css/app.css`, also in the `static` folder, using the same method. Don't forget `rel` attribute.
113
+
@pytest.mark.add-custom-css For the second `<link>` tag in `layout.html` construct an `href` for the file `css/app.css`, also in the `static` folder, using the same method. Don't forget the`rel` attribute.
112
114
113
115
## 2.4 - Add FontAwesome
114
116
@@ -117,6 +119,7 @@ For the `href` use the mustache template markup `{{}}` and the flask `url_for()`
117
119
## 2.5 - Extend Base Template
118
120
119
121
@pytest.mark.extend-base-template To use `layout.html` as the base template:
122
+
120
123
- Open `index.html`, above the `<h1>` use the template markup `{% %}` and the extends tag to inherit `layout.html`.
121
124
- Wrap the `<h1>` element in a `block` called `content`.
122
125
@@ -155,6 +158,7 @@ In the body of the `get_db` function use the built-in `getattr()` function to ge
155
158
## 3.6 - sqlite3 Row Factory
156
159
157
160
@pytest.mark.app-sqlite3-row-factory To make accessing data easier, after the if statement in `get_db`:
161
+
158
162
- Set the row_factory of `db` to `sqlite3.Row`. **Note: All rows returned from the database will be named tuples.**
159
163
- Return the `db` variable.
160
164
@@ -169,6 +173,7 @@ In the body of `query_db` create a variable called `db`. Assign this variable th
169
173
## 3.8 - Query Database Function Parameters
170
174
171
175
@pytest.mark.app-query-database-function-parameters Still working with the `query_db` function:
176
+
172
177
- Add three parameters: `query`, `args`, and `one`.
173
178
- Set the default of `args` to an empty tuple `()`.
174
179
- Set the default of `one` to `False`.
@@ -178,21 +183,25 @@ In the body of `query_db` create a variable called `db`. Assign this variable th
178
183
179
184
## 3.10 - Query Database Function Fetchall
180
185
@pytest.mark.app-query-database-function-fetchall In the body of `query_db`:
186
+
181
187
-`fetchall` data from the `cursor` and assign it to a variable called `results`.
182
188
- Close the `cursor` with the `close` function.
183
189
184
190
## 3.11 - Query Database Function Single
185
191
@pytest.mark.app-query-database-function-single Next, in the function body of `query_db` add a test if `one` is `True`:
192
+
186
193
- if true return a ternary if, `results[0] if results else None`.
187
194
- else return all `results`.
188
195
189
196
## 3.12 - Close the Connection
190
197
191
198
@pytest.mark.app-close-the-connection In order to make sure the database connection is closed when the `app_context` is torn down:
199
+
192
200
- Create a function in `app.py` called `close_connection`.
193
201
- Add a parameter called `exception` to the parameter list.
194
202
195
203
In the function body:
204
+
196
205
- Call `getattr` with three arguments `g`, `'_database'`, and `None`
197
206
- Assign the return value to a `db` variable.
198
207
- If `db` is not `None``close` the `db`.
@@ -225,8 +234,9 @@ In the function body:
225
234
## 4.5 - Show Job Macro Body
226
235
227
236
@pytest.mark.show-job-macro-body Next find the `<div>` with a class of `content` in the `show_job` macro and add a `<p>` tag.
228
-
In `<p>` tag add the following:
229
-
-`<a>` tag with an `href` of `{{ url_for('employer', employer_id=job['employer_id']) }}`.The content should be `{{ job['employer_name'] }}`.
237
+
In `<p>` tag add the following:
238
+
239
+
-`<a>` tag with an `href` of `{{ url_for('employer', employer_id=job['employer_id']) }}`. The content should be `{{ job['employer_name'] }}`.
230
240
- Line break
231
241
- ${{ job['salary'] }}
232
242
- Line break
@@ -239,20 +249,24 @@ In `<p>` tag add the following:
239
249
## 4.7 - Show Jobs Macro For Loop
240
250
241
251
@pytest.mark.show-jobs-macro-for-loop Still in `_macros.html` and in the body of the `show_jobs` macro add the following HTML:
252
+
242
253
- Add a `<div>` with two classes `columns` and `is-multiline`.
243
254
- In this `<div>` add a `for in` loop that loops through all jobs. **Note: Use the `{% %}` template syntax, don’t forget about ending the `for` loop.**
244
255
245
256
## 4.8 - Show Jobs Macro For Loop Body
246
257
247
-
@pytest.mark.show-jobs-macro-for-loop-body In the body of the `for` loop add a `<div>` with two classes `column` and `is-half`.
258
+
@pytest.mark.show-jobs-macro-for-loop-body In the body of the `for` loop add a `<div>` with two classes `column` and `is-half`.
259
+
248
260
- In this `column``<div>` add a call to the `show_job` macro passing in an individual `job` from the `for` loop.
249
261
250
262
## 4.9 - Import Macros
251
263
252
264
@pytest.mark.import-macros In `templates/layouts.html` import the `show_job`, and `show_jobs` macros using the following code:
265
+
253
266
```
254
267
{% from '_macros.html' import show_job, show_jobs with context %}
255
268
```
269
+
256
270
**Notes: Because each template extends `layouts.html` all of them will have access to these two new macros.**
257
271
258
272
## 4.10 - Import Macros
@@ -268,6 +282,7 @@ In `<p>` tag add the following:
268
282
@pytest.mark.gather-all-jobs In `app.py` locate the `jobs` function.
269
283
270
284
Above the `render_template` function, call the `query_db` function:
285
+
271
286
- Pass in the SQL statement: `'SELECT job.id, job.title, job.description, job.salary, employer.id as employer_id, employer.name as employer_name FROM job JOIN employer ON employer.id = job.employer_id'`.
272
287
- Assign the results of the call to a variable called `jobs`.
273
288
- In the `render_template` function, pass a keyword argument of `jobs=jobs`.
@@ -309,7 +324,8 @@ Still in `app.py`, add a route decorator with the URL path `/job/<job_id>` to th
309
324
## 5.5 - Job Route Data
310
325
311
326
@pytest.mark.app-job-route-data In the `job` function, above the `render_template` function, call the `query_db` function and assign the results of the call to a `job` variable.
312
-
Pass these three arguments to `query_db`:
327
+
Pass these three arguments to `query_db`:
328
+
313
329
- SQL Query: `'SELECT job.id, job.title, job.description, job.salary, employer.id as employer_id, employer.name as employer_name FROM job JOIN employer ON employer.id = job.employer_id WHERE job.id = ?'`
0 commit comments