+ ${{ job['employer_name'] }}
+
+ ${{ job['salary'] }}
+
+ ${{ job['description'] }}
+
+
diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..e69de29bb diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..fbf9358b0 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,14 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# Explicitly declare text files you want to always be normalized and converted +# to native line endings on checkout. +*.c text +*.h text + +# Declare files that will always have CRLF line endings on checkout. +*.sln text eol=crlf + +# Denote all files that are truly binary and should not be modified. +*.png binary +*.jpg binary diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..a47301c69 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.6-alpine + +WORKDIR /src/app/ + +COPY ./requirements.txt . + +RUN ["pip", "install", "-r", "./requirements.txt"] + +COPY . . + +RUN addgroup -S projects && adduser -S -H projects -G projects +RUN chown -R projects:projects /src/app +USER projects 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/jobs/app.py b/jobs/app.py index e69de29bb..54c9f09fa 100644 --- a/jobs/app.py +++ b/jobs/app.py @@ -0,0 +1,39 @@ +from flask import Flask, render_template, g +import sqlite3 + +PATH = 'db/jobs.sqlite' + +app = Flask(__name__) + + +def open_connection(): + connection = getattr(g, '_connection', None) + if connection is None: + connection = g._connection = sqlite3.connect(PATH) + connection.row_factory = sqlite3.Row + return connection + + +def execute_sql(sql, values=(), commit=False, single=False): + connection = open_connection() + cursor = connection.execute(sql, values) + if commit: + results = connection.commit() + else: + results = cursor.fetchone() if single else cursor.fetchall() + + cursor.close() + return results + + +@app.teardown_appcontext +def close_connection(exception): + connection = getattr(g, '_connection', None) + if connection is not None: + connection.close() + + +@app.route('/') +@app.route('/jobs') +def jobs(): + return render_template('index.html') diff --git a/jobs/templates/_macros.html b/jobs/templates/_macros.html new file mode 100644 index 000000000..7ef64bba6 --- /dev/null +++ b/jobs/templates/_macros.html @@ -0,0 +1,33 @@ +{% macro show_job(job) %} +
` 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 `