stranck-dev #31
39
admin.py
39
admin.py
|
@ -111,12 +111,12 @@ async def room_wizard(request, order:Order):
|
||||||
await clear_cache(request, order)
|
await clear_cache(request, order)
|
||||||
|
|
||||||
#Separate orders which have incomplete rooms and which have no rooms
|
#Separate orders which have incomplete rooms and which have no rooms
|
||||||
all_orders = {key:value for key,value in sorted(request.app.ctx.om.cache.items(), key=lambda x: len(x[1].room_members), reverse=True) if value.status not in ['c', 'e'] and not value.daily}
|
all_orders = {key:value for key,value in sorted(request.app.ctx.om.cache.items(), key=lambda x: (x[1].room_person_no, len(x[1].room_members)), reverse=True) if (value.status not in ['canceled', 'expired'] and not value.daily and value.bed_in_room != ITEM_VARIATIONS_MAP["bed_in_room"]["bed_in_room_no_room"])}
|
||||||
orders = {key:value for key,value in sorted(all_orders.items(), key=lambda x: x[1].ans('fursona_name')) if not value.room_confirmed}
|
orders = {key:value for key,value in sorted(all_orders.items(), key=lambda x: x[1].ans('fursona_name')) if not value.room_confirmed}
|
||||||
# Orders with incomplete rooms
|
# Orders with incomplete rooms
|
||||||
incomplete_orders = {key:value for key,value in orders.items() if value.code == value.room_id and (value.room_person_no - len(value.room_members)) > 0}
|
incomplete_orders = {key:value for key,value in orders.items() if value.code == value.room_id and (value.room_person_no - len(value.room_members)) > 0}
|
||||||
# Roomless furs
|
# Roomless furs
|
||||||
roomless_orders = {key:value for key,value in orders.items() if not value.room_id and not value.daily}
|
roomless_orders = {key:value for key,value in orders.items() if(not value.room_id and not value.daily and value.bed_in_room != ITEM_VARIATIONS_MAP["bed_in_room"]["bed_in_room_no_room"])}
|
||||||
|
|
||||||
# Result map
|
# Result map
|
||||||
result_map = {}
|
result_map = {}
|
||||||
|
@ -124,10 +124,13 @@ async def room_wizard(request, order:Order):
|
||||||
# Check overflows
|
# Check overflows
|
||||||
room_quota_overflow = {}
|
room_quota_overflow = {}
|
||||||
for key, value in ITEM_VARIATIONS_MAP['bed_in_room'].items():
|
for key, value in ITEM_VARIATIONS_MAP['bed_in_room'].items():
|
||||||
room_quota = get_quota(ITEMS_ID_MAP['bed_in_room'], value)
|
if key != "bed_in_room_no_room":
|
||||||
capacity = ROOM_CAPACITY_MAP[key] if key in ROOM_CAPACITY_MAP else 1
|
room_quota = get_quota(ITEMS_ID_MAP['bed_in_room'], value)
|
||||||
current_quota = len(list(filter(lambda y: y.bed_in_room == value and y.room_owner == True, orders.values())))
|
capacity = ROOM_CAPACITY_MAP[key] if key in ROOM_CAPACITY_MAP else 1
|
||||||
room_quota_overflow[value] = current_quota - int(room_quota.size / capacity) if room_quota else 0
|
current_quota = len(list(filter(lambda y: y.bed_in_room == value and y.room_owner == True, all_orders.values())))
|
||||||
|
room_quota_overflow[value] = current_quota - int(room_quota.size / capacity) if room_quota else 0
|
||||||
|
if DEV_MODE and EXTRA_PRINTS:
|
||||||
|
print(f"There are {current_quota} of room type {key} out of a total of ({room_quota.size} / {capacity})")
|
||||||
|
|
||||||
# Init rooms to remove
|
# Init rooms to remove
|
||||||
result_map["void"] = []
|
result_map["void"] = []
|
||||||
|
@ -135,6 +138,7 @@ async def room_wizard(request, order:Order):
|
||||||
# Remove rooms that are over quota
|
# Remove rooms that are over quota
|
||||||
for room_type, overflow_qty in {key:value for key,value in room_quota_overflow.items() if value > 0}.items():
|
for room_type, overflow_qty in {key:value for key,value in room_quota_overflow.items() if value > 0}.items():
|
||||||
sorted_rooms = sorted(incomplete_orders.values(), key=lambda r: len(r.room_members))
|
sorted_rooms = sorted(incomplete_orders.values(), key=lambda r: len(r.room_members))
|
||||||
|
sorted_rooms = [r for r in sorted_rooms if r.bed_in_room == room_type]
|
||||||
for room_to_remove in sorted_rooms[:overflow_qty]:
|
for room_to_remove in sorted_rooms[:overflow_qty]:
|
||||||
# Room codes to remove
|
# Room codes to remove
|
||||||
result_map["void"].append(room_to_remove.code)
|
result_map["void"].append(room_to_remove.code)
|
||||||
|
@ -147,8 +151,10 @@ async def room_wizard(request, order:Order):
|
||||||
for room_order in incomplete_orders.items():
|
for room_order in incomplete_orders.items():
|
||||||
room = room_order[1]
|
room = room_order[1]
|
||||||
to_add = []
|
to_add = []
|
||||||
missing_slots = room.room_person_no - len(room.room_members)
|
count = room.room_person_no
|
||||||
for i in range(missing_slots):
|
alreadyPresent = len(room.room_members)
|
||||||
|
missing_slots = count - alreadyPresent
|
||||||
|
for _ in range(missing_slots):
|
||||||
compatible_roomates = {key:value for key,value in roomless_orders.items() if value.bed_in_room == room.bed_in_room}
|
compatible_roomates = {key:value for key,value in roomless_orders.items() if value.bed_in_room == room.bed_in_room}
|
||||||
if len(compatible_roomates.items()) == 0: break
|
if len(compatible_roomates.items()) == 0: break
|
||||||
# Try picking a roomate that's from the same country and room type
|
# Try picking a roomate that's from the same country and room type
|
||||||
|
@ -165,7 +171,9 @@ async def room_wizard(request, order:Order):
|
||||||
del roomless_orders[code_to_add]
|
del roomless_orders[code_to_add]
|
||||||
result_map[room.code] = {
|
result_map[room.code] = {
|
||||||
'type': 'add_existing',
|
'type': 'add_existing',
|
||||||
'to_add': to_add
|
'to_add': to_add,
|
||||||
|
'count': count,
|
||||||
|
'previouslyPresent': alreadyPresent
|
||||||
}
|
}
|
||||||
|
|
||||||
generated_counter = 0
|
generated_counter = 0
|
||||||
|
@ -173,8 +181,10 @@ async def room_wizard(request, order:Order):
|
||||||
while len(roomless_orders.items()) > 0:
|
while len(roomless_orders.items()) > 0:
|
||||||
room = list(roomless_orders.items())[0][1]
|
room = list(roomless_orders.items())[0][1]
|
||||||
to_add = []
|
to_add = []
|
||||||
missing_slots = room.room_person_no - len(room.room_members)
|
count = room.room_person_no
|
||||||
for i in range(missing_slots):
|
alreadyPresent = len(room.room_members)
|
||||||
|
missing_slots = count - alreadyPresent
|
||||||
|
for _ in range(missing_slots):
|
||||||
compatible_roomates = {key:value for key,value in roomless_orders.items() if value.bed_in_room == room.bed_in_room}
|
compatible_roomates = {key:value for key,value in roomless_orders.items() if value.bed_in_room == room.bed_in_room}
|
||||||
if len(compatible_roomates.items()) == 0: break
|
if len(compatible_roomates.items()) == 0: break
|
||||||
# Try picking a roomate that's from the same country and room type
|
# Try picking a roomate that's from the same country and room type
|
||||||
|
@ -194,10 +204,13 @@ async def room_wizard(request, order:Order):
|
||||||
'type': 'new',
|
'type': 'new',
|
||||||
'room_name': f'Generated Room {generated_counter}',
|
'room_name': f'Generated Room {generated_counter}',
|
||||||
'room_type': room.bed_in_room,
|
'room_type': room.bed_in_room,
|
||||||
'to_add': to_add
|
'to_add': to_add,
|
||||||
|
'count': count,
|
||||||
|
'previouslyPresent': alreadyPresent
|
||||||
}
|
}
|
||||||
|
|
||||||
result_map["infinite"] = { 'to_add': [] }
|
result_map["infinite"] = { 'to_add': [] }
|
||||||
|
result_map = {k: v for k, v in sorted(result_map.items(), key=lambda x: ((x[1]["count"], x[1]["previouslyPresent"]) if("count" in x[1] and "previouslyPresent" in x[1]) else (4316, 0) ))}
|
||||||
tpl = request.app.ctx.tpl.get_template('wizard.html')
|
tpl = request.app.ctx.tpl.get_template('wizard.html')
|
||||||
return html(tpl.render(order=order, all_orders=all_orders, unconfirmed_orders=orders, data=result_map, jsondata=json.dumps(result_map, skipkeys=True, ensure_ascii=False)))
|
return html(tpl.render(order=order, all_orders=all_orders, unconfirmed_orders=orders, data=result_map, jsondata=json.dumps(result_map, skipkeys=True, ensure_ascii=False)))
|
||||||
|
|
||||||
|
@ -270,7 +283,7 @@ async def submit_from_room_wizard(request:Request, order:Order):
|
||||||
else: raise exceptions.BadRequest(f"Unexpected type ({value['type']})")
|
else: raise exceptions.BadRequest(f"Unexpected type ({value['type']})")
|
||||||
await room_order.edit_answer('pending_room', None)
|
await room_order.edit_answer('pending_room', None)
|
||||||
await room_order.edit_answer('pending_roommates', None)
|
await room_order.edit_answer('pending_roommates', None)
|
||||||
await room_order.edit_answer('room_confirmed', "True")
|
# await room_order.edit_answer('room_confirmed', "True") Use the autoconfirm button in the admin panel
|
||||||
await room_order.edit_answer('room_members', ','.join(list(set([*room_order.room_members, room_order.code, *value['to_add']]))))
|
await room_order.edit_answer('room_members', ','.join(list(set([*room_order.room_members, room_order.code, *value['to_add']]))))
|
||||||
await room_order.send_answers()
|
await room_order.send_answers()
|
||||||
await request.app.ctx.om.fill_cache()
|
await request.app.ctx.om.fill_cache()
|
||||||
|
|
7
ext.py
7
ext.py
|
@ -282,9 +282,12 @@ class Quota:
|
||||||
return f'Quota [items={self.items}, variations={self.variations}] [{self.available_number}/{self.size}]'
|
return f'Quota [items={self.items}, variations={self.variations}] [{self.available_number}/{self.size}]'
|
||||||
|
|
||||||
def get_quota(item: int, variation: int = None) -> Quota:
|
def get_quota(item: int, variation: int = None) -> Quota:
|
||||||
|
ret : Quota = None
|
||||||
for q in QUOTA_LIST:
|
for q in QUOTA_LIST:
|
||||||
if (q.has_item(item, variation)): return q
|
if (q.has_item(item, variation)):
|
||||||
return None
|
if(ret == None or (q.size != None and q.size < ret.size)):
|
||||||
|
ret = q
|
||||||
|
return ret
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Quotas:
|
class Quotas:
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
{%with room_order = unconfirmed_orders[room[0]] %}
|
{%with room_order = unconfirmed_orders[room[0]] %}
|
||||||
<div class="room" id="room-{{room_order.code}}" room-type="{{room_order.bed_in_room}}" room-size="{{room_order.room_person_no - len(room_order.room_members)}}" current-size="{{len(room[1]['to_add'])}}">
|
<div class="room" id="room-{{room_order.code}}" room-type="{{room_order.bed_in_room}}" room-size="{{room_order.room_person_no - len(room_order.room_members)}}" current-size="{{len(room[1]['to_add'])}}">
|
||||||
<h4 style="margin-top:1em;">
|
<h4 style="margin-top:1em;">
|
||||||
<span>{{room_order.room_name if room_order.room_name else room[1]['room_name'] if room[1] and room[1]['room_name'] else ''}}</span>
|
<span>{{room_order.room_name if room_order.room_name else room[1]['room_name'] if room[1] and room[1]['room_name'] else ''}} - {{room_order.room_person_no}} People max</span>
|
||||||
</h4>
|
</h4>
|
||||||
<div class="grid people" style="padding-bottom:1em;">
|
<div class="grid people" style="padding-bottom:1em;">
|
||||||
{% for m in room_order.room_members %}
|
{% for m in room_order.room_members %}
|
||||||
|
|
Loading…
Reference in New Issue