Refactor device management: add vendor field, enhance admin display, and improve MAC address handling
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m18s

This commit is contained in:
2025-06-01 19:27:04 +05:00
parent e1c862184e
commit 4db9d7fabd
8 changed files with 122 additions and 20 deletions

View File

@ -59,9 +59,13 @@ def send_sms(mobile: str, message: str):
return False
# def escape_markdown_v2(text: str) -> str:
# special_chars = r"\_*[]()~`>#+-=|{}.!"
# return "".join(["\\" + c if c in special_chars else c for c in text])
def escape_markdown_v2(text: str) -> str:
special_chars = r"\~`>#+-=|{}!"
return "".join(["\\" + c if c in special_chars else c for c in text])
def normalize_whitespace(text: str) -> str:
return "\n".join(line.strip() for line in text.strip().splitlines())
def send_telegram_markdown(message: str):
@ -83,3 +87,9 @@ def send_telegram_markdown(message: str):
except requests.RequestException as e:
logger.error(f"Error sending Telegram message: {e}")
return {"error": str(e)}
def send_clean_telegram_markdown(message: str):
text = normalize_whitespace(message)
escaped = escape_markdown_v2(text)
return send_telegram_markdown(escaped)

View File

@ -8,7 +8,7 @@ import os
import logging
from celery import shared_task
from django.utils import timezone
from api.notifications import send_telegram_markdown
from api.notifications import send_clean_telegram_markdown
logger = logging.getLogger(__name__)
@ -161,15 +161,15 @@ def verify_user_with_person_api_task(user_id: int):
verification_failed_message = f"""
_The following user verification failed_:
*ID Card:* {user.id_card} \n
*Name:* {user.first_name} {user.last_name} \n
*House Name:* {user.address} \n
*Date of Birth:* {user.dob} \n
*Island:* {(user.atoll.name if user.atoll else "N/A")} {(user.island.name if user.island else "N/A")} \n
*Mobile:* {user.mobile} \n
*ID Card:* {user.id_card}
*Name:* {user.first_name} {user.last_name}
*House Name:* {user.address}
*Date of Birth:* {user.dob}
*Island:* {(user.atoll.name if user.atoll else "N/A")} {(user.island.name if user.island else "N/A")}
*Mobile:* {user.mobile}
Visit [SAR Link Portal](https://portal.sarlink.net) to manually verify this user.
"""
logger.info(verification_failed_message)
if not PERSON_VERIFY_BASE_URL:
raise ValueError(
@ -245,7 +245,7 @@ def verify_user_with_person_api_task(user_id: int):
user.mobile,
f"Dear {user.first_name} {user.last_name}, \n\nYour account registration is being processed. \n\nWe will notify you once verification is complete. \n\n - SAR Link",
)
send_telegram_markdown(message=verification_failed_message)
send_clean_telegram_markdown(message=verification_failed_message)
return False
else:
# Handle the error case