From e6b7fdc594fc8077081fc233b6e343b986e018c3 Mon Sep 17 00:00:00 2001 From: mahdavi Date: Fri, 27 Mar 2020 00:19:26 +0430 Subject: [PATCH] remove notification app --- Pipfile | 2 -- Pipfile.lock | 28 ++++------------ apps/notifications/__init__.py | 0 apps/notifications/admin.py | 3 -- apps/notifications/apps.py | 5 --- apps/notifications/migrations/0001_initial.py | 28 ---------------- .../migrations/0002_auto_20200321_0854.py | 18 ----------- apps/notifications/migrations/__init__.py | 0 apps/notifications/models.py | 28 ---------------- apps/notifications/tasks.py | 32 ------------------- apps/notifications/tests.py | 3 -- apps/notifications/views.py | 3 -- apps/users/models.py | 5 ++- gooyal_accounts/__init__.py | 7 ---- gooyal_accounts/celery.py | 24 -------------- gooyal_accounts/settings.py | 1 - 16 files changed, 9 insertions(+), 178 deletions(-) delete mode 100644 apps/notifications/__init__.py delete mode 100644 apps/notifications/admin.py delete mode 100644 apps/notifications/apps.py delete mode 100644 apps/notifications/migrations/0001_initial.py delete mode 100644 apps/notifications/migrations/0002_auto_20200321_0854.py delete mode 100644 apps/notifications/migrations/__init__.py delete mode 100644 apps/notifications/models.py delete mode 100644 apps/notifications/tasks.py delete mode 100644 apps/notifications/tests.py delete mode 100644 apps/notifications/views.py delete mode 100644 gooyal_accounts/celery.py diff --git a/Pipfile b/Pipfile index 3ac0bc2..352b63c 100644 --- a/Pipfile +++ b/Pipfile @@ -17,8 +17,6 @@ django-model-utils = "*" mysqlclient = "*" django-mysql = "*" python-decouple = "*" -kavenegar = "*" -celery = "*" [requires] python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock index b4cf6ea..6688941 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "ac15ca54fa13ba02229053fc213eb914b17a1e63a5613810f124f0e6f766b8aa" + "sha256": "22ecb352f2ea0c572bef44b919bf830243068a64c19f8f13c4d8ce21df36b3da" }, "pipfile-spec": 6, "requires": { @@ -18,10 +18,10 @@ "default": { "asgiref": { "hashes": [ - "sha256:3e4192eaec0758b99722f0b0666d5fbfaa713054d92e8de5b58ba84ec5ce696f", - "sha256:c8f49dd3b42edcc51d09dd2eea8a92b3cfc987ff7e6486be734b4d0cbfd5d315" + "sha256:8036f90603c54e93521e5777b2b9a39ba1bad05773fcf2d208f0299d1df58ce5", + "sha256:9ca8b952a0a9afa61d30aa6d3d9b570bb3fd6bafcf7ec9e6bed43b936133db1c" ], - "version": "==3.2.5" + "version": "==3.2.7" }, "certifi": { "hashes": [ @@ -79,11 +79,11 @@ }, "django-oauth-toolkit": { "hashes": [ - "sha256:2c1e27f6c9b67782c86acbe38954b102e0593ba799cc69782f78448154127b6e", - "sha256:3c5233eaa3abdbc40c5a04c0eadea77cce098d3f91195272ab151bf68e6496b6" + "sha256:28508f83385ab4313936ddedfb310eaa8a1dcb737153d2956383ce47e75c2fab", + "sha256:d5a1044af9419ddc048390c5974777ea97874e5b78e33c609e17eebb8423afb2" ], "index": "pypi", - "version": "==1.3.0" + "version": "==1.3.2" }, "djangorestframework": { "hashes": [ @@ -100,13 +100,6 @@ ], "version": "==2.9" }, - "kavenegar": { - "hashes": [ - "sha256:37992560e93535b904ee908e26819713c5df28532edfc897767251f527b76f03" - ], - "index": "pypi", - "version": "==1.1.2" - }, "markdown": { "hashes": [ "sha256:90fee683eeabe1a92e149f7ba74e5ccdc81cd397bd6c516d93a8da0ef90b6902", @@ -194,13 +187,6 @@ "sha256:87716c2d2a7121198ebcb7ce7cccf6ce5e9ba539041cfbaeecfb641dc0bf6acc" ], "version": "==1.25.8" - }, - "uuid": { - "hashes": [ - "sha256:1f87cc004ac5120466f36c5beae48b4c48cc411968eed0eaecd3da82aa96193f" - ], - "index": "pypi", - "version": "==1.30" } }, "develop": {} diff --git a/apps/notifications/__init__.py b/apps/notifications/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/notifications/admin.py b/apps/notifications/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/apps/notifications/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/apps/notifications/apps.py b/apps/notifications/apps.py deleted file mode 100644 index a25babf..0000000 --- a/apps/notifications/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class NotificationsConfig(AppConfig): - name = 'apps.notifications' diff --git a/apps/notifications/migrations/0001_initial.py b/apps/notifications/migrations/0001_initial.py deleted file mode 100644 index 7b7f2e8..0000000 --- a/apps/notifications/migrations/0001_initial.py +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by Django 3.0.4 on 2020-03-21 02:33 - -from django.db import migrations, models -import uuid - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Notification', - fields=[ - ('uuid', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), - ('state', models.IntegerField(choices=[(1, 'created'), (2, 'delayed'), (3, 'pending'), (4, 'failed'), (5, 'done')], default=1)), - ('phone_number', models.CharField(blank=True, db_index=True, max_length=30, null=True)), - ('body', models.TextField(max_length=200)), - ('application_client_id', models.CharField(db_index=True, max_length=100, null=True)), - ('user_uuid', models.UUIDField(db_index=True, null=True)), - ('create', models.DateTimeField(auto_now=True, null=True, verbose_name='create')), - ('last_update', models.DateTimeField(auto_now=True, null=True, verbose_name='last update')), - ], - ), - ] diff --git a/apps/notifications/migrations/0002_auto_20200321_0854.py b/apps/notifications/migrations/0002_auto_20200321_0854.py deleted file mode 100644 index 3a023a8..0000000 --- a/apps/notifications/migrations/0002_auto_20200321_0854.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.0.4 on 2020-03-21 08:54 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('notifications', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='notification', - name='create', - field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='create'), - ), - ] diff --git a/apps/notifications/migrations/__init__.py b/apps/notifications/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/notifications/models.py b/apps/notifications/models.py deleted file mode 100644 index 3b7452c..0000000 --- a/apps/notifications/models.py +++ /dev/null @@ -1,28 +0,0 @@ -import uuid - -from django.db import models -from django.utils.translation import gettext_lazy as _ -from model_utils import Choices - - -class Notification(models.Model): - STATE_CHOICES = Choices( - (1, 'created', 'created'), - (2, 'delayed', 'delayed'), - (3, 'pending', 'pending'), - (4, 'failed', 'failed'), - (5, 'done', 'done'), - ) - uuid = models.UUIDField(primary_key=True, editable=False, default=uuid.uuid4, unique=True, - db_index=True) - state = models.IntegerField(choices=STATE_CHOICES, default=STATE_CHOICES.created) - phone_number = models.CharField(max_length=30, db_index=True, blank=True, null=True) - body = models.TextField(max_length=200) - application_client_id = models.CharField(max_length=100, db_index=True, null=True) - user_uuid = models.UUIDField(db_index=True, null=True) - create = models.DateTimeField(_('create'), blank=True, null=True, auto_now_add=True) - last_update = models.DateTimeField(_('last update'), blank=True, null=True, auto_now=True) - - def send(self): - from .tasks import send_sms - send_sms.delay(self.uuid) \ No newline at end of file diff --git a/apps/notifications/tasks.py b/apps/notifications/tasks.py deleted file mode 100644 index 5697c01..0000000 --- a/apps/notifications/tasks.py +++ /dev/null @@ -1,32 +0,0 @@ -from __future__ import absolute_import, unicode_literals - -from celery import shared_task -from apps.notifications.models import Notification -from django.conf import settings -from gooyal_accounts.celery import app -from kavenegar import * -api = KavenegarAPI(settings.SMS_KAVENEGAR_TOKEN) - -@shared_task -def send_sms(notification_uuid): - notification = Notification.objects.get(uuid=notification_uuid) - params = { - 'sender': settings.SMS_KAVENEGAR_SENDER, - 'receptor': notification.phone_number, - 'message': notification.body - } - response = api.sms_send(params) - mock_response = [ - {'messageid': 1088480346, - 'message': 'Gooyal OTP: 12345', - 'status': 1, - 'statustext': 'در صف ارسال', - 'sender': '1000596446', - 'receptor': '09106853582', - 'date': 1584797465, - 'cost': 402 - } - ] - # notification.state = - - print(response) diff --git a/apps/notifications/tests.py b/apps/notifications/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/apps/notifications/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/apps/notifications/views.py b/apps/notifications/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/apps/notifications/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/apps/users/models.py b/apps/users/models.py index 6e63324..23e8d85 100644 --- a/apps/users/models.py +++ b/apps/users/models.py @@ -169,13 +169,12 @@ class User(AbstractUser): self.notify(sms_body) def notify(self, body, notification_type='sms'): - from apps.notifications.models import Notification - notification = Notification.objects.create( + notification_client.send_request( user_uuid=self.uuid, phone_number=self.phone_number, body=body ) - notification.send() + def __str__(self): return f"{self.pk} - {self.username}" diff --git a/gooyal_accounts/__init__.py b/gooyal_accounts/__init__.py index d128d39..e69de29 100644 --- a/gooyal_accounts/__init__.py +++ b/gooyal_accounts/__init__.py @@ -1,7 +0,0 @@ -from __future__ import absolute_import, unicode_literals - -# This will make sure the app is always imported when -# Django starts so that shared_task will use this app. -from .celery import app as celery_app - -__all__ = ('celery_app',) \ No newline at end of file diff --git a/gooyal_accounts/celery.py b/gooyal_accounts/celery.py deleted file mode 100644 index e5d85f8..0000000 --- a/gooyal_accounts/celery.py +++ /dev/null @@ -1,24 +0,0 @@ -from __future__ import absolute_import, unicode_literals - -import os - -from celery import Celery - -# set the default Django settings module for the 'celery' program. -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gooyal_accounts.settings') - -app = Celery('gooyal_accounts') - -# Using a string here means the worker doesn't have to serialize -# the configuration object to child processes. -# - namespace='CELERY' means all celery-related configuration keys -# should have a `CELERY_` prefix. -app.config_from_object('django.conf:settings', namespace='CELERY') - -# Load task modules from all registered Django app configs. -app.autodiscover_tasks() - - -# @app.task(bind=True) -# def debug_task(self): -# print('Request: {0!r}'.format(self.request) \ No newline at end of file diff --git a/gooyal_accounts/settings.py b/gooyal_accounts/settings.py index 5fd7474..63ae3ee 100644 --- a/gooyal_accounts/settings.py +++ b/gooyal_accounts/settings.py @@ -42,7 +42,6 @@ INSTALLED_APPS = [ 'corsheaders', 'apps.users', 'apps.transactions', - 'apps.notifications', ] MIDDLEWARE = [