From ded6826d839dc95253e9ba3cd9fca1e5671922ba Mon Sep 17 00:00:00 2001 From: Philip M Otieno Date: Thu, 20 Jun 2019 17:43:10 +0300 Subject: [PATCH] 166872275-bg(Notifications):Fix get notification status -Added endpoint for getting notification status [starts #166872275] --- authors/apps/appnotifications/views.py | 7 +++++++ authors/apps/articles/models.py | 9 +-------- .../migrations/0002_auto_20190620_0920.py | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 authors/apps/profiles/migrations/0002_auto_20190620_0920.py diff --git a/authors/apps/appnotifications/views.py b/authors/apps/appnotifications/views.py index 66658f1..73a3e52 100644 --- a/authors/apps/appnotifications/views.py +++ b/authors/apps/appnotifications/views.py @@ -29,6 +29,13 @@ def update(self, request, *args, **kwargs): serializer.is_valid(raise_exception=True) serializer.save() return Response(serializer.data, status=status.HTTP_200_OK) + + def get(self, request, *args, **kwargs): + user = UserNotification.objects.get(user=request.user) + if user: + serializer = self.serializer_class(user, many=False) + print(serializer.data) + return Response(serializer.data, status=status.HTTP_200_OK) class UnsubscribeEmailAPIView(GenericAPIView): diff --git a/authors/apps/articles/models.py b/authors/apps/articles/models.py index 63e62ad..7ca587b 100644 --- a/authors/apps/articles/models.py +++ b/authors/apps/articles/models.py @@ -286,15 +286,8 @@ def ratings(self, article, user): Model to display rating for users in an articles """ - try: - article = self.article - user = self.rated_by - except Article.DoesNotExist: - pass - queryset = RatingModel.objects.filter( - article_id=article, rated_by_id=user).first() - + article_id=article).first() if queryset: return { "my_ratings": queryset.rate, diff --git a/authors/apps/profiles/migrations/0002_auto_20190620_0920.py b/authors/apps/profiles/migrations/0002_auto_20190620_0920.py new file mode 100644 index 0000000..6fbb003 --- /dev/null +++ b/authors/apps/profiles/migrations/0002_auto_20190620_0920.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2 on 2019-06-20 09:20 + +import cloudinary.models +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('profiles', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='profile', + name='image', + field=cloudinary.models.CloudinaryField(default='https://res.cloudinary.com/grean/image/upload/v1560445304/default_ddfimn.png', max_length=255, verbose_name='image'), + ), + ]