Esempio n. 1
0
def list_bays():
    if( 'logged_in' not in session or not session['logged_in']):
        return redirect(url_for('login'))
    # The user is just viewing the page
    if (request.method == 'GET'):
        # First check if specific bay
        bay = request.args.get('bay', '')
        val = None
        if(bay == ''):
            # No bay specified, try to get all the bays in a list
            val = database.get_all_bays()
            if(val is None):
                val = []
                flash("Error, no bays in our system.")
                page['bar'] = False
            return render_template('bay_list.html', bays=val, session=session)

        # Try to get from the database
        val = database.get_bay(bay)
        cars = database.get_cars_in_bay(bay)
        if(val is None):
            val = []
            flash("Error, car bay \'{}\' does not exist".format(bay))
            page['bar'] = False

        if(cars is None):
            cars = []
        return render_template('bay_detail.html', bay=val, cars=cars, session=session, user=user_details, page=page)

    elif(request.method == 'POST'):
        # The user is searching for a bay
        val = database.search_bays(request.form['search'])
        # TODO
        # Check for nulls / handle what happens if empty?
        return render_template('bay_list.html', bays=val, session=session)
Esempio n. 2
0
def list_bays():
    if ('logged_in' not in session or not session['logged_in']):
        return redirect(url_for('login'))
    # The user is just viewing the page
    if (request.method == 'GET'):
        # First check if specific bay
        bay = request.args.get('bay', '')
        val = None
        if (bay == ''):
            # No bay specified, try to get all the bays in a list
            val = database.get_all_bays(user_details['homebay'])
            if (val is None):
                val = []
                flash("Error, no bays in our system.")
                page['bar'] = False
            return render_template('bay_list.html', bays=val, session=session)

        if (bay == 'Add a homebay'):
            val = database.get_all_bays(user_details['homebay'])
            if (val is None):
                val = []
                flash("Error, no bays in our system.")
                page['bar'] = False
            return render_template('bay_list.html', bays=val, session=session)

        # Try to get from the database
        val = database.get_bay(bay)
        if (val is None):
            val = []
            flash("Error, car bay \'{}\' does not exist".format(bay))
            page['bar'] = False
        cars = database.get_cars_in_bay(val[5])
        if (cars is None):
            cars = []
        return render_template('bay_detail.html',
                               bay=val,
                               cars=cars,
                               session=session,
                               user=user_details,
                               page=page)

    elif (request.method == 'POST'):
        # The user is searching for a bay
        val = database.search_bays(request.form['search'])
        # If no matching bays were found
        if (val is None or len(val) < 1):
            flash("No results found.")
            page['bar'] = False
            val = []
            val.append([' ', 'No results found', ' '])
        return render_template('bay_list.html',
                               bays=val,
                               session=session,
                               page=page)
Esempio n. 3
0
def list_bays():
    if ('logged_in' not in session or not session['logged_in']):
        return redirect(url_for('login'))
    # The user is just viewing the page
    if (request.method == 'GET'):
        # First check if specific bay
        bay = request.args.get('bay', '')
        val = None
        if (bay == ''):
            # No bay specified, try to get all the bays in a list
            val = database.get_all_bays()
            if (val is None):
                val = []
                flash("Error, no bays in our system.")
                page['bar'] = False
            return render_template('bay_list.html', bays=val, session=session)

        # Try to get from the database
        val = database.get_bay(bay)
        cars = database.get_cars_in_bay(bay)
        if (val is None):
            val = []
            flash("Error, car bay \'{}\' does not exist".format(bay))
            page['bar'] = False

        if (cars is None):
            cars = []
        return render_template('bay_detail.html',
                               bay=val,
                               cars=cars,
                               session=session,
                               user=user_details,
                               page=page)

    elif (request.method == 'POST'):
        # The user is searching for a bay
        val = database.search_bays(request.form['search'])
        if (len(val) == 0):
            page['bar'] = False
            flash("Error, car bay \'{}\' does not exist".format(
                request.form['search']))

        # TODO
        # Check for nulls / handle what happens if empty?
        return render_template('bay_list.html',
                               bays=val,
                               session=session,
                               page=page)