def new_item(self, name: str, value: int, weight: float, id: int = None) -> Item: self.have_session() newitem = Item( name=name, value=value, weight=weight, ) if id is not None: newitem.id = id self.session.add(newitem) return newitem
def test_delete_item(self): item_to_delete = self.base_item_name + str(50) crud.delete_item_list(item_to_delete) res_data = crud.search_in_list(item_to_delete) i = Item('Pepe 99') result = crud.add_to_list(i.name) self.assertEqual(res_data, None)
def insert_items(): fpath = os.path.join(item_dir, "items.csv") with open(fpath, 'r') as f: reader = DictReader(f) headers = reader.fieldnames for row in reader: attrs = {header: row[header].lower() for header in headers} json_str = json.dumps(attrs) item_doc = Item.from_json(json_str) item_doc.save()
async def create_new_item(item: ItemData, current_user: User = Depends(get_current_user)): """Create new item and attach it to creator. If many items were passed only the last one will be promoted. """ async with session: query = select(Item).where(Item.title == item.title) result = await session.execute(query) if result.scalars().first(): raise HTTPException(status_code=400, detail=f"{item.title} has been already stored") if current_user: new_item = Item(title=item.title, user_id=current_user.id) async with session: session.add(new_item) await session.commit() query = (select(Item.id, Item.title, User.username).where( Item.title == item.title).join(User, User.id == current_user.id)) result = await session.execute(query) item = result.first() return {"message": "Item was successfully created", "item": item}
def test_insert(self): i = Item('Pepe1') result = crud.add_to_list(i.name) self.assertEqual(i.name, result.name)
print("result object: " + obj.__str__()) print('- - - - - -') ITEMS.append(obj) if conf.SAVE: for item in ITEMS: try: obj = Item.objects.get( internal_name=item.name, internal_id=item.id ) except Item.DoesNotExist: obj = Item( internal_name=item.name, internal_id=item.id, data_value=item.id+256 ) try: texture = Texture.objects.get(name__exact=obj.internal_name) obj.main_texture = texture except Exception as error: print(error) pass obj.save() # Print the miner summary and compile the new old data new_old_data = {} new_old_data['list'] = [] [new_old_data['list'].append(x.name) for x in ITEMS]
def add_item(name, price, qty): session = SQLManager().get_session() item = Item(name, price, qty) session.add(item) session.commit() session.close()
def add_to_list(item): i = Item(item) db_session.add(i) db_session.commit() return i