|
7 | 7 | from copy import deepcopy |
8 | 8 | from collections import defaultdict |
9 | 9 | from datetime import datetime, timedelta |
| 10 | +from pytz import UTC |
10 | 11 | from dateutil import parser as dateparser |
11 | 12 | from sqlalchemy import and_, func, or_ |
12 | 13 | from sqlalchemy.orm import joinedload |
@@ -256,16 +257,6 @@ def feed(self, session, message='', page='1', who='', what='', action=''): |
256 | 257 | Tracking.model == 'LotteryApplication').distinct().order_by(Tracking.who).values(Tracking.who)] |
257 | 258 | } |
258 | 259 |
|
259 | | - def mark_staff_processed(self, session, **params): |
260 | | - for app in session.query(LotteryApplication).filter(LotteryApplication.is_staff_entry, |
261 | | - LotteryApplication.status == c.COMPLETE): |
262 | | - app.status = c.PROCESSED |
263 | | - session.add(app) |
264 | | - session.commit() |
265 | | - |
266 | | - raise HTTPRedirect('index?message={}', |
267 | | - "All complete staff entries marked as processed.") |
268 | | - |
269 | 260 | @ajax |
270 | 261 | def validate_hotel_lottery(self, session, id=None, form_list=[], **params): |
271 | 262 | application = session.lottery_application(id) |
@@ -333,41 +324,6 @@ def history(self, session, id): |
333 | 324 | ).order_by(PageViewTracking.when).all(), |
334 | 325 | } |
335 | 326 |
|
336 | | - def show_awards(self, session, **params): |
337 | | - applications = session.query(LotteryApplication).filter(LotteryApplication.status.in_([c.AWARDED, c.REJECTED, c.REMOVED]), |
338 | | - LotteryApplication.final_status_hidden == True) |
339 | | - total = applications.count() |
340 | | - for app in applications: |
341 | | - app.final_status_hidden = False |
342 | | - session.add(app) |
343 | | - |
344 | | - raise HTTPRedirect('index?message={}', |
345 | | - f"{total} awarded, rejected, and removed from group lottery entries can now see their status.") |
346 | | - |
347 | | - |
348 | | - def publish_booking_links(self, session, **params): |
349 | | - applications = session.query(LotteryApplication).filter(LotteryApplication.booking_url != '', |
350 | | - LotteryApplication.booking_url_hidden == True) |
351 | | - total = applications.count() |
352 | | - for app in applications: |
353 | | - app.booking_url_hidden = False |
354 | | - session.add(app) |
355 | | - |
356 | | - raise HTTPRedirect('index?message={}', |
357 | | - f"{total} lottery entries can now see their booking link.") |
358 | | - |
359 | | - def close_waitlist(self, session, **params): |
360 | | - applications = session.query(LotteryApplication).filter(LotteryApplication.status == c.COMPLETE, |
361 | | - LotteryApplication.last_submitted < c.HOTEL_LOTTERY_FORM_WAITLIST) |
362 | | - |
363 | | - total = applications.count() |
364 | | - for app in applications: |
365 | | - app.last_submitted = localized_now() |
366 | | - session.add(app) |
367 | | - |
368 | | - raise HTTPRedirect('index?message={}', |
369 | | - f"{total} locked 'first-round' lottery entries are now unlocked.") |
370 | | - |
371 | 327 | def lottery_runs(self, session, message=''): |
372 | 328 | runs = session.query(LotteryRun).order_by(LotteryRun.run_at.desc()).all() |
373 | 329 | hotels = session.query(LotteryHotel).filter_by(active=True).order_by(LotteryHotel.name).all() |
@@ -451,6 +407,16 @@ def revert_run(self, session, id, **params): |
451 | 407 | raise HTTPRedirect('lottery_runs?message={}', |
452 | 408 | f"Run '{lottery_run.name}' reverted. {len(applications)} entries reset to complete.") |
453 | 409 |
|
| 410 | + def delete_run(self, session, id, **params): |
| 411 | + lottery_run = session.query(LotteryRun).get(id) |
| 412 | + if lottery_run.status != c.LOTTERY_REVERTED: |
| 413 | + raise HTTPRedirect('lottery_run_detail?id={}&message={}', id, 'Only reverted runs can be deleted.') |
| 414 | + |
| 415 | + name = lottery_run.name |
| 416 | + session.delete(lottery_run) |
| 417 | + session.commit() |
| 418 | + raise HTTPRedirect('lottery_runs?message={}', f"Run '{name}' has been deleted.") |
| 419 | + |
454 | 420 | def manage_inventory(self, session, message=''): |
455 | 421 | inventory = session.query(HotelRoomInventory).order_by( |
456 | 422 | HotelRoomInventory.hotel_id, HotelRoomInventory.is_suite, HotelRoomInventory.name).all() |
@@ -760,30 +726,32 @@ def hotel_inventory(self, session, message=''): |
760 | 726 | for hotel_id, room_type_id, status, count in assigned_applications: |
761 | 727 | assigned_applications_dict[(hotel_id, room_type_id)].append((status, count)) |
762 | 728 |
|
| 729 | + hotel_lookup = {str(h.id): h for h in session.query(LotteryHotel).all()} |
| 730 | + room_type_lookup = {str(rt.id): rt for rt in session.query(LotteryRoomType).all()} |
| 731 | + |
763 | 732 | room_inventory = defaultdict(list) |
764 | | - for inventory_info in HotelRoomInventory.get_inventory(session, is_suite=False): |
765 | | - hotel, room_type = inventory_info['id'], inventory_info['room_type'] |
766 | | - info_for_room = {'room_type': room_type, 'quantity': inventory_info['quantity']} |
767 | | - if assigned_applications_dict.get((hotel, room_type)): |
768 | | - for status, count in assigned_applications_dict[(hotel, room_type)]: |
| 733 | + for inv in session.query(HotelRoomInventory).filter_by(is_suite=False, active=True).all(): |
| 734 | + hotel_obj = hotel_lookup.get(str(inv.hotel_id)) |
| 735 | + rt_obj = room_type_lookup.get(str(inv.room_type_id)) |
| 736 | + info_for_room = {'room_type': rt_obj, 'quantity': inv.quantity} |
| 737 | + if assigned_applications_dict.get((str(inv.hotel_id), str(inv.room_type_id))): |
| 738 | + for status, count in assigned_applications_dict[(str(inv.hotel_id), str(inv.room_type_id))]: |
769 | 739 | info_for_room[status] = count |
770 | | - room_inventory[hotel].append(info_for_room) |
| 740 | + room_inventory[hotel_obj].append(info_for_room) |
771 | 741 |
|
772 | 742 | suite_inventory = defaultdict(list) |
773 | | - for inventory_info in HotelRoomInventory.get_inventory(session, is_suite=True): |
774 | | - hotel, room_type = inventory_info['id'], inventory_info['room_type'] |
775 | | - info_for_room = {'room_type': room_type, 'quantity': inventory_info['quantity']} |
776 | | - if assigned_applications_dict.get((hotel, room_type)): |
777 | | - for status, count in assigned_applications_dict[(hotel, room_type)]: |
| 743 | + for inv in session.query(HotelRoomInventory).filter_by(is_suite=True, active=True).all(): |
| 744 | + hotel_obj = hotel_lookup.get(str(inv.hotel_id)) |
| 745 | + st_obj = room_type_lookup.get(str(inv.suite_type_id)) |
| 746 | + info_for_room = {'room_type': st_obj, 'quantity': inv.quantity} |
| 747 | + if assigned_applications_dict.get((str(inv.hotel_id), str(inv.suite_type_id))): |
| 748 | + for status, count in assigned_applications_dict[(str(inv.hotel_id), str(inv.suite_type_id))]: |
778 | 749 | info_for_room[status] = count |
779 | | - suite_inventory[hotel].append(info_for_room) |
| 750 | + suite_inventory[hotel_obj].append(info_for_room) |
780 | 751 |
|
781 | 752 | return { |
782 | 753 | 'room_inventory': room_inventory, |
783 | 754 | 'suite_inventory': suite_inventory, |
784 | | - 'hotels': session.query(LotteryHotel).filter_by(active=True).order_by(LotteryHotel.name).all(), |
785 | | - 'room_types': session.query(LotteryRoomType).filter_by(is_suite=False, active=True).order_by(LotteryRoomType.name).all(), |
786 | | - 'suite_types': session.query(LotteryRoomType).filter_by(is_suite=True, active=True).order_by(LotteryRoomType.name).all(), |
787 | 755 | 'now': localized_now(), |
788 | 756 | } |
789 | 757 |
|
|
0 commit comments