Beispiel #1
0
def new_product():
    error = None
    form = AddProductForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            new_product = Product(
                form.donor_Id.data,
                form.product_Code.data,
                form.blood_Group.data,
                form.exp_Date.data,
                form.product_Vol.data,
                '1',
                session['user_id']
            )
            db.session.add(new_product)
            db.session.commit()
            flash('New entry was successfully posted. Thanks.')
            return redirect(url_for('products'))
        else:
            flash('All fields are required')
            return redirect(url_for('products'))
            return render_template(
                'products.html',
                form=form,
                error=error,
                open_products=open_products(),
                closed_products=closed_products
                 )
Beispiel #2
0
def add(request):
    context = {}
    context.update(csrf(request))
    if request.user.is_authenticated():
        context['login_mode'] = True
        context['user'] = request.user
        if request.user.is_superuser:
            context['user_admin'] = True
    form = AddProductForm()
    context['form'] = form
    if request.method == 'POST':
        form = AddProductForm(request.POST)

        if form.is_valid():
            product = form.save(commit=False)
            product.user = request.user
            product.save()
            dict = {'add': True, 'username': request.user.username}
            data = json.dumps(dict, cls=JSONEncoder)
            return HttpResponse(data, content_type="application/json")
        else:
            errors_dict = {}
            if form.errors:
                for error in form.errors:
                    e = form.errors[error]
                    errors_dict[error] = unicode(e)
            data = json.dumps(errors_dict, cls=JSONEncoder)
            return HttpResponse(data, content_type="application/json")

    return render_to_response('products/add-product.html', context)
def add_product():
    form = AddProductForm()
    if form.validate_on_submit():
        new_product = Product(name = form.name.data,
                    description=form.description.data,
                    price=form.price.data,
                    category_id=form.category.data, stock=form.stock.data)
        db.session.add(new_product)
        db.session.commit()
        flash('You have successfully added a new product.')
        return redirect(url_for('admin.add_product'))
    return render_template('admin/add_product.html', form=form, title="Add Product")
    def dispalyProductForm(self):

        classifications = self.session.query(Classification).all()

        if not classifications:

            QMessageBox.warning(self, 'تحذير',
                                'يرجي اضافة اصناف اولا ثم يمكنك اضافة منتجات')

        else:
            dialog = AddProductForm(self.session, classifications)
            dialog.exec_()
Beispiel #5
0
def addproduct():
  """Añadir Producto"""

  form = AddProductForm(request.form)

  if request.method == 'POST' and form.validate():
    product = Product()
    form.populate_obj(product)
    db.session.add(product)
    db.session.commit()
    return redirect(url_for('main'))

  return render_template('addproduct.html', form=form)
Beispiel #6
0
def addProduct():
    form = AddProductForm()
    makers = Maker.query.all()
    if makers:
        form.maker.choices = [(a.id, a.name) for a in makers]
    if form.validate_on_submit():

        product = Product()
        product.code = form.code.data
        product.maker_id = form.maker.data
        product.maker_code = form.maker_code.data
        product.desc_CS = form.desc_CS.data
        product.desc_JP = form.desc_JP.data

        product.long_desc = form.long_desc.data
        product.detailed_desc = form.detailed_desc.data
        product.subcategory_desc = form.subcategory_desc.data
        product.keywords = form.keywords.data

        product.price_unit = form.price_unit.data
        product.price_retail = form.price_retail.data
        product.qty_stock = form.qty_stock.data
        product.limited_flg = form.limited_flg.data
        product.axm_node = form.axm_node.data
        if form.package_size.data == '':
            product.package_size = None
        else:
            product.package_size = form.package_size.data
        category_id = Maker.query.filter_by(id=product.maker_id).first().category_id
        if category_id:
            product.category_id = category_id
        db.session.add(product)
        db.session.commit()

        term_ids_str = request.form.getlist('term')
        for id in term_ids_str:
            t = CatalogedProducts()
            t.product_id = product.id
            t.catalog_id = int(id)
            db.session.add(t)
        db.session.commit()

        flash(gettext("New product successfully added."))
        return redirect(url_for("editProduct", id=product.id))
    catalog = prepare_catalog()
    return render_template("product/addProduct.html",
                           title=gettext('Add new product'),
                           catalog=catalog,
                           form=form)
Beispiel #7
0
    def post(self):
        form = AddProductForm()

        product = Product.add_product(product_name=form.product_name.data,
                                      price=form.price.data,
                                      seller_username=current_user.username)

        flash('Added a product successfully!', category='success')
        return redirect(url_for('home_page'))
Beispiel #8
0
def app_results(query):
    amazon = AmazonAPI(AWS_KEY, SECRET_KEY, ASSOC_TAG)
    products = amazon.search(Keywords=query, SearchIndex='All')
    if referrer == 'dashboard':
        return render_template("amazon_bottlenose2.html", products=products)
    else:
        form = AddProductForm()
        return render_template("amazon_bottlenose_add.html",
                               products=products,
                               form=form)
Beispiel #9
0
	def view( self, request ):

		form = AddProductForm( request.REQUEST )

		update_info = {}
		error = {}	

		if form.is_valid():
			if 'id' not in request.REQUEST or request.REQUEST[ 'id' ] == AddChangeProductAction.ID_NOT_DEFINED:

				form.save()
				product = Product.objects.all().order_by( '-id' )[ 0 ]
			else:
				product = Product.objects.get( id = request.REQUEST[ 'id' ] )
				
				product.name = form.cleaned_data[ 'name' ]
				product.category = form.cleaned_data[ 'category' ]
				product.producer = form.cleaned_data[ 'producer' ]
				product.price = form.cleaned_data[ 'price' ]
				product.country = form.cleaned_data[ 'country' ]

				product.save()

			is_error = False

			update_info[ 'name' ] = product.name
			update_info[ 'product_category_name' ] = ProductCategory.objects.get( id = product.category_id ).name
			update_info[ 'producer_name' ] = Producer.objects.get( id = product.producer_id ).name
			update_info[ 'country' ] = Country.objects.get( id = product.country_id ).name
			update_info[ 'price' ] = product.price
			update_info[ 'id' ] = product.id
		else:
			is_error = True
			error[ 'error_description' ] = ""
			
		return JSONView.view(	self, request, 
									{ 
										'is_error': is_error, 
										'update_info': update_info 
									} )
Beispiel #10
0
def add_product(referrer):
    form = AddProductForm()
    search_bar = search()

    if form.validate_on_submit():
        user_id = form.user_id.data
        name = form.name.data.strip()
        asin = form.asin.data.strip()
        category_id = form.category_id.data
        default_photo = form.default_photo.data.strip()
        custom_photo = form.custom_photo.data

        new_product = model.Product(name=name,
                                    asin=asin,
                                    category_id=category_id,
                                    default_photo=default_photo,
                                    custom_photo=custom_photo)
        new_product_id = new_product.id

        if referrer == 'new':
            model.session.add(new_product)
            model.session.commit()

        add_to_lib = model.Library(user_id=user_id,
                                   product_id=new_product_id,
                                   product_desc=name,
                                   status=1)
        model.session.add(add_to_lib)
        model.session.commit()

        return jsonify(msg='Success')
    else:
        if referrer == 'new':
            return render_template("add_product.html",
                                   title="Add a Product",
                                   form=form,
                                   search=search_bar)
        else:
            return 'Fail'
def edit_product(id):
    products = Product.query.get(id)
    # if current_user.id != issue.user_id:
    #   abort(403)
    form = AddProductForm(obj=products)
    if form.validate_on_submit():
        products.name = form.name.data
        products.description = form.description.data
        products.category_id = form.category.data
        products.price = form.price.data
        products.stock = form.stock.data
        db.session.add(products)

        db.session.commit()

        return redirect(url_for('admin.view'))
    form.name.data = products.name
    form.description.data = products.description
    form.price.data = products.price
    form.category.data= products.category_id
    form.stock= products.stock
    #flash('You have successfully updated product.')
    return render_template('admin/edit_product.html', form=form, title="Edit Product")
Beispiel #12
0
def welcome_admin():
    print(admin)
    product_list = []

    for i in Products.query.with_entities(
            Products.category,
            func.count(Products.category)).group_by(Products.category).all():
        product_list.append(list(i))

    form = AddProductForm()
    if form.validate_on_submit():
        product = Products(name=form.name.data,
                           description=form.description.data,
                           price=form.price.data,
                           category=form.category.data)
        db.session.add(product)
        db.session.commit()
        flash("added successfully")
        return redirect(url_for('view_products'))
    return render_template("welcome_admin.html",
                           form=form,
                           admin=admin,
                           product_list=product_list)
Beispiel #13
0
def add_product(referrer):
    form = AddProductForm()
    search_bar = search()

    if form.validate_on_submit():
        user_id = form.user_id.data
        name = form.name.data.strip()
        asin = form.asin.data.strip()
        category_id = form.category_id.data
        default_photo = form.default_photo.data.strip()
        custom_photo = form.custom_photo.data

        
        new_product = model.Product(name = name, 
                                    asin = asin, 
                                    category_id=category_id, 
                                    default_photo = default_photo, 
                                    custom_photo=custom_photo)
        new_product_id = new_product.id

        if referrer == 'new':
            model.session.add(new_product)
            model.session.commit()

        add_to_lib = model.Library(user_id=user_id, 
                                product_id=new_product_id,
                                product_desc=name,
                                status=1)
        model.session.add(add_to_lib)
        model.session.commit()

        return jsonify(msg='Success')
    else:
        if referrer=='new':
            return render_template("add_product.html", title="Add a Product", form=form, search=search_bar)
        else:
            return 'Fail'
Beispiel #14
0
def search():
    form = SearchForm()
    if form.validate_on_submit():
        referrer = form.referrer.data
        query = form.query.data
        results = model.session.query(model.Library).filter(
            model.Library.product_desc.like('%' + query + '%')).all()

        if not results:
            #redirect to new page with amazon search results
            return redirect(
                url_for('amazon_bottlenose2', query=query, referrer=referrer))
        else:
            for i in results:
                similar_products = None
                if i.product.asin:
                    asin = i.product.asin
                    api = API(AWS_KEY, SECRET_KEY, 'us', ASSOC_TAG)
                try:
                    similar_root = api.similarity_lookup(asin,
                                                         ResponseGroup='Large')
                    #~ from lxml import etree
                    #~ print etree.tostring(root, pretty_print=True)
                    nspace = similar_root.nsmap.get(None, '')
                    similar_products = similar_root.xpath(
                        '//aws:Items/aws:Item', namespaces={'aws': nspace})
                except:
                    similar_products = None

                #render page with search results
                if referrer == 'dashboard':
                    return render_template('results.html',
                                           results=results,
                                           similar_products=similar_products)
                else:
                    form = AddProductForm()
                    return render_template('add_product_results.html',
                                           results=results,
                                           similar_products=similar_products,
                                           form=form)

    # else:
    #   flash("Invalid Search")

    return render_template("search.html", form=form)
Beispiel #15
0
def add_product():
    try:
        form = AddProductForm()

        #  if form.validate_on_submit(): check form if valid on submit before proceeding

        if request.method == "POST":
            products_list = mongo.db.products
            product_name = form.product_name.data
            product_desc = form.description.data
            barcode = form.barcode.data
            brand = form.brand.data
            price = form.price.data
            size = form.size.data
            description = form.description.data
            discount = form.discount.data
            # get file data
            file = form.image.data
            if file:
                filename = file.filename
                form.image.data.save('static/images/ProductImages/' + barcode +
                                     '.jpg')
                image = filename

            products_list.insert_one({
                'product_name': product_name,
                'barcode': barcode,
                'brand': brand,
                'price': price,
                'size': size,
                'description': description,
                'discount': discount,
                'image': image
            })
            flash(product_name + " added!")
            return redirect(url_for('products'))

        return render_template('admin/add_product.html',
                               title='Add Product',
                               form=form)

    except Exception as e:
        return str(e)
Beispiel #16
0
 def get(self):
     form = AddProductForm()
     return render_template('add_product.html',
                            title='Add Product',
                            current_page='new_product',
                            form=form)
Beispiel #17
0
def editProduct(id=0):
    # for stock: return to the same page
    stock_page = request.args.get('stock_page') if request.args.get('stock_page') else 1

    product = Product.query.filter_by(id=id).first()
    if product == None:
        flash(gettext('Product not found.'))
        return redirect(url_for('stock', page=stock_page))
    form = AddProductForm(obj=product)
    makers = Maker.query.all()
    if makers:
        form.maker.choices = [(a.id, a.name) for a in makers]
    #for existing code validation
    form.request = request

    if form.validate_on_submit():

        #delete product
        if 'delete' in request.form:
            product.active_flg = False
            db.session.add(product)
            db.session.commit()
            flash(gettext('Product has been deleted.'))
            return redirect(url_for("stock", page=stock_page))

        #update catalog terms
        new_ids_str = request.form.getlist('term')
        new_ids = []
        for id in new_ids_str:
            new_ids.append(int(id))
        old_ids = []
        for term in product.catalog_terms:
            old_ids.append(term.catalog_id)

        for id in old_ids:
            if id not in new_ids:
                t = CatalogedProducts.query\
                    .filter_by(catalog_id=id)\
                    .filter_by(product_id=product.id)\
                    .first()
                db.session.delete(t)
        for id in new_ids:
            if id not in old_ids:
                t = CatalogedProducts()
                t.product_id = product.id
                t.catalog_id = id
                db.session.add(t)
        db.session.commit()

        #update product
        product.code = form.code.data
        product.maker_id = form.maker.data
        product.maker_code = form.maker_code.data
        product.desc_CS = form.desc_CS.data
        product.desc_JP = form.desc_JP.data

        product.long_desc = form.long_desc.data
        product.detailed_desc = form.detailed_desc.data
        product.subcategory_desc = form.subcategory_desc.data
        product.keywords = form.keywords.data

        product.price_unit = form.price_unit.data
        product.price_retail = form.price_retail.data
        product.qty_stock = form.qty_stock.data
        product.limited_flg = form.limited_flg.data
        product.axm_node = form.axm_node.data
        if form.package_size.data == '':
            product.package_size = None
        else:
            product.package_size = form.package_size.data
        category_id = Maker.query.filter_by(id=product.maker_id).first().category_id
        if category_id:
            product.category_id = category_id
        db.session.add(product)
        db.session.commit()
        flash(gettext("Product successfully changed."))
        return redirect(url_for("stock", page=stock_page))
    selected_maker = product.maker_id
    imgUrls = getImgUrls(product.id)

    catalog = prepare_catalog()

    terms = product.catalog_terms
    terms.sort(key=lambda x: x.catalog.order)
    selected_catalog_terms = []
    for term in terms:
        if term.catalog.super_id == None:
            level = 0
        else:
            level = 1
        selected_catalog_terms.append([term.catalog.id, level, unicode(term.catalog.name_CS)])

    return render_template('product/editProduct.html',
                           title=gettext("Edit Product"),
                           product=product,
                           catalog=catalog,
                           imgUrls=imgUrls,
                           selected_maker=selected_maker,
                           selected_catalog_terms=selected_catalog_terms,
                           stock_page=stock_page,
                           form=form)
Beispiel #18
0
def add_product():
    form = AddProductForm()
    return render_template('add_product.html', form=form)