Allow empty tags in live preview

This commit is contained in:
Gabriel Augendre 2021-03-06 15:11:17 +01:00
parent 70946c6bfd
commit d66a2168a5
2 changed files with 16 additions and 2 deletions

View file

@ -57,6 +57,16 @@ def test_render_article_doesnt_save(published_article, client: Client):
assert published_article.content == original_content
@pytest.mark.django_db
def test_render_article_no_tags(published_article, client: Client):
client.force_login(published_article.author)
api_res = client.post(
reverse("api-render-article", kwargs={"article_pk": published_article.pk}),
data={"content": published_article.content, "tag_ids": ""},
)
assert api_res.status_code == 200
def post_article(client: Client, article: Article, content: str):
return client.post(
reverse("api-render-article", kwargs={"article_pk": article.pk}),

View file

@ -17,6 +17,10 @@ def render_article(request, article_pk):
has_code = request.POST.get("has_code")
if has_code is not None:
article.has_code = has_code == "true"
tags = Tag.objects.filter(pk__in=map(int, request.POST.get("tag_ids").split(",")))
html = render(request, template, context={"article": article, "tags": tags})
context = {"article": article}
tags = request.POST.get("tag_ids")
if tags:
tags = Tag.objects.filter(pk__in=map(int, tags.split(",")))
context["tags"] = tags
html = render(request, template, context=context)
return HttpResponse(html)