Пример #1
0
def addObject():
    """ Adds object to the website 
    """
    total = cart_count_total(Users_cart)
    form = BlockForm()
    allcats = returnallcatlist()
    if request.method == 'POST':
        if form.validate_on_submit():
            newobj = block_content(item={
                'name': form.name.data,
                'picture': form.picture.data,
                'about': form.discription.data,
                'price': form.price.data,
                'color': form.Color.data,
                'size': form.Size.data,
                'brand': form.Brand.data
            },
                                   category=form.cat.data)
            objdic = newobj.to_dict()
            newobj.save_to_file(objdic)
            data = block_content().load_from_file()
            return redirect('/items')
        else:
            error = "please fill out each field, or please enter a valid price (ie. 9.99)"
            return render_template('addobj.html',
                                   form=form,
                                   cartamount=total,
                                   error=error,
                                   categories=allcats)
    else:
        return render_template('addobj.html',
                               form=form,
                               cartamount=total,
                               categories=allcats)
Пример #2
0
def removec():
    total = cart_count_total(Users_cart)
    listofobjs = block_content().load_from_file()
    allcats = returnallcatlist()
    return render_template('removecat.html',
                           data=listofobjs,
                           cartamount="{0:.2f}".format(total),
                           categories=allcats)
Пример #3
0
def testshort():
    """ Home page
        return: template for index with required information
    """
    data = block_content().load_from_file()
    total = cart_count_total(Users_cart)
    return render_template('index.html',
                           box=data,
                           cartamount="{0:.2f}".format(total))
Пример #4
0
def display_block(oid):
    cart_count = len(Users_cart)
    total = cart_count_total(Users_cart)
    obj = block_content().grab_object(oid)
    return render_template('displayitem.html',
                           obj=obj,
                           cartamount=cart_count,
                           cart_total="{0:.2f}".format(total),
                           category=obj.get("category"))
Пример #5
0
def delObject():
    """ returns page to select object to delete
    """
    total = cart_count_total(Users_cart)
    listofobjs = block_content().load_from_file()
    allcats = returnallcatlist()
    return render_template('delobj.html',
                           data=listofobjs,
                           cartamount="{0:.2f}".format(total),
                           categories=allcats)
Пример #6
0
def settings():
    """ displays the settings page with options to different settings
    """
    total = cart_count_total(Users_cart)
    listofobjs = block_content().load_from_file()
    allcats = returnallcatlist()
    return render_template('objsettings.html',
                           data=listofobjs,
                           cartamount="{0:.2f}".format(total),
                           categories=allcats)
Пример #7
0
def items_manager():
    """ returns page to view all items on website
    """
    total = cart_count_total(Users_cart)
    listofobjs = block_content().load_from_file()
    allcats = returnallcatlist()
    return render_template('items.html',
                           data=listofobjs,
                           cartamount="{0:.2f}".format(total),
                           categories=allcats)
Пример #8
0
def grab_cat(cat_name):
    """ Grabs list of items with the category name 'cat_name'
        cat_name = category name
        return: list of objects with category equal to cat_name
    """
    newlist = []
    data = block_content().load_from_file()
    for obj in data:
        if obj.get("category") == cat_name:
            newlist.append(obj)
    return (newlist)
Пример #9
0
def return_onject():
    ''' Returns block object
        '''
    newobj = block_content(
        item={
            'name': 'Tire Iron',
            'picture': 'static/images/Items/tireiron.jpg',
            'about': "This is a tool, used for removing spinny things"
        })
    objdic = newobj.to_dict()

    newobj.save_to_file(objdic)

    return jsonify(objdic)
Пример #10
0
def items_update(object_id):
    total = cart_count_total(Users_cart)
    form = UpdateForm()
    obj = block_content().grab_object(object_id)
    allcats = returnallcatlist()

    if request.method == 'POST':
        if form.validate_on_submit():
            item_up = {
                'name': form.name.data,
                'picture': form.picture.data,
                'about': form.discription.data,
                'price': form.price.data,
                'color': form.Color.data,
                'size': form.Size.data,
                'brand': form.Brand.data
            }
            updated = block_content().updateobj(object_id, item_up)
            catadd = block_content().grab_object(object_id)
            update_cat(form.cat.data, object_id)
            return redirect('/UpdateObject')
        else:
            form.discription.data = item_value_grab(obj, "about")
            error = "please Fill out the objects fully, or please enter a valid price (ie. 9.99)"
            return render_template('updateitem.html',
                                   form=form,
                                   error=error,
                                   obj=obj,
                                   cartamount="{0:.2f}".format(total),
                                   categories=allcats)
    else:
        form.discription.data = item_value_grab(obj, "about")
        return render_template('updateitem.html',
                               obj=obj,
                               form=form,
                               cartamount="{0:.2f}".format(total),
                               categories=allcats)
Пример #11
0
def returncatlist():
    """ returns tuple list for form to use to show users available categories
        return: tuple list with format - [(item , item)]
    """
    data = block_content().load_from_file()
    for obj in data:
        if obj.get("category") not in newlist:
            newlist.append(obj.get("category"))
        else:
            pass
    for cname in newlist:
        tupto = (cname, cname)
        if tupto not in tuplist:
            tuplist.append(tupto)
    return (tuplist)
Пример #12
0
def remove_from_cat(obj_id):
    """ Sets category of object to none so it wont be sorted into a category
        obj_id = id of object to remove category tag from
        return: list of objects including updated object
    """
    newlist = []
    data = block_content().load_from_file()
    for obj in data:
        if obj.get("id") == obj_id:
            obj.update({"category": "None"})
            newlist.append(obj)
        else:
            newlist.append(obj)
    with open(__datafile, 'w') as fout:
        json.dump(newlist, fout)
    fout.close()
    return (newlist)
Пример #13
0
def del_object():

    new = block_content().del_object("b4acf5da-962c-4295-a896-bfb109588249")
    return jsonify(new)
Пример #14
0
def update_object():

    update = block_content().updateobj("69", {"item": {"name": "69"}})
    return jsonify(update)
Пример #15
0
def removefromcart(oid):
    obj = block_content().grab_object(oid)
    Users_cart.remove(obj)
    return redirect('/cart')
Пример #16
0
def addtocart(oid):
    obj = block_content().grab_object(oid)
    Users_cart.append(obj)
    return redirect('/display/' + oid)
Пример #17
0
def delObjectbyid(ojid):
    total = cart_count_total(Users_cart)

    block_content().del_object(ojid)
    listofobjs = block_content().load_from_file()
    return redirect('/DeleteObject')
Пример #18
0
def return_list():

    load = block_content().load_from_file()
    return jsonify(load)