From c6bc9c65acb42bfc196a009261d92641514f5d57 Mon Sep 17 00:00:00 2001 From: Stranck Date: Thu, 29 Feb 2024 11:41:49 +0100 Subject: [PATCH] Added remind propic feature for admins --- admin.py | 18 ++++++++++++++++- email_util.py | 33 +++++++++++++++++++++++++++----- messages.py | 52 +++++++++++++++++++++++++++++++------------------- tpl/admin.html | 7 ++++--- utils.py | 4 ++-- 5 files changed, 83 insertions(+), 31 deletions(-) diff --git a/admin.py b/admin.py index e3651a7..9c37864 100644 --- a/admin.py +++ b/admin.py @@ -1,4 +1,5 @@ from sanic import response, redirect, Blueprint, exceptions +from email_util import send_missing_propic_message from room import unconfirm_room_by_order from config import * from utils import * @@ -82,4 +83,19 @@ async def rename_room(request, code, order:Order): await dOrder.edit_answer("room_name", name) await dOrder.send_answers() - return redirect(f'/manage/nosecount') \ No newline at end of file + return redirect(f'/manage/nosecount') + +@bp.get('/propic/remind') +async def propic_remind_missing(request, order:Order): + await clear_cache(request, order) + + orders = request.app.ctx.om.cache.values() + order: Order + for order in orders: + missingPropic = order.propic is None + missingFursuitPropic = order.is_fursuiter and order.propic_fursuiter is None + if(missingPropic or missingFursuitPropic): + # print(f"{order.code}: prp={missingPropic} fpr={missingFursuitPropic} - {order.name}") + await send_missing_propic_message(order, missingPropic, missingFursuitPropic) + + return redirect(f'/manage/admin') \ No newline at end of file diff --git a/email_util.py b/email_util.py index 6621e66..4687c5b 100644 --- a/email_util.py +++ b/email_util.py @@ -54,6 +54,13 @@ async def sendEmail(message : MIMEMultipart): smptSender.sendmail(message['From'], message['to'], message.as_string()) sslLock.release() +def render_email_template(title = "", body = ""): + tpl = Environment(loader=FileSystemLoader("tpl"), autoescape=False).get_template('email/comunication.html') + return str(tpl.render(title=title, body=body)) + + + + async def send_unconfirm_message(room_order, orders): memberMessages = [] @@ -72,8 +79,8 @@ async def send_unconfirm_message(room_order, orders): issues_html += "" for member in orders: - plain_body = ROOM_UNCONFIRM_TEXT['plain'].format(member.name, room_order.room_name, issues_plain) - html_body = render_email_template(ROOM_UNCONFIRM_TITLE, ROOM_UNCONFIRM_TEXT['html'].format(member.name, room_order.room_name, issues_html)) + plain_body = EMAILS_TEXT["ROOM_UNCONFIRM_TEXT"]['plain'].format(member.name, room_order.room_name, issues_plain) + html_body = render_email_template(EMAILS_TEXT["ROOM_UNCONFIRM_TITLE"], EMAILS_TEXT["ROOM_UNCONFIRM_TEXT"]['html'].format(member.name, room_order.room_name, issues_html)) plain_text = MIMEText(plain_body, "plain") html_text = MIMEText(html_body, "html") message = MIMEMultipart("alternative") @@ -89,6 +96,22 @@ async def send_unconfirm_message(room_order, orders): for message in memberMessages: await sendEmail(message) -def render_email_template(title = "", body = ""): - tpl = Environment(loader=FileSystemLoader("tpl"), autoescape=False).get_template('email/comunication.html') - return str(tpl.render(title=title, body=body)) \ No newline at end of file +async def send_missing_propic_message(order, missingPropic, missingFursuitPropic): + t = [] + if(missingPropic): t.append("your propic") + if(missingFursuitPropic): t.append("your fursuit's badge") + missingText = " and ".join(t) + + plain_body = EMAILS_TEXT["MISSING_PROPIC_TEXT"]['plain'].format(order.name, missingText) + html_body = render_email_template(EMAILS_TEXT["MISSING_PROPIC_TITLE"], EMAILS_TEXT["MISSING_PROPIC_TEXT"]['html'].format(order.name, missingText)) + plain_text = MIMEText(plain_body, "plain") + html_text = MIMEText(html_body, "html") + message = MIMEMultipart("alternative") + message.attach(plain_text) + message.attach(html_text) + message['Subject'] = f"[{EMAIL_SENDER_NAME}] You haven't uploaded your badges yet!" + message['From'] = f'{EMAIL_SENDER_NAME} <{EMAIL_SENDER_MAIL}>' + message['To'] = f"{order.name} <{order.email}>" + + await sendEmail(message) + diff --git a/messages.py b/messages.py index 98fc102..5664829 100644 --- a/messages.py +++ b/messages.py @@ -1,30 +1,42 @@ ROOM_ERROR_TYPES = { - 'room_id_mismatch': "There's a member in your room that is actually in another room, too. Please contact us as soon as possible in order to fix this issue.", - 'unpaid': "Somebody in your room has not paid for their reservation, yet.", - 'type_mismatch': "A member in your room has a ticket for a different type of room capacity. This happens when users swap their room types with others, without abandoning the room.", - 'daily': "Some member in your room has a Daily ticket. These tickets do not include a hotel reservation.", - 'capacity_mismatch': "The number of people in your room mismatches your type of ticket." + 'room_id_mismatch': "There's a member in your room that is actually in another room, too. Please contact us as soon as possible in order to fix this issue.", + 'unpaid': "Somebody in your room has not paid for their reservation, yet.", + 'type_mismatch': "A member in your room has a ticket for a different type of room capacity. This happens when users swap their room types with others, without abandoning the room.", + 'daily': "Some member in your room has a Daily ticket. These tickets do not include a hotel reservation.", + 'capacity_mismatch': "The number of people in your room mismatches your type of ticket." } -ROOM_UNCONFIRM_TITLE = "Your room got unconfirmed" -ROOM_UNCONFIRM_TEXT = { - 'html': "Hello {0}
We had to unconfirm your room '{1}' due to the following issues:

{2}

Please contact your room's owner or contact our support for further informations at https://furizon.net/contact/.
Thank you.

Manage booking", - 'plain': "Hello {0}\nWe had to unconfirm your room '{1}' due to the following issues:\n{2}\nPlease contact your room's owner or contact our support for further informations at https://furizon.net/contact/.\nThank you\n\nTo manage your booking: https://reg.furizon.net/manage/welcome" +EMAILS_TEXT = { + "ROOM_UNCONFIRM_TITLE": "Your room got unconfirmed", + "ROOM_UNCONFIRM_TEXT": { + 'html': "Hello {0}
We had to unconfirm your room '{1}' due to the following issues:

{2}

Please contact your room's owner or contact our support for further informations at https://furizon.net/contact/.
Thank you.

Manage booking", + + 'plain': "Hello {0}\nWe had to unconfirm your room '{1}' due to the following issues:\n{2}\nPlease contact your room's owner or contact our support for further informations at https://furizon.net/contact/.\nThank you\n\nTo manage your booking: https://reg.furizon.net/manage/welcome" + }, + + + "MISSING_PROPIC_TITLE": "You haven't uploaded your badges yet!", + "MISSING_PROPIC_TEXT": { + 'html': "Hello {0}
We noticed you still have to upload {1}!
Please enter your booking page at https://reg.furizon.net/manage/welcome and upload them under the \"Badge Customization\" section.
Thank you.

Manage booking", + + 'plain': "Hello {0}\nWe noticed you still have to upload {1}!\nPlease enter your booking page at https://reg.furizon.net/manage/welcome and upload them under the \"Badge Customization\" section.\nThank you." + }, } + NOSECOUNT = { - 'filters': { - 'capacity': "Here are some furs that share your room type and don't have a confirmed room." - } + 'filters': { + 'capacity': "Here are some furs that share your room type and don't have a confirmed room." + } } LOCALES = { - 'shuttle_link': { - 'en': 'Book now', - 'it': 'Prenota ora' - }, - 'shuttle_link_url': { - 'en': 'https://visitfiemme.regiondo.com/furizon?_ga=2.129644046.307369854.1705325023-235291123.1705325023', - 'it': 'https://experience.visitfiemme.it/furizon' - } + 'shuttle_link': { + 'en': 'Book now', + 'it': 'Prenota ora' + }, + 'shuttle_link_url': { + 'en': 'https://visitfiemme.regiondo.com/furizon?_ga=2.129644046.307369854.1705325023-235291123.1705325023', + 'it': 'https://experience.visitfiemme.it/furizon' + } } \ No newline at end of file diff --git a/tpl/admin.html b/tpl/admin.html index 0b2829f..2c1b0fb 100644 --- a/tpl/admin.html +++ b/tpl/admin.html @@ -9,10 +9,11 @@ -

Admin panel

- Clear cache - Manage rooms +

Admin panel

+ Clear cache + Manage rooms Verify Rooms + Remind badge upload
diff --git a/utils.py b/utils.py index b257544..d347419 100644 --- a/utils.py +++ b/utils.py @@ -151,7 +151,7 @@ async def get_people_in_room_by_code(request, code, om=None): await om.update_cache() return filter(lambda rm: rm.room_id == code, om.cache.values()) -async def unconfirm_room_by_order(order, room_members:[]=None, throw=True, request=None, om=None): +async def unconfirm_room_by_order(order, room_members=None, throw=True, request=None, om=None): if not om: om = request.app.ctx.om if not order.room_confirmed: if throw: @@ -216,7 +216,7 @@ async def validate_rooms(request, rooms, om): order = rtu[0] member_orders = rtu[2] try: - await send_unconfirm_message (order, member_orders) + await send_unconfirm_message(order, member_orders) sent_count += len(member_orders) except Exception as ex: if EXTRA_PRINTS: logger.exception(str(ex))