Skip to content

Commit ce5a651

Browse files
committed
docs: tasks rewrite
1 parent 2dd481a commit ce5a651

File tree

3 files changed

+319
-204
lines changed

3 files changed

+319
-204
lines changed

scratch_tasks.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,108 @@ Next, create a new folder called `admin` in the `templates` folder, then create
3939
## 2.6 - Navigation
4040

4141
@pytest.mark.navigation We want to allow the user to navigate to the admin from the front page. In the `index.html` template file create a link to the main admin page by creating an `<a>` tag nested in the `<div>` with the two classes `columns` and `is-one-fifth`. The `<a>` tag should have an `href` with the value `/admin` and the classes `button`, `is-info`, and `is-pulled-right`. In the admin we allow the user to create a new job. In the `admin/index.html` template file create a link to the new job form by creating an `<a>` tag nested in the `<div>` with the two classes `columns` and `is-one-fifth`. The `<a>` tag should have an `href` with the value `/admin/create` and the classes `button`, `is-info`, and `is-pulled-right`.
42+
43+
44+
locate the `jobs` function. Above the `render_template` function call, call the `query_db`function. 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'`. Assign the results of the call to a variable called `jobs`. In the `render_template` function, pass a keyword argument of `jobs=jobs`.
45+
46+
## 4.2 - Individual Job Details
47+
48+
@pytest.mark.app-individual-job-details To bring back just one job from the database we are going to use a where clause. In the where clause we will need a `job_id`. We are going to get this from the URL. In `app.py` locate the `job` function. In the route decorator for the function after the URL path `/job` add `/<job_id>`. To use this `job_id` we also need to pass it to the job function add `job_id` to the parameter list of the `job` function. Above the `render_template` function, call the `query_db` function and assign the results of the call to a `job` variable. Pass the function three arguments:
49+
- 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 = ?'`
50+
- List Literal: [job_id]
51+
- True: This will bring back only one result.
52+
53+
In the `render_template` function, pass a keyword argument of `job=job`
54+
55+
## 4.3 - Individual Employer Details
56+
57+
@pytest.mark.app-individual-employer-details Similar to the `job` function the employer route will only need the details of one employer. Locate the `employer` function in `app.py`. Again we need the unique id of an employer and will receive this from the URL. Add `/<employer_id>` in the route decorator after `/employer`. So that the `employer` function has access to this value add `employer_id`to the parameter list. Make a call to `query_db` and assign the return value to `employer`. Pass in the arguments:
58+
- SQL Query: 'SELECT * FROM employer WHERE id=?'
59+
- List Literal: [employer_id]
60+
- True: This will bring back only one result.
61+
62+
In the `render_template` function, pass a keyword argument of `employer=employer`
63+
64+
## 4.4 - All Employer Jobs
65+
66+
@pytest.mark.app-all-employer-jobs On the employer details page, we want to display all of the employers’ jobs. In the `employer` function in `app.py` below the `employer` variable, add a call to the `query_db` function and assign the results to a variable called `jobs`. Pass the function two arguments:
67+
- SQL Query: `'SELECT job.id, job.title, job.description, job.salary FROM job JOIN employer ON employer.id = job.employer_id WHERE employer.id = ?'`
68+
- List Literal: [employer_id]
69+
70+
In the `render_template` function, add another keyword argument of `jobs=jobs`
71+
72+
## 4.5 - Job Card
73+
74+
@pytest.mark.job-card Open the file `templates/_jobs.html` find the `<p>` tag with a class of `card-header-title`. Add an `<a>` tag with an `href` of `{{ url_for('job', job_id=job['id']) }}`. The content should be `{{ job['title'] }}`. Next find the `<div>` with a class of `content`. To this tag add a `<p>` tag and in this tag add the following:
75+
- `<a>` tag with an `href` of `{{ url_for('employer', employer_id=job['employer_id']) }}`. The content should be `{{ job['employer_name'] }}`. Add line break.
76+
- ${{ job['salary'] }}. Add line break.
77+
- {{ job['description'] }}
78+
79+
## 4.6 -Display All Jobs
80+
81+
@pytest.mark.display-all-jobs Open the file `templates/index.html` above the `{% endblock %}` add a `<div>` with two classes `columns` and `is-multiline`. In the div add a `for in` loop that loops through all jobs. Use the `{% %}` template syntax, don’t forget about ending the `for` loop. In the `for` loop add a `<div>` with two classes `column` and `is-half`. Too this `<div>` add the following template code:
82+
83+
```
84+
{% with job=job %}
85+
{% include "_job.html" %}
86+
{% endwith %}
87+
```
88+
89+
## 4.7 - Display Individual Job Details
90+
91+
@pytest.mark.display-individual-job-details In `templates/job.html` add a template block called `content` using the `{% %}` template markup. In the template block add the following template code:
92+
93+
```
94+
{% with job=job %}
95+
{% include "_job.html" %}
96+
{% endwith %}
97+
```
98+
99+
## 4.8 - Display Individual Employer Details
100+
101+
@pytest.mark.display-individual-employer-details Open `templates/employer.html` as the first thing in the template block add the following HTML:
102+
103+
- `<div>`
104+
- Nested in the `<div>` add an `<h1>` with the content {{ employer['name'] }}
105+
- Nested in the `<div>` add a`<div>` with a class of `description`
106+
- Nested in the description `<div>`add a`<p>` with the content {{ employer['description'] }}
107+
108+
## 4.9 -Display All Employer Jobs
109+
110+
@pytest.mark.display-all-employer-jobs Open the file `templates/employer.html` below the jobs `<h2>` add a `<div>` with two classes `columns` and `is-multiline`. In the div add a `for in` loop that loops through all jobs. Use the `{% %}` template syntax, don’t forget about ending the `for` loop. In the `for` loop add a `<div>` with two classes `column` and `is-half`. To the `<div>` add the following template code:
111+
112+
```
113+
{% with job=job %}
114+
{% include "_job.html" %}
115+
{% endwith %}
116+
```
117+
118+
# Module 08 - Add Jobs
119+
120+
## 8.1 - Admin Route
121+
122+
@pytest.mark.app-admin-route We will display all jobs on the admin page. To start, in `app.py` create a basic route that displays the contents of the admin index template. Create a function called `admin` and attach a `route()` decorator with the URL of `/admin`. In the body of the function use the `query_db` function to get all jobs from the database. The SQL can be found in other routes. Next, return a call to the `render_template()` passing in the `admin/index.html` template and the correct keyword arguments.
123+
124+
## 8.2 - Admin Create Job Route
125+
126+
@pytest.mark.app-admin-create-job-route In `app.py` create a route at the path `/admin/create` that accepts the methods 'GET' and 'POST'.
127+
128+
## 8.3 - Check for POST method
129+
130+
@pytest.mark.app-admin-check-for-post-method In the body of your route check if data has been posted then create four variables `title`, `description`, `salary`, and `employer_id`. Set them equal to their respective `request.form` values. Create an `error` variable set to `None`.
131+
132+
## 8.3 - Check for Values
133+
134+
@pytest.mark.app-admin-check-for-values In the body of the post `if` statement in your route function in `app.py`, below the variables, check if there is a value for `title`, and `employer_id`. If either is empty set `error` to an appropriate error message i.e. 'Title field is required.'
135+
136+
## 8.4 - Check for Error
137+
138+
@pytest.mark.app-admin-check-for-error Still in your route function below the value checks add an `if` statement that checks if `error` is `None`. If there are no errors we are going to add the form values to the database. Connect to the database and commit the changes.
139+
**Hint: The SQL is `'INSERT INTO job (title, description, salary, employer_id) VALUES (?, ?, ?, ?)'`**
140+
141+
If there are errors `flash` the error. **Hint: `else` statement**
142+
143+
## 8.5 - Admin Navigation
144+
145+
@pytest.mark.admin-navigation Find the admin index template and add an href attribute to the `New Job` link. Send the user to the URL ``/admin/create`. Open create job template and find the cancel anchor tag. Point the link back to the admin page using `url_for()`.
146+

0 commit comments

Comments
 (0)