Skip to content

Commit

Permalink
Bug(get slug): return slug in notifications response
Browse files Browse the repository at this point in the history
- return article slug on notification response

[Finishes #165524386]
  • Loading branch information
kevpy committed Apr 23, 2019
1 parent 49a8dbb commit 6f6f579
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 deletions authors/apps/article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ def post(self, request):

NotifyMe.objects.create(
username=user,
notification="A new article from {}".format(author_name),
title="New Article")
notification="A new article titled {} from {}".format(article_title, author_name),
slug=serializer.data["slug"])

# End of notification sending

return Response(serializer.data, status=status.HTTP_201_CREATED)
Expand Down
1 change: 1 addition & 0 deletions authors/apps/profiles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class NotifyMe(models.Model):
article_id = models.CharField(blank=True, max_length=255)
if_read = models.BooleanField(default=False)
created = models.DateTimeField(auto_now_add=True)
slug = models.CharField(blank=True, max_length=255)

def created_time(self):
return timesince(self.created) + " " + "ago"
Expand Down
2 changes: 1 addition & 1 deletion authors/apps/profiles/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class NotifySerializer(serializers.ModelSerializer):

class Meta:
model = NotifyMe
fields = ["username", "notification", "title", "time_posted",]
fields = ["username", "notification", "time_posted", "slug", ]


class OptNotificationSerializer(serializers.ModelSerializer):
Expand Down
4 changes: 1 addition & 3 deletions authors/apps/profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def list(self, request, *args, **kwargs):

queryset = self.queryset.filter(Q(username_id__in=my_follows) | Q(article_id__in=my_articles))
serializer = self.serializer_class(queryset, many=True)
data = {obj['title'] + "-" + str(uuid.uuid4()): obj for obj in serializer.data}
data = {obj['slug'] + "-" + str(uuid.uuid4()): obj for obj in serializer.data}
return Response(data)


Expand Down Expand Up @@ -453,5 +453,3 @@ def update(self, request):
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


0 comments on commit 6f6f579

Please sign in to comment.