コード例 #1
0
ファイル: backend.py プロジェクト: Wiederickj/327-Repo
def sell_ticket(name, quantity, price, date, user):
#Used to test the sell ticket function
    ticket = Ticket()
    ticket.name = name
    ticket.quantity = quantity
    ticket.price = price
    ticket.date = date
    ticket.user = user
    db.session.add(ticket)
    db.session.commit()
コード例 #2
0
ファイル: backend.py プロジェクト: Wiederickj/327-Repo
def update_ticekt(name, quantity, price, date, user):
    ticket = Ticket()
    ticket.name = name
    ticket.quantity = quantity
    ticket.price = price
    ticket.date = date
    ticket.user = user
    db.session.add(ticket)
    db.session.sell(ticket)
    db.session.commit()
コード例 #3
0
ファイル: backend.py プロジェクト: atangent/chad-CI-python
def sell_ticket(name, quantity, price, date, user):
    """
    Create new ticket in the database
    :param ticket_id: the id of the ticket to be updated
    :param name: the name of the ticket
    :param quantity: the amount of tickets for sale
    :param price: the price of the ticket
    :param date: the expiry date of the ticket
    :param user: seller of the ticket
    :return: an error message if there is any, or None if creation succeeds
    """
    ticket = Ticket()
    ticket.name = name
    ticket.quantity = quantity
    ticket.price = price
    ticket.date = date
    ticket.user = user
    db.session.add(ticket)
    db.session.commit()
コード例 #4
0
ファイル: backend.py プロジェクト: EricFillion/CMPE-327
def sell_ticket(user, name, quantity, price, expiryDate):
    """
    Update the quantity, price and expiry date of a ticket of a given name
    :param user: the user who is selling the ticket
    :param name: the name of the ticket to be updated
    :param quantity: the new quantity for the ticket
    :param price: the new price for the ticket
    :param expiryDate: the new expiry date of the ticket
    :return: a string describing the error that occurred, or False for no error
    """
    if not isinstance(user, User):
        return "Internal Error: 'user' must be of type 'User'"
    if not isinstance(name, str):
        return "Internal Error: 'name' must be of type 'str'"
    if not isinstance(quantity, int):
        return "Internal Error: 'quantity' must be of type 'int'"
    if not isinstance(price, float):
        return "Internal Error: 'price' must be of type 'float'"
    if not isinstance(expiryDate, date):
        return "Internal Error: 'expiryDate' must be of type 'date'"
    if User.query.filter_by(id=user.id).first() is None:
        return "Internal Error: user does not exist in database"
    new_ticket = Ticket()
    new_ticket.owner = user
    new_ticket.name = name
    new_ticket.quantity = quantity
    new_ticket.price = int(price * 100)
    new_ticket.expiry = expiryDate
    db.session.add(new_ticket)
    try:
        db.session.commit()
    except IntegrityError as e:
        db.session.rollback()
        # We got an integrity error. Check if it was due to
        # UNIQUE constraint being violated.
        # I can't find a better way to do this unfortunately.
        args_str = ' '.join(e.args)
        if 'UNIQUE constraint failed' in args_str:
            return 'A ticket with that name already exists.'
        raise e
    return False