Skip to content
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

Merged
merged 14 commits into from
Feb 3, 2019

Conversation

MaggieChege
Copy link
Contributor

What does this PR do?

  • A user can create an article draft.
  • A user can publish the article later.
  • A user can view all the drafts he/she has.

Description of Task to be completed?

  • A user can create an article draft and publish it later.

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

image

Get all drafts

image

Publish Article

image

@MaggieChege MaggieChege changed the title #163499467save article draft #163499467 . save article draft Jan 31, 2019
@MaggieChege MaggieChege changed the title #163499467 . save article draft #163499467 save article draft Jan 31, 2019
@MaggieChege MaggieChege changed the title #163499467 save article draft #163499467 Save article draft Jan 31, 2019
serializer_class = PublishArticleSerializer
lookup_field = 'slug'


class DeleteArticle(UpdateAPIView):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a class comment

@MaggieChege MaggieChege force-pushed the ft-save-article-draft-163499467 branch from ca1a446 to 480d17b Compare February 1, 2019 06:21
@d-kahara d-kahara temporarily deployed to ah-django-unchained-stag-pr-32 February 1, 2019 06:21 Inactive
Copy link
Contributor

@d-kahara d-kahara left a 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

@d-kahara d-kahara temporarily deployed to ah-django-unchained-stag-pr-32 February 1, 2019 07:28 Inactive
@@ -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',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

favorites is duplicated

@MaggieChege MaggieChege force-pushed the ft-save-article-draft-163499467 branch from 50a040d to c07e506 Compare February 1, 2019 10:18
@d-kahara d-kahara temporarily deployed to ah-django-unchained-stag-pr-32 February 1, 2019 10:19 Inactive
@d-kahara d-kahara temporarily deployed to ah-django-unchained-stag-pr-32 February 1, 2019 10:21 Inactive
@d-kahara d-kahara temporarily deployed to ah-django-unchained-stag-pr-32 February 1, 2019 10:22 Inactive
Copy link

@ignatiusukwuoma ignatiusukwuoma left a 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(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate

LikeCommentApiView, DislikeCommentApiView
LikeCommentApiView, DislikeCommentApiView,
ReadTime, PublishArticle, GetDraft,
PublishArticle, GetDraft

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate imports

@@ -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/',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

articles/

class GetDraft(ListAPIView):
"""Get all Drafts"""
pagination_class = CustomPagination
permission_classes = (IsAuthorOrReadOnly,)

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'

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',

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))

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

path('article/<slug>/publish/',
PublishArticle.as_view(),
name="publish_article"),
path('article/draft/', GetDraft.as_view(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

articles/drafts/

@MaggieChege MaggieChege force-pushed the ft-save-article-draft-163499467 branch from f695003 to 234b92c Compare February 2, 2019 13:46
@d-kahara d-kahara temporarily deployed to ah-django-unchained-stag-pr-32 February 2, 2019 13:46 Inactive
@d-kahara d-kahara temporarily deployed to ah-django-unchained-stag-pr-32 February 2, 2019 14:33 Inactive
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)

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertFalse

@d-kahara d-kahara temporarily deployed to ah-django-unchained-stag-pr-32 February 2, 2019 15:29 Inactive
class GetDraft(ListAPIView):
"""Get all Drafts"""
pagination_class = CustomPagination
permission_classes = (IsAuthenticated,)

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

Margaret Chege added 2 commits February 3, 2019 17:03
- Allow user to create a draft
- Allow user to publish
[Delivers #162948852]
@MaggieChege MaggieChege force-pushed the ft-save-article-draft-163499467 branch from cc2a96f to 7e5c503 Compare February 3, 2019 14:07
@d-kahara d-kahara temporarily deployed to ah-django-unchained-stag-pr-32 February 3, 2019 14:07 Inactive
@d-kahara d-kahara temporarily deployed to ah-django-unchained-stag-pr-32 February 3, 2019 14:31 Inactive
@d-kahara d-kahara temporarily deployed to ah-django-unchained-stag-pr-32 February 3, 2019 15:37 Inactive
@d-kahara d-kahara temporarily deployed to ah-django-unchained-stag-pr-32 February 3, 2019 15:48 Inactive
@ignatiusukwuoma ignatiusukwuoma merged commit acf9f9b into master Feb 3, 2019
@ignatiusukwuoma ignatiusukwuoma deleted the ft-save-article-draft-163499467 branch February 3, 2019 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants