remove notification app

This commit is contained in:
mahdavi 2020-03-27 00:19:26 +04:30
parent 450eff5a17
commit e6b7fdc594
16 changed files with 9 additions and 178 deletions

View file

@ -17,8 +17,6 @@ django-model-utils = "*"
mysqlclient = "*"
django-mysql = "*"
python-decouple = "*"
kavenegar = "*"
celery = "*"
[requires]
python_version = "3.7"

28
Pipfile.lock generated
View file

@ -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": {}

View file

@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View file

@ -1,5 +0,0 @@
from django.apps import AppConfig
class NotificationsConfig(AppConfig):
name = 'apps.notifications'

View file

@ -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')),
],
),
]

View file

@ -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'),
),
]

View file

@ -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)

View file

@ -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)

View file

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.

View file

@ -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}"

View file

@ -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',)

View file

@ -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)

View file

@ -42,7 +42,6 @@ INSTALLED_APPS = [
'corsheaders',
'apps.users',
'apps.transactions',
'apps.notifications',
]
MIDDLEWARE = [