コード例 #1
0
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()
コード例 #2
0
def main(crsid, postgres_settings):
    logger.info("Creating raven user 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)

    conn.commit()
コード例 #3
0
def main(crsid, postgres_settings):
    logger.info("Creating free VIP upgrade 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)

    lookup_data = lookup.get_crsid(crsid)
    user = users.new_raven_user(crsid, ["current"], lookup_data, pg=conn)
    ticket_id, = tickets.buy("vip", False, 1, user=user, pg=conn)

    with conn.cursor() as cur:
        cur.execute("UPDATE tickets "
                    "SET expires = NULL, expires_reason = NULL, "
                    "    price = 6900 "
                    "WHERE ticket_id = %s",
                    (ticket_id, ))

    logging.info("Free VIP upgraded ticket %s", ticket_id)

    conn.commit()
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()