8000 Added a couple of updates to the ebook. by LUS24 · Pull Request #70 · tecladocode/web-dev-bootcamp · GitHub
[go: up one dir, main page]

Skip to content

Added a couple of updates to the ebook. #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,22 @@ Note that the form pre-population mechanism is the `obj=movie` part.

## Rendering the extended movie form

Let's create the `templates/movie_form.html` template:
First, let's edit the `templates/macros/fields.html` template to add the a new macro in order to render the custom field:

```jinja2
{% macro render_area_field(field) %}
<div class="form__group">
{{ field.label(class_="form__label") }}
{{ field(rows=4, class_="form__field", style="resize: none") }}

{%- for error in field.errors %}
<span class="form__error">{{ error }}</span>
{% endfor %}
</div>
{% endmacro %}
```

And then create the `templates/movie_form.html` template:

```jinja2
{% from "macros/fields.html" import render_text_field, render_area_field %}
Expand Down Expand Up @@ -90,6 +105,32 @@ Let's create the `templates/movie_form.html` template:
{% endblock %}
```

Finally we can update the anchor tags in the `templates/movie_details.html` template since we now can edit the fields:

```diff
...
{% else %}
<p><a href="{{ url_for('pages.watch_today', _id=movie._id) }}" class="watched__link">Not watched yet</a></p>
{% endif %}
- <a class="movie__edit" href="#">Edit {{ pencil("pencil") }}</a>
+ <a class="movie__edit" href="{{ url_for('pages.edit_movie', _id=movie._id) }}">Edit {{ pencil("pencil") }}</a>
</div>
</div>
<div class="header__row">
...
```

```diff
...
{% if movie.description %}
<p class="movie__description">{{ movie.description }}</p>
{% else %}
- <p class="movie__description">No description yet. <a class="link" href="#">Add one?</a></p>
+ <p class="movie__description">No description yet. <a class="link" href="{{ url_for('pages.edit_movie', _id=movie._id) }}">Add one?</a></p>
{% endif %}
...
```

Also nothing new here!

Note that our custom WTForm field is identical to the `TextAreaField`, except when it comes to receiving form data and putting it in our Python object. Everything else behaves the same way as the parent class.
Expand Down
0