def insert_admin(): Session.initialize_db(initialize=True) with Session() as session: if session.insert_test_admin_account(): print("Test admin account created successfully") else: print("Not allowed to create admin account at this time")
def notify_admins_of_pending_emails(): from uber.tasks.email import notify_admins_of_pending_emails as notify_admins Session.initialize_db(initialize=True) results = timed(notify_admins)() if results: print('Notification emails sent to:\n{}'.format( dumps(results, indent=2, sort_keys=True)))
def send_automated_emails(): from uber.tasks.email import send_automated_emails as send_emails Session.initialize_db(initialize=True) timed(AutomatedEmail.reconcile_fixtures)() results = timed(send_emails)() if results: print('Unapproved email counts:\n{}'.format(dumps(results, indent=2, sort_keys=True)))
def resave_all_attendees_and_groups(): """ Re-save all valid attendees and groups in the database. this is useful to re-run all validation code and allow re-calculation of automatically calculated values. This is sometimes needed when doing database changes and we need to re-save everything. SAFETY: This -should- be safe to run at any time, but, for safety sake, recommend turning off any running sideboard servers before running this command. """ Session.initialize_db(modify_tables=False, drop=False, initialize=True) with Session() as session: print("Re-saving all attendees....") for a in session.valid_attendees(): try: a.presave_adjustments() session.add(a) session.commit() except Exception: pass print("Re-saving all groups....") for g in session.query(Group).all(): try: g.presave_adjustments() session.add(g) session.commit() except Exception: pass print("Done!")
def resave_all_staffers(): """ Re-save all staffers in the database, and re-assign all badge numbers. SAFETY: This -should- be safe to run at any time, but, for safety sake, recommend turning off any running sideboard servers before running this command. """ assert c.BEFORE_PRINTED_BADGE_DEADLINE, \ 'resave_all_staffers is only available before badge numbers have been sent to the printer' Session.initialize_db(modify_tables=False, drop=False, initialize=True) with Session() as session: staffers = session.query(Attendee).filter_by( badge_type=c.STAFF_BADGE).all() first_staff_badge_num = c.BADGE_RANGES[c.STAFF_BADGE][0] last_staff_badge_num = c.BADGE_RANGES[c.STAFF_BADGE][1] assert len(staffers) < last_staff_badge_num - first_staff_badge_num + 1, \ 'not enough free staff badges, please increase limit' badge_num = first_staff_badge_num print("Re-saving all staffers....") for a in staffers: a.presave_adjustments() a.badge_num = badge_num badge_num += 1 assert badge_num <= last_staff_badge_num print( "Saving resulting changes to database (can take a few minutes)...") print("Done!")
def has_admin(): Session.initialize_db(initialize=True) with Session() as session: if session.query(AdminAccount).first() is None: print('Could not find any admin accounts', file=sys.stderr) sys.exit(1) else: print('At least one admin account exists', file=sys.stderr) sys.exit(0)
def import_uber_test_data(test_data_file): with open(test_data_file) as f: global dump dump = json.load(f) Session.initialize_db(initialize=True) with Session() as session: import_groups(session) import_attendees(session) import_events(session) import_jobs(session)
def decline_and_convert_dealer_groups(): from uber.site_sections.groups import _decline_and_convert_dealer_group Session.initialize_db(initialize=True) with Session() as session: groups = session.query(Group) \ .filter(Group.tables > 0, Group.status == c.WAITLISTED) \ .options( subqueryload(Group.attendees).subqueryload(Attendee.admin_account), subqueryload(Group.attendees).subqueryload(Attendee.shifts)) \ .order_by(Group.name, Group.id).all() for group in groups: print('{}: {}'.format( group.name, _decline_and_convert_dealer_group(session, group)))
def import_uber_test_data(test_data_file): if not c.JOB_LOCATION_OPTS: print("JOB_LOCATION_OPTS is empty! " "Try copying the [[job_location]] section from test-defaults.ini to your development.ini.") exit(1) with open(test_data_file) as f: global dump dump = json.load(f) Session.initialize_db(initialize=True) with Session() as session: import_groups(session) import_attendees(session) import_events(session) import_jobs(session)
def resave_all_attendees_and_groups(): """ Re-save all attendees and groups in the database. this is useful to re-run all validation code and allow re-calculation of automatically calculated values. This is sometimes needed when doing database changes and we need to re-save everything. SAFETY: This -should- be safe to run at any time, but, for safety sake, recommend turning off any running sideboard servers before running this command. """ Session.initialize_db(modify_tables=False, drop=False, initialize=True) with Session() as session: print("Re-saving all attendees....") [a.presave_adjustments() for a in session.query(Attendee).all()] print("Re-saving all groups....") [g.presave_adjustments() for g in session.query(Group).all()] print("Saving resulting changes to database (can take a few minutes)...") print("Done!")
def init_worker_process(*args, **kwargs): Session.initialize_db(initialize=True)
def drop_uber_db(): assert c.DEV_BOX, 'drop_uber_db is only available on development boxes' Session.initialize_db(modify_tables=False, drop=True)
def notify_admins_of_pending_emails(): from uber.tasks.email import notify_admins_of_pending_emails as notify_admins Session.initialize_db(initialize=True) results = timed(notify_admins)() if results: print('Notification emails sent to:\n{}'.format(dumps(results, indent=2, sort_keys=True)))
def reset_uber_db(): assert c.DEV_BOX, 'reset_uber_db is only available on development boxes' Session.initialize_db(modify_tables=True, drop=True) insert_admin()