-
Notifications
You must be signed in to change notification settings - Fork 4
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
#163499467 Save article draft #32
Conversation
serializer_class = PublishArticleSerializer | ||
lookup_field = 'slug' | ||
|
||
|
||
class DeleteArticle(UpdateAPIView): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a class comment
ca1a446
to
480d17b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
@@ -19,6 +19,10 @@ class Article(models.Model): | |||
is_published = models.BooleanField(default=False) | |||
favorite = models.ManyToManyField( | |||
User, related_name='favorite', default=False) | |||
|
|||
favorite = models.ManyToManyField(User, related_name='favorite', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
favorites is duplicated
50a040d
to
c07e506
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See these
thread_comment = super( | ||
CommentSerializer, self).to_representation(instance) | ||
|
||
thread_comment = super(CommentSerializer, self).to_representation( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate
authors/apps/articles/urls.py
Outdated
LikeCommentApiView, DislikeCommentApiView | ||
LikeCommentApiView, DislikeCommentApiView, | ||
ReadTime, PublishArticle, GetDraft, | ||
PublishArticle, GetDraft |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate imports
authors/apps/articles/urls.py
Outdated
@@ -58,4 +60,10 @@ | |||
LikeCommentApiView.as_view(), name='comment_like'), | |||
path('articles/<slug>/comments/<int:id>/dislike', | |||
DislikeCommentApiView.as_view(), name='comment_dislike'), | |||
|
|||
path('article/<slug>/publish/', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
articles/
authors/apps/articles/views.py
Outdated
class GetDraft(ListAPIView): | ||
"""Get all Drafts""" | ||
pagination_class = CustomPagination | ||
permission_classes = (IsAuthorOrReadOnly,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll still be able to see drafts of other authors
permission_classes = (IsAuthorOrReadOnly,) | ||
queryset = Article.objects.filter(is_deleted=False, is_published=False) | ||
serializer_class = PublishArticleSerializer | ||
lookup_field = 'slug' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's return the published article
self.create_article(self.create_article_data, token) | ||
self.create_article(self.create_article_data2, token) | ||
# publish articles | ||
self.client.put(reverse('articles:publish_article', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert the value of is_published
is as expected before and after publishing
token = self.signup_user_one() | ||
del self.create_article_data['images'] | ||
response = self.client.post(self.article_listcreate, | ||
self.create_article_data, | ||
format='json', | ||
HTTP_AUTHORIZATION='token {}'.format(token)) | ||
HTTP_AUTHORIZATION='token {}'.format( | ||
token)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also assert the value of is_published, that's what makes it a draft
authors/apps/articles/urls.py
Outdated
path('article/<slug>/publish/', | ||
PublishArticle.as_view(), | ||
name="publish_article"), | ||
path('article/draft/', GetDraft.as_view(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
articles/drafts/
f695003
to
234b92c
Compare
response = self.client.get(self.article_listcreate, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(response.data['results'][0]['is_published'], True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertTrue
self.create_article(self.create_article_data, token) | ||
self.create_article(self.create_article_data2, token) | ||
# publish articles | ||
self.assertNotEqual(self.create_article_data['is_published'], True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertFalse
authors/apps/articles/views.py
Outdated
class GetDraft(ListAPIView): | ||
"""Get all Drafts""" | ||
pagination_class = CustomPagination | ||
permission_classes = (IsAuthenticated,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create an isAuthor
class for this... so only an author can see his drafts
- Allow user to create a draft - Allow user to publish [Delivers #162948852]
cc2a96f
to
7e5c503
Compare
What does this PR do?
Description of Task to be completed?
How should this be manually tested?
Clone the repo locally
cd ah-django-unchained
git checkout ft-save-article-draft-163499467
get started with the app as from the README section. Follow the sample .env file supplied to obtain the right variables
SCREENSHOTS
Create an article draft
Get all drafts
Publish Article