Example #1
0
def addItem(user_id):
    form = ItemForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        name = form.name.data
        url = form.item_url.data
        description = form.description.data

        if url:
            r = requests.get(url)
            html_content = r.text
            soup = BeautifulSoup(html_content)
            if "amazon" in url:
                image_url = soup.find('img', {
                    'id': 'miniATF_image'
                }).get('src')
            elif "ebay" in url:
                image_url = soup.find('img', {'id': 'icImg'}).get('src')

            print(image_url)

        item = Item(name, description, url, image_url, user_id)
        db.session.add(item)
        db.session.commit()
        return redirect(url_for('displayList', user_id=user_id))

    return render_template("newItem.html", form=form, user_id=user_id)
Example #2
0
def add_item(request, url_category_name):
	context = RequestContext(request)
	
	cat_name = decode_url(url_category_name)
	if request.method == 'POST':
		form = ItemForm(request.POST, request.FILES)
		
		if form.is_valid() and form.is_multipart():
			save_files(request.FILES['photos'])
			item = form.save(commit=False)
			
			cat = Category.objects.get(name=cat_name)
			item.category = cat
			
			item.views = 0			
			item.likes = 0
			
			item.save()
			
			return category(request, url_category_name)
		else:
			print form.errors
	else:
		form = ItemForm()
		
	return render_to_response('app/add_item.html', {'url_category_name':url_category_name, 'cat_name':cat_name, 'form':form}, context)
Example #3
0
def edit_item(request, item_id):
	item = get_object_or_404(Item, pk=item_id)
	if request.method == "POST":
		form = ItemForm(request.POST)
		if form.is_valid():
			item.listing = form.cleaned_data['listing']
			item.name = form.cleaned_data['name']
			item.category = form.cleaned_data['category']
			item.department = form.cleaned_data['department']
			item.description = form.cleaned_data['description']
			item.update_item = form.cleaned_data['update_item']
			item.save()
			# Siempre que cree el dato correctamente redireccionar
			return HttpResponseRedirect('/items/%s/' % item.id)
	else:
		item_data = {
			'listing' : item.listing,
			'name' : item.name,
			'category' : item.category.id,
			'department' : item.department,
			'description' : item.description,
			'update_item' :item.update_item
		}
		form = ItemForm(initial=item_data)
	context = Context({'title' : 'Editar el item', 'form' : form})
	return render_to_response('add-item.html', context, context_instance=RequestContext(request))
Example #4
0
def index():
    form = ItemForm()
    if form.validate_on_submit():
        item = Item(name=form.name.data,
                    manufacturer=form.manufacturer.data,
                    purchase_date=form.purchase_date.data,
                    purchase_price=form.purchase_price.data,
                    warranty=form.warranty.data,
                    insured=form.insured.data,
                    current_value=form.current_value.data,
                    serial=form.serial.data,
                    user_id=current_user.id)
        db.session.add(item)
        db.session.commit()
        flash('Item added to your inventory!')
        return redirect(url_for('index'))

    page = request.args.get('page', 1, type=int)
    items = current_user.items.order_by(Item.timestamp.desc()).paginate(\
        page, app.config['ITEMS_PER_PAGE'], False)
    next_url = url_for('index', page=items.next_num) \
        if items.has_next else None
    prev_url = url_for('index', page=items.prev_num) \
        if items.has_prev else None
    return render_template('index.html',
                           title='Home',
                           form=form,
                           items=items.items,
                           next_url=next_url,
                           prev_url=prev_url)
Example #5
0
def addItem(user_id):
    if 'email' not in session:
        return redirect('/')
    else:
        form = ItemForm(request.form, csrf_enabled=False)
        if form.validate_on_submit():
            name = form.name.data
            url = form.item_url.data
            description = form.description.data

            if url:
                r = requests.get(url)
                html_content  = r.text
                soup = BeautifulSoup(html_content)
                if "amazon" in url: 
                    print(soup.find('img',{'id':'miniATF_image'}))
                    image_url = soup.find('img',{'id':'miniATF_image'}).get('src')
                elif "ebay" in url:
                    image_url = soup.find('img',{'id':'icImg'}).get('src')
                
                print (image_url)

            item = Item(name, description, url,image_url, user_id)
            db.session.add(item)
            db.session.commit()
            flash("Item added")
            return redirect(url_for('displayList', user_id = user_id)) 

        return render_template("newItem.html", form = form, user_id = user_id)
Example #6
0
def index():

    items = current_user.get_items().all()
    print(items)

    form = LoginHomeForm()
    if form.validate_on_submit():
        home = Home.query.filter_by(home_name=form.home_name.data).first()
        if home is None or not home.check_password(form.password.data):
            flash('Invalid home name or password')
            return redirect(url_for('index'))
        current_user.home_id = home.id
        db.session.commit()
        flash('Congratulations, you are part of home!')

        return redirect(url_for('index'))
    form_item = ItemForm()
    if form_item.validate_on_submit():
        item = Item(item_name=form_item.item_name.data,
                    type=form_item.type.data,
                    amount=form_item.amount.data,
                    note=form_item.note.data,
                    bought=False,
                    author_item=current_user)
        db.session.add(item)
        db.session.commit()
        flash('Your item is now added!')
        return redirect(url_for('index'))
    return render_template('index.html',
                           title='Home',
                           items=items,
                           form=form,
                           form_item=form_item)
Example #7
0
def search(keyword):
    form = ItemForm()
    if form.validate_on_submit():
        if current_user.is_authenticated:
            item = Item(name=form.name.data, image=form.image.data)
            db.session.add(item)
            db.session.commit()
    item_list = Item.query.filter_by(name=keyword).all()
    return render_template("listings/items.html", title="Nontrivial - Search", keyword=keyword, form=form, items=item_list)
Example #8
0
def save_item(request):
    response = reply_object()
    item_form = ItemForm(request.POST)
    if item_form.is_valid():
        response = item_form.save()
    else:
        response["code"] = settings.APP_CODE["FORM ERROR"]
        response["errors"] = item_form.errors

    return HttpResponse(simplejson.dumps(response))
Example #9
0
def items_list():
    form = ItemForm()
    error = ""
    if request.method == "POST":
        if form.validate_on_submit():
            items.create(form.data)
        return redirect(url_for("items_list"))

    return render_template("items.html",
                           form=form,
                           items=items.all(),
                           error=error)
Example #10
0
def add():
    form = ItemForm()
    if form.validate_on_submit():
        flash('Here')
        toDoItem = ToDoItem(item=form.item.data, completed=form.completed.data)
        db.session.add(toDoItem)
        db.session.commit()
        flash('Added item!')
        return redirect(url_for('home'))
    else:
        flash('Bad')
    return render_template('addItem.html', form=form)
def addItem(category_id):
    if current_user.is_authenticated:
        category = Category.query.filter_by(id=category_id).one()
        form = ItemForm()
        if form.validate_on_submit():
            item = Item(title=form.name.data, description=form.description.data, category_id=category.id)
            db.session.add(item)
            db.session.commit()
            flash('Successfully Added the Item!')
            return redirect(url_for('item', category_id=category_id))
        elif form.cancel.data == True:
            return redirect(url_for('item', category_id=category_id))
    return render_template('item/addItem.html', title='Add Item', form=form, category=category)
Example #12
0
def index():
    items = Item.query.filter_by(user_id=current_user.get_id()).all()
    form = ItemForm()
    if form.validate_on_submit():
        item = Item(name=form.name.data,
                    quantity=form.quantity.data,
                    type=form.type.data,
                    priority=form.priority.data,
                    user_id=current_user.get_id())
        db.session.add(item)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('index.html', form=form, items=items)
def add_item():
    form = ItemForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        new_cart = Cart(user_id=form.user_id.data,
                        item_id=form.item_id.data,
                        quantity=form.quantity.data,
                        preferences=form.preferences.data)
        db.session.add(new_cart)
        db.session.commit()
        return new_cart.to_dict()
    else:
        return {"errors": "invalid submission"}
Example #14
0
def new_item(category_id):
    form = ItemForm(request.form)
    if request.method == 'POST' and form.validate():
        new = Items(name=request.form['name'],
                    description=request.form['description'],
                    category_id=category_id,
                    user_id=login_session['user_id'])
        db_session.add(new)
        db_session.commit()
        flash('New item {} successfully created!'.format(new.name))
        return redirect(url_for('category_owner.show_categories',
                                category_id=category_id))
    return render_template('newitem.html', category_id=category_id,
                           form=form)
Example #15
0
def create_item(typeId):
    form = ItemForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        item = Item(
            name=form.data['name'],
            description=form.data['description'],
            user_id=current_user.id,
            type_id=typeId,
        )
        db.session.add(item)
        db.session.commit()
        return {"item": item.to_dict()}
    return {"errors": "error with item form / post route"}
Example #16
0
def edit_item(item):
    form = ItemForm(formdata=request.form, obj=item)

    if form.validate_on_submit():
        filename = save_image_get_filename(form.image.data)
        update_item(item, form, filename)
        flash('Updated item: {}'.format(item.name))
        return redirect(url_for('view_item', item_id=item.id))

    return render_template(
        'item-form.html',
        form=form,
        item_action='Edit'
    )
def editItem(category_id, item_id):
    if current_user.is_authenticated:
        category = Category.query.filter_by(id=category_id).first()
        editedItem = Item.query.filter_by(category_id=category.id).one()
        form = ItemForm()
        if form.validate_on_submit():
            if request.form['name']:
                editedItem.title = form.name.data
            if request.form['description']:    
                editedItem.description = form.description.data
            db.session.add(editedItem)
            db.session.commit()
            flash('Successfully Edited the Item!')
            return redirect(url_for('item', category_id=category_id))
    return render_template('item/editItem.html', title='Edit Item', editedItem=editedItem, category_id=category.id, form=form)
Example #18
0
def inventory():

    form = ItemForm(request.form)

    if form.validate_on_submit():
        new_item = Item(item_name=form.item_name.data,
                        item_price=form.item_price.data,
                        item_category=form.item_category.data,
                        user_id=current_user.id)
        db.session.add(new_item)
        db.session.commit()
        flash('Item added to inventory')
        return redirect(url_for('inventory'))

    return render_template('inventory.html', title='Inventory', form=form)
Example #19
0
def create_item():
    form = ItemForm()

    if form.validate_on_submit():
        filename = save_image_get_filename(form.image.data)
        item = _create_item(form, filename)
        flash('Created new item: {}'.format(item.name))
        return redirect(url_for('show_items'))

    return render_template(
        'item-form.html',
        title='Create New Item',
        form=form,
        item_action='Create'
    )
Example #20
0
def adjustItem():

    form = ItemSelectForm()

    populateItemSelectField(form)

    if form.validate_on_submit():

        if form.action.data == "delete":

            return render_template("items/deleteConfirmation.html", form=DeleteConfirmationForm(hidden=form.items.data))

        elif form.action.data == "edit":

            item = Items.query.filter_by(user=current_user).filter_by(
                itemName=form.items.data).first_or_404()

            # Populate an itemForm object with item data
            itemForm = ItemForm(price=Decimal(item.price),
                                quantity=item.quantity, itemName=item.itemName)

            # Store the current name of the item in a hidden field to track if the user makes changes to the itemName.
            itemForm.hidden.data = item.itemName

            itemForm.submit.label.text = form.action.data.capitalize()

            return render_template("items/addItem.html", form=itemForm, action="Edit")

    return redirect(url_for("items.items"))
Example #21
0
def add_item():
        form = ItemForm()
        if request.method == 'POST' and request.files and 'photo' in request.files and form.validate_on_submit():
            filename = photos.save(request.files['photo'])
            #url = photos.url(filename)
            item = Item(title=form.name.data,
                price=form.price.data,
                description=form.description.data,
                stock=form.stock.data,
                vendorid=current_user.id,
                image=filename)
            db.session.add(item)
            db.session.commit()
            flash("Congratulations, your item has been added")
            return redirect(url_for('inventory',username=current_user.username))
        else:
            return render_template('add_item.html', title="Add Item", form=form)
Example #22
0
def add_item():
    form = ItemForm()
    if form.validate_on_submit():
        item = Item(name=form.name.data,
                    manufacturer=form.manufacturer.data,
                    purchase_date=form.purchase_date.data,
                    purchase_price=form.purchase_price.data,
                    warranty=form.warranty.data,
                    insured=form.insured.data,
                    current_value=form.current_value.data,
                    serial=form.serial.data,
                    user_id=current_user.id)
        db.session.add(item)
        db.session.commit()
        flash('Item added to your inventory!')
        return redirect(url_for('index'))
    return render_template('add_item.html', title='Add Item', form=form)
Example #23
0
def planit_items(id):
    """
    Creates items for a party.
    """
    form = ItemForm()
    # print(request.get_json())
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        item = Item(
            name=form.data['name'],
            party_id=form.data['party_id'],
            # user_id=form.data['user_id']
        )
        db.session.add(item)
        db.session.commit()
        return item.to_dict()
    return {'errors': validation_errors_to_error_messages(form.errors)}
Example #24
0
def deleteItem(category_name, item_name, **kwds):
    category = kwds['category']
    item = kwds['item']
    item_form = ItemForm()
    item_form.item_name.data = item.name
    item_form.item_category.data = category.name
    item_form.item_description.data = item.description
    item_form.item_category.choices = [
        (cat.name, cat.name) for cat in db.session.query(Category).all()
    ]
    if request.method == 'POST' and item_form.validate_on_submit():
        db.session.delete(item)
        db.session.commit()
        flash('Item deleted successfully', 'success')
        return redirect(
            url_for('catalog.viewCategory', category_name=category.name))
    return render_template('delete_item.html', item_form=item_form, item=item)
Example #25
0
def item_details(item_id):
    def __init__():
        pass

    item = items.get(item_id - 1)
    form = ItemForm(data=item)

    if request.method == "POST":
        if request.form.get('delete'):
            items.delete(item_id - 1)
        elif form.validate_on_submit():
            if item_id > 0:
                items.update(item_id - 1, form.data)
            else:
                pass
        return redirect(url_for("items_list"))
    return render_template("item.html", form=form, item_id=item_id)
Example #26
0
def index(request):

    if request.method == 'POST':
        form = BrandForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/')
    form = BrandForm()

    if request.method == 'POST':
        category_form = CategoryForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/')
    category_form = CategoryForm()

    if request.method == 'POST':
        item_form = ItemForm(request.POST)
        if item_form.is_valid():
            item_form.save()
            return HttpResponseRedirect('/')
    item_form = ItemForm()

    return render(request, 'index.html', {
        'form': form,
        'item_form': item_form,
        'category_form': category_form
    })
Example #27
0
def new_item():
    form = ItemForm()
    try:
        if form.validate_on_submit():
            item = Item(name=form.name.data)
            db.session.add(item)
            db.session.commit()
            msg = 'Novo item cadastrado: {}'.format(form.name.data)
            app.logger.info(msg)
            flash(msg)
            return redirect(url_for('list_items'))
    except Exception as err:
        db.session.rollback()
        app.logger.error(
            'O produto "{}" já tinha sido cadastrado! Detalhes: {}'.format(
                form.name.data, str(err)))
        flash('ERRO: O produto "{}" já tinha sido cadastrado!'.format(
            form.name.data))
    return render_template('quickform.html', title='Cadastrar item', form=form)
Example #28
0
def register(request):
    if request.method == 'POST':
        form = ItemForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/app/')
    else:
        form = ItemForm()
    return render(request, 'register.html', {'form': form})
Example #29
0
def createItem(category_name, **kwds):
    category = kwds['category']
    item_form = ItemForm()
    item_form.item_category.choices = [
        (cat.name, cat.name) for cat in db.session.query(Category).all()
    ]
    if request.method == 'POST' and item_form.validate_on_submit():
        selected_category = db.session.query(Category).filter_by(
            name=item_form.data['item_category']).first()
        item = Item(name=item_form.data['item_name'],
                    description=item_form.data['item_description'],
                    category=selected_category,
                    user_id=session.get('user_id'))
        db.session.add(item)
        db.session.commit()
        flash('Item created successfully', 'success')
        return redirect(
            url_for('catalog.viewCategory', category_name=item.category.name))
    item_form.item_category.data = category.name
    return render_template('create_item.html', item_form=item_form)
Example #30
0
def account():
    user = load_user(current_user.get_id())
    form = ItemForm()

    if user.user_data.store_type == 'Food Pantry':
        print(user.user_data.store_type)
        return render_template('pantry.html', user=user, itemForm=form)
    elif user.user_data.store_type == "Store":
        return render_template('store.html', user=user)
    else:
        return render_template('user.html', user=user)
Example #31
0
def add_item(request):
	if request.method == "POST":
		form = ItemForm(request.POST)
		if form.is_valid():
			# Crear un nuevo item
			item = Item.objects.create(
				listing = form.cleaned_data['listing'],
				name = form.cleaned_data['name'],
				category=form.cleaned_data['category'],
				department=form.cleaned_data['department'],
				description = form.cleaned_data['description'],
				update_item = form.cleaned_data['update_item'],
			)
			# Siempre que cree el dato correctamente redireccionar
			return HttpResponseRedirect('/items/%s/' % item.id)
	else:
		form = ItemForm()

	context = Context({'title' : 'Adicionar item', 'form' : form})
	return render_to_response('add-item.html', context, context_instance=RequestContext(request))
Example #32
0
def requestItem():
    user = load_user(current_user.get_id())
    form = ItemForm()

    if form.validate_on_submit():
        f = form.photo.data
        filename = secure_filename(f.filename)
        f.save(os.path.join(
            app.instance_path, 'photos', filename
        ))

        requestedItem = RequestedItem(
            name=form.name.data,
            description=form.description.data,
            image=filename,
            price=form.price.data,
            quantity=form.quantity.data,
            user=user
        )
        db.session.add(requestedItem)
        db.session.commit()
Example #33
0
def add_item_to_drop_list(droplist_id):
    """Add an item to the drop list"""
    droplist = DropList.query.get_or_404(droplist_id)

    form = ItemForm()

    form.set_choices(db, Location)

    if form.validate_on_submit():
        item = Item(row_letter=form.row_letter.data,
                    column_number=form.column_number.data,
                    location_id=form.location_id.data,
                    description=form.description.data,
                    droplist_id=droplist.id)

        db.session.add(item)
        db.session.commit()

        return redirect(f"/droplists/{droplist.id}")

    return render_template("/droplist_items_new.html", form=form)
Example #34
0
def index():
    session.permanent = True
    form = ItemForm()
    form2 = FilterItem()
    if form.validate_on_submit():
        newItem = item()
        newItem.save_item(form.itemname.data, form.avaclass.data,
                          form.itemclass.data, form.have_it.data)
        return redirect('/index')
    if form2.validate_on_submit():
        session['have_it'] = form2.filt_have_it.data
        session['itemclass'] = form2.filt_itemclass.data
        session['avaclass'] = form2.filt_avaclass.data
        filterItem = item()
        filter = {}
        if form2.filt_have_it.data != 'Alle':
            if form2.filt_have_it.data == "Fehlt":
                filter.update({"haveit": False})
            else:
                filter.update({"haveit": True})
        if form2.filt_itemclass.data != "Alle":
            filter.update({'kind': form2.filt_itemclass.data})
        if form2.filt_avaclass.data != "Alle":
            filter.update({'art': form2.filt_avaclass.data})
        session['filter'] = filter
        #data = filterItem.filter(filter)
        #tabel = ItemTable(data)
        #return render_template('index.html', title='Home', form=form, form2=form2, tabel=tabel)
    form2.filt_have_it.default = session.get('have_it', "Alle")
    form2.filt_avaclass.default = session.get('avaclass', "Alle")
    form2.filt_itemclass.default = session.get('itemclass', "Alle")
    form2.process()
    allItems = item()
    dinge = allItems.filter(session.get('filter', {}))
    tabel = ItemTable(dinge)
    return render_template('index.html',
                           title='Home',
                           form=form,
                           form2=form2,
                           tabel=tabel)
Example #35
0
def save_wishlist_item(id_user, wishlist_name):
	token = request.headers.get('auth-token')
	data = MultiDict(mapping=request.json)
	inputs = ItemForm(data, csrf_enabled=False)

	if not inputs.validate():
		return jsonify({'error': 'invalid inputs'})

	wishlist = db.session.query(Wishlist).filter(id_user=id_user, name=wishlist_name).first()
	
	name = data['name']
	description = data['description']

	collection = Item(name, description=description)

	wishlist.items.append(collection)

	db.session.add(collection)
	db.session.commit()

	return jsonify(item.__repr__())
	return jsonify(item.__repr__())