Example #1
0
def delete_from_session():
    """Delete a property from the session.
    Also deletes a property from comparison table
    when it's deleted from session.
    Done with Ajax to take out the property from the table"""

    global RGB_TUPLES 
    global HEX_COLOR_STRINGS

    #delete from session
    props_in_list = session.get('properties',[])
    used_color_map = session.get('used_color_map',{})

    zpid = request.form.get('property') 

    if zpid in props_in_list:
        zpid_index = props_in_list.index(zpid)
        props_in_list.pop(zpid_index)
        if str(zpid) in used_color_map:
            color_map = used_color_map[str(zpid)]
            rgb_tuple = (color_map['r'], color_map['g'], color_map['b'])
            hex_color_string = color_map['hex']
            RGB_TUPLES.append(rgb_tuple)
            HEX_COLOR_STRINGS.append(hex_color_string)
            del used_color_map[str(zpid)]

    zpids_in_table = session.get('comp_table',[])
    if zpid in zpids_in_table:
        zpid_index2 = zpids_in_table.index(zpid)
        zpids_in_table.pop(zpid_index2) 

    return "Victory"
Example #2
0
def get_propeties_list():
    """Have user confirm the search results.
    Upon confirmation, add property to session.
    Show list of properties stored in the session."""

    
    #Get the properties stored in session or create an empty session
    #Turn the list of properties into a set to get rid of repeats
    props_in_set = set(session.get('properties',[]))

    # Our output cart will be a dictionary (so we can easily see if we
    # already have the property in there
    properties = []
    used_color_map = session.get('used_color_map', {})

    # Loop over the ZPIDs in the session cart and add each one to
    # the output cart

    for zpid in props_in_set:
        house_data = Property.query.get(zpid)
        if house_data is not None:
            properties.append(house_data)
            if str(zpid) not in used_color_map:
                rgb_tuple = RGB_TUPLES.pop()
                r,g,b = rgb_tuple
                hex_color_string = HEX_COLOR_STRINGS.pop()
                color_map = {'r': r, 'g': g, 'b': b, 'hex': hex_color_string}
                used_color_map[str(zpid)] = color_map


    session['used_color_map'] = used_color_map
    user_id = session.get('user_id')
    liked = None

    if user_id:
        results = db.session.query(UserProperty.zpid).filter_by(user_id=user_id).all()
        liked = [zpid for (zpid, ) in results]

    props_in_table = [int(x) for x in session.get('comp_table',[])]

    page_state = request.args.get('view-state', 0)

    return render_template("left-column.html", properties=properties, liked=liked, props_in_table=props_in_table, used_color_map=used_color_map, page_state=int(page_state))
Example #3
0
def login_process():
    """Process login."""

    # Get form variables
    email = request.form["email"]
    password = request.form["password"]

    user = User.query.filter_by(email=email).first()

    if not user:
        flash("No such user. Please register an account.")
        return "register"

    # if user.password != password:
    if not user.check_password(password):
        flash("Incorrect password")
        return "incorrectlogin"

    session["user_id"] = user.user_id

    liked = UserProperty.query.filter_by(user_id=user.user_id).all()
    liked = [x.zpid for x in liked]

    session['properties'] = liked
    session['comp_table'] = []
    session['used_color_map']={}

    for zpid in liked:
        if str(zpid) not in session['used_color_map']:
            rgb_tuple = RGB_TUPLES.pop()
            r,g,b = rgb_tuple
            hex_color_string = HEX_COLOR_STRINGS.pop()
            color_map = {'r': r, 'g': g, 'b': b, 'hex': hex_color_string}
            session['used_color_map'][str(zpid)] = color_map


    flash("Hello, %s!" % user.fname)

    return render_template("session-login.html", session=session)