From 447a48c2b84f0609eca6b89c97bbd3d5252e94d4 Mon Sep 17 00:00:00 2001 From: arezoo88 Date: Fri, 22 Oct 2021 18:51:45 +0330 Subject: [PATCH 01/10] creating notification app --- notification/__init__.py | 0 notification/admin.py | 3 +++ notification/apps.py | 5 +++++ notification/migrations/__init__.py | 0 notification/models.py | 3 +++ notification/tests.py | 3 +++ notification/views.py | 3 +++ 7 files changed, 17 insertions(+) create mode 100644 notification/__init__.py create mode 100644 notification/admin.py create mode 100644 notification/apps.py create mode 100644 notification/migrations/__init__.py create mode 100644 notification/models.py create mode 100644 notification/tests.py create mode 100644 notification/views.py diff --git a/notification/__init__.py b/notification/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/notification/admin.py b/notification/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/notification/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/notification/apps.py b/notification/apps.py new file mode 100644 index 0000000..40b3eb9 --- /dev/null +++ b/notification/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class NotificationConfig(AppConfig): + name = 'notification' diff --git a/notification/migrations/__init__.py b/notification/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/notification/models.py b/notification/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/notification/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/notification/tests.py b/notification/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/notification/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/notification/views.py b/notification/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/notification/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From f34052c3c59b84287f2a3679d8cafc9bb57dd5c8 Mon Sep 17 00:00:00 2001 From: arezoo88 Date: Fri, 22 Oct 2021 21:47:51 +0330 Subject: [PATCH 02/10] add notification app into setting --- BaseDRF/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/BaseDRF/settings.py b/BaseDRF/settings.py index f2a5c3d..9bfae01 100644 --- a/BaseDRF/settings.py +++ b/BaseDRF/settings.py @@ -37,6 +37,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'notification' ] MIDDLEWARE = [ From f0931e79631e6a53601b1cb97010947393fa172c Mon Sep 17 00:00:00 2001 From: arezoo88 Date: Fri, 22 Oct 2021 21:48:42 +0330 Subject: [PATCH 03/10] create models notification --- notification/models.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/notification/models.py b/notification/models.py index 71a8362..153ad3b 100644 --- a/notification/models.py +++ b/notification/models.py @@ -1,3 +1,14 @@ from django.db import models +from django.contrib.auth.models import User +class UserNotification(models.Model): + user = models.OneToOneField(to=User,on_delete=models.DO_NOTHING) -# Create your models here. +class Notification(models.Model): + user_notification = models.ForeignKey(to=UserNotification,on_delete=models.DO_NOTHING) + TYPE = ( + (0, "Email"), + (2, "In app"), + (1, "SMS") + ) + + notif_type = models.CharField(max_length=10,choices=TYPE) \ No newline at end of file From 1b3132ca1e53a8eccb5130ca935636b3a4404878 Mon Sep 17 00:00:00 2001 From: arezoo88 Date: Fri, 22 Oct 2021 21:49:04 +0330 Subject: [PATCH 04/10] create api signal --- notification/signal.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 notification/signal.py diff --git a/notification/signal.py b/notification/signal.py new file mode 100644 index 0000000..9f2f7c9 --- /dev/null +++ b/notification/signal.py @@ -0,0 +1,10 @@ +from django.dispatch import receiver +from django.db.models.signals import post_save +from django.contrib.auth.models import User +from notification.models import UserNotification + + +@receiver(post_save, sender=User) +def auto_create_user_notification(sender, instance, created, **kwargs): + if created: + UserNotification.objects.create(user=instance) \ No newline at end of file From c303ba668e55a1e23eef895b52efb134477b75ef Mon Sep 17 00:00:00 2001 From: arezoo88 Date: Fri, 29 Oct 2021 18:36:35 +0330 Subject: [PATCH 05/10] add models into admin file --- notification/admin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/notification/admin.py b/notification/admin.py index 8c38f3f..ff4bb34 100644 --- a/notification/admin.py +++ b/notification/admin.py @@ -1,3 +1,4 @@ from django.contrib import admin - -# Register your models here. +from notification.models import * +admin.site.register(UserNotification) +admin.site.register(Notification) \ No newline at end of file From f2b324a9d51fe0f10fa4b3ed5c15e0390794014e Mon Sep 17 00:00:00 2001 From: arezoo Date: Thu, 4 Nov 2021 13:12:49 +0330 Subject: [PATCH 06/10] change types --- notification/models.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/notification/models.py b/notification/models.py index 153ad3b..8baa700 100644 --- a/notification/models.py +++ b/notification/models.py @@ -1,14 +1,18 @@ from django.db import models from django.contrib.auth.models import User class UserNotification(models.Model): - user = models.OneToOneField(to=User,on_delete=models.DO_NOTHING) + user = models.OneToOneField(to=User,on_delete=models.CASCADE) class Notification(models.Model): - user_notification = models.ForeignKey(to=UserNotification,on_delete=models.DO_NOTHING) - TYPE = ( - (0, "Email"), - (2, "In app"), - (1, "SMS") + user_notification = models.ForeignKey(to=UserNotification,on_delete=models.CASCADE) + TYPE_SMS = 'sms' + TYPE_EMAIL = 'email' + TYPE_IN_APP = 'In app' + + TYPES = ( + (TYPE_SMS, 'sms'), + (TYPE_EMAIL, 'email'), + (TYPE_IN_APP, 'In app'), ) - notif_type = models.CharField(max_length=10,choices=TYPE) \ No newline at end of file + notif_type = models.CharField(max_length=10,choices=TYPES) \ No newline at end of file From 871394d71ed2a8e7c2a41dc3209d0a9f4cbf68ae Mon Sep 17 00:00:00 2001 From: arezoo Date: Fri, 12 Nov 2021 15:09:07 +0330 Subject: [PATCH 07/10] import signals --- notification/apps.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/notification/apps.py b/notification/apps.py index 40b3eb9..a29a035 100644 --- a/notification/apps.py +++ b/notification/apps.py @@ -3,3 +3,5 @@ class NotificationConfig(AppConfig): name = 'notification' + def ready(self): + from . import signals \ No newline at end of file From ad8a2b6593da0cc6af9e0ce67ec5b4205a3a8caf Mon Sep 17 00:00:00 2001 From: arezoo Date: Fri, 12 Nov 2021 15:09:40 +0330 Subject: [PATCH 08/10] change way of importing notification app --- BaseDRF/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BaseDRF/settings.py b/BaseDRF/settings.py index 9bfae01..eae7067 100644 --- a/BaseDRF/settings.py +++ b/BaseDRF/settings.py @@ -37,7 +37,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'notification' + 'notification.apps.NotificationConfig' ] MIDDLEWARE = [ From 1b7b8bc3f2968aaf2a8beb9f04d513c9cbb4a947 Mon Sep 17 00:00:00 2001 From: arezoo Date: Fri, 12 Nov 2021 15:10:03 +0330 Subject: [PATCH 09/10] change name of signal file to signals --- notification/{signal.py => signals.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename notification/{signal.py => signals.py} (100%) diff --git a/notification/signal.py b/notification/signals.py similarity index 100% rename from notification/signal.py rename to notification/signals.py From 65520508787606693d1e817a5c427ac4c61ac64f Mon Sep 17 00:00:00 2001 From: arezoo Date: Fri, 12 Nov 2021 15:59:50 +0330 Subject: [PATCH 10/10] WIP --- notification/serializers.py | 15 +++++++++++++++ notification/views.py | 11 +++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 notification/serializers.py diff --git a/notification/serializers.py b/notification/serializers.py new file mode 100644 index 0000000..c959777 --- /dev/null +++ b/notification/serializers.py @@ -0,0 +1,15 @@ +from django.db import models +from rest_framework import fields,serializers + + +class NotificationInputsSerializer(serializers.Serializer): + TYPE_SMS = 'sms' + TYPE_EMAIL = 'email' + TYPE_IN_APP = 'In app' + + TYPES = ( + (TYPE_SMS, 'sms'), + (TYPE_EMAIL, 'email'), + (TYPE_IN_APP, 'In app'), + ) + notif_type = fields.ChoiceField(choices=TYPES) \ No newline at end of file diff --git a/notification/views.py b/notification/views.py index 91ea44a..e2102f8 100644 --- a/notification/views.py +++ b/notification/views.py @@ -1,3 +1,10 @@ +from django.contrib.auth.models import Permission from django.shortcuts import render - -# Create your views here. +from rest_framework import serializers +from rest_framework.generics import CreateAPIView +from .serializers import NotificationInputsSerializer +class Notification(CreateAPIView): + serializer_class = NotificationInputsSerializer + # Permission_classes = ? + def perform_create(self, serializer): + return super().perform_create(serializer)