Beispiel #1
0
def catalog_items(catalog_id):
    """Route to catalog's items page"""
    catalogs = Catalog.get_all()
    catalog = Catalog.get_by_id(catalog_id)
    items = catalog.items
    return render_template('index.html',
                           type='catalog',
                           catalogs=catalogs,
                           items=items,
                           catalog=catalog)
Beispiel #2
0
def rebuild():
    db.drop_all()
    db.create_all()
    db.session.commit()
    db.session.add(Role(name='Admin'))
    db.session.add(Role(name='User'))
    db.session.add(Role(name='Provider'))
    db.session.add(Catalog(catalog_name="Tea package"))
    db.session.add(Catalog(catalog_name="Tea set"))
    db.session.add(Catalog(catalog_name="Tea food"))
    db.session.commit()
Beispiel #3
0
def rebuild():
    db.drop_all()
    db.create_all()
    db.session.commit()
    db.session.add(Role(name='Admin'))
    db.session.add(Role(name='User'))
    db.session.add(Role(name='Provider'))
    db.session.add(Catalog(catalog_name="5 PAX"))
    db.session.add(Catalog(catalog_name="7 PAX"))
    db.session.add(Catalog(catalog_name="9 PAX"))
    db.session.commit()
Beispiel #4
0
def edit_item(item_id, item):
    """Route to item edit form + update item"""
    catalogs = Catalog.get_all()
    # GET request
    if request.method == 'GET':
        return render_template('items/edit.html', item=item, catalogs=catalogs,
                               name=item.name, catalog_id=item.catalog_id,
                               description=item.description)

    # 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.name = name
        item.description = description
        item.catalog_id = catalog_id
        db_session.add(item)
        db_session.commit()
        flash('Item %s is updated' % 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/edit.html', catalogs=catalogs, item=item, name=name,
                               catalog_id=catalog_id, description=description)
Beispiel #5
0
def seed():
    catalogs = [
        {
            'name': 'Football'
        },
        {
            'name': 'Baseball'
        },
        {
            'name': 'Basketball'
        },
        {
            'name': 'Snowboarding'
        },
        {
            'name': 'Skating'
        },
        {
            'name': 'Hockey'
        },
    ]

    from app.models import Catalog

    for catalog in catalogs:
        new_catalog = Catalog(name=catalog['name'])
        db_session.add(new_catalog)

    db_session.commit()
Beispiel #6
0
def add_catalog_from_google_sheet(values):
    header = values[0]
    errors = []

    # clear catalog before uploading new data
    try:
        Catalog.query.delete()
        db.session.commit()
    except Exception as e:
        errors.append({
            'records': 'all',
            'exception': f'could not clear catalog. {str(e)}'
        })
        return errors

    for record in values[1:]:
        if not Catalog.query.get(strip(record[0])):
            try:
                db_save(
                    Catalog(product_id=strip(record[0]),
                            brand=strip(record[1]),
                            description=strip(record[2]),
                            mrp=float(strip(record[3])),
                            category_id=strip(record[4]),
                            size=strip(record[5]),
                            unit=strip(record[6]),
                            discount=float(strip(record[7]))))
            except Exception as e:
                errors.append({'record': record, 'exception': e})

    return errors
Beispiel #7
0
def home_page():
    """Route to home page"""
    catalogs = Catalog.get_all()
    items = db_session.query(CatalogItem).order_by(desc(
        CatalogItem.id)).limit(10).all()
    return render_template('index.html',
                           type='index',
                           catalogs=catalogs,
                           items=items)
Beispiel #8
0
def test_catalogs_json(client, app):
    catalogs = Catalog.get_all()
    with app.test_request_context():
        response = client.get(url_for('catalog.catalogs_json'))
        data = json.loads(response.data)

        # It should render item list
        assert len(data) == len(catalogs)
        for index in range(len(data)):
            assert data[index]['id'] == catalogs[index].id
            assert data[index]['name'] == catalogs[index].name
Beispiel #9
0
def find_new_catalog_entries(file):
    new_entries = []
    for record in csv.DictReader(
        (r.decode('utf-8') for r in file.readlines())):
        if not Catalog.query.get(record['product_id']):
            new_entries.append(
                Catalog(product_id=record['product_id'],
                        brand=record['brand'],
                        description=record['description'],
                        mrp=record['mrp'],
                        category_id=record['category_id'],
                        size=record['size'],
                        unit=record['unit']))
    return new_entries
Beispiel #10
0
def seed_db():
    user1 = User(name='user1', email='*****@*****.**')
    user2 = User(name='user2', email='*****@*****.**')
    db_session.add(user1)
    db_session.add(user2)
    db_session.commit()

    catalog_datas = [
        {
            'name': 'Skating'
        },
        {
            'name': 'Hockey'
        },
    ]

    for catalog in catalog_datas:
        new_catalog = Catalog(name=catalog['name'])
        db_session.add(new_catalog)

    db_session.commit()
Beispiel #11
0
def add_catalog():
    data = request.form.to_dict()
    name = data.get('name')
    catlog = Catalog.query.filter(Catalog.name == name).first()
    if catlog == None:
        cat = Catalog(name)
        cat.code = data.get('code')
        cat.is_show = data.get('is_show')
        cat.comments = data.get('comments')
        cat.created_time = datetime.now()
        db.session.add(cat)
        db.session.commit()
    else:
        return jsonify({'msg': 'catalog code exist !'})
    action_log(request, '添加字典目录')
    return jsonify({'msg': 'ok !'})
Beispiel #12
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)
Beispiel #13
0
def generateCatalog(request):
  packages  = request.POST.getlist('packagelist[]')
  hostname  = request.POST['hostname']
  ip        = request.POST['ip']
  try:
    obj = Catalog.objects.filter(title=hostname)
    if obj:
      updated_packages = obj.update(packages=packages,ip=ip)
      if updated_packages:
        LogMessageCatalog(hostname, 'Successfully updated')
    else:
      obj = Catalog(title=hostname,packages=packages,ip=ip,slug=hostname)
      obj.save()
      LogMessageCatalog(hostname,'Successfully created')
  except Catalog.DoesNotExist:
      obj = Catalog(title=hostname,packages=packages,ip=ip,slug=hostname)
      obj.save()
      LogMessageCatalog(hostname, 'Successfully created')

  return HttpResponse(packages)
Beispiel #14
0
def catalogs_json():
    """Render JSON for catalogs"""
    catalogs = Catalog.get_all()
    return render_json([c.serialize for c in catalogs])