cleanings
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -10,5 +10,7 @@ node_modules
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
package.json
|
package.json
|
||||||
old_bot
|
old_bot
|
||||||
|
*.mmdb
|
||||||
|
*.log
|
||||||
|
|
||||||
# Ignore files
|
# Ignore files
|
||||||
0
antifroud/__init__.py
Normal file
0
antifroud/__init__.py
Normal file
253
antifroud/admin.py
Normal file
253
antifroud/admin.py
Normal file
@@ -0,0 +1,253 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from django.urls import path
|
||||||
|
from django.http import JsonResponse
|
||||||
|
from django.shortcuts import redirect, get_object_or_404
|
||||||
|
from django.contrib import messages
|
||||||
|
from django.db import transaction
|
||||||
|
from antifroud.models import UserActivityLog, ExternalDBSettings, RoomDiscrepancy, ImportedHotel
|
||||||
|
from hotels.models import Hotel
|
||||||
|
import pymysql
|
||||||
|
import logging
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(ExternalDBSettings)
|
||||||
|
class ExternalDBSettingsAdmin(admin.ModelAdmin):
|
||||||
|
change_form_template = "antifroud/admin/external_db_settings_change_form.html"
|
||||||
|
list_display = ("name", "host", "port", "user", "database", "table_name", "is_active", "created_at", "updated_at")
|
||||||
|
search_fields = ("name", "host", "user", "database")
|
||||||
|
list_filter = ("is_active", "created_at", "updated_at")
|
||||||
|
readonly_fields = ("created_at", "updated_at")
|
||||||
|
|
||||||
|
def add_view(self, request, form_url='', extra_context=None):
|
||||||
|
new_instance = ExternalDBSettings.objects.create(
|
||||||
|
name="Новая настройка", # Значение по умолчанию
|
||||||
|
host="",
|
||||||
|
port=3306,
|
||||||
|
user="",
|
||||||
|
password="",
|
||||||
|
is_active=False
|
||||||
|
)
|
||||||
|
return redirect(reverse('admin:antifroud_externaldbsettings_change', args=(new_instance.id,)))
|
||||||
|
|
||||||
|
def get_urls(self):
|
||||||
|
urls = super().get_urls()
|
||||||
|
custom_urls = [
|
||||||
|
path('test-connection/', self.admin_site.admin_view(self.test_connection), name='test_connection'),
|
||||||
|
path('fetch-tables/', self.admin_site.admin_view(self.fetch_tables), name='fetch_tables'),
|
||||||
|
path('fetch-table-data/', self.admin_site.admin_view(self.fetch_table_data), name='fetch_table_data'),
|
||||||
|
]
|
||||||
|
return custom_urls + urls
|
||||||
|
|
||||||
|
def test_connection(self, request):
|
||||||
|
db_id = request.GET.get('db_id')
|
||||||
|
if not db_id:
|
||||||
|
return JsonResponse({"status": "error", "message": "ID подключения отсутствует."}, status=400)
|
||||||
|
try:
|
||||||
|
db_settings = ExternalDBSettings.objects.get(id=db_id)
|
||||||
|
if not db_settings.user or not db_settings.password:
|
||||||
|
return JsonResponse({"status": "error", "message": "Имя пользователя или пароль не указаны."}, status=400)
|
||||||
|
|
||||||
|
connection = pymysql.connect(
|
||||||
|
host=db_settings.host,
|
||||||
|
port=db_settings.port,
|
||||||
|
user=db_settings.user,
|
||||||
|
password=db_settings.password,
|
||||||
|
database=db_settings.database
|
||||||
|
)
|
||||||
|
connection.close()
|
||||||
|
return JsonResponse({"status": "success", "message": "Подключение успешно установлено."})
|
||||||
|
except ExternalDBSettings.DoesNotExist:
|
||||||
|
return JsonResponse({"status": "error", "message": "Настройки подключения не найдены."}, status=404)
|
||||||
|
except pymysql.MySQLError as e:
|
||||||
|
return JsonResponse({"status": "error", "message": f"Ошибка MySQL: {str(e)}"}, status=500)
|
||||||
|
except Exception as e:
|
||||||
|
return JsonResponse({"status": "error", "message": f"Неизвестная ошибка: {str(e)}"}, status=500)
|
||||||
|
|
||||||
|
def fetch_tables(self, request):
|
||||||
|
try:
|
||||||
|
db_id = request.GET.get('db_id')
|
||||||
|
db_settings = ExternalDBSettings.objects.get(id=db_id)
|
||||||
|
connection = pymysql.connect(
|
||||||
|
host=db_settings.host,
|
||||||
|
port=db_settings.port,
|
||||||
|
user=db_settings.user,
|
||||||
|
password=db_settings.password,
|
||||||
|
database=db_settings.database
|
||||||
|
)
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute("SHOW TABLES;")
|
||||||
|
tables = [row[0] for row in cursor.fetchall()]
|
||||||
|
connection.close()
|
||||||
|
return JsonResponse({"status": "success", "tables": tables})
|
||||||
|
except Exception as e:
|
||||||
|
return JsonResponse({"status": "error", "message": str(e)})
|
||||||
|
|
||||||
|
def fetch_table_data(self, request):
|
||||||
|
try:
|
||||||
|
db_id = request.GET.get('db_id')
|
||||||
|
table_name = request.GET.get('table_name')
|
||||||
|
db_settings = ExternalDBSettings.objects.get(id=db_id)
|
||||||
|
connection = pymysql.connect(
|
||||||
|
host=db_settings.host,
|
||||||
|
port=db_settings.port,
|
||||||
|
user=db_settings.user,
|
||||||
|
password=db_settings.password,
|
||||||
|
database=db_settings.database
|
||||||
|
)
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute(f"SELECT * FROM `{table_name}` LIMIT 10;")
|
||||||
|
columns = [desc[0] for desc in cursor.description]
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
connection.close()
|
||||||
|
return JsonResponse({"status": "success", "columns": columns, "rows": rows})
|
||||||
|
except Exception as e:
|
||||||
|
return JsonResponse({"status": "error", "message": str(e)})
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(UserActivityLog)
|
||||||
|
class UserActivityLogAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ("id", "timestamp", "date_time", "page_id", "url_parameters", "created", "page_title", "type", "hits")
|
||||||
|
search_fields = ("page_title", "url_parameters")
|
||||||
|
list_filter = ("type", "created")
|
||||||
|
readonly_fields = ("created", "timestamp")
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(RoomDiscrepancy)
|
||||||
|
class RoomDiscrepancyAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ("hotel", "room_number", "booking_id", "check_in_date_expected", "check_in_date_actual", "discrepancy_type", "created_at")
|
||||||
|
search_fields = ("hotel__name", "room_number", "booking_id")
|
||||||
|
list_filter = ("discrepancy_type", "created_at")
|
||||||
|
readonly_fields = ("created_at",)
|
||||||
|
|
||||||
|
|
||||||
|
# @admin.register(ImportedHotel)
|
||||||
|
# class ImportedHotelAdmin(admin.ModelAdmin):
|
||||||
|
# change_list_template = "antifroud/admin/imported_hotels.html"
|
||||||
|
# list_display = ("external_id", "display_name", "name", "created", "updated", "imported")
|
||||||
|
# search_fields = ("name", "display_name", "external_id")
|
||||||
|
# list_filter = ("imported", "created", "updated")
|
||||||
|
# actions = ['mark_as_imported', 'delete_selected_hotels_action']
|
||||||
|
|
||||||
|
# def get_urls(self):
|
||||||
|
# urls = super().get_urls()
|
||||||
|
# custom_urls = [
|
||||||
|
# path('import_selected_hotels/', self.import_selected_hotels, name='antifroud_importedhotels_import_selected_hotels'),
|
||||||
|
# path('delete_selected_hotels/', self.delete_selected_hotels, name='delete_selected_hotels'),
|
||||||
|
# path('edit_hotel/', self.edit_hotel, name='edit_hotel'),
|
||||||
|
# path('delete_hotel/', self.delete_hotel, name='delete_hotel'),
|
||||||
|
# ]
|
||||||
|
# return custom_urls + urls
|
||||||
|
|
||||||
|
# @transaction.atomic
|
||||||
|
# def import_selected_hotels(self, request): # Метод теперь правильно принимает request
|
||||||
|
# if request.method == 'POST':
|
||||||
|
# selected_hotels = request.POST.getlist('hotels')
|
||||||
|
# if selected_hotels:
|
||||||
|
# # Обновление статуса импорта для выбранных отелей
|
||||||
|
# ImportedHotel.objects.filter(id__in=selected_hotels).update(imported=True)
|
||||||
|
# return JsonResponse({'success': True})
|
||||||
|
# else:
|
||||||
|
# return JsonResponse({'success': False})
|
||||||
|
# return JsonResponse({'success': False})
|
||||||
|
|
||||||
|
# @transaction.atomic
|
||||||
|
# def delete_selected_hotels(self, request):
|
||||||
|
# if request.method == 'POST':
|
||||||
|
# selected = request.POST.get('selected', '')
|
||||||
|
# if selected:
|
||||||
|
# external_ids = selected.split(',')
|
||||||
|
# deleted_count, _ = ImportedHotel.objects.filter(external_id__in=external_ids).delete()
|
||||||
|
# messages.success(request, f"Удалено отелей: {deleted_count}")
|
||||||
|
# else:
|
||||||
|
# messages.warning(request, "Не выбрано ни одного отеля для удаления.")
|
||||||
|
# return redirect('admin:antifroud_importedhotel_changelist')
|
||||||
|
|
||||||
|
# @transaction.atomic
|
||||||
|
# def delete_hotel(self, request):
|
||||||
|
# if request.method == 'POST':
|
||||||
|
# hotel_id = request.POST.get('hotel_id')
|
||||||
|
# imported_hotel = get_object_or_404(ImportedHotel, id=hotel_id)
|
||||||
|
# imported_hotel.delete()
|
||||||
|
# messages.success(request, f"Отель {imported_hotel.name} успешно удалён.")
|
||||||
|
# return redirect('admin:antifroud_importedhotel_changelist')
|
||||||
|
|
||||||
|
# def delete_selected_hotels_action(self, request, queryset):
|
||||||
|
# deleted_count, _ = queryset.delete()
|
||||||
|
# self.message_user(request, f'{deleted_count} отелей было удалено.')
|
||||||
|
# delete_selected_hotels_action.short_description = "Удалить выбранные отели"
|
||||||
|
|
||||||
|
# def mark_as_imported(self, request, queryset):
|
||||||
|
# updated = queryset.update(imported=True)
|
||||||
|
# self.message_user(request, f"Отмечено как импортированное: {updated}", messages.SUCCESS)
|
||||||
|
# mark_as_imported.short_description = "Отметить выбранные как импортированные"
|
||||||
|
|
||||||
|
# def edit_hotel(self, request):
|
||||||
|
# if request.method == 'POST':
|
||||||
|
# hotel_id = request.POST.get('hotel_id')
|
||||||
|
# display_name = request.POST.get('display_name')
|
||||||
|
# original_name = request.POST.get('original_name')
|
||||||
|
# imported = request.POST.get('imported') == 'True'
|
||||||
|
|
||||||
|
# imported_hotel = get_object_or_404(ImportedHotel, id=hotel_id)
|
||||||
|
# imported_hotel.display_name = display_name
|
||||||
|
# imported_hotel.name = original_name
|
||||||
|
# imported_hotel.imported = imported
|
||||||
|
# imported_hotel.save()
|
||||||
|
|
||||||
|
# messages.success(request, f"Отель {imported_hotel.name} успешно обновлён.")
|
||||||
|
# return redirect('admin:antifroud_importedhotel_changelist')
|
||||||
|
# return redirect('admin:antifroud_importedhotel_changelist')
|
||||||
|
|
||||||
|
from .views import import_selected_hotels
|
||||||
|
# Регистрируем admin класс для ImportedHotel
|
||||||
|
@admin.register(ImportedHotel)
|
||||||
|
class ImportedHotelAdmin(admin.ModelAdmin):
|
||||||
|
change_list_template = "antifroud/admin/import_hotels.html"
|
||||||
|
list_display = ("external_id", "display_name", "name", "created", "updated", "imported")
|
||||||
|
search_fields = ("name", "display_name", "external_id")
|
||||||
|
list_filter = ("name", "display_name", "external_id")
|
||||||
|
actions = ['mark_as_imported', 'delete_selected_hotels_action']
|
||||||
|
|
||||||
|
def get_urls(self):
|
||||||
|
# Получаем стандартные URL-адреса и добавляем наши
|
||||||
|
urls = super().get_urls()
|
||||||
|
custom_urls = [
|
||||||
|
path('import_selected_hotels/', import_selected_hotels, name='antifroud_importedhotels_import_selected_hotels'),
|
||||||
|
path('delete_selected_hotels/', self.delete_selected_hotels, name='delete_selected_hotels'),
|
||||||
|
path('delete_hotel/<int:hotel_id>/', self.delete_hotel, name='delete_hotel'), # Изменили на URL параметр
|
||||||
|
]
|
||||||
|
return custom_urls + urls
|
||||||
|
|
||||||
|
@transaction.atomic
|
||||||
|
def delete_selected_hotels(self, request):
|
||||||
|
if request.method == 'POST':
|
||||||
|
selected = request.POST.get('selected', '')
|
||||||
|
if selected:
|
||||||
|
external_ids = selected.split(',')
|
||||||
|
deleted_count, _ = ImportedHotel.objects.filter(external_id__in=external_ids).delete()
|
||||||
|
messages.success(request, f"Удалено отелей: {deleted_count}")
|
||||||
|
else:
|
||||||
|
messages.warning(request, "Не выбрано ни одного отеля для удаления.")
|
||||||
|
return redirect('admin:antifroud_importedhotel_changelist')
|
||||||
|
|
||||||
|
def delete_selected_hotels(self, request, queryset):
|
||||||
|
deleted_count, _ = queryset.delete()
|
||||||
|
self.message_user(request, f'{deleted_count} отелей было удалено.')
|
||||||
|
delete_selected_hotels.short_description = "Удалить выбранные отели"
|
||||||
|
|
||||||
|
def mark_as_imported(self, request, queryset):
|
||||||
|
updated = queryset.update(imported=True)
|
||||||
|
self.message_user(request, f"Отмечено как импортированное: {updated}", messages.SUCCESS)
|
||||||
|
mark_as_imported.short_description = "Отметить выбранные как импортированные"
|
||||||
|
|
||||||
|
# Метод для удаления одного отеля
|
||||||
|
@transaction.atomic
|
||||||
|
def delete_hotel(self, request, hotel_id):
|
||||||
|
imported_hotel = get_object_or_404(ImportedHotel, id=hotel_id)
|
||||||
|
imported_hotel.delete()
|
||||||
|
messages.success(request, f"Отель {imported_hotel.name} успешно удалён.")
|
||||||
|
return redirect('admin:antifroud_importedhotel_changelist')
|
||||||
6
antifroud/apps.py
Normal file
6
antifroud/apps.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class AntifroudConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'antifroud'
|
||||||
243
antifroud/data_sync.py
Normal file
243
antifroud/data_sync.py
Normal file
@@ -0,0 +1,243 @@
|
|||||||
|
import pymysql
|
||||||
|
from django.db import transaction
|
||||||
|
from django.utils import timezone
|
||||||
|
from datetime import datetime
|
||||||
|
from html import unescape
|
||||||
|
from urllib.parse import unquote, parse_qs
|
||||||
|
|
||||||
|
from .models import ExternalDBSettings, UserActivityLog, RoomDiscrepancy, ImportedHotel
|
||||||
|
from hotels.models import Reservation, Hotel
|
||||||
|
|
||||||
|
class DataSyncManager:
|
||||||
|
"""
|
||||||
|
Класс для управления загрузкой, записью и сверкой данных.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, db_settings_id):
|
||||||
|
self.db_settings_id = db_settings_id
|
||||||
|
self.db_settings = None
|
||||||
|
self.connection = None
|
||||||
|
self.table_name = None
|
||||||
|
|
||||||
|
def connect_to_db(self):
|
||||||
|
"""
|
||||||
|
Устанавливает соединение с внешней базой данных и получает имя таблицы.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
self.db_settings = ExternalDBSettings.objects.get(id=self.db_settings_id)
|
||||||
|
self.table_name = self.db_settings.table_name
|
||||||
|
self.connection = pymysql.connect(
|
||||||
|
host=self.db_settings.host,
|
||||||
|
port=self.db_settings.port,
|
||||||
|
user=self.db_settings.user,
|
||||||
|
password=self.db_settings.password,
|
||||||
|
database=self.db_settings.database,
|
||||||
|
charset='utf8mb4',
|
||||||
|
use_unicode=True
|
||||||
|
)
|
||||||
|
except ExternalDBSettings.DoesNotExist:
|
||||||
|
raise ValueError("Настройки подключения не найдены.")
|
||||||
|
except pymysql.MySQLError as e:
|
||||||
|
raise ConnectionError(f"Ошибка подключения к базе данных: {e}")
|
||||||
|
|
||||||
|
def fetch_data(self, limit=100):
|
||||||
|
"""
|
||||||
|
Загружает данные из указанной таблицы.
|
||||||
|
"""
|
||||||
|
if not self.connection:
|
||||||
|
self.connect_to_db()
|
||||||
|
|
||||||
|
cursor = self.connection.cursor()
|
||||||
|
try:
|
||||||
|
cursor.execute(f"SELECT * FROM `{self.table_name}` LIMIT {limit};")
|
||||||
|
columns = [desc[0] for desc in cursor.description]
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
return {"columns": columns, "rows": rows}
|
||||||
|
except pymysql.MySQLError as e:
|
||||||
|
raise RuntimeError(f"Ошибка выполнения запроса: {e}")
|
||||||
|
finally:
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
def parse_datetime(self, dt_str):
|
||||||
|
"""
|
||||||
|
Преобразует строку формата 'YYYY-MM-DD HH:MM:SS' или 'YYYY-MM-DDTHH:MM:SS' в aware datetime.
|
||||||
|
"""
|
||||||
|
if dt_str is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if isinstance(dt_str, datetime):
|
||||||
|
if timezone.is_naive(dt_str):
|
||||||
|
return timezone.make_aware(dt_str, timezone.get_default_timezone())
|
||||||
|
return dt_str
|
||||||
|
|
||||||
|
for fmt in ("%Y-%m-%d %H:%M:%S", "%Y-%m-%dT%H:%M:%S"):
|
||||||
|
try:
|
||||||
|
naive_dt = datetime.strptime(dt_str, fmt)
|
||||||
|
return timezone.make_aware(naive_dt, timezone.get_default_timezone())
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def decode_html_entities(self, text):
|
||||||
|
"""
|
||||||
|
Раскодирует HTML-сущности в строке.
|
||||||
|
"""
|
||||||
|
if text and isinstance(text, str):
|
||||||
|
return unescape(text)
|
||||||
|
return text
|
||||||
|
|
||||||
|
def process_url_parameters(self, url_params):
|
||||||
|
"""
|
||||||
|
Парсит url_parameters, извлекает utm_content (имя отеля) и utm_term (ID отеля).
|
||||||
|
"""
|
||||||
|
if not url_params:
|
||||||
|
return {}
|
||||||
|
decoded = unquote(url_params)
|
||||||
|
qs = parse_qs(decoded)
|
||||||
|
hotel_name = qs.get('utm_content', [None])[0]
|
||||||
|
hotel_id = qs.get('utm_term', [None])[0]
|
||||||
|
return {
|
||||||
|
'hotel_name': hotel_name,
|
||||||
|
'hotel_id': hotel_id
|
||||||
|
}
|
||||||
|
|
||||||
|
def check_and_store_imported_hotel(self, hotel_name, hotel_id):
|
||||||
|
"""
|
||||||
|
Проверяет, есть ли отель с данным ID в основной БД.
|
||||||
|
Если hotel_id не число или отеля с таким ID нет, добавляет во временную таблицу ImportedHotel.
|
||||||
|
"""
|
||||||
|
if not hotel_id or not hotel_name:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Проверим, что hotel_id — число
|
||||||
|
if hotel_id.isdigit():
|
||||||
|
hotel_id_int = int(hotel_id)
|
||||||
|
hotel_exists = Hotel.objects.filter(id=hotel_id_int).exists()
|
||||||
|
else:
|
||||||
|
# Если не число, считаем что отеля в основной БД нет
|
||||||
|
hotel_exists = False
|
||||||
|
|
||||||
|
if not hotel_exists:
|
||||||
|
ImportedHotel.objects.update_or_create(
|
||||||
|
external_id=str(hotel_id),
|
||||||
|
defaults={
|
||||||
|
'name': hotel_name
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
@transaction.atomic
|
||||||
|
def write_to_db(self, data):
|
||||||
|
"""
|
||||||
|
Записывает данные в UserActivityLog и при необходимости в ImportedHotel.
|
||||||
|
"""
|
||||||
|
for row in data["rows"]:
|
||||||
|
record = dict(zip(data["columns"], row))
|
||||||
|
|
||||||
|
external_id = record.get("id", None)
|
||||||
|
if external_id is not None:
|
||||||
|
external_id = str(external_id)
|
||||||
|
|
||||||
|
created = self.parse_datetime(record.get("created"))
|
||||||
|
date_time = self.parse_datetime(record.get("date_time"))
|
||||||
|
|
||||||
|
referred = self.decode_html_entities(record.get("referred", ""))
|
||||||
|
agent = self.decode_html_entities(record.get("agent", ""))
|
||||||
|
platform = self.decode_html_entities(record.get("platform", ""))
|
||||||
|
version = self.decode_html_entities(record.get("version", ""))
|
||||||
|
model = self.decode_html_entities(record.get("model", ""))
|
||||||
|
device = self.decode_html_entities(record.get("device", ""))
|
||||||
|
UAString = self.decode_html_entities(record.get("UAString", ""))
|
||||||
|
location = self.decode_html_entities(record.get("location", ""))
|
||||||
|
page_title = self.decode_html_entities(record.get("page_title", ""))
|
||||||
|
page_url = self.decode_html_entities(record.get("page_url", ""))
|
||||||
|
|
||||||
|
url_parameters = self.decode_html_entities(record.get("url_parameters", ""))
|
||||||
|
hotel_info = self.process_url_parameters(url_parameters)
|
||||||
|
|
||||||
|
if hotel_info.get('hotel_name') and hotel_info.get('hotel_id'):
|
||||||
|
self.check_and_store_imported_hotel(
|
||||||
|
hotel_name=hotel_info['hotel_name'],
|
||||||
|
hotel_id=hotel_info['hotel_id']
|
||||||
|
)
|
||||||
|
|
||||||
|
url_parameters = unquote(url_parameters)
|
||||||
|
|
||||||
|
UserActivityLog.objects.update_or_create(
|
||||||
|
external_id=external_id,
|
||||||
|
defaults={
|
||||||
|
"user_id": record.get("user_id"),
|
||||||
|
"ip": record.get("ip"),
|
||||||
|
"created": created,
|
||||||
|
"timestamp": record.get("timestamp"),
|
||||||
|
"date_time": date_time,
|
||||||
|
"referred": referred,
|
||||||
|
"agent": agent,
|
||||||
|
"platform": platform,
|
||||||
|
"version": version,
|
||||||
|
"model": model,
|
||||||
|
"device": device,
|
||||||
|
"UAString": UAString,
|
||||||
|
"location": location,
|
||||||
|
"page_id": record.get("page_id"),
|
||||||
|
"url_parameters": url_parameters,
|
||||||
|
"page_title": page_title,
|
||||||
|
"type": record.get("type"),
|
||||||
|
"last_counter": record.get("last_counter"),
|
||||||
|
"hits": record.get("hits"),
|
||||||
|
"honeypot": record.get("honeypot"),
|
||||||
|
"reply": record.get("reply"),
|
||||||
|
"page_url": page_url,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def reconcile_data(self):
|
||||||
|
"""
|
||||||
|
Сверяет данные таблицы user_activity_log с таблицей hotels.reservations
|
||||||
|
и записывает несоответствия в таблицу RoomDiscrepancy.
|
||||||
|
"""
|
||||||
|
discrepancies = []
|
||||||
|
reservations = Reservation.objects.values("hotel_id", "room_number", "check_in", "check_out")
|
||||||
|
|
||||||
|
for log in UserActivityLog.objects.all():
|
||||||
|
for reservation in reservations:
|
||||||
|
if (
|
||||||
|
log.page_id != reservation["room_number"] or
|
||||||
|
log.created.date() < reservation["check_in"] or
|
||||||
|
log.created.date() > reservation["check_out"]
|
||||||
|
):
|
||||||
|
discrepancies.append(RoomDiscrepancy(
|
||||||
|
hotel_id=reservation["hotel_id"],
|
||||||
|
room_number=log.page_id,
|
||||||
|
booking_id=f"Log-{log.id}",
|
||||||
|
check_in_date_expected=reservation["check_in"],
|
||||||
|
check_in_date_actual=log.created.date() if log.created else None,
|
||||||
|
discrepancy_type="Mismatch",
|
||||||
|
))
|
||||||
|
|
||||||
|
RoomDiscrepancy.objects.bulk_create(discrepancies)
|
||||||
|
|
||||||
|
def sync(self):
|
||||||
|
"""
|
||||||
|
Основной метод для загрузки, записи и сверки данных.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
self.connect_to_db()
|
||||||
|
data = self.fetch_data()
|
||||||
|
self.write_to_db(data)
|
||||||
|
self.reconcile_data()
|
||||||
|
except Exception as e:
|
||||||
|
raise RuntimeError(f"Ошибка синхронизации данных: {e}")
|
||||||
|
finally:
|
||||||
|
if self.connection:
|
||||||
|
self.connection.close()
|
||||||
|
|
||||||
|
|
||||||
|
def scheduled_sync():
|
||||||
|
"""
|
||||||
|
Плановая задача для синхронизации данных.
|
||||||
|
"""
|
||||||
|
db_settings_list = ExternalDBSettings.objects.filter(is_active=True)
|
||||||
|
for db_settings in db_settings_list:
|
||||||
|
sync_manager = DataSyncManager(db_settings.id)
|
||||||
|
sync_manager.sync()
|
||||||
9
antifroud/forms.py
Normal file
9
antifroud/forms.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
from django import forms
|
||||||
|
from .models import Hotel
|
||||||
|
|
||||||
|
class HotelImportForm(forms.Form):
|
||||||
|
hotels = forms.ModelMultipleChoiceField(
|
||||||
|
queryset=Hotel.objects.all(),
|
||||||
|
widget=forms.CheckboxSelectMultiple,
|
||||||
|
required=True
|
||||||
|
)
|
||||||
86
antifroud/migrations/0001_initial.py
Normal file
86
antifroud/migrations/0001_initial.py
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
# Generated by Django 5.1.4 on 2024-12-12 12:28
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('hotels', '0004_alter_reservation_room_number'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='ExternalDBSettings',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(help_text='Имя подключения для идентификации.', max_length=255, unique=True)),
|
||||||
|
('host', models.CharField(help_text='Адрес сервера базы данных.', max_length=255)),
|
||||||
|
('port', models.PositiveIntegerField(default=3306, help_text='Порт сервера базы данных.')),
|
||||||
|
('database', models.CharField(help_text='Имя базы данных.', max_length=255)),
|
||||||
|
('user', models.CharField(help_text='Имя пользователя базы данных.', max_length=255)),
|
||||||
|
('password', models.CharField(help_text='Пароль для подключения.', max_length=255)),
|
||||||
|
('table_name', models.CharField(blank=True, help_text='Имя таблицы для загрузки данных.', max_length=255, null=True)),
|
||||||
|
('selected_fields', models.TextField(blank=True, help_text='Список полей для загрузки (через запятую).', null=True)),
|
||||||
|
('is_active', models.BooleanField(default=True, help_text='Флаг активности подключения.')),
|
||||||
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('updated_at', models.DateTimeField(auto_now=True)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Настройки подключения к БД',
|
||||||
|
'verbose_name_plural': 'Настройки подключений к БД',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='UserActivityLog',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigIntegerField(primary_key=True, serialize=False)),
|
||||||
|
('user_id', models.BigIntegerField(verbose_name='ID пользователя')),
|
||||||
|
('ip', models.GenericIPAddressField(verbose_name='IP-адрес')),
|
||||||
|
('created', models.DateTimeField(verbose_name='Дата создания')),
|
||||||
|
('timestamp', models.BigIntegerField(verbose_name='Метка времени')),
|
||||||
|
('date_time', models.DateTimeField(verbose_name='Дата и время')),
|
||||||
|
('referred', models.TextField(blank=True, null=True, verbose_name='Реферальная ссылка')),
|
||||||
|
('agent', models.TextField(verbose_name='Агент пользователя')),
|
||||||
|
('platform', models.CharField(blank=True, max_length=255, null=True, verbose_name='Платформа')),
|
||||||
|
('version', models.CharField(blank=True, max_length=255, null=True, verbose_name='Версия')),
|
||||||
|
('model', models.CharField(blank=True, max_length=255, null=True, verbose_name='Модель устройства')),
|
||||||
|
('device', models.CharField(blank=True, max_length=255, null=True, verbose_name='Тип устройства')),
|
||||||
|
('UAString', models.TextField(verbose_name='User-Agent строка')),
|
||||||
|
('location', models.CharField(blank=True, max_length=255, null=True, verbose_name='Местоположение')),
|
||||||
|
('page_id', models.BigIntegerField(blank=True, null=True, verbose_name='ID страницы')),
|
||||||
|
('url_parameters', models.TextField(blank=True, null=True, verbose_name='Параметры URL')),
|
||||||
|
('page_title', models.TextField(blank=True, null=True, verbose_name='Заголовок страницы')),
|
||||||
|
('type', models.CharField(max_length=50, verbose_name='Тип')),
|
||||||
|
('last_counter', models.IntegerField(verbose_name='Последний счетчик')),
|
||||||
|
('hits', models.IntegerField(verbose_name='Количество обращений')),
|
||||||
|
('honeypot', models.BooleanField(verbose_name='Метка honeypot')),
|
||||||
|
('reply', models.BooleanField(verbose_name='Ответ пользователя')),
|
||||||
|
('page_url', models.URLField(blank=True, null=True, verbose_name='URL страницы')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Регистрация посетителей',
|
||||||
|
'verbose_name_plural': 'Регистрации посетителей',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='RoomDiscrepancy',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('room_number', models.CharField(max_length=50, verbose_name='Номер комнаты')),
|
||||||
|
('booking_id', models.CharField(max_length=255, verbose_name='ID бронирования')),
|
||||||
|
('check_in_date_expected', models.DateField(verbose_name='Ожидаемая дата заселения')),
|
||||||
|
('check_in_date_actual', models.DateField(verbose_name='Фактическая дата заселения')),
|
||||||
|
('discrepancy_type', models.CharField(choices=[('early', 'Раннее заселение'), ('late', 'Позднее заселение'), ('missed', 'Неявка')], max_length=50, verbose_name='Тип несоответствия')),
|
||||||
|
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Дата создания')),
|
||||||
|
('hotel', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='hotels.hotel', verbose_name='Отель')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Несовпадение в заселении',
|
||||||
|
'verbose_name_plural': 'Несовпадения в заселении',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
# Generated by Django 5.1.4 on 2024-12-12 13:07
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('antifroud', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='externaldbsettings',
|
||||||
|
name='database',
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='externaldbsettings',
|
||||||
|
name='host',
|
||||||
|
field=models.CharField(default='', help_text='Адрес сервера базы данных.', max_length=255),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='externaldbsettings',
|
||||||
|
name='is_active',
|
||||||
|
field=models.BooleanField(default=False, help_text='Флаг активности подключения.'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='externaldbsettings',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(default='Новая настройка', help_text='Имя подключения для идентификации.', max_length=255, unique=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='externaldbsettings',
|
||||||
|
name='password',
|
||||||
|
field=models.CharField(default='', help_text='Пароль для подключения.', max_length=255),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='externaldbsettings',
|
||||||
|
name='user',
|
||||||
|
field=models.CharField(default='', help_text='Имя пользователя базы данных.', max_length=255),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
# Generated by Django 5.1.4 on 2024-12-12 13:10
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('antifroud', '0002_remove_externaldbsettings_database_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='externaldbsettings',
|
||||||
|
name='database',
|
||||||
|
field=models.CharField(default='', help_text='Имя базы данных.', max_length=255),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='externaldbsettings',
|
||||||
|
name='host',
|
||||||
|
field=models.CharField(help_text='Адрес сервера базы данных.', max_length=255),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='externaldbsettings',
|
||||||
|
name='is_active',
|
||||||
|
field=models.BooleanField(default=True, help_text='Флаг активности подключения.'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='externaldbsettings',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(help_text='Имя подключения для идентификации.', max_length=255, unique=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='externaldbsettings',
|
||||||
|
name='password',
|
||||||
|
field=models.CharField(help_text='Пароль для подключения.', max_length=255),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='externaldbsettings',
|
||||||
|
name='user',
|
||||||
|
field=models.CharField(help_text='Имя пользователя базы данных.', max_length=255),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# Generated by Django 5.1.4 on 2024-12-12 14:42
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('antifroud', '0003_externaldbsettings_database_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='externaldbsettings',
|
||||||
|
options={'verbose_name': 'Настройка подключения к БД', 'verbose_name_plural': 'Настройки подключений к БД'},
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='externaldbsettings',
|
||||||
|
name='database',
|
||||||
|
field=models.CharField(default='u1510415_wp832', help_text='Имя базы данных.', max_length=255),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='externaldbsettings',
|
||||||
|
name='table_name',
|
||||||
|
field=models.CharField(blank=True, default='wpts_user_activity_log', help_text='Имя таблицы для загрузки данных.', max_length=255, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
24
antifroud/migrations/0005_importedhotel.py
Normal file
24
antifroud/migrations/0005_importedhotel.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Generated by Django 5.1.4 on 2024-12-12 23:57
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('antifroud', '0004_alter_externaldbsettings_options_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='ImportedHotel',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('external_id', models.CharField(max_length=255, unique=True, verbose_name='Внешний ID отеля')),
|
||||||
|
('name', models.CharField(max_length=255, verbose_name='Имя отеля')),
|
||||||
|
('created', models.DateTimeField(auto_now_add=True, verbose_name='Дата создания')),
|
||||||
|
('updated', models.DateTimeField(auto_now=True, verbose_name='Дата обновления')),
|
||||||
|
('imported', models.BooleanField(default=False, verbose_name='Импортирован в основную базу')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
17
antifroud/migrations/0006_alter_importedhotel_options.py
Normal file
17
antifroud/migrations/0006_alter_importedhotel_options.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 5.1.4 on 2024-12-12 23:58
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('antifroud', '0005_importedhotel'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='importedhotel',
|
||||||
|
options={'verbose_name': 'Импортированный отель', 'verbose_name_plural': 'Импортированные отели'},
|
||||||
|
),
|
||||||
|
]
|
||||||
18
antifroud/migrations/0007_useractivitylog_external_id.py
Normal file
18
antifroud/migrations/0007_useractivitylog_external_id.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.4 on 2024-12-13 00:03
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('antifroud', '0006_alter_importedhotel_options'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='useractivitylog',
|
||||||
|
name='external_id',
|
||||||
|
field=models.CharField(blank=True, max_length=255, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
antifroud/migrations/0008_alter_useractivitylog_id.py
Normal file
18
antifroud/migrations/0008_alter_useractivitylog_id.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.4 on 2024-12-13 00:09
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('antifroud', '0007_useractivitylog_external_id'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='useractivitylog',
|
||||||
|
name='id',
|
||||||
|
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
antifroud/migrations/0009_importedhotel_display_name.py
Normal file
18
antifroud/migrations/0009_importedhotel_display_name.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.4 on 2024-12-13 00:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('antifroud', '0008_alter_useractivitylog_id'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='importedhotel',
|
||||||
|
name='display_name',
|
||||||
|
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Отображаемое имя'),
|
||||||
|
),
|
||||||
|
]
|
||||||
0
antifroud/migrations/__init__.py
Normal file
0
antifroud/migrations/__init__.py
Normal file
153
antifroud/models.py
Normal file
153
antifroud/models.py
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
from django.db import models
|
||||||
|
from hotels.models import Hotel, Reservation
|
||||||
|
|
||||||
|
|
||||||
|
class UserActivityLog(models.Model):
|
||||||
|
external_id = models.CharField(max_length=255, null=True, blank=True)
|
||||||
|
user_id = models.BigIntegerField(verbose_name="ID пользователя")
|
||||||
|
ip = models.GenericIPAddressField(verbose_name="IP-адрес")
|
||||||
|
created = models.DateTimeField(verbose_name="Дата создания")
|
||||||
|
timestamp = models.BigIntegerField(verbose_name="Метка времени")
|
||||||
|
date_time = models.DateTimeField(verbose_name="Дата и время")
|
||||||
|
referred = models.TextField(blank=True, null=True, verbose_name="Реферальная ссылка")
|
||||||
|
agent = models.TextField(verbose_name="Агент пользователя")
|
||||||
|
platform = models.CharField(max_length=255, blank=True, null=True, verbose_name="Платформа")
|
||||||
|
version = models.CharField(max_length=255, blank=True, null=True, verbose_name="Версия")
|
||||||
|
model = models.CharField(max_length=255, blank=True, null=True, verbose_name="Модель устройства")
|
||||||
|
device = models.CharField(max_length=255, blank=True, null=True, verbose_name="Тип устройства")
|
||||||
|
UAString = models.TextField(verbose_name="User-Agent строка")
|
||||||
|
location = models.CharField(max_length=255, blank=True, null=True, verbose_name="Местоположение")
|
||||||
|
page_id = models.BigIntegerField(blank=True, null=True, verbose_name="ID страницы")
|
||||||
|
url_parameters = models.TextField(blank=True, null=True, verbose_name="Параметры URL")
|
||||||
|
page_title = models.TextField(blank=True, null=True, verbose_name="Заголовок страницы")
|
||||||
|
type = models.CharField(max_length=50, verbose_name="Тип")
|
||||||
|
last_counter = models.IntegerField(verbose_name="Последний счетчик")
|
||||||
|
hits = models.IntegerField(verbose_name="Количество обращений")
|
||||||
|
honeypot = models.BooleanField(verbose_name="Метка honeypot")
|
||||||
|
reply = models.BooleanField(verbose_name="Ответ пользователя")
|
||||||
|
page_url = models.URLField(blank=True, null=True, verbose_name="URL страницы")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"UserActivityLog {self.id}: {self.page_title}"
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Регистрация посетителей"
|
||||||
|
verbose_name_plural = "Регистрации посетителей"
|
||||||
|
|
||||||
|
|
||||||
|
class ExternalDBSettings(models.Model):
|
||||||
|
name = models.CharField(max_length=255, unique=True, help_text="Имя подключения для идентификации.")
|
||||||
|
host = models.CharField(max_length=255, help_text="Адрес сервера базы данных.")
|
||||||
|
port = models.PositiveIntegerField(default=3306, help_text="Порт сервера базы данных.")
|
||||||
|
user = models.CharField(max_length=255, help_text="Имя пользователя базы данных.")
|
||||||
|
password = models.CharField(max_length=255, help_text="Пароль для подключения.")
|
||||||
|
database = models.CharField(max_length=255, default="u1510415_wp832", help_text="Имя базы данных.")
|
||||||
|
table_name = models.CharField(max_length=255, blank=True, default="wpts_user_activity_log", null=True, help_text="Имя таблицы для загрузки данных.")
|
||||||
|
selected_fields = models.TextField(blank=True, null=True, help_text="Список полей для загрузки (через запятую).")
|
||||||
|
is_active = models.BooleanField(default=True, help_text="Флаг активности подключения.")
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.name} ({self.host}:{self.port})"
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Настройка подключения к БД"
|
||||||
|
verbose_name_plural = "Настройки подключений к БД"
|
||||||
|
|
||||||
|
|
||||||
|
class RoomDiscrepancy(models.Model):
|
||||||
|
hotel = models.ForeignKey(Hotel, on_delete=models.CASCADE, verbose_name="Отель")
|
||||||
|
room_number = models.CharField(max_length=50, verbose_name="Номер комнаты")
|
||||||
|
booking_id = models.CharField(max_length=255, verbose_name="ID бронирования")
|
||||||
|
check_in_date_expected = models.DateField(verbose_name="Ожидаемая дата заселения")
|
||||||
|
check_in_date_actual = models.DateField(verbose_name="Фактическая дата заселения")
|
||||||
|
discrepancy_type = models.CharField(
|
||||||
|
max_length=50,
|
||||||
|
choices=[("early", "Раннее заселение"), ("late", "Позднее заселение"), ("missed", "Неявка")],
|
||||||
|
verbose_name="Тип несоответствия"
|
||||||
|
)
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True, verbose_name="Дата создания")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.hotel.name} - Room {self.room_number}: {self.discrepancy_type}"
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Несовпадение в заселении"
|
||||||
|
verbose_name_plural = "Несовпадения в заселении"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def detect_discrepancies(expected_bookings, actual_check_ins):
|
||||||
|
"""
|
||||||
|
Сравнение ожидаемых и фактических данных о заселении.
|
||||||
|
"""
|
||||||
|
discrepancies = []
|
||||||
|
|
||||||
|
# Преобразуем фактические заселения в словарь для быстрого доступа
|
||||||
|
actual_dict = {
|
||||||
|
(entry.hotel_id, entry.room_number): entry.check_in_date
|
||||||
|
for entry in actual_check_ins
|
||||||
|
}
|
||||||
|
|
||||||
|
for booking in expected_bookings:
|
||||||
|
key = (booking.hotel_id, booking.room_number)
|
||||||
|
actual_date = actual_dict.get(key)
|
||||||
|
|
||||||
|
if actual_date is None:
|
||||||
|
discrepancies.append(RoomDiscrepancy(
|
||||||
|
hotel=booking.hotel,
|
||||||
|
room_number=booking.room_number,
|
||||||
|
booking_id=booking.booking_id,
|
||||||
|
check_in_date_expected=booking.check_in_date,
|
||||||
|
discrepancy_type="missed"
|
||||||
|
))
|
||||||
|
elif actual_date < booking.check_in_date:
|
||||||
|
discrepancies.append(RoomDiscrepancy(
|
||||||
|
hotel=booking.hotel,
|
||||||
|
room_number=booking.room_number,
|
||||||
|
booking_id=booking.booking_id,
|
||||||
|
check_in_date_expected=booking.check_in_date,
|
||||||
|
check_in_date_actual=actual_date,
|
||||||
|
discrepancy_type="early"
|
||||||
|
))
|
||||||
|
elif actual_date > booking.check_in_date:
|
||||||
|
discrepancies.append(RoomDiscrepancy(
|
||||||
|
hotel=booking.hotel,
|
||||||
|
room_number=booking.room_number,
|
||||||
|
booking_id=booking.booking_id,
|
||||||
|
check_in_date_expected=booking.check_in_date,
|
||||||
|
check_in_date_actual=actual_date,
|
||||||
|
discrepancy_type="late"
|
||||||
|
))
|
||||||
|
|
||||||
|
RoomDiscrepancy.objects.bulk_create(discrepancies)
|
||||||
|
|
||||||
|
from urllib.parse import unquote
|
||||||
|
from html import unescape
|
||||||
|
|
||||||
|
class ImportedHotel(models.Model):
|
||||||
|
external_id = models.CharField(max_length=255, unique=True, verbose_name="Внешний ID отеля")
|
||||||
|
name = models.CharField(max_length=255, verbose_name="Имя отеля")
|
||||||
|
display_name = models.CharField(max_length=255, null=True, blank=True, verbose_name="Отображаемое имя")
|
||||||
|
created = models.DateTimeField(auto_now_add=True, verbose_name="Дата создания")
|
||||||
|
updated = models.DateTimeField(auto_now=True, verbose_name="Дата обновления")
|
||||||
|
imported = models.BooleanField(default=False, verbose_name="Импортирован в основную базу")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.display_name or self.name} ({self.external_id})"
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Импортированный отель"
|
||||||
|
verbose_name_plural = "Импортированные отели"
|
||||||
|
|
||||||
|
def set_display_name_from_page_title(self, page_title):
|
||||||
|
"""
|
||||||
|
Декодирует HTML-сущности, URL-кодировку и устанавливает display_name.
|
||||||
|
"""
|
||||||
|
if page_title:
|
||||||
|
decoded = unquote(unescape(page_title))
|
||||||
|
self.display_name = decoded
|
||||||
|
else:
|
||||||
|
self.display_name = self.name
|
||||||
|
self.save()
|
||||||
|
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
{% extends "admin/base_site.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#table-data-preview {
|
||||||
|
max-height: 300px; /* Ограничиваем высоту предпросмотра */
|
||||||
|
overflow-y: auto; /* Прокрутка по вертикали */
|
||||||
|
overflow-x: auto; /* Прокрутка по горизонтали */
|
||||||
|
}
|
||||||
|
|
||||||
|
#table-data-preview table {
|
||||||
|
width: auto; /* Автоматическая ширина таблицы */
|
||||||
|
table-layout: auto; /* Автоматическая ширина колонок */
|
||||||
|
}
|
||||||
|
|
||||||
|
#table-data-preview th,
|
||||||
|
#table-data-preview td {
|
||||||
|
white-space: nowrap; /* Предотвращаем перенос текста */
|
||||||
|
overflow: hidden; /* Скрываем текст, выходящий за границы ячейки */
|
||||||
|
text-overflow: ellipsis; /* Добавляем многоточие для обрезанного текста */
|
||||||
|
padding: 8px; /* Внутренний отступ */
|
||||||
|
height: 40px; /* Фиксированная высота строк */
|
||||||
|
}
|
||||||
|
|
||||||
|
#table-data-preview th {
|
||||||
|
position: sticky; /* Фиксируем заголовки при прокрутке */
|
||||||
|
top: 0; /* Располагаем заголовки вверху таблицы */
|
||||||
|
background-color: #f8f9fa; /* Цвет фона заголовков */
|
||||||
|
z-index: 1; /* Заголовки перекрывают содержимое */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="container mt-4">
|
||||||
|
<h2 class="text-center">Настройки подключения к БД</h2>
|
||||||
|
<form id="connection-form" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="db-name">Name</label>
|
||||||
|
<input id="db-name" class="form-control" type="text" name="name" value="{{ original.name }}" required />
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="db-host">DB Host</label>
|
||||||
|
<input id="db-host" class="form-control" type="text" name="host" value="{{ original.host }}" required />
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="db-port">DB Port</label>
|
||||||
|
<input id="db-port" class="form-control" type="number" name="port" value="{{ original.port }}" required />
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="db-user">User</label>
|
||||||
|
<input id="db-user" class="form-control" type="text" name="user" value="{{ original.user }}" required />
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="db-password">Password</label>
|
||||||
|
<input id="db-password" class="form-control" type="password" name="password" value="{{ original.password }}" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="db-database">Database</label>
|
||||||
|
<input id="db-database" class="form-control" type="text" name="database" value="{{ original.database }}" required />
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="table-selector">Таблицы</label>
|
||||||
|
<select id="table-selector" class="form-select" name="table_name">
|
||||||
|
{% if original.table_name %}
|
||||||
|
<option value="{{ original.table_name }}" selected>{{ original.table_name }}</option>
|
||||||
|
{% else %}
|
||||||
|
<option value="">-- Выберите таблицу --</option>
|
||||||
|
{% endif %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="table-data-preview">Столбцы и данные</label>
|
||||||
|
<div id="table-data-preview" class="table-responsive">
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead id="table-header"></thead>
|
||||||
|
<tbody id="table-body"></tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="is-active">Активное подключение</label>
|
||||||
|
<input id="is-active" class="form-check-input" type="checkbox" name="is_active" {% if original.is_active %}checked{% endif %} />
|
||||||
|
</div>
|
||||||
|
<div class="form-group text-center">
|
||||||
|
<button class="btn btn-success" type="submit">Сохранить</button>
|
||||||
|
<button class="btn btn-secondary" type="button" id="close-button">Закрыть</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<hr>
|
||||||
|
<div id="connection-status" class="mt-4"></div>
|
||||||
|
<div class="text-center mt-3">
|
||||||
|
<button id="test-connection" class="btn btn-primary" type="button">Проверить подключение</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if original.id %}
|
||||||
|
<script>
|
||||||
|
const dbId = "{{ original.id }}";
|
||||||
|
</script>
|
||||||
|
{% else %}
|
||||||
|
<script>
|
||||||
|
const dbId = null;
|
||||||
|
document.getElementById("test-connection").style.display = "none";
|
||||||
|
alert("Сохраните запись перед выполнением проверки подключения.");
|
||||||
|
</script>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Закрыть окно
|
||||||
|
document.getElementById("close-button").addEventListener("click", function() {
|
||||||
|
window.history.back(); // Вернуться назад
|
||||||
|
});
|
||||||
|
|
||||||
|
// Проверить подключение и загрузить таблицы
|
||||||
|
document.getElementById("test-connection").addEventListener("click", function() {
|
||||||
|
if (!dbId) {
|
||||||
|
alert("ID подключения отсутствует.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fetch(`/admin/antifroud/externaldbsettings/test-connection/?db_id=${dbId}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.status === "success") {
|
||||||
|
document.getElementById("connection-status").innerHTML = `<div class="alert alert-success">${data.message}</div>`;
|
||||||
|
fetch(`/admin/antifroud/externaldbsettings/fetch-tables/?db_id=${dbId}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(tableData => {
|
||||||
|
if (tableData.status === "success") {
|
||||||
|
const selector = document.getElementById("table-selector");
|
||||||
|
selector.innerHTML = tableData.tables.map(table => `<option value="${table}">${table}</option>`).join("");
|
||||||
|
} else {
|
||||||
|
alert("Ошибка при загрузке таблиц: " + tableData.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
document.getElementById("connection-status").innerHTML = `<div class="alert alert-danger">${data.message}</div>`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
alert("Ошибка при проверке подключения.");
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// При выборе таблицы загрузить столбцы и строки данных
|
||||||
|
document.getElementById("table-selector").addEventListener("change", function () {
|
||||||
|
const tableName = this.value;
|
||||||
|
if (!tableName) {
|
||||||
|
document.getElementById("table-header").innerHTML = "";
|
||||||
|
document.getElementById("table-body").innerHTML = "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch(`/admin/antifroud/externaldbsettings/fetch-table-data/?db_id=${dbId}&table_name=${tableName}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.status === "success") {
|
||||||
|
const headerRow = data.columns.map(col => `<th>${col}</th>`).join("");
|
||||||
|
document.getElementById("table-header").innerHTML = `<tr>${headerRow}</tr>`;
|
||||||
|
|
||||||
|
const rows = data.rows.map(row => {
|
||||||
|
const cells = row.map(cell => `<td>${cell}</td>`).join("");
|
||||||
|
return `<tr>${cells}</tr>`;
|
||||||
|
}).join("");
|
||||||
|
document.getElementById("table-body").innerHTML = rows;
|
||||||
|
} else {
|
||||||
|
alert("Ошибка при загрузке данных таблицы: " + data.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
alert("Ошибка при загрузке данных таблицы.");
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
97
antifroud/templates/antifroud/admin/import_hotels.html
Normal file
97
antifroud/templates/antifroud/admin/import_hotels.html
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
{% extends "admin/change_list.html" %}
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Кнопка импорта -->
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<button type="submit" class="btn btn-primary" form="importHotelsForm">
|
||||||
|
Импортировать выбранные отели
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Действия админки -->
|
||||||
|
{{ block.super }}
|
||||||
|
|
||||||
|
<!-- Уведомление -->
|
||||||
|
<div id="notification" class="alert alert-info d-none" role="alert">
|
||||||
|
Здесь появятся уведомления.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Форма для импорта отелей -->
|
||||||
|
<form id="importHotelsForm" method="POST">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }} <!-- Отображаем форму -->
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extrahead %}
|
||||||
|
{{ block.super }}
|
||||||
|
<!-- Подключаем Bootstrap 4 -->
|
||||||
|
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const importButton = document.querySelector("button[type='submit']");
|
||||||
|
const notificationElement = document.getElementById('notification');
|
||||||
|
|
||||||
|
// Слушатель для отправки формы
|
||||||
|
importButton.addEventListener('click', function(e) {
|
||||||
|
e.preventDefault(); // предотвращаем стандартное поведение кнопки
|
||||||
|
|
||||||
|
// Извлекаем выбранные отели
|
||||||
|
const checkboxes = document.querySelectorAll('input[name="hotels"]:checked');
|
||||||
|
const selectedHotels = [];
|
||||||
|
console.log("Чекбоксы:", checkboxes); // Консольная отладка
|
||||||
|
|
||||||
|
checkboxes.forEach(function(checkbox) {
|
||||||
|
selectedHotels.push(checkbox.value);
|
||||||
|
console.log("Выбранный отель:", checkbox.value); // Консольная отладка
|
||||||
|
});
|
||||||
|
|
||||||
|
// Если выбраны отели
|
||||||
|
if (selectedHotels.length > 0) {
|
||||||
|
// Преобразуем CSRF токен
|
||||||
|
const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value;
|
||||||
|
console.log("CSRF токен:", csrfToken); // Консольная отладка
|
||||||
|
|
||||||
|
// Отправляем данные на сервер
|
||||||
|
fetch('/import_hotels/', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRFToken': csrfToken,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ hotels: selectedHotels })
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
console.log("Ответ от сервера:", data); // Консольная отладка
|
||||||
|
// Показать успешное уведомление
|
||||||
|
notificationElement.classList.remove('d-none');
|
||||||
|
notificationElement.classList.add('alert-success');
|
||||||
|
notificationElement.textContent = data.message || "Отели успешно импортированы!";
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Ошибка при импорте:", error); // Консольная отладка
|
||||||
|
// Показать ошибку
|
||||||
|
notificationElement.classList.remove('d-none');
|
||||||
|
notificationElement.classList.add('alert-danger');
|
||||||
|
notificationElement.textContent = "Произошла ошибка при импорте отелей.";
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
// Сброс кнопки
|
||||||
|
importButton.disabled = false;
|
||||||
|
importButton.textContent = 'Импортировать выбранные отели';
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log("Не выбраны отели"); // Консольная отладка
|
||||||
|
notificationElement.classList.remove('d-none');
|
||||||
|
notificationElement.classList.add('alert-warning');
|
||||||
|
notificationElement.textContent = "Пожалуйста, выберите хотя бы один отель для импорта.";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
{% extends "admin/base_site.html" %}
|
||||||
|
{% load i18n static %}
|
||||||
|
|
||||||
|
{% block title %}Редактирование отеля{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container-fluid">
|
||||||
|
<h3 class="text-dark mb-4">Редактирование отеля</h3>
|
||||||
|
|
||||||
|
<form method="post" action="{% url 'admin:save_edited_hotel' hotel.id %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="display_name" class="form-label">Отображаемое имя</label>
|
||||||
|
<input class="form-control" type="text" id="display_name" name="display_name" value="{{ hotel.display_name }}" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="original_name" class="form-label">Оригинальное имя</label>
|
||||||
|
<input class="form-control" type="text" id="original_name" name="original_name" value="{{ hotel.name }}" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<label for="imported" class="form-label">Импортирован</label>
|
||||||
|
<select class="form-select" id="imported" name="imported">
|
||||||
|
<option value="True" {% if hotel.imported %} selected {% endif %}>Да</option>
|
||||||
|
<option value="False" {% if not hotel.imported %} selected {% endif %}>Нет</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<button type="submit" class="btn btn-primary">Сохранить изменения</button>
|
||||||
|
<a href="{% url 'admin:hotel_list' %}" class="btn btn-secondary">Назад</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
143
antifroud/templates/antifroud/admin/imported_hotels.html
Normal file
143
antifroud/templates/antifroud/admin/imported_hotels.html
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
{% extends "admin/change_list.html" %}
|
||||||
|
{% block content %}
|
||||||
|
<!-- Кнопка импорта -->
|
||||||
|
<div class="form-group mb-3">
|
||||||
|
<button type="button" class="btn btn-primary" id="importHotelsButton">
|
||||||
|
Импортировать выбранные отели
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Уведомление -->
|
||||||
|
<div id="notification" class="alert alert-info d-none" role="alert">
|
||||||
|
Здесь появятся уведомления.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Действия админки -->
|
||||||
|
{{ block.super }}
|
||||||
|
|
||||||
|
<!-- Список отелей для выбора в виде таблицы -->
|
||||||
|
<form id="importHotelsForm" method="POST">
|
||||||
|
{% csrf_token %}
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead class="thead-dark">
|
||||||
|
<tr>
|
||||||
|
<!-- Чекбокс для выбора всех отелей -->
|
||||||
|
<th><input type="checkbox" id="select-all" /></th>
|
||||||
|
<th>Внешний ID</th>
|
||||||
|
<th>Отображаемое имя</th>
|
||||||
|
<th>Имя отеля</th>
|
||||||
|
<th>Дата создания</th>
|
||||||
|
<th>Дата обновления</th>
|
||||||
|
<th>Импортирован в основную базу</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for hotel in imported_hotels %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<input type="checkbox" name="hotels" value="{{ hotel.id }}" id="hotel{{ hotel.id }}" class="select-row" />
|
||||||
|
</td>
|
||||||
|
<td>{{ hotel.external_id }}</td>
|
||||||
|
<td>{{ hotel.display_name }}</td>
|
||||||
|
<td>{{ hotel.name }}</td>
|
||||||
|
<td>{{ hotel.creation_date }}</td>
|
||||||
|
<td>{{ hotel.updated_at }}</td>
|
||||||
|
<td>{{ hotel.imported_to_main_db }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Здесь вы можете добавить скрытые поля или другие элементы формы, если они нужны -->
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extrahead %}
|
||||||
|
{{ block.super }}
|
||||||
|
<!-- Подключаем Bootstrap 4 -->
|
||||||
|
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
// Обработчик для выбора всех чекбоксов
|
||||||
|
const selectAllCheckbox = document.getElementById('select-all');
|
||||||
|
selectAllCheckbox.addEventListener('change', function() {
|
||||||
|
const checkboxes = document.querySelectorAll(".select-row");
|
||||||
|
checkboxes.forEach(function(checkbox) {
|
||||||
|
checkbox.checked = selectAllCheckbox.checked;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Кнопка импорта
|
||||||
|
const importButton = document.getElementById('importHotelsButton');
|
||||||
|
const notificationElement = document.getElementById('notification');
|
||||||
|
|
||||||
|
importButton.addEventListener('click', function(e) {
|
||||||
|
e.preventDefault(); // предотвращаем стандартное поведение кнопки
|
||||||
|
|
||||||
|
// Даем время DOM полностью загрузиться
|
||||||
|
setTimeout(function() {
|
||||||
|
const checkboxes = document.querySelectorAll('input[name="hotels"]:checked');
|
||||||
|
const selectedHotels = [];
|
||||||
|
|
||||||
|
console.log("Чекбоксы:", checkboxes); // Отладка: выводим все выбранные чекбоксы
|
||||||
|
|
||||||
|
checkboxes.forEach(function(checkbox) {
|
||||||
|
selectedHotels.push(checkbox.value);
|
||||||
|
console.log("Выбранный отель:", checkbox.value); // Отладка: выводим ID выбранного отеля
|
||||||
|
});
|
||||||
|
|
||||||
|
if (selectedHotels.length > 0) {
|
||||||
|
const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value;
|
||||||
|
console.log("CSRF токен:", csrfToken);
|
||||||
|
|
||||||
|
importButton.disabled = true;
|
||||||
|
importButton.textContent = 'Импортируем...';
|
||||||
|
|
||||||
|
// Отправка выбранных отелей на сервер через fetch
|
||||||
|
fetch('/import_hotels/', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRFToken': csrfToken,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ hotels: selectedHotels })
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
console.log("Ответ сервера:", data);
|
||||||
|
notificationElement.classList.remove('d-none');
|
||||||
|
notificationElement.classList.add('alert-success');
|
||||||
|
notificationElement.textContent = "Отели успешно импортированы!";
|
||||||
|
checkboxes.forEach(checkbox => checkbox.checked = false); // Снимаем выделение с чекбоксов
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Ошибка при импорте:", error);
|
||||||
|
notificationElement.classList.remove('d-none');
|
||||||
|
notificationElement.classList.add('alert-danger');
|
||||||
|
notificationElement.textContent = "Произошла ошибка при импорте отелей.";
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
importButton.disabled = false;
|
||||||
|
importButton.textContent = 'Импортировать выбранные отели';
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log("Не выбраны отели");
|
||||||
|
notificationElement.classList.remove('d-none');
|
||||||
|
notificationElement.classList.add('alert-warning');
|
||||||
|
notificationElement.textContent = "Пожалуйста, выберите хотя бы один отель для импорта.";
|
||||||
|
}
|
||||||
|
}, 100); // Задержка 100ms, чтобы дождаться рендеринга всех элементов
|
||||||
|
});
|
||||||
|
});
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const checkboxes = document.querySelectorAll('input[name="hotels"]');
|
||||||
|
console.log("Чекбоксы на странице:", checkboxes); // Проверим, есть ли чекбоксы
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
3
antifroud/tests.py
Normal file
3
antifroud/tests.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
10
antifroud/urls.py
Normal file
10
antifroud/urls.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# antifroud/urls.py
|
||||||
|
from django.urls import path
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
app_name = 'antifroud'
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('import_selected_hotels/', views.import_selected_hotels, name='importedhotels_import_selected_hotels'),
|
||||||
|
# Другие URL-адреса
|
||||||
|
]
|
||||||
110
antifroud/views.py
Normal file
110
antifroud/views.py
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
import logging
|
||||||
|
from django.http import JsonResponse
|
||||||
|
from django.shortcuts import render
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from .models import ImportedHotel
|
||||||
|
from hotels.models import Hotel
|
||||||
|
|
||||||
|
from django.contrib.admin.views.decorators import staff_member_required
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
# Создаем логгер
|
||||||
|
logger = logging.getLogger('antifroud')
|
||||||
|
|
||||||
|
@staff_member_required
|
||||||
|
def import_selected_hotels(request):
|
||||||
|
if request.method != 'POST':
|
||||||
|
logger.error("Invalid request method. Only POST is allowed.")
|
||||||
|
return JsonResponse({'success': False, 'error': 'Invalid request method'})
|
||||||
|
|
||||||
|
selected_hotels = request.POST.getlist('hotels')
|
||||||
|
if not selected_hotels:
|
||||||
|
logger.warning("No hotels selected for import.")
|
||||||
|
return JsonResponse({'success': False, 'error': 'No hotels selected'})
|
||||||
|
|
||||||
|
try:
|
||||||
|
logger.info("Fetching selected hotels from ImportedHotel model.")
|
||||||
|
|
||||||
|
# Получаем отели, которые были выбраны для импорта
|
||||||
|
imported_hotels = ImportedHotel.objects.filter(id__in=selected_hotels)
|
||||||
|
logger.info(f"Found {imported_hotels.count()} selected hotels for import.")
|
||||||
|
|
||||||
|
# Список для хранения новых объектов отелей
|
||||||
|
hotels_to_import = []
|
||||||
|
|
||||||
|
for imported_hotel in imported_hotels:
|
||||||
|
logger.debug(f"Preparing hotel data for import: {imported_hotel.name}, {imported_hotel.city}")
|
||||||
|
|
||||||
|
# Получаем APIConfiguration (если имеется)
|
||||||
|
api_configuration = None
|
||||||
|
if imported_hotel.api:
|
||||||
|
api_configuration = imported_hotel.api
|
||||||
|
|
||||||
|
# Получаем PMSConfiguration (если имеется)
|
||||||
|
pms_configuration = None
|
||||||
|
if imported_hotel.pms:
|
||||||
|
pms_configuration = imported_hotel.pms
|
||||||
|
|
||||||
|
# Проверяем, импортирован ли отель из другого отеля (imported_from)
|
||||||
|
imported_from = None
|
||||||
|
if imported_hotel.imported_from:
|
||||||
|
imported_from = imported_hotel.imported_from
|
||||||
|
|
||||||
|
# Подготовим данные для нового отеля
|
||||||
|
hotel_data = {
|
||||||
|
'name': imported_hotel.name,
|
||||||
|
'api': api_configuration,
|
||||||
|
'pms': pms_configuration,
|
||||||
|
'imported_from': imported_from,
|
||||||
|
'imported_at': timezone.now(), # Устанавливаем дату импорта
|
||||||
|
'import_status': 'completed', # Устанавливаем статус импорта
|
||||||
|
}
|
||||||
|
|
||||||
|
# Создаем новый объект Hotel
|
||||||
|
hotel = Hotel(**hotel_data)
|
||||||
|
hotels_to_import.append(hotel)
|
||||||
|
|
||||||
|
# Массово сохраняем новые отели в таблице Hotels
|
||||||
|
logger.info(f"Importing {len(hotels_to_import)} hotels into Hotel model.")
|
||||||
|
Hotel.objects.bulk_create(hotels_to_import)
|
||||||
|
logger.info("Hotels imported successfully.")
|
||||||
|
|
||||||
|
# Обновляем статус импортированных отелей
|
||||||
|
imported_hotels.update(imported=True)
|
||||||
|
logger.info(f"Updated {imported_hotels.count()} imported hotels' status.")
|
||||||
|
|
||||||
|
return JsonResponse({'success': True})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error during hotel import: {str(e)}", exc_info=True)
|
||||||
|
return JsonResponse({'success': False, 'error': str(e)})
|
||||||
|
|
||||||
|
from django.http import JsonResponse
|
||||||
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
from .models import Hotel
|
||||||
|
from .forms import HotelImportForm
|
||||||
|
@csrf_exempt # Или используйте @login_required, если нужно ограничить доступ
|
||||||
|
def import_hotels(request):
|
||||||
|
if request.method == 'POST':
|
||||||
|
form = HotelImportForm(request.POST)
|
||||||
|
if form.is_valid():
|
||||||
|
# Получаем выбранные отели
|
||||||
|
selected_hotels = form.cleaned_data['hotels']
|
||||||
|
|
||||||
|
# Логика импорта отелей (например, можно их обновить или импортировать в другую базу)
|
||||||
|
# Для примера, просто устанавливаем флаг "imported" в True
|
||||||
|
for hotel in selected_hotels:
|
||||||
|
hotel.imported_to_main_db = True
|
||||||
|
hotel.save()
|
||||||
|
|
||||||
|
# Возвращаем успешный ответ
|
||||||
|
return JsonResponse({"message": "Отели успешно импортированы!"}, status=200)
|
||||||
|
else:
|
||||||
|
# Если форма невалидна
|
||||||
|
return JsonResponse({"message": "Ошибка при импорте отелей."}, status=400)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# GET-запрос, просто показываем форму
|
||||||
|
form = HotelImportForm()
|
||||||
|
|
||||||
|
return render(request, 'antifroud/admin/import_hotels.html', {'form': form})
|
||||||
@@ -121,6 +121,52 @@ async def delete_hotel(update: Update, context):
|
|||||||
# await pms_manager.save_log("error", str(e))
|
# await pms_manager.save_log("error", str(e))
|
||||||
# await query.edit_message_text(f"❌ Ошибка: {e}")
|
# await query.edit_message_text(f"❌ Ошибка: {e}")
|
||||||
|
|
||||||
|
# async def check_pms(update, context):
|
||||||
|
# query = update.callback_query
|
||||||
|
|
||||||
|
# try:
|
||||||
|
# # Получение ID отеля из callback_data
|
||||||
|
# hotel_id = query.data.split("_")[2]
|
||||||
|
|
||||||
|
# # Получение конфигурации отеля и PMS
|
||||||
|
# hotel = await sync_to_async(Hotel.objects.select_related('pms').get)(id=hotel_id)
|
||||||
|
# pms_config = hotel.pms
|
||||||
|
|
||||||
|
# if not pms_config:
|
||||||
|
# await query.edit_message_text("PMS конфигурация не найдена.")
|
||||||
|
# return
|
||||||
|
|
||||||
|
# # Создаем экземпляр PMSIntegrationManager
|
||||||
|
# pms_manager = PMSIntegrationManager(hotel_id=hotel_id)
|
||||||
|
# await pms_manager.load_hotel()
|
||||||
|
# await sync_to_async(pms_manager.load_plugin)()
|
||||||
|
|
||||||
|
# # Проверяем, какой способ интеграции использовать
|
||||||
|
# if hasattr(pms_manager.plugin, 'fetch_data') and callable(pms_manager.plugin.fetch_data):
|
||||||
|
# # Плагин поддерживает метод fetch_data
|
||||||
|
# data = await pms_manager.plugin.fetch_data()
|
||||||
|
# elif pms_config.api_url and pms_config.token:
|
||||||
|
# # Используем прямой запрос к API
|
||||||
|
# from pms_integration.api_client import APIClient
|
||||||
|
# api_client = APIClient(base_url=pms_config.api_url, access_token=pms_config.token)
|
||||||
|
# data = api_client.fetch_reservations()
|
||||||
|
# else:
|
||||||
|
# # Если подходящий способ не найден
|
||||||
|
# await query.edit_message_text("Подходящий способ интеграции с PMS не найден.")
|
||||||
|
# return
|
||||||
|
|
||||||
|
# # Сохраняем данные в базу
|
||||||
|
# from bot.utils.database import save_reservations
|
||||||
|
# await sync_to_async(save_reservations)(data)
|
||||||
|
|
||||||
|
# # Уведомляем об успешной интеграции
|
||||||
|
# await query.edit_message_text(f"Интеграция PMS {pms_config.name} завершена успешно.")
|
||||||
|
# except Exception as e:
|
||||||
|
# # Обрабатываем и логируем ошибки
|
||||||
|
# await query.edit_message_text(f"❌ Ошибка: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def check_pms(update, context):
|
async def check_pms(update, context):
|
||||||
query = update.callback_query
|
query = update.callback_query
|
||||||
|
|
||||||
@@ -144,28 +190,28 @@ async def check_pms(update, context):
|
|||||||
# Проверяем, какой способ интеграции использовать
|
# Проверяем, какой способ интеграции использовать
|
||||||
if hasattr(pms_manager.plugin, 'fetch_data') and callable(pms_manager.plugin.fetch_data):
|
if hasattr(pms_manager.plugin, 'fetch_data') and callable(pms_manager.plugin.fetch_data):
|
||||||
# Плагин поддерживает метод fetch_data
|
# Плагин поддерживает метод fetch_data
|
||||||
data = await pms_manager.plugin.fetch_data()
|
report = await pms_manager.plugin._fetch_data()
|
||||||
elif pms_config.api_url and pms_config.token:
|
|
||||||
# Используем прямой запрос к API
|
|
||||||
from pms_integration.api_client import APIClient
|
|
||||||
api_client = APIClient(base_url=pms_config.api_url, access_token=pms_config.token)
|
|
||||||
data = api_client.fetch_reservations()
|
|
||||||
else:
|
else:
|
||||||
# Если подходящий способ не найден
|
|
||||||
await query.edit_message_text("Подходящий способ интеграции с PMS не найден.")
|
await query.edit_message_text("Подходящий способ интеграции с PMS не найден.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Сохраняем данные в базу
|
# Формируем сообщение о результатах
|
||||||
from bot.utils.database import save_reservations
|
result_message = (
|
||||||
await sync_to_async(save_reservations)(data)
|
f"Интеграция PMS завершена успешно.\n"
|
||||||
|
f"Обработано интервалов: {report['processed_intervals']}\n"
|
||||||
|
f"Обработано записей: {report['processed_items']}\n"
|
||||||
|
f"Ошибки: {len(report['errors'])}"
|
||||||
|
)
|
||||||
|
if report["errors"]:
|
||||||
|
result_message += "\n\nСписок ошибок:\n" + "\n".join(report["errors"])
|
||||||
|
|
||||||
# Уведомляем об успешной интеграции
|
await query.edit_message_text(result_message)
|
||||||
await query.edit_message_text(f"Интеграция PMS {pms_config.name} завершена успешно.")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Обрабатываем и логируем ошибки
|
# Обрабатываем и логируем ошибки
|
||||||
await query.edit_message_text(f"❌ Ошибка: {str(e)}")
|
await query.edit_message_text(f"❌ Ошибка: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def setup_rooms(update: Update, context):
|
async def setup_rooms(update: Update, context):
|
||||||
"""Настроить номера отеля."""
|
"""Настроить номера отеля."""
|
||||||
query = update.callback_query
|
query = update.callback_query
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta, timezone
|
||||||
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
|
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
|
||||||
from telegram.ext import ContextTypes
|
from telegram.ext import ContextTypes
|
||||||
from asgiref.sync import sync_to_async
|
from asgiref.sync import sync_to_async
|
||||||
@@ -7,7 +7,7 @@ from users.models import User
|
|||||||
|
|
||||||
from bot.utils.pdf_report import generate_pdf_report
|
from bot.utils.pdf_report import generate_pdf_report
|
||||||
from bot.utils.database import get_hotels_for_user, get_hotel_by_name
|
from bot.utils.database import get_hotels_for_user, get_hotel_by_name
|
||||||
|
from django.utils.timezone import make_aware
|
||||||
|
|
||||||
async def statistics(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def statistics(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
"""Вывод списка отелей для статистики."""
|
"""Вывод списка отелей для статистики."""
|
||||||
@@ -55,6 +55,7 @@ async def stats_select_period(update: Update, context: ContextTypes.DEFAULT_TYPE
|
|||||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||||
await query.edit_message_text("Выберите период времени:", reply_markup=reply_markup)
|
await query.edit_message_text("Выберите период времени:", reply_markup=reply_markup)
|
||||||
|
|
||||||
|
|
||||||
async def generate_statistics(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def generate_statistics(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
"""Генерация и отправка статистики."""
|
"""Генерация и отправка статистики."""
|
||||||
query = update.callback_query
|
query = update.callback_query
|
||||||
@@ -66,47 +67,70 @@ async def generate_statistics(update: Update, context: ContextTypes.DEFAULT_TYPE
|
|||||||
return
|
return
|
||||||
|
|
||||||
period = query.data.split("_")[2]
|
period = query.data.split("_")[2]
|
||||||
|
print(f'Period raw: {query.data}')
|
||||||
|
print(f'Selected period: {period}')
|
||||||
|
|
||||||
|
now = datetime.utcnow().replace(tzinfo=timezone.utc) # Используем timezone.utc
|
||||||
|
|
||||||
now = datetime.now()
|
|
||||||
if period == "day":
|
if period == "day":
|
||||||
start_date = (now - timedelta(days=1)).date() # Вчерашняя дата
|
start_date = (now - timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
end_date = now.date() # Сегодняшняя дата
|
end_date = now.replace(hour=23, minute=59, second=59, microsecond=999999)
|
||||||
elif period == "week":
|
elif period == "week":
|
||||||
start_date = (now - timedelta(days=7)).date()
|
start_date = (now - timedelta(days=7)).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
end_date = now.date()
|
end_date = now.replace(hour=23, minute=59, second=59, microsecond=999999)
|
||||||
elif period == "month":
|
elif period == "month":
|
||||||
start_date = (now - timedelta(days=30)).date()
|
start_date = (now - timedelta(days=30)).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
end_date = now.date()
|
end_date = now.replace(hour=23, minute=59, second=59, microsecond=999999)
|
||||||
else:
|
else: # "all"
|
||||||
start_date = None
|
start_date = None
|
||||||
end_date = None
|
end_date = None
|
||||||
|
|
||||||
|
print(f'Raw start_date: {start_date}, Raw end_date: {end_date}')
|
||||||
|
|
||||||
|
# Убедитесь, что даты имеют временную зону UTC
|
||||||
|
if start_date:
|
||||||
|
start_date = make_aware(start_date) if start_date.tzinfo is None else start_date
|
||||||
|
if end_date:
|
||||||
|
end_date = make_aware(end_date) if end_date.tzinfo is None else end_date
|
||||||
|
|
||||||
|
print(f'Filtered start_date: {start_date}, Filtered end_date: {end_date}')
|
||||||
|
|
||||||
# Фильтрация по "дата заезда"
|
# Фильтрация по "дата заезда"
|
||||||
if start_date and end_date:
|
if start_date and end_date:
|
||||||
reservations = await sync_to_async(list)(
|
reservations = await sync_to_async(list)(
|
||||||
Reservation.objects.filter(
|
Reservation.objects.filter(
|
||||||
hotel_id=hotel_id,
|
hotel_id=hotel_id,
|
||||||
check_in__date__gte=start_date,
|
check_in__gte=start_date,
|
||||||
check_in__date__lte=end_date
|
check_in__lte=end_date
|
||||||
).prefetch_related('guests')
|
).select_related('hotel')
|
||||||
)
|
)
|
||||||
else:
|
else: # Без фильтра по дате
|
||||||
reservations = await sync_to_async(list)(
|
reservations = await sync_to_async(list)(
|
||||||
Reservation.objects.filter(hotel_id=hotel_id).prefetch_related('guests')
|
Reservation.objects.filter(
|
||||||
|
hotel_id=hotel_id
|
||||||
|
).select_related('hotel')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print(f'Filtered reservations count: {len(reservations)}')
|
||||||
|
|
||||||
if not reservations:
|
if not reservations:
|
||||||
await query.edit_message_text("Нет данных для статистики за выбранный период.")
|
await query.edit_message_text("Нет данных для статистики за выбранный период.")
|
||||||
return
|
return
|
||||||
|
|
||||||
hotel = await sync_to_async(Hotel.objects.get)(id=hotel_id)
|
hotel = await sync_to_async(Hotel.objects.get)(id=hotel_id)
|
||||||
|
print(f'Hotel: {hotel.name}')
|
||||||
|
|
||||||
|
for reservation in reservations:
|
||||||
|
print(f"Reservation ID: {reservation.reservation_id}, Hotel: {reservation.hotel.name}, "
|
||||||
|
f"Room number: {reservation.room_number}, Check-in: {reservation.check_in}, Check-out: {reservation.check_out}")
|
||||||
|
|
||||||
|
# Генерация PDF отчета (пример)
|
||||||
file_path = generate_pdf_report(hotel.name, reservations, start_date, end_date)
|
file_path = generate_pdf_report(hotel.name, reservations, start_date, end_date)
|
||||||
|
print(f'Generated file path: {file_path}')
|
||||||
|
|
||||||
with open(file_path, "rb") as file:
|
with open(file_path, "rb") as file:
|
||||||
await query.message.reply_document(document=file, filename=f"{hotel.name}_report.pdf")
|
await query.message.reply_document(document=file, filename=f"{hotel.name}_report.pdf")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def stats_back(update: Update, context):
|
async def stats_back(update: Update, context):
|
||||||
"""Возврат к выбору отеля."""
|
"""Возврат к выбору отеля."""
|
||||||
query = update.callback_query
|
query = update.callback_query
|
||||||
|
|||||||
Reference in New Issue
Block a user