def send_mail(user_id, pg): tickets.user_pg_lock(user_id, pg=pg) user = users.get_user(user_id, pg=pg) name = user["othernames"] + " " + user["surname"] alumnus = user["person_type"] == "alumnus" paid_tickets = tickets.tickets(user_id=user_id, paid=True, pg=pg) if not paid_tickets: logger.warning("Not mailing %s (no tickets)", user_id, extra={"user_id": user_id}) return def k(t): return (t["othernames"], t["surname"]) paid_tickets.sort(key=k) logger.info("Sending pickup mail to user %s; paid tickets %r", user["user_id"], [t["ticket_id"] for t in paid_tickets], extra={"user_id": user_id}) # drop the locks pg.commit() utils.send_email("correction.txt", recipient=(name, user["email"]), sender=("Snowball Ticketing", "*****@*****.**"), paid_tickets=paid_tickets, alumnus=alumnus)
def main(crsid, postgres_settings): logger.info("Creating half price ticket for %s", crsid) logging_setup.add_postgresql_handler(postgres_settings) logging_setup.add_syslog_handler() logging_setup.add_smtp_handler() conn = psycopg2.connect(connection_factory=utils.PostgreSQLConnection, **postgres_settings) user = users.get_raven_user(crsid, pg=conn) if user is None: conn.commit() lookup_data = lookup.get_crsid(crsid) user = users.new_raven_user(crsid, ["current"], lookup_data, pg=conn) if tickets.tickets(user_id=user["user_id"], expired=False, pg=conn): raise ValueError("User {0} already has some tickets" .format(user["user_id"])) ticket_id, = tickets.buy("standard", True, 1, user=user, pg=conn) with conn.cursor() as cur: cur.execute("UPDATE tickets " "SET waiting_list = FALSE, quota_exempt = TRUE, " " expires = NULL, expires_reason = NULL, " " price = 3450, notes = E'Ents half price ticket\n' " "WHERE ticket_id = %s", (ticket_id, )) conn.commit()
def user_info(user, pg): print("User", user["user_id"]) user["outstanding_balance"] = \ tickets.outstanding_balance(user_id=user["user_id"], pg=pg) user["reference"] = tickets.reference(user) keys(user, ("othernames", "surname", "person_type", "college_name", "crsid", "email", "outstanding_balance", "reference"), pg=pg) if user["notes"]: notes("notes", user["notes"]) print() ts = tickets.tickets(user_id=user["user_id"], expired=expired, pg=pg) ts.sort(key=lambda t: (t["surname"], t["othernames"], t["waiting_list"], not t["vip"])) print("Tickets summary") for ticket in ts: print(" {0}:".format(ticket["ticket_id"]).ljust(4 + 5), ticket["othernames"], ticket["surname"], "(" + types(ticket) + ")") print() ts.sort(key=lambda t: t["ticket_id"]) for ticket in ts: print("Ticket", ticket["ticket_id"], types(ticket), utils.pounds_pence(ticket["price"])) keys(ticket, ("created", "expires", "expires_reason", "finalised", "paid", "othernames", "surname", "person_type", "college_name"), pg=pg) if ticket["notes"]: notes("notes", ticket["notes"]) if ticket["desk_notes"]: notes("desk_notes", ticket["desk_notes"]) print() with pg.cursor() as cur: cur.execute("SELECT created, session_id, message " "FROM log WHERE user_id = %s", (user["user_id"], )) for created, session_id, message in cur: session_id = str(session_id).ljust(5) print(created, session_id, message)
def main(postgres_settings): conn = psycopg2.connect(connection_factory=utils.PostgreSQLConnection, **postgres_settings) logging_setup.add_postgresql_handler(postgres_settings) logging_setup.add_syslog_handler() # logging_setup.add_smtp_handler() crsid = raw_input("CRSid of the Cambridge student responsible for the ticket: ").strip() if not crsid: sys.exit(1) user = users.get_raven_user(crsid, pg=conn) if user is None: conn.commit() lookup_data = lookup.get_crsid(crsid) user = users.new_raven_user(crsid, ["current"], lookup_data, pg=conn) else: print("They already have an account:") print("Surname:", user["surname"]) print("Othernames:", user["othernames"]) print("College:", utils.college_name(user["college_id"], pg=conn)) print() ts = tickets.tickets(user_id=user["user_id"], pg=conn) if ts: ts.sort(key=lambda t: (t["surname"], t["othernames"], t["waiting_list"], not t["vip"])) print("They currently have these tickets:") for ticket in ts: print(" {0}:".format(ticket["ticket_id"]).ljust(4 + 5), ticket["othernames"], ticket["surname"], "(" + types(ticket) + ")") print() # Don't idle in transaction. conn.commit() print("To cancel, press Ctrl-C.") while True: try: num = int(raw_input("Number of tickets: ").strip()) except ValueError: continue else: if 1 <= num <= 200: break while True: ticket_type = raw_input("Standard or VIP: ").strip().lower() if ticket_type in {"vip", "standard"}: break while True: free = raw_input("Should the tickets be free? [yes|no] ").strip().lower() if free in {"y", "yes"}: free = True break elif free in {"n", "no"}: free = False break notes = raw_input("Comment (stored against the ticket): ").strip() if notes: notes += "\n" notes = "Added using manual_add_unfinalised_ticket.py\n" + notes logger.info("Creating %s %s%s ticket(s)", num, ticket_type, " free" if free else "") ids = tickets.buy(ticket_type, False, num, user=user, quota_exempt=True, pg=conn) with conn.cursor() as cur: cur.execute("UPDATE tickets " "SET expires = NULL, expires_reason = NULL, " " notes = %s " "WHERE ticket_id in %s", (notes, tuple(ids))) if free: cur.execute("UPDATE tickets SET price = 0 WHERE ticket_id in %s", (tuple(ids), )) conn.commit() print() print("Done. Next step: inform the user that they should log into the website.") print("They will see the following message:") print(" You reserved N tickets recently, but are yet to fill out the details on them.") print(" [Resume order]") print("(there is no time limit)") print("and they can then put the names on their tickets.") print()
def main(postgres_settings): conn = psycopg2.connect(connection_factory=utils.PostgreSQLConnection, **postgres_settings) logging_setup.add_postgresql_handler(postgres_settings) logging_setup.add_syslog_handler() # logging_setup.add_smtp_handler() crsid = raw_input( "CRSid of the Cambridge student responsible for the ticket: ").strip() if not crsid: sys.exit(1) user = users.get_raven_user(crsid, pg=conn) if user is None: conn.commit() lookup_data = lookup.get_crsid(crsid) user = users.new_raven_user(crsid, ["current"], lookup_data, pg=conn) else: print("They already have an account:") print("Surname:", user["surname"]) print("Othernames:", user["othernames"]) print("College:", utils.college_name(user["college_id"], pg=conn)) print() ts = tickets.tickets(user_id=user["user_id"], pg=conn) if ts: ts.sort(key=lambda t: (t["surname"], t["othernames"], t[ "waiting_list"], not t["vip"])) print("They currently have these tickets:") for ticket in ts: print(" {0}:".format(ticket["ticket_id"]).ljust(4 + 5), ticket["othernames"], ticket["surname"], "(" + types(ticket) + ")") print() # Don't idle in transaction. conn.commit() print("To cancel, press Ctrl-C.") while True: try: num = int(raw_input("Number of tickets: ").strip()) except ValueError: continue else: if 1 <= num <= 200: break while True: ticket_type = raw_input("Standard or VIP: ").strip().lower() if ticket_type in {"vip", "standard"}: break while True: free = raw_input( "Should the tickets be free? [yes|no] ").strip().lower() if free in {"y", "yes"}: free = True break elif free in {"n", "no"}: free = False break notes = raw_input("Comment (stored against the ticket): ").strip() if notes: notes += "\n" notes = "Added using manual_add_unfinalised_ticket.py\n" + notes logger.info("Creating %s %s%s ticket(s)", num, ticket_type, " free" if free else "") ids = tickets.buy(ticket_type, False, num, user=user, quota_exempt=True, pg=conn) with conn.cursor() as cur: cur.execute( "UPDATE tickets " "SET expires = NULL, expires_reason = NULL, " " notes = %s " "WHERE ticket_id in %s", (notes, tuple(ids))) if free: cur.execute("UPDATE tickets SET price = 0 WHERE ticket_id in %s", (tuple(ids), )) conn.commit() print() print( "Done. Next step: inform the user that they should log into the website." ) print("They will see the following message:") print( " You reserved N tickets recently, but are yet to fill out the details on them." ) print(" [Resume order]") print("(there is no time limit)") print("and they can then put the names on their tickets.") print()