Skip to content

Commit

Permalink
feat: Стартовый набор
Browse files Browse the repository at this point in the history
Основная часть:
 - Сделаны базовые методы для отправки смс
 - Заведена в админку возможность смотреть за логами смс
  • Loading branch information
iredun committed Jan 19, 2021
0 parents commit 96c124f
Show file tree
Hide file tree
Showing 21 changed files with 1,714 additions and 0 deletions.
118 changes: 118 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

.idea/*
.vscode/*

# Distribution / packaging
.Python
env/
venv/
tmp/
build/
develop-eggs/
dist/gi
static/
!**/api/static
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/
.vscode
# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

.DS_Store
*.sqlite3
media/
*.pyc
*.db
*.pid

.env.dev
.env.prod
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2021, Redun Ivan
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include LICENSE
include README.md
recursive-include smsru/locale *
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Django SMS.RU


Приложение Django для быстрой интеграции API сервиса [sms.ru](https://sms.ru/?panel=api)

Быстрый старт
-----------

1. Добавьте `smsru` в INSTALLED_APPS:
```
INSTALLED_APPS = [
...
'smsru',
]
```
2. В настройках так же следует добавить параметр `SMS_RU`:
```
SMS_RU = {
"API_ID": '<API KEY>', # если указан API ключ, логин и пароль пропускаем
"LOGIN": '<login>', # если нет API, то авторизуемся чезер логин и пароль
"PASSWORD": '<password>',
"TEST": True, # отправка смс в тестовом режиме, по умолчанию False
"SENDER": 'sms', # отправитель - необязательно поле
"PARTNER_ID": 1111 # ID партнера - необязательно поле
}
```

3. Добавьте в свой `urls.py` импорт URL (для работы callback, по желанию):
```
path('smsru/', include('smsru.urls'))
```

4. Запустите ``python manage.py migrate`` для создания необъодимых таблиц.

5. В админ панели вы сможете увидеть лог сообщений и запросить статус любого из них.

6. Так же добавилась консольная команда для отправки смс
```
python manage.py send-sms-ru --phone +79888888888 --msg Тест
```

# Использование библиотеки в коде
```python
from smsru.service import SmsRuApi
api = SmsRuApi()
result = api.send_one_sms("+79888888888", "Test")
# result: {'79888888888': True}
```
31 changes: 31 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[metadata]
name = django-smsru
version = 0.1.0
description = Django app for sms.ru.
long_description = file: README.md
url = 'https://github.com/iredun/django-smsru'
author = 'Redun Ivan'
author_email = [email protected]
license = BSD 3-Clause License
install_requires =
requests
Django
classifiers =
Environment :: Web Environment
Framework :: Django
Framework :: Django :: 3.0
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Topic :: Internet :: WWW/HTTP
Topic :: Internet :: WWW/HTTP :: Dynamic Content

[options]
include_package_data = true
packages = find:
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from setuptools import setup

setup()
Empty file added smsru/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions smsru/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from typing import List

from django.contrib import admin
from smsru.models import Log

from django.utils.translation import gettext as _

from smsru.service import SmsRuApi


def update_sms_status(model, request, queryset):
api = SmsRuApi()
for item in queryset:
if item.sms_id:
result, data = api.get_status(item.sms_id)
if result:
item.status = data['status']
item.status_code = data['status_code']
item.status_text = data['status_text']
item.save()


update_sms_status.short_description = _("Update selected sms status")


@admin.register(Log)
class LogAdmin(admin.ModelAdmin):
list_display = ['phone', 'sms_id', 'msg', 'status', 'status_text', 'created_at']
date_hierarchy = 'created_at'
actions = [update_sms_status]
5 changes: 5 additions & 0 deletions smsru/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class SmsruConfig(AppConfig):
name = 'smsru'
Binary file added smsru/locale/ru/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit 96c124f

Please sign in to comment.