Allow empty tags in live preview
This commit is contained in:
parent
70946c6bfd
commit
d66a2168a5
2 changed files with 16 additions and 2 deletions
|
@ -57,6 +57,16 @@ def test_render_article_doesnt_save(published_article, client: Client):
|
||||||
assert published_article.content == original_content
|
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):
|
def post_article(client: Client, article: Article, content: str):
|
||||||
return client.post(
|
return client.post(
|
||||||
reverse("api-render-article", kwargs={"article_pk": article.pk}),
|
reverse("api-render-article", kwargs={"article_pk": article.pk}),
|
||||||
|
|
|
@ -17,6 +17,10 @@ def render_article(request, article_pk):
|
||||||
has_code = request.POST.get("has_code")
|
has_code = request.POST.get("has_code")
|
||||||
if has_code is not None:
|
if has_code is not None:
|
||||||
article.has_code = has_code == "true"
|
article.has_code = has_code == "true"
|
||||||
tags = Tag.objects.filter(pk__in=map(int, request.POST.get("tag_ids").split(",")))
|
context = {"article": article}
|
||||||
html = render(request, template, context={"article": article, "tags": tags})
|
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)
|
return HttpResponse(html)
|
||||||
|
|
Reference in a new issue