Exemple #1
0
def create_items():
    for item in ITEMS:
        new_item = CatalogItem(name=item['name'],
                               description=item['description'],
                               user_id=item['user_id'],
                               catalog_id=item['catalog_id'])
        db_session.add(new_item)

    db_session.commit()
Exemple #2
0
def new():
    categories = Category.query \
        .all()
    form = CatalogItemForm()
    form.category_id.choices = [(c.id, c.name) for c in categories]
    if form.validate_on_submit():
        catalog_item = CatalogItem()
        form.populate_obj(catalog_item)
        db.session.add(catalog_item)
        db.session.commit()
        flash('Catalog Item is added!', 'success')
        return redirect(url_for('admin.index'))

    return render_template('admin/new.html', form=form, title='Catalog Items')
Exemple #3
0
def test_delete_items(client, app):
    create_items()
    item = db_session.query(CatalogItem).first()
    user = item.user
    with app.test_request_context():

        # Case unauthorized user
        g.current_user = None
        client.post(url_for('item.delete_item', item_id=item.id))
        # Item should not be delete
        assert CatalogItem.get_by_id(item.id) is not None

        g.current_user = user
        response = client.get(url_for('item.delete_item', item_id=item.id))
        # It should response form
        assert response.status_code == 200
        assert 'form' in response.data

        # Case authorized user
        response = client.post(url_for('item.delete_item', item_id=item.id))
        # It should redirect to home
        assert response.status_code == 302
        # Item should be delete
        assert CatalogItem.get_by_id(item.id) is None
Exemple #4
0
def test_edit_items(client, app):
    create_items()
    item = db_session.query(CatalogItem).first()
    user = item.user
    with app.test_request_context():
        g.current_user = user

        # Case get form
        response = client.get(url_for('item.edit_item', item_id=item.id))
        assert response.status_code == 200
        # Response should have item's info
        assert item.name in response.data

        # Case edit invalid form
        response = edit_item(client, item.id, {'name': ' ', 'description': '', 'catalog_id': 1})
        # It should not update and render current from
        assert response.location is None

        # Case edit success
        edit_item(client, item.id, ITEMS[1])
        edited_item = CatalogItem.get_by_id(item.id)
        assert (edited_item.name == ITEMS[1]['name']
                and edited_item.description == ITEMS[1]['description'])
Exemple #5
0
def add_new_item():
    """Route to new item page + create item"""
    catalogs = Catalog.get_all()

    # GET request
    if request.method == 'GET':
        return render_template('items/new.html', catalogs=catalogs)

    # POST request
    name, description, catalog_id = convert_item_fields(request.form.get('name'),
                                                        request.form.get('description'),
                                                        request.form.get('catalog_id'))
    if name and description and catalog_id:
        item = CatalogItem(name=name, description=description,
                           catalog_id=catalog_id, user_id=g.current_user.id)
        db_session.add(item)
        db_session.commit()
        flash('Item %s is created' % item.name, 'info')
        return redirect(url_for('item.get_item', item_id=item.id))

    else:
        flash('Name, description and catalog are required', 'warning')
        return render_template('items/new.html', name=name, catalog_id=catalog_id,
                               description=description, catalogs=catalogs)
Exemple #6
0
    def seed_catalog():
        print('Adding catalog')
        if config.DevelopmentConfig:
            baseurl = 'http://localhost:5000/static/'
        else:
            baseurl = '/static/'

        paper_note = CatalogItem(
            name='Paper Note',
            description="120 sheets",
            image_url="/static/images/products/paper_note.jpg",
            # image_url="{}images/products/paper_note.jpg".format(baseurl),
            price=20,
            category_id=1)

        double_ring = CatalogItem(
            name='Plantation Double Ring Note',
            description="80 sheets",
            image_url="/static/images/products/plantation_double_ring_note.jpg",
            # image_url="{}images/products/plantation_double_ring_note.jpg".format(
            #    baseurl),
            price=2.5,
            category_id=1)

        paper_note_set = CatalogItem(
            name='Planation Paper Note 5PCS/Set',
            description="30 sheets/book",
            image_url="/static/images/products/plantation_paper_note_set.jpg",
            # image_url="{}images/products/plantation_paper_note_set.jpg".format(
            # baseurl),
            price=3.5,
            category_id=1)

        recyle_paper = CatalogItem(
            name='Recycle Paper Double Ring Note',
            description="80 sheets",
            image_url=
            "/static/images/products/recycle_paper_double_ring_note.jpg",
            # image_url="{}images/products/recycle_paper_double_ring_note.jpg".format(
            # baseurl),
            price=3,
            category_id=1)

        db.session.add(paper_note)
        db.session.add(double_ring)
        db.session.add(paper_note_set)
        db.session.add(recyle_paper)

        colored_pencils = CatalogItem(
            name='12 Colored Pencils',
            description="Material: Cedar",
            image_url="/static/images/products/colored_pencils.jpg",
            # image_url="{}images/products/colored_pencils.jpg".format(baseurl),
            price=5,
            category_id=2)

        ballpoint_pens = CatalogItem(
            name='Gel-Ink BallPoint Pen 6PCS/SET',
            description="Pen Nib: 0.38mm",
            image_url="/static/images/products/ballpoint_pen_set.jpg",
            # image_url="{}images/products/ballpoint_pen_set.jpg".format(
            # baseurl),
            price=8,
            category_id=2)

        hexa_pen = CatalogItem(
            name='10 Colors Hexa Pen Set Minia',
            description="Material: Polyproplene",
            image_url="/static/images/products/hexa_pen_set_minia.jpg",
            # image_url="{}images/products/hexa_pen_set_minia.jpg".format(
            # baseurl),
            price=5,
            category_id=2)

        db.session.add(colored_pencils)
        db.session.add(ballpoint_pens)
        db.session.add(hexa_pen)

        calculator = CatalogItem(
            name='Calculator',
            description="Color: Black",
            image_url="/static/images/products/calculator.jpg",
            # image_url="{}images/products/calculator.jpg".format(baseurl),
            price=25,
            category_id=3)

        correction_tape = CatalogItem(
            name='Correction Tape',
            description="Dimensions: 5mmx10cm",
            image_url="/static/images/products/correction_tape.jpg",
            # image_url="{}images/products/correction_tape.jpg".format(baseurl),
            price=8,
            category_id=3)

        hole_puncher = CatalogItem(
            name='2 Hole Puncher',
            description="Maximum Capacity:10c",
            image_url="/static/images/products/hole_puncher.jpg",
            # image_url="{}images/products/hole_puncher.jpg".format(baseurl),
            price=5.5,
            category_id=3)

        db.session.add(calculator)
        db.session.add(correction_tape)
        db.session.add(hole_puncher)
Exemple #7
0
    c29 = Category(
        id=29,
        name="Golf",
        description=
        "Golf is a club and ball sport in which players use various clubs to hit balls into a series of holes on a course in as few strokes as possible.",
        picture="golf-1.png",
        user=u)
    session.add(c29)
    session.commit()

    # Sport Items

    i = CatalogItem(
        id=1,
        name="Goalpost",
        description=
        "The crossbar of these posts is ten feet (3 meters) above the ground, with vertical uprights at the end of the crossbar 18 feet 6 inches (5.64 m) apart for professional and collegiate play and 23 feet 4 inches (7.11 m) apart for high school play.[62][63][64] The uprights extend vertically 35 feet on professional fields, a minimum of 10 yards on college fields, and a minimum of ten feet on high school fields. Goal posts are padded at the base, and orange ribbons are normally placed at the tip of each upright.",
        picture="goal-post.png",
        category=c,
        user=u)
    session.add(i)
    session.commit()

    i2 = CatalogItem(
        id=2,
        name="Ball",
        description=
        "The football itself is an oval ball, similar to the balls used in rugby or Australian rules football.[65] At all levels of play, the football is inflated to  12 1⁄2 to  13 1⁄2 pounds per square inch (psi) and weighs 14 to 15 ounces (397 to 425 grams);[64][66][67] beyond that, the exact dimensions vary slightly. In professional play the ball has a long axis of 11 to  11 1⁄4 inches, a long circumference of 28 to  28 1⁄2 inches, and a short circumference of 21 to  21 1⁄4 inches,[68] while in college and high school play the ball has a long axis of  10 7⁄8 to  11 7⁄16 inches, a long circumference of  27 3⁄4 to  28 1⁄2 inches, and a short circumference of  20 3⁄4 to  21 1⁄4 inches.",
        picture="american-football.png",
        category=c,
        user=u)
    session.add(i2)
Exemple #8
0
 def decorated_func(item_id, **kwargs):
     item = CatalogItem.get_by_id(item_id)
     if item is None:
         flash('Item not found', 'error')
         return redirect(url_for('catalog.home_page'))
     return f(item_id, item, **kwargs)