From 75bdb310d4642a78593f9dd003977886878672e8 Mon Sep 17 00:00:00 2001
From: lbenno <110334648+lbenno@users.noreply.github.com>
Date: Thu, 18 Apr 2024 10:46:18 +0200
Subject: [PATCH 1/7] Add {% filename %} tags before each code block in
README.md
---
en/homework/README.md | 33 +++++++++++++++++++++++----------
1 file changed, 23 insertions(+), 10 deletions(-)
diff --git a/en/homework/README.md b/en/homework/README.md
index 227346b..547d4ec 100644
--- a/en/homework/README.md
+++ b/en/homework/README.md
@@ -6,6 +6,7 @@ Our blog has come a long way but there's still room for improvement. Next, we wi
Currently when we're creating new posts using our *New post* form the post is published directly. To instead save the post as a draft, **remove** this line in `blog/views.py` in the `post_new` and `post_edit` methods:
+{% filename %}blog/views.py{% endfilename %}
```python
post.published_date = timezone.now()
```
@@ -18,20 +19,23 @@ Remember the chapter about querysets? We created a view `post_list` that display
Time to do something similar, but for draft posts.
-Let's add a link in `blog/templates/blog/base.html` in the header. We don't want to show our list of drafts to everybody, so we'll put it inside the {% raw %}`{% if user.is_authenticated %}`{% endraw %} check, right after the button for adding new posts.
+Let's add a link to the header.of our `base.html` template. We don't want to show our list of drafts to everybody, so we'll put it inside the {% raw %}`{% if user.is_authenticated %}`{% endraw %} check, right after the button for adding new posts.
+{% filename %}blog/templates/blog/base.html{% endfilename %}
```django
```
-Next: urls! In `blog/urls.py` we add:
+Next we define the url path!
+{% filename %}blog/urls.py{% endfilename %}
```python
path('drafts/', views.post_draft_list, name='post_draft_list'),
```
-Time to create a view in `blog/views.py`:
+Time to create a view:
+{% filename %}blog/views.py{% endfilename %}
```python
def post_draft_list(request):
posts = Post.objects.filter(published_date__isnull=True).order_by('created_date')
@@ -40,8 +44,9 @@ def post_draft_list(request):
The line ` posts = Post.objects.filter(published_date__isnull=True).order_by('created_date')` makes sure that we take only unpublished posts (`published_date__isnull=True`) and order them by `created_date` (`order_by('created_date')`).
-Ok, the last bit is of course a template! Create a file `blog/templates/blog/post_draft_list.html` and add the following:
+Ok, the last bit is of course a template! Create a new template file `post_draft_list.html` and add the following:
+{% filename %}blog/templates/blog/post_draft_list.html{% endfilename %}
```django
{% extends 'blog/base.html' %}
@@ -66,8 +71,9 @@ Yay! Your first task is done!
It would be nice to have a button on the blog post detail page that will immediately publish the post, right?
-Let's open `blog/templates/blog/post_detail.html` and change these lines:
+Let's open `post_detail.html` and change these lines:
+{% filename %}blog/templates/blog/post_detail.html{% endfilename %}
```django
{% if post.published_date %}
@@ -78,6 +84,7 @@ Let's open `blog/templates/blog/post_detail.html` and change these lines:
into these:
+{% filename %}blog/templates/blog/post_detail.html{% endfilename %}
```django
{% if post.published_date %}
@@ -90,14 +97,16 @@ into these:
As you noticed, we added {% raw %}`{% else %}`{% endraw %} line here. That means, that if the condition from {% raw %}`{% if post.published_date %}`{% endraw %} is not fulfilled (so if there is no `published_date`), then we want to do the line {% raw %}`
Publish`{% endraw %}. Note that we are passing a `pk` variable in the {% raw %}`{% url %}`{% endraw %}.
-Time to create a URL (in `blog/urls.py`):
+Time to create a URL:
+{% filename %}blog/urls.py{% endfilename %}
```python
path('post/
/publish/', views.post_publish, name='post_publish'),
```
-and finally, a *view* (as always, in `blog/views.py`):
+and finally, a *view*:
+{% filename %}blog/views.py{% endfilename %}
```python
def post_publish(request, pk):
post = get_object_or_404(Post, pk=pk)
@@ -107,6 +116,7 @@ def post_publish(request, pk):
Remember, when we created a `Post` model we wrote a method `publish`. It looked like this:
+{% filename %}blog/models.py{% endfilename %}
```python
def publish(self):
self.published_date = timezone.now()
@@ -123,22 +133,25 @@ Congratulations! You are almost there. The last step is adding a delete button!
## Delete post
-Let's open `blog/templates/blog/post_detail.html` once again and add this line:
+Let's open `post_detail.html` once again and add this line:
+{% filename %}blog/templates/blog/post_detail.html{% endfilename %}
```django
```
just under a line with the edit button.
-Now we need a URL (`blog/urls.py`):
+Now we need a URL:
+{% filename %}blog/urls.py{% endfilename %}
```python
path('post//remove/', views.post_remove, name='post_remove'),
```
-Now, time for a view! Open `blog/views.py` and add this code:
+Now, time for a view!
+{% filename %}blog/views.py{% endfilename %}
```python
def post_remove(request, pk):
post = get_object_or_404(Post, pk=pk)
From c2cefe5ed2f66c8972fbed36f6c254377dbf6d85 Mon Sep 17 00:00:00 2001
From: lbenno <110334648+lbenno@users.noreply.github.com>
Date: Thu, 18 Apr 2024 10:51:30 +0200
Subject: [PATCH 2/7] Added filename tags before each code bock instruction in
README.md
---
en/authentication_authorization/README.md | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/en/authentication_authorization/README.md b/en/authentication_authorization/README.md
index cd29f51..90f1655 100644
--- a/en/authentication_authorization/README.md
+++ b/en/authentication_authorization/README.md
@@ -8,12 +8,14 @@ First let's make things secure. We will protect our `post_new`, `post_edit`, `po
So edit your `blog/views.py` and add these lines at the top along with the rest of the imports:
+{% filename %}blog/views.py{% endfilename %}
```python
from django.contrib.auth.decorators import login_required
```
Then add a line before each of the `post_new`, `post_edit`, `post_draft_list`, `post_remove` and `post_publish` views (decorating them) like the following:
+{% filename %}blog/views.py{% endfilename %}
```python
@login_required
def post_new(request):
@@ -37,6 +39,7 @@ We could now try to do lots of magical stuff to implement users and passwords an
In your `mysite/urls.py` add a url `path('accounts/login/', views.LoginView.as_view(), name='login')`. So the file should now look similar to this:
+{% filename %}mysite/urls.py{% endfilename %}
```python
from django.urls import path, include
from django.contrib import admin
@@ -52,6 +55,7 @@ urlpatterns = [
Then we need a template for the login page, so create a directory `blog/templates/registration` and a file inside named `login.html`:
+{% filename %}blog/templates/registration/login.html{% endfilename %}
```django
{% extends "blog/base.html" %}
@@ -83,6 +87,7 @@ You will see that this also makes use of our _base_ template for the overall loo
The nice thing here is that this _just worksTM_. We don't have to deal with handling of the form submission nor with passwords and securing them. Only more thing is left to do. We should add a setting to `mysite/settings.py`:
+{% filename %}mysite/settings.py{% endfilename %}
```python
LOGIN_REDIRECT_URL = '/'
```
@@ -99,8 +104,9 @@ We will add a login button that looks like this:
```
-For this we need to edit the templates, so let's open up `blog/templates/blog/base.html` and change it so the part between the `` tags looks like this:
+For this we need to edit the templates, so let's open up `base.html` and change it so the part between the `` tags looks like this:
+{% filename %}blog/templates/blog/base.html{% endfilename %}
```django