def post(self, command): user = users.get_current_user() if not user: self.redirect(users.create_login_url("/sell")) else: if command == 'add': image = self.request.get("image") item = model.Item( title=self.request.get("title"), description=self.request.get("description"), price=long(round(float(self.request.get("price")) * 100)), available=long(self.request.get("available")), image=db.Blob(image), enabled=True) item.put() if settings.USE_EBAY: # ebay specific add = ebay.Add(item, self.request.host_url) if add.success: self._process( "The item was added to the online store and eBay.") else: self._process( "The item was added to the online store. An error occurred while adding the item to eBay." ) else: self._process("The item was added.") else: self._process("Unsupported command.")
def Add(): """ Add: Renders the form for adding a new item Args: None Returns: html """ if 'email' in login_session: user_mail = login_session['email'] else: return redirect(url_for('home')) user = db.add_user(user_mail) categories = db.get_categories() item = model.Item(title='new item', category=categories[0], user=user) if request.method == 'GET': return render_template('edit.html', categories=categories, item=item, route=url_for('Add', item_title=item.title)) else: if request.form['title']: item.title = request.form['title'] if request.form['description']: item.description = request.form['description'] if request.form['category']: category_name = request.form['category'] category = db.get_category(category_name) item.category = category db.add_item(item) return redirect(url_for('home'))
async def find_value(key: str = None): try: query = items.select().where(items.c.key == key) query = await database.fetch_one(query) value = model.Item(**query).dict()["value"] return PlainTextResponse(value, 200) except: return 'key not found!'
def post(self): items = self.request.get( "items" ) count = 0 for item in items.split( "\n" ): if len(item) > 0: model.Item( title=item.strip(), status="READY" ).save() count += 1 path = os.path.join(os.path.dirname(__file__), 'templates/add.htm') self.response.out.write(template.render(path, { 'message': "%i items added" % count } ))
def post(self, command): user = users.get_current_user() if not user: self.redirect( users.create_login_url( "/sell" ) ) else: if command == 'add': image = self.request.get("image") item = model.Item( owner=user, title=self.request.get("title"), price=long( float(self.request.get("price")) * 100 ), image=db.Blob(image), enabled=True ) item.put() self._process("The item was added.") else: self._process("Unsupported command.")
def create_item(db: Session, item: schema.Item) -> schema.Item: if read_items(db, name=item.name): raise HTTPException(400, "Item with same name already existing") if item.listed_since is None: item.listed_since = date.today() db_item = model.Item(**item.dict()) db.add(db_item) db.commit() db.refresh(db_item) return db_item
def add_item(): ''' Adds a new item to the database. Body: {"name", "upc", "price", "user", "store", "lat", "long"[, "image", "image_url"]} Response: - {"success": true or false}, - {"error": error description} ''' data = request.get_json(force=True) required_fields = ['name', 'upc', 'price', 'user', 'store', 'lat', 'long'] if not validation.has_required(data, required_fields): return json.dumps({'success': False, 'error': Error.MISSING_FIELDS.value}) if not validation.validate_unique_upc(data['upc']): return json.dumps({'success': False, 'error': Error.ITEM_EXISTS.value}) new_price = model.Price( user=data['user'], upvotes=[], downvotes=[], price=data['price'], date=datetime.now().timestamp() ) new_store = model.Store( name=data['store'], location={ 'lat': data['lat'], 'long': data['long'] }, prices=[new_price] ) new_item = model.Item( upc=data['upc'], name=data['name'], image_url='', image=None, stores=[new_store] ) if 'image' in data: add_image(data['image'], new_item) elif 'image_url' in data: new_item.image_url = data['image_url'] try: new_item.save() except (validation.ValidationException, mongoengine.errors.ValidationError) as e: return json.dumps({'success': False, 'error': str(e)}) return json.dumps({'success': True, 'error': None})
def load_items(session): with open("seed_data/u.items") as csvfile: items = csv.reader(csvfile,delimiter=",") for item in items: if item[1] == '': item[1] = None if item[2] == '': item[2] = None if item[3] == '': item[3] = None if item[4] == '': item[4] = None new_item = model.Item(name=item[0],min_qty=item[1],max_qty=item[2],time_type=item[3], always=item[4]) session.add(new_item) return session
store4, store5, store6, store7, store8, store9, store12, store13, store14, store15 ] # valid item0 = model.Item( name='apple', upc='042100005264', stores=valid_stores ) # valid item1 = model.Item( name='milk', upc='787735087189', stores=valid_stores[::-1] ) # valid item6 = model.Item( name='testItem1', upc='042100005265', stores=valid_stores[0:3]
def add_item(self, name, amount=None): """Add an item to the drawer""" self.subelems.append(model.Item(name, amount))