Browse Source

админпанель для бота #5

Anton 1 year ago
parent
commit
c0070eeb3c
  1. 3
      .gitignore
  2. 0
      adminpanel/__init__.py
  3. 16
      adminpanel/asgi.py
  4. 11
      adminpanel/urls.py
  5. 16
      adminpanel/wsgi.py
  6. 0
      adminpanelapp/__init__.py
  7. 44
      adminpanelapp/admin.py
  8. 6
      adminpanelapp/apps.py
  9. 0
      adminpanelapp/migrations/__init__.py
  10. 3
      adminpanelapp/tests.py
  11. 10
      adminpanelapp/urls.py
  12. 4
      bot_sys/config.py
  13. 22
      manage.py
  14. 2
      template/bd_item_add.py

3
.gitignore vendored

@ -3,3 +3,6 @@ config_root_ids
__pycache__
log.txt
bot.db
adminpanelapp/migrations
adminpanel/__init__.py
.env

0
adminpanel/__init__.py

16
adminpanel/asgi.py

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

11
adminpanel/urls.py

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

16
adminpanel/wsgi.py

@ -1,16 +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()

0
adminpanelapp/__init__.py

44
adminpanelapp/admin.py

@ -1,44 +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)

6
adminpanelapp/apps.py

@ -1,6 +0,0 @@
from django.apps import AppConfig
class AdminpanelappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'adminpanelapp'

0
adminpanelapp/migrations/__init__.py

3
adminpanelapp/tests.py

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

10
adminpanelapp/urls.py

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

4
bot_sys/config.py

@ -24,8 +24,12 @@ root_ids_file_name = 'config_root_ids'
# Дополнительные функции
def ClearReadLine(a_Line):
<<<<<<< HEAD
line = a_Line.strip()
return line
=======
return a_Line[:-1]
>>>>>>> parent of 88fcd3e (админпанель для бота #5)
def GetFirstLineFromFile(a_FileName):
f = open(a_FileName, 'r')

22
manage.py

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

2
template/bd_item_add.py

@ -82,7 +82,7 @@ def FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableNa
if a_Message.photo == None or len(a_Message.photo) == 0:
await state.finish()
return simple_message.WorkFuncResult(bot_messages.MakeBotMessage(error_photo_type_message), keyboard_func = a_FinishButtonFunc)
field_value = a_Message.photo[-1].file_id
field_value = a_Message.photo[0].file_id
else:
result = a_Message.text
if a_PostProcessFunc:

Loading…
Cancel
Save