-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Articles):Users can report Articles
- Loading branch information
kafuuma Henry
authored and
kafuuma Henry
committed
Dec 18, 2018
1 parent
16d90d8
commit 850eb93
Showing
7 changed files
with
227 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,4 +96,4 @@ db.sqlite3 | |
.vscode/ | ||
.DS_Store | ||
*.swp | ||
# migrations/ | ||
migrations/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class ReporteArticleAPIView(GenericAPIView): | ||
permission_classes = (IsAuthenticated,) | ||
renderer_classes = (ArticleReportJSONRenderer,) | ||
serializer_class = ReportArticleSerializer | ||
|
||
def post(self, request, *args, **kwargs): | ||
|
||
user_data = JWTAuthentication().authenticate(request) | ||
profile = Profile.objects.get(user__id=user_data[0].id) | ||
slug = kwargs['slug'] | ||
report = request.data.get('report', {}) | ||
if report == {}: | ||
return Response( | ||
{"errors": "Provide reason for reporting"}, | ||
status=status.HTTP_400_BAD_REQUEST | ||
) | ||
try: | ||
article_ob = Article.objects.get( | ||
slug=slug | ||
) | ||
except Article.DoesNotExist: | ||
return Response( | ||
{"errors": "This article doesnot exist"}, | ||
status=status.HTTP_404_NOT_FOUND | ||
) | ||
article_to_repot = ReportArticle.objects.filter( | ||
article_id=article_ob.id).first() | ||
|
||
if article_to_repot is not None: | ||
return Response( | ||
data={"errors": "This article has been reported already"}, | ||
status=status.HTTP_409_CONFLICT | ||
) | ||
serializer = self.serializer_class(data=report, partial=True) | ||
serializer.is_valid(raise_exception=True) | ||
serializer.save | ||
serializer.save( | ||
article=article_ob, | ||
reported_by=profile | ||
) | ||
article_ob.published = False | ||
reported_art_obj = ReportArticle.objects.filter( | ||
article_id=article_ob.id).first() | ||
serializerized_data = self.serializer_class(reported_art_obj) | ||
images = ArticleImg.objects.filter( | ||
article_id=reported_art_obj.article_id) | ||
image_list = list(images.values()) | ||
data = serializerized_data.data | ||
data['images'] = image_list | ||
data['message'] = 'article has been reported' | ||
return Response(data=data, status=status.HTTP_200_OK) |