예제 #1
0
def update_post():
    title = request.form.get('upd-name')
    try:
        quantity = int(request.form.get('upd-quantity'))
        price = int(request.form.get('upd-price'))
        expDate = int(request.form.get('upd-exp'))
    except:
        return redirect('/?uMessage=Field Requires Integer')

    temp = str(expDate)
    expDateLen = len(temp)
    ticket = bn.get_ticket(title)

    if not ticket:
        return redirect('/?uMessage=Ticket Does Not Exist')
    elif not re.search(regex_title, title):
        return redirect('/?uMessage=Name Format Error')
    elif quantity <= 0 or quantity > 100:
        return redirect('/?uMessage=Invalid Quantity')
    elif price < 10 or price > 100:
        return redirect('/?uMessage=Invalid Price')
    elif expDateLen != 8:
        return redirect('/?uMessage=Invalid Date Format (YYYYMMDD)')

    bn.update_ticket(title, quantity, price, expDate)
    return render_template('temp.html', message='Updated')
예제 #2
0
def updateticket():
    ticket_id = request.form['ticket_id']
    ticket_name = request.form['name']
    ticket_quantity = int(request.form['quantity'])
    ticket_price = float(request.form['price'])
    ticket_date = request.form['date']
    ticket_date = datetime.datetime.strptime(ticket_date, '%Y-%m-%d')
    user_email = request.form['user']
    user = bn.get_user(user_email)

    message = ""

    # check ticket exists
    if not does_ticket_exist(ticket_id):
        message = "Ticket not found."
    # check name
    if not is_ticket_name_valid(ticket_name):
        message = "Ticket name is invalid."
    # check quantity
    if not is_quantity_of_tickets_valid(ticket_quantity):
        message = "Ticket quantity must be between 0 and 100."
    # check price
    if not is_ticket_price_valid(ticket_price):
        message = "Ticket price is invalid."
    # check date
    if not is_ticket_date_valid(ticket_date):
        message = "Ticket data is invalid."

    if not message:  # if message is empty, indicating no validation errors
        bn.update_ticket(ticket_id, ticket_name, ticket_quantity, ticket_price,
                         ticket_date)
        message = "Ticket successfully updated"

    # redirect user to profile page with result message
    return redirect("/?message={}".format(message))
예제 #3
0
def update_post():
    name = request.form.get('tname')
    quantity = request.form.get('tquantity')
    price = request.form.get('price')
    expiration = request.form.get('expiration')
    email = session['logged_in']
    user = bn.get_user(email)
    ticket = bn.get_ticket(name)
    error_message = None
    #checks if the expiration date is in the correct format, assigns checkDate 
    #to None if it is not
    try:
        checkDate = datetime.datetime.strptime(expiration, '%Y%m%d')
    except: 
        checkDate = None


    #verifies that checkDate is not equal to None
    if checkDate == None:
        error_message = "Incorrect expiration date format"
    #redirects for any errors
   # elif error_message:
       #return render_template('/', message=error_message)
    #error_message = None

    #Validating information submitted in update form

    #Name of ticket has to be alphanumeric only 
    elif not all(chr.isalnum() or chr.isspace() for chr in name):
        error_message = "name not alphanumeric"
  
    #Name must have no spaces at the beginning or end
    elif name.startswith(" ") or name.endswith(" "):
        error_message = "The ticket name can't begin or end with a space."
    #Name of the ticket can't be longer than 60 characters
    elif len(name) > 60:
        error_message = "The ticket name can't be longer than 60 characters."
    #Quantity has to be more than zero, and less than or equal to 100
    elif int(quantity) <= 0 or int(quantity) > 100:
        error_message = "The ticket quantity must be between 1 and 100 (inclusive)."
    #Price has to be in the range 10-100
    elif int(price) < 10 or int(price) > 100:
        error_message = "The ticket price must be between 10 and 100 (inclusive)."
    elif ticket == None:
        error_message = "Sorry, this ticket is not available."
    if error_message:
        tickets = bn.get_all_tickets()
        return render_template('index.html', message=error_message, user=user, tickets=tickets)
    else:
        bn.update_ticket(name,quantity,price,int(expiration))
        return redirect('/')
예제 #4
0
파일: frontend.py 프로젝트: 15vrs/cmpe-327
def update_post():
    user_email = session['logged_in']
    ticket_name = request.form.get('update-name')
    ticket_quantity = int(request.form.get('update-quantity'))
    ticket_price = int(request.form.get('update-price'))
    ticket_date = int(request.form.get('update-date'))
    error_message = None

    if (ticket_name_check(ticket_name) is None):  # no match in regex
        error_message = 'Ticket name is incorrect'

    elif quantity_check(ticket_quantity):
        error_message = "Invalid quantity in ticket update form"

    elif price_check(ticket_price):
        error_message = "Invalid price in ticket update form"

    elif date_check(ticket_date):
        error_message = "Invalid date in ticket update form"

    else:
        error_message = bn.update_ticket(user_email, ticket_name,
                                         ticket_quantity, ticket_price,
                                         ticket_date)

    return error_message
예제 #5
0
def update():
    name = request.form.get('name')
    quantity = request.form.get('quantity')
    price = request.form.get('price')
    date = request.form.get('date')

    error_message = None

    if error_message == None:
        error_message = validate_ticket(name, quantity, price, date)

        if error_message == False:
            error_message = None

    if error_message == None:
        # The ticket of the given name must exist
        if not bn.ticket_exists(name):
            error_message = 'Ticket does not exist.'
        else:
            error_message = bn.update_ticket(name, quantity, price, date)

    if error_message is not None:
        flash(error_message)
    else:
        flash('Successfully updated ticket')

    # For any errors, redirect back to / and show an error message
    return redirect('/')
예제 #6
0
def update():
    """
    Route to update a ticket.
    This route will validate the ticket form, if valid it will update the ticket on the database
    through a backend function
    """
    if 'logged_in' not in session:
        return redirect('/login')

    # Grab necessary information from update form
    user = bn.get_user(session['logged_in'])
    tickets = bn.get_all_tickets()

    name = request.form.get('name')
    quantity = request.form.get('quantity')
    price = request.form.get('price')
    date = request.form.get('date')

    error_message = check_ticket_form(name, quantity, price, date)
    if error_message:
        return render_template('index.html',
                               update_message=error_message,
                               user=user,
                               tickets=tickets)

    # Check if ticket exists in database
    ticket = bn.get_ticket(name)
    if ticket is None:
        return render_template('index.html',
                               update_message='Ticket does not exist',
                               user=user,
                               tickets=tickets)

    # Update tickets to database
    bn.update_ticket(name, quantity, price, date)
    return render_template('index.html',
                           update_message='Successfully updated tickets',
                           user=user,
                           tickets=tickets)
예제 #7
0
def update_ticket(user): 

    name = request.form.get('Name').strip()
    price = float(request.form.get('Price'))
    date = request.form.get('Date').replace("/", "")
    quantity = int(request.form.get('Quantity'))
    ticket_id = int(request.form.get("Ticket_Id"))

    error_message = bn.update_ticket(name, price, date, quantity, user, ticket_id)

    if error_message:
        session['error_message'] = error_message
        return ('', 400)

    # Any response will have the webpage reload itself.
    return ('', 200)
예제 #8
0
def update_tickets():
    """
    This function is responsible for completing the update action on tickets, so taking
    the inputs from the update section and converting them to updated tickets

    :return: If the forms don't adhere to the required formatting, return with error message,
    otherwise return with successfull ticket modification
    """

    # Retrieve info from forms
    ticket_name = request.form.get('update_ticket_name')
    num_tickets = request.form.get('update_num_tickets')
    ticket_price = request.form.get('update_ticket_price')
    ticket_date = request.form.get('update_ticket_date')
    error_message = ticket_info_sanitizer(ticket_name,
                                          num_tickets,
                                          ticket_price=ticket_price,
                                          date=ticket_date)

    # Find out info on logged in user and tickets
    email = session['logged_in']
    user = bn.get_user(email)

    #Convert datetime into something we can put in db
    date = datetime.datetime.strptime(ticket_date, '%Y-%m-%d').date()

    if error_message == None:
        if not bn.update_ticket(ticket_name, num_tickets, ticket_price, date):
            error_message = "No such Ticket with that name."

    # get Info on Tickets
    tickets = bn.get_all_tickets()

    # if there is any error messages when updating ticket info
    # at the backend, go back to the register page.
    if error_message:
        return render_template('index.html',
                               user=user,
                               update_message=error_message,
                               tickets=tickets)

    return render_template('index.html', user=user, tickets=tickets)
예제 #9
0
def update_post():
    """ 
    Called when a user clicks update on the update form. If the given inputs match 
    R5 requirements the quantity, price and expiry date of a ticket of the given name
    are update, else an error message is shown. 
    """
    name = request.form.get('name')
    quantity = request.form.get('quantity')
    price = request.form.get('price')
    expiry = request.form.get('expiry')
    error = validate_ticket_format.check_for_update_ticket_format_error(
        name, quantity, price, expiry)
    if not error:
        error = bn.update_ticket(name, quantity, price, expiry)
    if not error:
        flash('Ticket was updated successfully.', 'info')
        return redirect('/')
    else:
        flash('Unable to update ticket: ' + error, 'error')
        return redirect('/')
예제 #10
0
def update_form_post(user):
    name = request.form.get('updateName')
    quantity = int(request.form.get('updateQuantity'))
    price = int(request.form.get('updatePrice'))
    expireDate = request.form.get('updateExpireDate')
    updateErrorMessage = None
    if not (bn.validateTicketName(name)):
        updateErrorMessage = "Invalid ticket name"
    elif not (bn.validateTicketQuantity(quantity)):
        updateErrorMessage = "Invalid ticket quantity"
    elif not (bn.validateTicketPrice(price)):
        updateErrorMessage = "Invalid ticket price"
    elif not (bn.validateTicketExpiryDate(expireDate)):
        updateErrorMessage = "Invalid ticket expiry date"
    elif not (bn.validateTicketExists(name)):
        updateErrorMessage = "Invalid ticket name: does not exist"
    if updateErrorMessage:
        return redirect(
            url_for('.profile', updateErrorMessage=updateErrorMessage))
    error = bn.update_ticket(user.email, name, quantity, price, expireDate)
    if error:
        return redirect(url_for('.profile', updateErrorMessage=error))
    return redirect('/')
예제 #11
0
def update_post(user):
    """
	"""
    orig_name = request.form.get('orig_name')
    update_name = request.form.get('update_name')
    qty = request.form.get('update_qty')
    price = request.form.get('update_price')
    date = request.form.get('update_date')
    error_list = []
    error_list = bn.update_ticket(orig_name, update_name, qty, price, date)
    tickets = bn.get_all_tickets()

    if len(error_list) > 0:
        return render_template('index.html',
                               user=user,
                               tickets=tickets,
                               balance=user.balance,
                               message=error_list[0])
    else:
        return render_template('index.html',
                               user=user,
                               tickets=tickets,
                               balance=user.balance,
                               message='Ticket Updated')
예제 #12
0
def buy_ticket():
    email = session['logged_in']
    user = bn.get_user(email)
    ticket_name = request.form.get('name_buy')
    ticket_quantity = int(
        request.form.get('quantity_buy')
    )  # TODO a user should not have the option to buy their own tickets
    ticket = bn.check_name_exist(ticket_name)
    error_message = ""
    error_list = []

    # validate ticket name
    error_list.append(validate_ticket_name(ticket_name, error_message))

    # validate ticket quantity
    error_list.append(validate_ticket_quantity(ticket_quantity, error_message))

    if ticket is None:
        error_list.append("The ticket of the given name must exist")
    else:
        error_list.append("")

    # validate the ticket quantity in the database
    try:
        if ticket.quantity < ticket_quantity:
            error_list.append(
                "ticket quantity cannot exceed more than what is listed")
        else:
            error_list.append("")

        # Validate user balance
        if user.balance < (ticket.price * ticket_quantity +
                           ticket.price * ticket_quantity * 0.35 * 0.05):
            error_list.append(
                "The user has less balance than the ticket price * quantity + service fee (35%) + tax (5%)"
            )
        else:
            error_list.append("")
    except AttributeError:
        error_list.append(
            ""
        )  # we don't actually need these two lines(just feel like filling in the list all the way is consistent)
        error_list.append("")

    tickets = bn.get_all_tickets()
    if error_list[0] != "":
        return render_template('index.html',
                               user=user,
                               buy_message=error_list[0],
                               tickets=tickets)
    elif error_list[1] != "":
        return render_template('index.html',
                               user=user,
                               buy_message=error_list[1],
                               tickets=tickets)
    elif error_list[2] != "":
        return render_template('index.html',
                               user=user,
                               buy_message=error_list[2],
                               tickets=tickets)
    elif error_list[3] != "":
        return render_template('index.html',
                               user=user,
                               buy_message=error_list[3],
                               tickets=tickets)
    elif error_list[4] != "":
        return render_template('index.html',
                               user=user,
                               buy_message=error_list[4],
                               tickets=tickets)
    else:
        remaining_tickets = ticket.quantity - ticket_quantity
        # if all tickets purchased delete ticket object from data base else update ticket to right quantity
        if remaining_tickets == 0:
            bn.delete_ticket(ticket_name)
        else:
            bn.update_ticket(ticket_name, remaining_tickets, ticket.price,
                             ticket.date)
        # update user balance
        new_balance = user.balance - ticket.price * ticket_quantity - ticket.price * ticket_quantity * 0.35 * 0.05
        bn.update_user_balance(user, new_balance)
        tickets = bn.get_all_tickets()
        return render_template('index.html', user=user, tickets=tickets)
예제 #13
0
def update_ticket():
    email = session['logged_in']
    user = bn.get_user(email)
    ticket_name = request.form.get('name_update')
    ticket_quantity = int(request.form.get('quantity_update'))
    ticket_price = int(request.form.get('price_update'))
    ticket_date = request.form.get('expdate_update')
    ticket = bn.check_name_exist(
        ticket_name
    )  # TODO a user should only be able to update their own tickets not everybodies
    error_message = ""
    error_list = []

    # validate ticket quantity
    error_list.append(validate_ticket_name(ticket_name, error_message))
    # validate ticket quantity
    error_list.append(validate_ticket_quantity(ticket_quantity, error_message))

    # validate ticket price
    error_list.append(validate_ticket_price(ticket_price, error_message))

    # validate ticket date
    error_list.append(validate_ticket_date(ticket_date, error_message))

    if ticket is None:
        error_list.append("The ticket of the given name must exist")
    else:
        error_list.append("")

    # For any errors, redirect back to / and show an error message
    tickets = bn.get_all_tickets()
    if error_list[0] != "":
        return render_template('index.html',
                               user=user,
                               update_message=error_list[0],
                               tickets=tickets)
    elif error_list[1] != "":
        return render_template('index.html',
                               user=user,
                               update_message=error_list[1],
                               tickets=tickets)
    elif error_list[2] != "":
        return render_template('index.html',
                               user=user,
                               update_message=error_list[2],
                               tickets=tickets)
    elif error_list[3] != "":
        return render_template('index.html',
                               user=user,
                               update_message=error_list[3],
                               tickets=tickets)
    elif error_list[4] != "":
        return render_template('index.html',
                               user=user,
                               update_message=error_list[4],
                               tickets=tickets)
    # The added new ticket information will be posted on the user profile page
    else:
        bn.update_ticket(ticket_name, ticket_quantity, ticket_price,
                         ticket_date)
        tickets = bn.get_all_tickets()
        return render_template('index.html', user=user, tickets=tickets)
예제 #14
0
def update_post():

    # Get current user's email, with is the ticket owner's email.
    email = session['logged_in']
    user = bn.get_user(email)

    # Get ticket information from post form.
    name = request.form.get('update-name')
    quantity = int(request.form.get('update-quantity'))
    price = int(request.form.get('update-price'))
    date = request.form.get('update-date')

    # The name of the ticket has to be alphanumeric-only, and space allowed only if it is not the first or the last character
    # name of the ticket is no longer than 60 characters
    name_valid = name.isalnum() and name[0] != " " and name[-1] != " " and len(
        name) >= 6 and len(name) <= 60

    # The quantity of the tickets has to be more than 0, and less than or equal to 100
    quantity_valid = quantity > 0 and quantity <= 100

    # Price has to be of range [10, 100]
    price_valid = price >= 10 and price <= 100

    # Date must be given in the format YYYYMMDD
    date_valid = len(date) == 10 and date[4] == '-' and date[7] == '-'

    # The ticket of the given name must exist
    name_exist = False
    ticket = bn.get_ticket(name)
    if ticket:
        name_exist = True

    # If all elements have valid format, then ticket information is valid, redirect to sell page and show message.
    if name_valid and quantity_valid and price_valid and date_valid and name_exist:
        # Call backend update ticket method.
        bn.update_ticket(name, email, quantity, price, date)
        # Get all tickets' info from backend.
        tickets = bn.get_all_tickets()
        all_name = []
        all_price = []
        all_quantity = []
        all_email = []
        # Add all information to corresponding collumn.
        for ticket in tickets:
            all_name.append(ticket.name)
            all_price.append(ticket.price)
            all_quantity.append(ticket.quantity)
            all_email.append(ticket.owner_email)
        # Pass all information to the HTML page.
        return render_template('index.html',
                               message_u="Ticket information updated",
                               user=user,
                               names=all_name,
                               prices=all_price,
                               quantities=all_quantity,
                               emails=all_email)
    # For any errors, redirect back to / and show an error message.
    else:
        # Get all tickets' info from backend.
        tickets = bn.get_all_tickets()
        all_name = []
        all_price = []
        all_quantity = []
        all_email = []
        # Add all information to corresponding collumn.
        for ticket in tickets:
            all_name.append(ticket.name)
            all_price.append(ticket.price)
            all_quantity.append(ticket.quantity)
            all_email.append(ticket.owner_email)
        # Pass all information to the HTML page.
        return render_template('index.html',
                               message_u="Ticket format invalid",
                               user=user,
                               names=all_name,
                               prices=all_price,
                               quantities=all_quantity,
                               emails=all_email)