Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Update template
Browse files Browse the repository at this point in the history
  • Loading branch information
blablatdinov committed Sep 22, 2023
1 parent 7444c72 commit b772a6c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions server/apps/pictures/templates/pictures/pages/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ <h3>Профиль</h3>
<input type="hidden" name="url" value="{{ picture.url }}" />
<button type="submit">Добавить в избранное</button>
</form>
<form method="post" action="{% url 'pictures:remove_favourite' picture_id=picture.id %}">
{% csrf_token %}
<button type="submit">Удалить из избранного</button>
</form>
</div>
<hr />
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions server/apps/pictures/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ def get_queryset(self) -> QuerySet[FavouritePicture]:
@dispatch_decorator(login_required)
class FavouriteDeleteView(View):

def delete(self, request, picture_id):
FavouritePicture.objects.filter(id=picture_id, user=request.user).delete()
def post(self, request, picture_id):
FavouritePicture.objects.filter(foreign_id=picture_id, user=request.user).delete()
return HttpResponseRedirect(reverse('pictures:dashboard'))
2 changes: 1 addition & 1 deletion tests/test_apps/test_pictures/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_create(user_client, exists_user):
@pytest.mark.usefixtures()
def test_delete(user_client, exists_user, existed_picture):
"""Test delete picture from favourite."""
got = user_client.delete('/pictures/favourites/{0}'.format(existed_picture.id))
got = user_client.delete('/pictures/favourites/{0}'.format(existed_picture.foreign_id))

assert got.status_code == HTTPStatus.FOUND
assert got.headers['location'] == '/pictures/dashboard'
Expand Down

0 comments on commit b772a6c

Please sign in to comment.