stranck-dev #25
9
admin.py
9
admin.py
|
@ -54,6 +54,15 @@ async def unconfirm_room(request, code, order:Order):
|
|||
await unconfirm_room_by_order(order=dOrder, throw=True, request=request)
|
||||
return redirect(f'/manage/nosecount')
|
||||
|
||||
@bp.get('/room/autoconfirm')
|
||||
async def autoconfirm_room(request, code, order:Order):
|
||||
orders = request.app.ctx.om.cache.values()
|
||||
for order in orders:
|
||||
if(order.code == order.room_id and not order.room_confirmed and len(order.room_members) == order.room_person_no):
|
||||
logger.info(f"Auto-Confirming room {order.room_id}")
|
||||
await confirm_room_by_order(order, request)
|
||||
return redirect(f'/manage/admin')
|
||||
|
||||
@bp.get('/room/delete/<code>')
|
||||
async def delete_room(request, code, order:Order):
|
||||
dOrder = await get_order_by_code(request, code, throwException=True)
|
||||
|
|
36
room.py
36
room.py
|
@ -5,6 +5,7 @@ from ext import *
|
|||
from config import headers
|
||||
import os
|
||||
from image_util import generate_room_preview, get_room
|
||||
from utils import confirm_room_by_order
|
||||
|
||||
bp = Blueprint("room", url_prefix="/manage/room")
|
||||
|
||||
|
@ -303,40 +304,7 @@ async def confirm_room(request, order: Order, quotas: Quotas):
|
|||
#if quotas.get_left(len(order.room_members)) == 0:
|
||||
# raise exceptions.BadRequest("There are no more rooms of this size to reserve.")
|
||||
|
||||
bed_in_room = order.bed_in_room # Variation id of the ticket for that kind of room
|
||||
room_members = []
|
||||
for m in order.room_members:
|
||||
if m == order.code:
|
||||
res = order
|
||||
else:
|
||||
res = await request.app.ctx.om.get_order(code=m)
|
||||
|
||||
if res.room_id != order.code:
|
||||
raise exceptions.BadRequest("Please contact support: some of the members in your room are actually somewhere else")
|
||||
|
||||
if res.status != 'paid':
|
||||
raise exceptions.BadRequest("Somebody hasn't paid.")
|
||||
|
||||
if res.bed_in_room != bed_in_room:
|
||||
raise exceptions.BadRequest("Somebody has a ticket for a different type of room!")
|
||||
|
||||
if res.daily:
|
||||
raise exceptions.BadRequest("Somebody in your room has a daily ticket!")
|
||||
|
||||
room_members.append(res)
|
||||
|
||||
|
||||
if len(room_members) != order.room_person_no:
|
||||
raise exceptions.BadRequest("The number of people in your room mismatches your type of ticket!")
|
||||
|
||||
for rm in room_members:
|
||||
await rm.edit_answer('room_id', order.code)
|
||||
await rm.edit_answer('room_confirmed', "True")
|
||||
await rm.edit_answer('pending_roommates', None)
|
||||
await rm.edit_answer('pending_room', None)
|
||||
|
||||
for rm in room_members:
|
||||
await rm.send_answers()
|
||||
confirm_room_by_order(order, request)
|
||||
|
||||
return redirect('/manage/welcome')
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
<a href="/manage/nosecount" role="button" title="Shortcut to the nosecount's admin data">Manage rooms</a>
|
||||
<a href="/manage/admin/room/verify" role="button" title="Will unconfirm rooms that fail the default check. Useful when editing answers from Pretix">Verify Rooms</a>
|
||||
<a href="#" onclick="confirmAction('propicReminder', this)" role="button" title="Will remind via mail all people who event uploaded a badge to do it" action="/manage/admin/propic/remind">Remind badge upload</a>
|
||||
<a href="/manage/admin/room/autoconfirm" role="button" title="Will confirm all the full rooms that are still unconfirmed">Auto-confirm Rooms</a>
|
||||
<hr>
|
||||
{% include 'components/confirm_action_modal.html' %}
|
||||
</main>
|
||||
|
|
36
utils.py
36
utils.py
|
@ -151,6 +151,42 @@ 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 confirm_room_by_order(order, request):
|
||||
bed_in_room = order.bed_in_room # Variation id of the ticket for that kind of room
|
||||
room_members = []
|
||||
for m in order.room_members:
|
||||
if m == order.code:
|
||||
res = order
|
||||
else:
|
||||
res = await request.app.ctx.om.get_order(code=m)
|
||||
|
||||
if res.room_id != order.code:
|
||||
raise exceptions.BadRequest("Please contact support: some of the members in your room are actually somewhere else")
|
||||
|
||||
if res.status != 'paid':
|
||||
raise exceptions.BadRequest("Somebody hasn't paid.")
|
||||
|
||||
if res.bed_in_room != bed_in_room:
|
||||
raise exceptions.BadRequest("Somebody has a ticket for a different type of room!")
|
||||
|
||||
if res.daily:
|
||||
raise exceptions.BadRequest("Somebody in your room has a daily ticket!")
|
||||
|
||||
room_members.append(res)
|
||||
|
||||
|
||||
if len(room_members) != order.room_person_no:
|
||||
raise exceptions.BadRequest("The number of people in your room mismatches your type of ticket!")
|
||||
|
||||
for rm in room_members:
|
||||
await rm.edit_answer('room_id', order.code)
|
||||
await rm.edit_answer('room_confirmed', "True")
|
||||
await rm.edit_answer('pending_roommates', None)
|
||||
await rm.edit_answer('pending_room', None)
|
||||
|
||||
for rm in room_members:
|
||||
await rm.send_answers()
|
||||
|
||||
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:
|
||||
|
|
Loading…
Reference in New Issue