Skip to content

Commit

Permalink
Adding tests for delete_article and edit_article
Browse files Browse the repository at this point in the history
  • Loading branch information
finziamit committed Jan 18, 2023
1 parent dc10355 commit 785c8de
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions projboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,15 @@ def edit_article(request, article_pk=None):
try:
article = Article.objects.get(id=article_pk)
user_id = article.user_id

title = article.title
subject_id = article.subject_id
content = article.content
initial = {'user_id': user_id, 'title': title, 'subject_id': subject_id, 'content': content}

initial = {'title': title, 'subject_id': subject_id, 'content': content}

if request.method == "POST":
form = EditArticleForm(request.POST, initial)
form = EditArticleForm(request.POST)
if form.is_valid():
article.edit(form.data['title'], form.data['content'], form.cleaned_data['subject_id'])
return redirect(f"/my_articles/{user_id.nickname}/")
Expand All @@ -190,8 +193,7 @@ def edit_article(request, article_pk=None):
form = EditArticleForm(initial=initial)

return render(request, 'editArticle/edit_article.html', {
'user_id': user_id,
'form': form,
'form': form
})
except Article.DoesNotExist:
raise Http404()

0 comments on commit 785c8de

Please sign in to comment.