Skip to content
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

Fix "Add publish button" and "Delete post" sections #181

Merged
merged 5 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Current tutorials are:
## Contributing

These tutorials are maintained by [DjangoGirls](http://djangogirls.org/). If you find any mistakes or want to update the tutorial
please [follow the contributing guidelines](https://github.com/DjangoGirls/tutorial-extension/contributing/).
please [follow the contributing guidelines](./contributing/README.md).
14 changes: 7 additions & 7 deletions en/homework/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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.

```django
<a href="{% url 'post_draft_list' %}" class="top-menu"><span class="glyphicon glyphicon-edit"></span></a>
<a href="{% url 'post_draft_list' %}" class="top-menu">Drafts</span></a>
```

Next: urls! In `blog/urls.py` we add:
Expand Down Expand Up @@ -84,8 +84,8 @@ into these:
{{ post.published_date }}
</div>
{% else %}
<form method="POST" action="{% url post_publish pk=post.pk %} class="post-form">{% csrf_token %}
<button type="submit" class="post btn btn-info" name="publish">Publish</button>
<form method="POST" action="{% url 'post_publish' pk=post.pk %}" class="post-form">{% csrf_token %}
<button type="submit" class="post btn btn-secondary" name="publish">Publish</button>
</form>
{% endif %}
```
Expand All @@ -101,7 +101,7 @@ Now, let's take a look at the details of the form. We are using a new attribute,
Time to create a URL (in `blog/urls.py`):

```python
path('post/<pk>/publish/', views.post_publish, name='post_publish'),
path('post/<int:pk>/publish/', views.post_publish, name='post_publish'),
```

and finally, a *view* (as always, in `blog/views.py`):
Expand Down Expand Up @@ -137,9 +137,9 @@ Congratulations! You are almost there. The last step is adding a delete button!
Let's open `blog/templates/blog/post_detail.html` once again and add these lines:

```django
<form method="POST" action="{% url post_remove pk=post.pk %} class="post-form">{% csrf_token %}
<form method="POST" action="{% url 'post_remove' pk=post.pk %}" class="post-form">{% csrf_token %}
<button type="submit" class="post btn btn-danger" name="delete">
<span class="glyphicon glyphicon-remove"></span>
Delete
</button>
</form>
```
Expand All @@ -149,7 +149,7 @@ just under a line with the edit button.
Now we need a URL (`blog/urls.py`):

```python
path('post/<pk>/remove/', views.post_remove, name='post_remove'),
path('post/<int:pk>/remove/', views.post_remove, name='post_remove'),
```

Now, time for a view! Open `blog/views.py` and add this code:
Expand Down
22 changes: 15 additions & 7 deletions es/homework/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Es tiempo de hacer algo similiar, pero con borradores.
Vamos a añadir un enlace en `blog/templates/blog/base.html` en el encabezado. No queremos mostrar nuestro borradores a todo el mundo, entonces vamos a colocarlo dentro de la verificación {% raw %}`{% if user.is_authenticated %}`{% endraw %}, justo después del botón de agregar posts.

```django
<a href="{% url 'post_draft_list' %}" class="top-menu"><span class="glyphicon glyphicon-edit"></span></a>
<a href="{% url 'post_draft_list' %}" class="top-menu">Drafts</span></a>
```

Siguiente: ¡urls! en `blog/urls.py` vamos a agregar:
Expand Down Expand Up @@ -84,7 +84,9 @@ por estas:
{{ post.published_date }}
</div>
{% else %}
<a class="btn btn-default" href="{% url 'post_publish' pk=post.pk %}">Publish</a>
<form method="POST" action="{% url 'post_publish' pk=post.pk %}" class="post-form">{% csrf_token %}
<button type="submit" class="post btn btn-secondary" name="publish">Publish</button>
</form>
{% endif %}
```

Expand All @@ -93,15 +95,16 @@ Como puedes ver, hemos agregado la línea {% raw %}`{% else %}`{% endraw %}. Est
Tiempo de crear una URL (en `blog/urls.py`):

```python
path('post/<pk>/publish/', views.post_publish, name='post_publish'),
path('post/<int:pk>/publish/', views.post_publish, name='post_publish'),
```

Y finalmente una *vista* (como siempre, en `blog/views.py`):

```python
def post_publish(request, pk):
post = get_object_or_404(Post, pk=pk)
post.publish()
if request.method=='POST':
post.publish()
return redirect('post_detail', pk=pk)
```

Expand All @@ -126,23 +129,28 @@ Y de nuevo al publicar el post, ¡somos redirigidos inmediatamente a la página
Vamos a abrir `blog/templates/blog/post_detail.html` de nuevo y vamos a añadir esta línea

```django
<a class="btn btn-default" href="{% url 'post_remove' pk=post.pk %}"><span class="glyphicon glyphicon-remove"></span></a>
<form method="POST" action="{% url 'post_remove' pk=post.pk %}" class="post-form">{% csrf_token %}
<button type="submit" class="post btn btn-danger" name="delete">
Delete
</button>
</form>
```

Justo debajo de la línea co el botón editar.

Ahora necesitamos una URL (`blog/urls.py`):

```python
path('post/<pk>/remove/', views.post_remove, name='post_remove'),
path('post/<int:pk>/remove/', views.post_remove, name='post_remove'),
```

Ahora, ¡Tiempo para la vista! Abre `blog/views.py` y agrega este código:

```python
def post_remove(request, pk):
post = get_object_or_404(Post, pk=pk)
post.delete()
if request.method=='POST':
post.delete()
return redirect('post_list')
```

Expand Down
24 changes: 16 additions & 8 deletions fa/homework/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ post.published_date = timezone.now()
حالا می‌خواهیم در هدر فایل `blog/templates/blog/base.html` یک لینک اضافه کنیم. از آنجا که نمی‌خواهیم لیست پست‌های پیش‌نویس را به همه نشان بدهیم، پس این لینک رادر عبارت کنترلی {% raw %}`{% if user.is_authenticated %}`{% endraw %} و دقیقاً بعد از دکمه مربوط به اضافه کردن پست جدید، اضافه می‌کنیم.

```django
<a href="{% url 'post_draft_list' %}" class="top-menu"><span class="glyphicon glyphicon-edit"></span></a>
<a href="{% url 'post_draft_list' %}" class="top-menu">Drafts</span></a>
```

حالا وقت اصلاح urlها در فایل `blog/urls.py` است:
Expand Down Expand Up @@ -84,7 +84,9 @@ def post_draft_list(request):
{{ post.published_date }}
</div>
{% else %}
<a class="btn btn-default" href="{% url 'post_publish' pk=post.pk %}">Publish</a>
<form method="POST" action="{% url 'post_publish' pk=post.pk %}" class="post-form">{% csrf_token %}
<button type="submit" class="post btn btn-secondary" name="publish">Publish</button>
</form>
{% endif %}
```

Expand All @@ -93,15 +95,16 @@ def post_draft_list(request):
زمان ساختن یک URL (در فایل `blog/urls.py`) است:

```python
path('post/<pk>/publish/', views.post_publish, name='post_publish'),
path('post/<int:pk>/publish/', views.post_publish, name='post_publish'),
```

و در نهایت یک *ویو* (مانند همیشه در فایل `blog/views.py`) می‌سازیم:

```python
def post_publish(request, pk):
post = get_object_or_404(Post, pk=pk)
post.publish()
if request.method=='POST':
post.publish()
return redirect('post_detail', pk=pk)
```

Expand All @@ -115,7 +118,7 @@ def publish(self):

حالا بالاخره می‌توانیم از آن استفاده کنیم!

و یک بار دیگر بعد از انتشار پست ما بلافاصله به صفحه جزییات پست یا `post_detail` هدایت خواهیم شد!
و یک بار دیگر بعد از انتشار پست ما بلافاصله به صفحه جزییات پست یا `post_detail` هدایت خواهیم شد!

![Publish button](images/publish2.png)

Expand All @@ -126,23 +129,28 @@ def publish(self):
بیایید یک بار دیگر فایل `blog/templates/blog/post_detail.html` را باز کنید و این خط را به آن اضافه کنید:

```django
<a class="btn btn-default" href="{% url 'post_remove' pk=post.pk %}"><span class="glyphicon glyphicon-remove"></span></a>
<form method="POST" action="{% url 'post_remove' pk=post.pk %}" class="post-form">{% csrf_token %}
<button type="submit" class="post btn btn-danger" name="delete">
Delete
</button>
</form>
```

دقیقاً زیر خطی که دکمه اصلاح یا Edit button قرار دارد.

حالا یک URL لازم داریم (`blog/urls.py`):

```python
path('post/<pk>/remove/', views.post_remove, name='post_remove'),
path('post/<int:pk>/remove/', views.post_remove, name='post_remove'),
```

و الان زمان اضافه کردن یک ویو است! فایل `blog/views.py` را باز کنید و این کد را به آن اضافه کنید:

```python
def post_remove(request, pk):
post = get_object_or_404(Post, pk=pk)
post.delete()
if request.method=='POST':
post.delete()
return redirect('post_list')
```

Expand Down
22 changes: 15 additions & 7 deletions ja/homework/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Djangoのクエリセットを勉強した章を覚えていますか? `post_lis
`blog/templates/blog/base.html` のヘッダーにリンクを追加しましょう。草稿の一覧は誰でも見られるようにはしません。なので、 {% raw %}`{% if user.is_authenticated %}`{% endraw %} という条件の確認に続く箇所で、新しい投稿を追加するボタンのすぐ後にリンクを書いてください。

```django
<a href="{% url 'post_draft_list' %}" class="top-menu"><span class="glyphicon glyphicon-edit"></span></a>
<a href="{% url 'post_draft_list' %}" class="top-menu">Drafts</span></a>
```

次は `blog/urls.py` に、urlを追加しましょう!
Expand Down Expand Up @@ -84,7 +84,9 @@ def post_draft_list(request):
{{ post.published_date }}
</div>
{% else %}
<a class="btn btn-default" href="{% url 'post_publish' pk=post.pk %}">Publish</a>
<form method="POST" action="{% url 'post_publish' pk=post.pk %}" class="post-form">{% csrf_token %}
<button type="submit" class="post btn btn-secondary" name="publish">Publish</button>
</form>
{% endif %}
```

Expand All @@ -93,15 +95,16 @@ def post_draft_list(request):
それでは新しいURLを追加しましょう。( `blog/urls.py` に)

```python
path('post/<pk>/publish/', views.post_publish, name='post_publish'),
path('post/<int:pk>/publish/', views.post_publish, name='post_publish'),
```

最後に *ビュー* を追加します。(いつものように `blog/views.py` に)

```python
def post_publish(request, pk):
post = get_object_or_404(Post, pk=pk)
post.publish()
if request.method=='POST':
post.publish()
return redirect('post_detail', pk=pk)
```

Expand All @@ -127,21 +130,26 @@ def publish(self):
下の行を編集ボタンの行の直後に追加します:

```django
<a class="btn btn-default" href="{% url 'post_remove' pk=post.pk %}"><span class="glyphicon glyphicon-remove"></span></a>
<form method="POST" action="{% url 'post_remove' pk=post.pk %}" class="post-form">{% csrf_token %}
<button type="submit" class="post btn btn-danger" name="delete">
Delete
</button>
</form>
```

URLも必要ですね。( `blog/urls.py` に)

```python
path('post/<pk>/remove/', views.post_remove, name='post_remove'),
path('post/<int:pk>/remove/', views.post_remove, name='post_remove'),
```

次はビューも作りましょう。 `blog/views.py` を開いて下のコードを追加してください。

```python
def post_remove(request, pk):
post = get_object_or_404(Post, pk=pk)
post.delete()
if request.method=='POST':
post.delete()
return redirect('post_list')
```

Expand Down
26 changes: 17 additions & 9 deletions ko/homework/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ post.published_date = timezone.now()
새 글 추가하기 버튼 근처에 `blog/templates/blog/base.html` 링크를 추가하세요({% raw %}`<h1><a href="/">Django Girls Blog</a></h1>`{% endraw %}위에 바로 추가하면 됩니다!). 발행 전 미리 보기가 모두에게 보이는 걸 원치 않을 거예요. 새로운 글 추가하기 바로 아래에 {% raw %}`{% if user.is_authenticated %}`{% endraw %}을 추가해 주세요.

```django
<a href="{% url 'post_draft_list' %}" class="top-menu"><span class="glyphicon glyphicon-edit"></span></a>
<a href="{% url 'post_draft_list' %}" class="top-menu">Drafts</span></a>
```

다음: url입니다! `blog/urls.py`을 열고 아래 내용을 추가할 거에요.

```python
url(r'^drafts/$', views.post_draft_list, name='post_draft_list'),
path('drafts/', views.post_draft_list, name='post_draft_list'),
```

`blog/views.py`에 view를 생성할 차례입니다.
Expand Down Expand Up @@ -59,7 +59,7 @@ def post_draft_list(request):

`post_list.html` 템플릿과 코드가 많이 비슷해보이죠?

브라우저로 `http://127.0.0.1:8000/draft/` 페이지를 열어보면, 미 게시된 글목록을 확인할 수 있어요.
브라우저로 `http://127.0.0.1:8000/drafts/` 페이지를 열어보면, 미 게시된 글목록을 확인할 수 있어요.

야호! 첫 번째 일이 마쳤어요!

Expand All @@ -85,7 +85,9 @@ def post_draft_list(request):
{{ post.published_date }}
</div>
{% else %}
<a class="btn btn-default" href="{% url 'post_publish' pk=post.pk %}">Publish</a>
<form method="POST" action="{% url 'post_publish' pk=post.pk %}" class="post-form">{% csrf_token %}
<button type="submit" class="post btn btn-secondary" name="publish">Publish</button>
</form>
{% endif %}
```

Expand All @@ -94,15 +96,16 @@ def post_draft_list(request):
`blog/urls.py`에 URL 패턴을 추가해봅시다.

```python
url(r'^post/(?P<pk>\d+)/publish/$', views.post_publish, name='post_publish'),
path('post/<int:pk>/publish/', views.post_publish, name='post_publish'),
```

마지막으로 `post_publish` *뷰*를 `blog/views.py` 에 추가해봅시다.

```python
def post_publish(request, pk):
post = get_object_or_404(Post, pk=pk)
post.publish()
if request.method=='POST':
post.publish()
return redirect('post_detail', pk=pk)
```

Expand All @@ -127,23 +130,28 @@ def publish(self):
`blog/templates/blog/post_detail.html` 파일에 아래 코드를 추가해주세요.

```django
<a class="btn btn-default" href="{% url 'post_remove' pk=post.pk %}"><span class="glyphicon glyphicon-remove"></span></a>
<form method="POST" action="{% url 'post_remove' pk=post.pk %}" class="post-form">{% csrf_token %}
<button type="submit" class="post btn btn-danger" name="delete">
Delete
</button>
</form>
```

수정 버튼 바로 아래 줄에 추가해주세요.

(`blog/urls.py`)에 URL 패턴을 추가해봅시다:

```python
url(r'^post/(?P<pk>\d+)/remove/$', views.post_remove, name='post_remove'),
path('post/<int:pk>/remove/', views.post_remove, name='post_remove'),
```

이제 post_remove 뷰를 구현해봅시다. `blog/views.py` 에 아래 코드를 추가해주세요.

```python
def post_remove(request, pk):
post = get_object_or_404(Post, pk=pk)
post.delete()
if request.method=='POST':
post.delete()
return redirect('post_list')
```

Expand Down
Loading