Merging to main

This commit is contained in:
Jonas Linter
2025-10-06 14:46:58 +02:00
parent 17c3fc57b2
commit b8e4f4fd01
2 changed files with 68 additions and 18 deletions

View File

@@ -31,6 +31,7 @@ from datetime import datetime
from typing import Dict, Any, Optional, List
import json
import os
import asyncio
import gzip
import xml.etree.ElementTree as ET
from .alpinebits_server import AlpineBitsClientInfo, AlpineBitsServer, Version, AlpineBitsActionName
@@ -113,13 +114,25 @@ async def push_listener(customer: DBCustomer, reservation: DBReservation, hotel)
if request.status_code != 200:
_LOGGER.error(f"Failed to generate push request for hotel {hotel_id}, reservation {reservation.unique_id}: {request.xml_content}")
return
print(request.xml_content)
# TODO: Generate AlpineBits OTA_HotelResNotifRQ request
# action = "OTA_HotelResNotifRQ"
# request = server.handle_request(action, ...)
print(f"--- Push Payload --- received. Sending to endpoint., hotelid {hotel_id}, reservation {reservation.unique_id}")
# save push request to file
logs_dir = "logs/push_requests"
if not os.path.exists(logs_dir):
os.makedirs(logs_dir, mode=0o755, exist_ok=True)
stat_info = os.stat(logs_dir)
_LOGGER.info(
f"Created directory owner: uid:{stat_info.st_uid}, gid:{stat_info.st_gid}"
)
_LOGGER.info(f"Directory mode: {oct(stat_info.st_mode)[-3:]}")
log_filename = (
f"{logs_dir}/alpinebits_push_{hotel_id}_{reservation.unique_id}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.xml"
)
with open(log_filename, "w", encoding="utf-8") as f:
f.write(request.xml_content)
return
headers = {"Authorization": f"Bearer {push_endpoint.get('token','')}"} if push_endpoint.get('token') else {}
@@ -337,7 +350,7 @@ async def process_wix_form_submission(request: Request, data: Dict[str, Any], db
name_prefix = data.get("field:anrede")
email_newsletter_string = data.get("field:form_field_5a7b", "")
yes_values = {"Selezionato", "Angekreuzt"}
yes_values = {"Selezionato", "Angekreuzt", "Checked"}
email_newsletter = (email_newsletter_string in yes_values)
address_line = None
city_name = None
@@ -460,17 +473,21 @@ async def process_wix_form_submission(request: Request, data: Dict[str, Any], db
await db.commit()
await db.refresh(db_reservation)
async def push_event():
# Fire event for listeners (push, etc.) - hotel-specific dispatch
dispatcher = getattr(request.app.state, "event_dispatcher", None)
if dispatcher:
# Get hotel_code from reservation to target the right listeners
hotel_code = getattr(db_reservation, 'hotel_code', None)
if hotel_code and hotel_code.strip():
await dispatcher.dispatch_for_hotel("form_processed", hotel_code, db_customer, db_reservation)
_LOGGER.info(f"Dispatched form_processed event for hotel {hotel_code}")
else:
_LOGGER.warning("No hotel_code in reservation, skipping push notifications")
# Fire event for listeners (push, etc.) - hotel-specific dispatch
dispatcher = getattr(request.app.state, "event_dispatcher", None)
if dispatcher:
# Get hotel_code from reservation to target the right listeners
hotel_code = getattr(db_reservation, 'hotel_code', None)
if hotel_code and hotel_code.strip():
await dispatcher.dispatch_for_hotel("form_processed", hotel_code, db_customer, db_reservation)
_LOGGER.info(f"Dispatched form_processed event for hotel {hotel_code}")
else:
_LOGGER.warning("No hotel_code in reservation, skipping push notifications")
asyncio.create_task(push_event())
return {
"status": "success",