Compare commits
No commits in common. 'master' and 'auth_koop' have entirely different histories.
43 changed files with 165 additions and 1414 deletions
@ -1,16 +0,0 @@
|
||||
""" |
||||
ASGI config for adminpanel project. |
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``. |
||||
|
||||
For more information on this file, see |
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ |
||||
""" |
||||
|
||||
import os |
||||
|
||||
from django.core.asgi import get_asgi_application |
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'adminpanel.settings') |
||||
|
||||
application = get_asgi_application() |
@ -1,23 +0,0 @@
|
||||
g_telegram_bot_api_token = '' |
||||
# --------------------------------------------------------- |
||||
# Файлы для настройки, которые не коммитятся в git |
||||
telegram_bot_api_token_file_name = 'config_telegram_bot_api_token' |
||||
# --------------------------------------------------------- |
||||
# Дополнительные функции |
||||
def GetFirstLineFromFile(a_FileName): |
||||
f = open(a_FileName, 'r') |
||||
result = f.readline() |
||||
f.close() |
||||
return result |
||||
def GetAllLinesFromFile(a_FileName): |
||||
f = open(a_FileName, 'r') |
||||
result = f.readlines() |
||||
f.close() |
||||
return result |
||||
# --------------------------------------------------------- |
||||
# Основные функции |
||||
def GetTelegramBotApiToken(): |
||||
global g_telegram_bot_api_token |
||||
if len(g_telegram_bot_api_token) == 0: |
||||
g_telegram_bot_api_token = str().strip(GetFirstLineFromFile(telegram_bot_api_token_file_name)) |
||||
return g_telegram_bot_api_token |
@ -1,126 +0,0 @@
|
||||
""" |
||||
Django settings for adminpanel project. |
||||
|
||||
Generated by 'django-admin startproject' using Django 4.1.4. |
||||
|
||||
For more information on this file, see |
||||
https://docs.djangoproject.com/en/4.1/topics/settings/ |
||||
|
||||
For the full list of settings and their values, see |
||||
https://docs.djangoproject.com/en/4.1/ref/settings/ |
||||
""" |
||||
import os |
||||
from pathlib import Path |
||||
from dotenv import load_dotenv |
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'. |
||||
BASE_DIR = Path(__file__).resolve().parent.parent |
||||
|
||||
# Quick-start development settings - unsuitable for production |
||||
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ |
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret! |
||||
load_dotenv() |
||||
SECRET_KEY = os.getenv('PLATFORM_ADMINPANEL_SECRET_KEY') |
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production! |
||||
DEBUG = False |
||||
|
||||
ALLOWED_HOSTS = ['*'] |
||||
|
||||
# Application definition |
||||
|
||||
INSTALLED_APPS = [ |
||||
'django.contrib.admin', |
||||
'django.contrib.auth', |
||||
'django.contrib.contenttypes', |
||||
'django.contrib.sessions', |
||||
'django.contrib.messages', |
||||
'django.contrib.staticfiles', |
||||
'adminpanelapp', |
||||
|
||||
] |
||||
|
||||
MIDDLEWARE = [ |
||||
'django.middleware.security.SecurityMiddleware', |
||||
'django.contrib.sessions.middleware.SessionMiddleware', |
||||
'django.middleware.common.CommonMiddleware', |
||||
'django.middleware.csrf.CsrfViewMiddleware', |
||||
'django.contrib.auth.middleware.AuthenticationMiddleware', |
||||
'django.contrib.messages.middleware.MessageMiddleware', |
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware', |
||||
] |
||||
|
||||
ROOT_URLCONF = 'adminpanel.urls' |
||||
|
||||
TEMPLATES = [ |
||||
{ |
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates', |
||||
'DIRS': [], |
||||
'APP_DIRS': True, |
||||
'OPTIONS': { |
||||
'context_processors': [ |
||||
'django.template.context_processors.debug', |
||||
'django.template.context_processors.request', |
||||
'django.contrib.auth.context_processors.auth', |
||||
'django.contrib.messages.context_processors.messages', |
||||
], |
||||
}, |
||||
}, |
||||
] |
||||
|
||||
WSGI_APPLICATION = 'adminpanel.wsgi.application' |
||||
|
||||
# Database |
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases |
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
||||
DATABASES = { |
||||
'default': { |
||||
'ENGINE': 'django.db.backends.sqlite3', |
||||
'NAME': os.path.join(BASE_DIR, 'bot.db'), |
||||
} |
||||
} |
||||
|
||||
|
||||
# Password validation |
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators |
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [ |
||||
{ |
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', |
||||
}, |
||||
{ |
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', |
||||
}, |
||||
{ |
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', |
||||
}, |
||||
{ |
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', |
||||
}, |
||||
] |
||||
|
||||
# Internationalization |
||||
# https://docs.djangoproject.com/en/4.1/topics/i18n/ |
||||
|
||||
LANGUAGE_CODE = 'ru' |
||||
|
||||
TIME_ZONE = 'UTC' |
||||
|
||||
USE_I18N = True |
||||
|
||||
USE_TZ = True |
||||
|
||||
# Static files (CSS, JavaScript, Images) |
||||
# https://docs.djangoproject.com/en/4.1/howto/static-files/ |
||||
|
||||
STATIC_URL = 'static/' |
||||
|
||||
# Default primary key field type |
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field |
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' |
||||
|
||||
ASGI_APPLICATION = 'adminpanelapp.asgi.application' |
||||
ASYNC_MODE = 'django' |
@ -1,11 +0,0 @@
|
||||
from django.contrib import admin |
||||
from django.urls import path, include |
||||
from django.views.generic import RedirectView |
||||
from django.conf import settings |
||||
from django.conf.urls.static import static |
||||
|
||||
urlpatterns = [ |
||||
path('admin/', admin.site.urls), |
||||
path('', include('adminpanelapp.urls')), |
||||
path('', RedirectView.as_view(url='/admin/adminpanelapp/orders'), name='') |
||||
] |
@ -1,15 +0,0 @@
|
||||
""" |
||||
WSGI config for adminpanel project. |
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``. |
||||
|
||||
For more information on this file, see |
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ |
||||
""" |
||||
|
||||
import os |
||||
|
||||
from django.core.wsgi import get_wsgi_application |
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'adminpanel.settings') |
||||
application = get_wsgi_application() |
@ -1,40 +0,0 @@
|
||||
from django.http import HttpResponseRedirect |
||||
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME |
||||
from django.utils.safestring import mark_safe |
||||
from .models import Orders |
||||
|
||||
from django.contrib import admin, messages |
||||
from django.urls import reverse |
||||
|
||||
class OrdersAdmin(admin.ModelAdmin): |
||||
list_display = ('orderName', 'orderCreateDateTime', 'orderDesc', 'orderAddress', 'show_photo', 'show_photopay') |
||||
actions =['send_message'] |
||||
exclude = ['orderAccess', 'userID', 'orderPhoto', 'orderPhotoPay'] |
||||
|
||||
def show_photo(self, obj): |
||||
html = obj.get_photo_html() |
||||
return mark_safe(html) |
||||
|
||||
show_photo.short_description = 'Фото' |
||||
|
||||
def show_photopay(self, obj): |
||||
html = obj.get_photopay_html() |
||||
return mark_safe(html) |
||||
|
||||
show_photopay.short_description = 'Чек' |
||||
|
||||
def send_message(orders, request, queryset): |
||||
selected_objects = request.POST.getlist(ACTION_CHECKBOX_NAME) |
||||
if len(selected_objects) != 1: |
||||
messages.error(request, "Выберите только один объект") |
||||
return |
||||
|
||||
selected_user_id = int(selected_objects[0]) |
||||
obj = queryset.get(orderID=selected_user_id) |
||||
user_id = obj.userID |
||||
url = reverse('send_telegram_message', kwargs={'chat_id': user_id}) |
||||
return HttpResponseRedirect(url) |
||||
|
||||
send_message.short_description = 'Отправка сообщения' |
||||
|
||||
admin.site.register(Orders, OrdersAdmin) |
@ -1,5 +0,0 @@
|
||||
from django.apps import AppConfig |
||||
|
||||
class AdminpanelappConfig(AppConfig): |
||||
default_auto_field = 'django.db.models.BigAutoField' |
||||
name = 'adminpanelapp' |
@ -1,142 +0,0 @@
|
||||
import time |
||||
from urllib.parse import quote |
||||
|
||||
import requests |
||||
from django.db import models |
||||
|
||||
from bot_sys.config import GetTelegramBotApiToken |
||||
|
||||
class Orders(models.Model): |
||||
orderID = models.AutoField(primary_key=True, verbose_name='id заказа') |
||||
userID = models.CharField(max_length=100, verbose_name='id пользователя в tg', null=True) |
||||
orderName = models.CharField(max_length=100, verbose_name='наименование', null=True) |
||||
orderDesc = models.TextField(verbose_name='описание', null=True) |
||||
orderPhoto = models.ImageField(verbose_name='фото', null=True) |
||||
orderPhotoPay = models.ImageField(verbose_name='чек') |
||||
orderAddress = models.CharField(max_length=100, verbose_name='адрес доставки', blank=True, null=True) |
||||
orderAccess = models.CharField(max_length=100, verbose_name='доступ', blank=True, null=True) |
||||
orderCreateDateTime = models.DateTimeField(auto_now_add=True, null=True, verbose_name='дата и время создания') |
||||
orderStatus = models.CharField(max_length=100, verbose_name='статус заказа', blank=True, null=True) |
||||
|
||||
def get_photo_html(self, width=100, height=100, large_width=400, large_height=400): |
||||
file_id = self.orderPhoto |
||||
token = GetTelegramBotApiToken() |
||||
url = f"https://api.telegram.org/bot{token}/getFile?file_id={file_id}" |
||||
|
||||
response = requests.get(url) |
||||
data = response.json() |
||||
|
||||
if data['ok']: |
||||
file_path = data["result"]["file_path"] |
||||
photo_url = f"https://api.telegram.org/file/bot{token}/{quote(file_path, safe='')}" |
||||
|
||||
html = f""" |
||||
<html> |
||||
<body> |
||||
<img src="{photo_url}" width="{width}" height="{height}" class="small-photo"> |
||||
<img src="{photo_url}" width="{large_width}" height="{large_height}" class="large-photo"> |
||||
<a href="#" onclick="togglePhoto(event)" class="button">Увеличить фото</a> |
||||
<script> |
||||
function togglePhoto(event) {{ |
||||
var toggleButton = event.target; |
||||
var container = toggleButton.parentNode; |
||||
var smallPhoto = container.querySelector(".small-photo"); |
||||
var largePhoto = container.querySelector(".large-photo"); |
||||
|
||||
if (smallPhoto.style.display === "none") {{ |
||||
smallPhoto.style.display = "block"; |
||||
largePhoto.style.display = "none"; |
||||
toggleButton.innerHTML = "Увеличить фото"; |
||||
}} else {{ |
||||
smallPhoto.style.display = "none"; |
||||
largePhoto.style.display = "block"; |
||||
toggleButton.innerHTML = "Уменьшить фото"; |
||||
}} |
||||
}} |
||||
</script> |
||||
<style> |
||||
.large-photo {{ |
||||
display: none; |
||||
}} |
||||
.button {{ |
||||
display: inline-block; |
||||
padding: 10px 20px; |
||||
background-color: #4CAF50; |
||||
color: white; |
||||
text-align: center; |
||||
text-decoration: none; |
||||
font-size: 16px; |
||||
border: none; |
||||
border-radius: 5px; |
||||
cursor: pointer; |
||||
}} |
||||
</style> |
||||
</body> |
||||
</html> |
||||
""" |
||||
return html |
||||
|
||||
|
||||
def get_photopay_html(self, width=100, height=100, large_width=400, large_height=400): |
||||
token = GetTelegramBotApiToken() |
||||
file_id = self.orderPhotoPay |
||||
url = f"https://api.telegram.org/bot{token}/getFile?file_id={file_id}" |
||||
|
||||
response = requests.get(url) |
||||
data = response.json() |
||||
|
||||
if data['ok']: |
||||
file_path = data["result"]["file_path"] |
||||
photo_url = f"https://api.telegram.org/file/bot{token}/{quote(file_path, safe='')}" |
||||
|
||||
html = f""" |
||||
<html> |
||||
<body> |
||||
<img src="{photo_url}" width="{width}" height="{height}" class="small-photo"> |
||||
<img src="{photo_url}" width="{large_width}" height="{large_height}" class="large-photo"> |
||||
<a href="#" onclick="togglePhoto(event)" class="button">Увеличить фото</a> |
||||
<script> |
||||
function togglePhoto(event) {{ |
||||
var toggleButton = event.target; |
||||
var container = toggleButton.parentNode; |
||||
var smallPhoto = container.querySelector(".small-photo"); |
||||
var largePhoto = container.querySelector(".large-photo"); |
||||
|
||||
if (smallPhoto.style.display === "none") {{ |
||||
smallPhoto.style.display = "block"; |
||||
largePhoto.style.display = "none"; |
||||
toggleButton.innerHTML = "Увеличить фото"; |
||||
}} else {{ |
||||
smallPhoto.style.display = "none"; |
||||
largePhoto.style.display = "block"; |
||||
toggleButton.innerHTML = "Уменьшить фото"; |
||||
}} |
||||
}} |
||||
</script> |
||||
<style> |
||||
.large-photo {{ |
||||
display: none; |
||||
}} |
||||
.button {{ |
||||
display: inline-block; |
||||
padding: 10px 20px; |
||||
background-color: #4CAF50; |
||||
color: white; |
||||
text-align: center; |
||||
text-decoration: none; |
||||
font-size: 16px; |
||||
border: none; |
||||
border-radius: 5px; |
||||
cursor: pointer; |
||||
}} |
||||
</style> |
||||
</body> |
||||
</html> |
||||
""" |
||||
return html |
||||
|
||||
class Meta: |
||||
|
||||
verbose_name_plural = 'Заказы' |
||||
managed = False |
||||
db_table = 'orders' |
@ -1,8 +0,0 @@
|
||||
<form method="post"> |
||||
{% csrf_token %} |
||||
<div><label for="message">Сообщение:</label></div> |
||||
<div><pre> |
||||
<textarea id="message" name="message" cols="50" rows="10" placeholder="Введите сообщение"></textarea> |
||||
</pre></div> |
||||
<div><button type="submit">Отправить сообщение</button></div> |
||||
</form> |
@ -1,3 +0,0 @@
|
||||
from django.test import TestCase |
||||
|
||||
# Create your tests here. |
@ -1,6 +0,0 @@
|
||||
from django.urls import path, include |
||||
from .views import send_telegram_message |
||||
|
||||
urlpatterns = [ |
||||
path('send_telegram_message/<int:chat_id>/', send_telegram_message, name='send_telegram_message'), |
||||
] |
@ -1,25 +0,0 @@
|
||||
from django.contrib import messages |
||||
from django.http import HttpResponseRedirect |
||||
import requests |
||||
from django.urls import reverse |
||||
from django.shortcuts import render |
||||
from bot_sys.config import GetTelegramBotApiToken |
||||
|
||||
def send_telegram_message(request, chat_id): |
||||
if request.method == 'POST': |
||||
message = request.POST.get('message') |
||||
|
||||
bot_token = GetTelegramBotApiToken() |
||||
url = f'https://api.telegram.org/bot{bot_token}/sendMessage?text={message}&chat_id={chat_id}' |
||||
|
||||
response = requests.get(url) |
||||
if response.status_code == 200: |
||||
messages.success(request, "Сообщение успешно отправлено") |
||||
back_url = reverse('') |
||||
return HttpResponseRedirect(back_url) |
||||
else: |
||||
messages.error(request, "Сообщение не отправлено") |
||||
back_url = reverse('') |
||||
return HttpResponseRedirect(back_url) |
||||
else: |
||||
return render(request, 'send_telegram_message.html') |
@ -1,138 +0,0 @@
|
||||
# -*- coding: utf8 -*- |
||||
# Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) <AlexeiBv+mirocod_platform_bot@narod.ru> |
||||
|
||||
# Категории для заказов |
||||
|
||||
from bot_sys import bot_bd, keyboard, user_access, bd_table, bot_subscribes |
||||
from bot_modules import mod_table_operate, mod_simple_message |
||||
|
||||
# --------------------------------------------------------- |
||||
# БД |
||||
module_name = 'orders_cat' |
||||
|
||||
table_name = module_name |
||||
key_name = 'catID' |
||||
name_field = 'catName' |
||||
desc_field = 'catDesc' |
||||
photo_field = 'catPhoto' |
||||
access_field = 'catAccess' |
||||
create_datetime_field = 'catCreateDateTime' |
||||
|
||||
table = bd_table.Table(table_name, [ |
||||
bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), |
||||
bd_table.TableField(name_field, bd_table.TableFieldDestiny.NAME, bd_table.TableFieldType.STR), |
||||
bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), |
||||
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), |
||||
bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), |
||||
bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR), |
||||
]) |
||||
|
||||
init_access = f'{user_access.user_access_group_new}=v' |
||||
|
||||
# --------------------------------------------------------- |
||||
# Сообщения и кнопки |
||||
|
||||
button_names = { |
||||
mod_simple_message.ButtonNames.START: "🟥 Категории", |
||||
mod_table_operate.ButtonNames.LIST: "📃 Список категорий", |
||||
mod_table_operate.ButtonNames.ADD: "✅ Добавить категорию", |
||||
mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать категорию", |
||||
mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в категории", |
||||
mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в категории", |
||||
mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в категории", |
||||
mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к категории", |
||||
mod_table_operate.ButtonNames.DEL: "❌ Удалить категорию", |
||||
} |
||||
|
||||
messages = { |
||||
mod_simple_message.Messages.START: f''' |
||||
<b>{button_names[mod_simple_message.ButtonNames.START]}</b> |
||||
|
||||
''', |
||||
mod_table_operate.Messages.SELECT: ''' |
||||
Пожалуйста, выберите категорию: |
||||
''', |
||||
mod_table_operate.Messages.ERROR_FIND: ''' |
||||
❌ Ошибка, категория не найдена |
||||
''', |
||||
mod_table_operate.Messages.OPEN: f''' |
||||
<b>Категория: #{name_field}</b> |
||||
|
||||
#{desc_field} |
||||
|
||||
Время создания: #{create_datetime_field} |
||||
''', |
||||
mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME): ''' |
||||
Создание категории. Шаг №1 |
||||
|
||||
Введите название категории: |
||||
''', |
||||
mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.DESC): ''' |
||||
Создание категории. Шаг №2 |
||||
|
||||
Введите описание категории: |
||||
''', |
||||
mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.PHOTO): ''' |
||||
Создание категории. Шаг №3 |
||||
|
||||
Загрузите обложку для категории (Фото): |
||||
Она будет отображаться в его описании. |
||||
''', |
||||
mod_table_operate.Messages.SUCCESS_CREATE: '''✅ Категория успешно добавлена!''', |
||||
mod_table_operate.Messages.START_EDIT: ''' |
||||
Пожалуйста, выберите действие: |
||||
''', |
||||
mod_table_operate.Messages.SELECT_TO_EDIT: ''' |
||||
Выберите проект, который вы хотите отредактировать. |
||||
''', |
||||
mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO): ''' |
||||
Загрузите новую обложку для категории (Фото): |
||||
Она будет отображаться в его описании. |
||||
''', |
||||
mod_table_operate.EditMessage(bd_table.TableFieldDestiny.NAME): f''' |
||||
Текущее название категории: |
||||
#{name_field} |
||||
|
||||
Введите новое название категории: |
||||
''', |
||||
mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DESC): f''' |
||||
Текущее описание категории: |
||||
#{desc_field} |
||||
|
||||
Введите новое описание категории: |
||||
''', |
||||
mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f''' |
||||
Текущий доступ к категории: |
||||
#{access_field} |
||||
|
||||
{user_access.user_access_readme} |
||||
|
||||
Введите новую строку доступа: |
||||
''', |
||||
mod_table_operate.Messages.SUCCESS_EDIT: '''✅ Категория успешно отредактирована!''', |
||||
mod_table_operate.Messages.SELECT_TO_DELETE: ''' |
||||
Выберите категорию, которую вы хотите удалить. |
||||
''', |
||||
mod_table_operate.Messages.SUCCESS_DELETE: '''✅ Категория успешно удалёна!''', |
||||
} |
||||
|
||||
messages_subscribes = { |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_ADD):f'''Категория создана''', |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_EDIT):f'''Категория отредактирована''', |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_DEL):f'''Категория удалена''', |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ITEM_EDIT):f'''Категория отредактирована #item_id''', |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ITEM_DEL):f'''Категория удалена #item_id''', |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_ADD_WITH_PARENT):f'''Категория создана''', |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_EDIT_WITH_PARENT):f'''Категория отредактирована''', |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_DEL_WITH_PARENT):f'''Категория удалена''', |
||||
} |
||||
|
||||
messages.update(messages_subscribes) |
||||
|
||||
class ModuleOrdersCat(mod_table_operate.TableOperateModule): |
||||
def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): |
||||
super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) |
||||
|
||||
def GetName(self): |
||||
return module_name |
||||
|
@ -1,143 +0,0 @@
|
||||
# -*- coding: utf8 -*- |
||||
# Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) <AlexeiBv+mirocod_platform_bot@narod.ru> |
||||
|
||||
# Сообщения пользователю |
||||
|
||||
from bot_sys import bot_bd, keyboard, user_access, bd_table, bot_subscribes, bot_messages, interfaces |
||||
from bot_modules import mod_table_operate, mod_simple_message, users |
||||
|
||||
# --------------------------------------------------------- |
||||
# БД |
||||
module_name = 'user_messge' |
||||
|
||||
table_name = module_name |
||||
key_name = 'userMessageID' |
||||
desc_field = 'messageText' |
||||
access_field = 'catAccess' |
||||
create_datetime_field = 'catCreateDateTime' |
||||
parent_id_field = users.key_name |
||||
|
||||
table = bd_table.Table(table_name, [ |
||||
bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), |
||||
bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), |
||||
bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), |
||||
bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR), |
||||
bd_table.TableField(parent_id_field, bd_table.TableFieldDestiny.PARENT_ID, bd_table.TableFieldType.INT), |
||||
]) |
||||
|
||||
init_access = f'{user_access.user_access_group_new}=-' |
||||
|
||||
# --------------------------------------------------------- |
||||
# Сообщения и кнопки |
||||
|
||||
button_names = { |
||||
mod_simple_message.ButtonNames.START: "📩 Сообщения для польователей", |
||||
mod_table_operate.ButtonNames.LIST: "📃 Список отправленных сообщений", |
||||
mod_table_operate.ButtonNames.ADD: "📨 Отправить сообщение", |
||||
mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать сообщение", |
||||
mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание у сообщения", |
||||
mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к сообщению", |
||||
mod_table_operate.ButtonNames.DEL: "❌ Удалить отправленное сообщение", |
||||
} |
||||
|
||||
messages = { |
||||
mod_simple_message.Messages.START: f''' |
||||
<b>{button_names[mod_simple_message.ButtonNames.START]}</b> |
||||
|
||||
''', |
||||
mod_table_operate.Messages.SELECT: ''' |
||||
Пожалуйста, выберите сообщение: |
||||
''', |
||||
mod_table_operate.Messages.ERROR_FIND: ''' |
||||
❌ Ошибка, сообщение не найдено |
||||
''', |
||||
mod_table_operate.Messages.OPEN: f''' |
||||
<b>Категория: </b> |
||||
|
||||
Пользоватеель: #{parent_id_field} |
||||
|
||||
Текст сообщения: #{desc_field} |
||||
|
||||
Время создания: #{create_datetime_field} |
||||
''', |
||||
mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.DESC): ''' |
||||
Отправка сообщения |
||||
|
||||
Введите текст сообщения: |
||||
''', |
||||
mod_table_operate.Messages.SUCCESS_CREATE: f'''✅ Сообщение успешно отправлено пользователю!''', |
||||
mod_table_operate.Messages.START_EDIT: ''' |
||||
Пожалуйста, выберите действие: |
||||
''', |
||||
mod_table_operate.Messages.SELECT_TO_EDIT: ''' |
||||
Выберите проект, который вы хотите отредактировать. |
||||
''', |
||||
mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DESC): f''' |
||||
Текущий текст сообщения: |
||||
#{desc_field} |
||||
|
||||
Введите новый текст: |
||||
''', |
||||
mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f''' |
||||
Текущий доступ к сообщению: |
||||
#{access_field} |
||||
|
||||
{user_access.user_access_readme} |
||||
|
||||
Введите новую строку доступа: |
||||
''', |
||||
mod_table_operate.Messages.SUCCESS_EDIT: '''✅ Сообщение успешно отредактировано!''', |
||||
mod_table_operate.Messages.SELECT_TO_DELETE: ''' |
||||
Выберите категорию, которую вы хотите удалить. |
||||
''', |
||||
mod_table_operate.Messages.SUCCESS_DELETE: '''✅ Сообщение успешно удалёно!''', |
||||
} |
||||
|
||||
messages_subscribes = { |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_ADD):f'''Сообщение создано''', |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_EDIT):f'''Сообщение отредактировано''', |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_DEL):f'''Сообщение удалено''', |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ITEM_EDIT):f'''Сообщение отредактировано #item_id''', |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ITEM_DEL):f'''Сообщение удалено #item_id''', |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_ADD_WITH_PARENT):f'''Сообщение создано''', |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_EDIT_WITH_PARENT):f'''Сообщение отредактировано''', |
||||
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_DEL_WITH_PARENT):f'''Сообщение удалено''', |
||||
} |
||||
|
||||
messages.update(messages_subscribes) |
||||
|
||||
class ModuleUserMessage(mod_table_operate.TableOperateModule): |
||||
def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): |
||||
super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) |
||||
|
||||
def GetName(self): |
||||
return module_name |
||||
|
||||
async def AddBDItemFunc(self, a_ItemData, a_UserID): |
||||
res, error = await super().AddBDItemFunc(a_ItemData, a_UserID) |
||||
desc_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.DESC) |
||||
user_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) |
||||
|
||||
if not await self.SendMessageToUser(bot_messages.MakeBotMessage(a_ItemData[desc_field]), a_ItemData[user_id_field], parse_mode=interfaces.ParseMode.HTML.value): |
||||
return None, '❌ Ошибка отправки сообщения' |
||||
return res, error |
||||
|
||||
def GetStartButtons(self, a_Message, a_UserGroups): |
||||
return [ |
||||
[mod_table_operate.ButtonNames.ADD, user_access.AccessMode.ADD], |
||||
[mod_table_operate.ButtonNames.LIST, user_access.AccessMode.VIEW], |
||||
[mod_table_operate.ButtonNames.EDIT, user_access.AccessMode.EDIT], |
||||
[mod_table_operate.ButtonNames.DEL, user_access.AccessMode.DELETE], |
||||
] |
||||
|
||||
def GetButtonNameAndKeyValueAndAccess(self, a_Item): |
||||
key_name_id = self.GetKeyFieldID() |
||||
date_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.CREATE_DATE) |
||||
access_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS) |
||||
assert key_name_id != None |
||||
assert date_field_id != None |
||||
assert access_field_id != None |
||||
return \ |
||||
a_Item[date_field_id],\ |
||||
a_Item[key_name_id],\ |
||||
a_Item[access_field_id] |
@ -1,22 +0,0 @@
|
||||
#!/usr/bin/env python |
||||
"""Django's command-line utility for administrative tasks.""" |
||||
import os |
||||
import sys |
||||
|
||||
|
||||
def main(): |
||||
"""Run administrative tasks.""" |
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'adminpanel.settings') |
||||
try: |
||||
from django.core.management import execute_from_command_line |
||||
except ImportError as exc: |
||||
raise ImportError( |
||||
"Couldn't import Django. Are you sure it's installed and " |
||||
"available on your PYTHONPATH environment variable? Did you " |
||||
"forget to activate a virtual environment?" |
||||
) from exc |
||||
execute_from_command_line(sys.argv) |
||||
|
||||
|
||||
if __name__ == '__main__': |
||||
main() |
Loading…
Reference in new issue