diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..e69de29bb diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..409fcd54b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.6-alpine + +ENV APP_DIR /src/app/ + +RUN mkdir -p $APP_DIR + +COPY ./requirements.txt ${APP_DIR} + +WORKDIR ${APP_DIR} + +RUN ["pip", "install", "-r", "./requirements.txt"] + +COPY . . diff --git a/README.md b/README.md index d9cca4f37..798fcf313 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Once that completes, also run this command from the same folder. Windows ``` -\venv\Scripts\activate.bat +venv\Scripts\activate.bat ``` macOS & Linux @@ -46,4 +46,4 @@ Every time you want to check your work locally you can type that command, and it ### Previewing Your Work -You can preview your work by running `flask run` in the root of your fork and then visit`http://localhost:5000` in your browser. \ No newline at end of file +You can preview your work by running `flask run` in the root of your fork and then visit`http://localhost:5000` in your browser. diff --git a/tasks.md b/tasks.md index c8c700e51..ca0828c68 100644 --- a/tasks.md +++ b/tasks.md @@ -1,12 +1,10 @@ -# Build a Job Board with Python & Flask +# Setup -## Setup - -### Create Virtual Environment +## Create Virtual Environment In a terminal run the following commands from the root folder of the forked project. -``` shell +``` python -m venv venv ``` @@ -14,162 +12,162 @@ Once that completes, also run this command from the same folder. Windows -``` shell +``` \venv\Scripts\activate.bat ``` macOS & Linux -``` shell +``` source venv/bin/activate ``` Now that you are working in the virtualenv, install the project dependencies with the following command. -``` shell +``` pip install -r requirements.txt ``` -### Verify Setup +## Verify Setup In order to verify that everything is setup correctly, run the following command, which should show you the failing tests. This is good! We’ll be fixing this test once we jump into the build step. -``` shell +``` pytest ``` Every time you want to check your work locally you can type that command, and it will report the status of every task in the project. -### Previewing Your Work +## Previewing Your Work You can preview your work by running `flask run` in the root of your fork. Then visit `http://localhost:5000` in your browser. -## Module 01 - Flask Setup +# Module 01 - Flask Setup -### 1.1 - Import Flask +## 1.1 - Import Flask @pytest.mark.app_import_flask In order to create a flask application, import the `Flask` class and the `render_template` function from `flask` at the top of the `jobs/app.py` file. -### 1.2 - Create a Flask Application +## 1.2 - Create a Flask Application @pytest.mark.app_create_flask_app Still in `app.py` create an instance of the `Flask` class called `app`. Pass the special variable `__name__` to the `Flask` class constructor. -### 1.3 - Templates Folder +## 1.3 - Templates Folder @pytest.mark.templates_folder Create a folder called `templates` in the `jobs` directory. -### 1.4 - Create Index Template +## 1.4 - Create Index Template @pytest.mark.index_template In the root of the `templates` folder, create a file called `index.html`. Add a single line to the file: - `
` tag with a class of `card_header_title`.
-- Add an `` tag with an `href` of `{{ url_for('job', job_id=job['id']) }}`.
-- The content should be `{{ job['title'] }}`.
+- Add an `` tag with an `href` of `{{ url_for('job', job_id=job['id']) }}`.
+- The content should be `{{ job['title'] }}`.
-### 4.5 - Show Job Macro Body
+## 4.5 - Show Job Macro Body
-@pytest.mark.show_job_macro_body Next find the ` ` tag.
+@pytest.mark.show_job_macro_body Next find the ` ` tag.
In ` ` tag add the following:
-- `` tag with an `href` of `{{ url_for('employer', employer_id=job['employer_id']) }}`. The content should be `{{ job['employer_name'] }}`.
+- `` tag with an `href` of `{{ url_for('employer', employer_id=job['employer_id']) }}`. The content should be `{{ job['employer_name'] }}`.
- Line break
-- ${{ job['salary'] }}
+- ${{ job['salary'] }}
- Line break
- {{ job['description'] }}
-### 4.6 - Show Jobs Macro Definition
+## 4.6 - Show Jobs Macro Definition
@pytest.mark.show_jobs_macro_definition In `_macros.html` create a template macro using the `macro` tag call it `show_jobs`. `show_jobs` should take one parameter called `jobs`. Don't forgot to end the macro.
-### 4.7 - Show Jobs Macro For Loop
+## 4.7 - Show Jobs Macro For Loop
@pytest.mark.show_jobs_macro_for_loop Still in `_macros.html` and in the body of the `show_jobs` macro add the following HTML:
- Add a ` ` with the content {{ employer['description'] }}
-### 6.3 - Employer Template All Jobs
+## 6.3 - Employer Template All Jobs
@pytest.mark.employer_template_all_jobs Below the `` with the copied HTML structure.
-### 4.11 - Display All Jobs
+## 4.11 - Display All Jobs
@pytest.mark.display_all_jobs In the `index.html` template above the `{% endblock %}` add a call to the `show_jobs` macro passing in the argument `jobs`.
-### 4.12 - Gather All Jobs
+## 4.12 - Gather All Jobs
-@pytest.mark.app_jobs_route_jobs In `app.py` locate the `jobs` function.
+@pytest.mark.app_jobs_route_jobs In `app.py` locate the `jobs` function.
Above the `render_template` function, call the `execute_sql` 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`.
+- 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`.
-### Preview Module 4
+**Preview**
At this point you can see all jobs on the homepage:
- Open a terminal at the root of the project
-- Run the command `flask run`.
-- Open a browser and navigate to the URL: `http://localhost:5000`.
+- Run the command `flask run`.
+- Open a browser and navigate to the URL: `http://localhost:5000`.
**Note: Appending `/jobs` should display the same page.**
-## Module 05 - Display Individual Jobs
+# Module 05 - Display Individual Jobs
-### 5.1 - Job Template
+## 5.1 - Job Template
-@pytest.mark.app_job_template We need a template to display an individual job. Create a new file called `job.html` in the `template` folder.
+@pytest.mark.app_job_template We need a template to display an individual job. Create a new file called `job.html` in the `template` folder.
-In the file use an `extends` template tag to inherit `layout.html`.
+In the file use an `extends` template tag to inherit `layout.html`.
After the `extends` tag add a template `block` called `content`. In the block call the `show_job` macro passing in `job`. **Note: Use the `{{}}` for the macro call.**
-### 5.2 - Job Route Function
+## 5.2 - Job Route Function
@pytest.mark.app_job_route In `app.py` create a function called `job`. In the body return a call to the `render_template` function passing in the newly created `job.html` template.
-### 5.3 - Job Route Decorator
+## 5.3 - Job Route Decorator
-@pytest.mark.app_job_route_decorator We only need one job from the database, we will use the `execute_sql` function passing in a query with a where clause. In the where clause we will need a `job_id`. We are going to get this from the URL.
+@pytest.mark.app_job_route_decorator We only need one job from the database, we will use the `execute_sql` function passing in a query with a where clause. In the where clause we will need a `job_id`. We are going to get this from the URL.
-Still in `app.py`, add a route decorator with the URL path `/job/
` Jobs header in `employer.html` add a call to the `show_jobs` macro passing in `jobs`.
-### 6.4 - Employer Template Reviews
+## 6.4 - Employer Template Reviews
-@pytest.mark.employer_template_reviews Still in `employer.html` find the review `
`, remove the comment surrounding the empty `{% %}` template tag. To this tag add a `for in` loop to loop through all `reviews`. Add the `endfor` directive to the second empty `{% %}` template tag, don't forget to the remove the comment.
+@pytest.mark.employer_template_reviews Still in `employer.html` find the review `
`, remove the comment surrounding the empty `{% %}` template tag. To this tag add a `for in` loop to loop through all `reviews`. Add the `endfor` directive to the second empty `{% %}` template tag, don't forget to the remove the comment.
-### 6.5 - Employer Template Review Stars
+## 6.5 - Employer Template Review Stars
@pytest.mark.employer_template_review_stars Still `employer.html` in the `