def delete(var): ''' delete(var): Renders the object selected and ask confirmation to delete the object. Then deletes it. ''' conn = sqlite3.connect(DATABASE_PATH) try: with conn: cursor = conn.cursor() if request.method=='POST': delete_item(var['obj'], cursor, app, var['id']) var['deleted'] = True else: cursor = conn.cursor() var['item'] = retrieve_item(var['obj'], var['id'], cursor) except ValueError as e: var['upload'] = 'fail' var['msg'] = e var['item'] = retrieve_item(var['obj'], var['id'], cursor) app.logger.info('Deletion failed due to Value Error. Erro Code: {0}'.format(e) ) except sqlite3.Error as e: if conn: conn.rollback() app.logger.error('SQLite failure during deletion of a full object. Error code:{e}'.format(e) ) raise except Exception as e: var['msg'] = e app.logger.error('Unexpected error in DELETE. Error Code: {0}'.format(e) ) raise return var
def remove_command(self): try: tup = inv_selected['selected'] item = self.inventory_treeview.item(tup, 'text') self.inventory_treeview.delete(tup) database.delete_item(self.conn, item, user_info['inv']) except TclError: error_box.no_inventory_item_selected()
def save_funct(self, command1, command2): for item in self.items_list: if item['id'] == 0: command1(item) else: command2(item) for item in self.to_delete: db.delete_item(item['id'], self.item_type) self.items_list = db.open_item_type(self.item_type, self.char_id)
def sell_command(self): tup = inv_selected['selected'] item = self.inventory_treeview.item(tup, 'text') user_info['char'].buy_sell(item, 'sell', self.conn) currency_dict = static_functions.convert_currency( user_info['char'].currency) self.update_currency_treeview(currency_dict) self.sell_item_gui(inv_selected['selected']) self.root.update() if not database.in_inventory(self.conn, user_info['inv'], item, '-'): database.delete_item(self.conn, item, user_info['inv'])
def subtract_one_command(self): try: tup = inv_selected['selected'] item = self.inventory_treeview.item(tup, 'text') self.sell_item_gui(inv_selected['selected']) if not database.in_inventory(self.conn, user_info['inv'], item, '-'): database.delete_item(self.conn, item, user_info['inv']) except TclError: error_box.no_inventory_item_selected()
def delete_result(): request_id = request.args.get("id", "") try: TaskManipulator.kill(request_id) delete_item(request_id) result = { "request_successful": True } except Exception as e: result = { "request_successful": False, "message": str(e) } return result
def delete(args): """Removes an item from the database Usage: delete delete [vendId]""" if len(args) == 0: vendId = raw_input("? vendId: ") elif len(args) == 1: vendId = args[0] vendId = validate['vendId'](vendId) if vendId == None: print "! vendId must be two digits." return #[know nothin in life| but the best shit] #[ go quote me boy |cause i said shit] if database.item_exists(vendId): name = database.get_item_name(vendId) confirm = ask("? Really delete %s (%02d) from database?(y/n) " % (name, int(vendId)), validate_y_n) if confirm == "y": database.delete_item(vendId) print "# Item removed." else: print "# Item not removed." else: print "! No item with that vendId."
def menu(): connection = database.connect() database.create_tables(connection) while (user_input := input(MENU_PROMPT)) != "6": #print(user_input) if user_input == "1": nod = input("Cuir nod ann: ") teideal = input("Cuir teideal ann: ") udar = input("Cuir udar ann: ") bp = input("Cuir bliain phróiseála ann: ") database.add_book(connection, nod, teideal, udar, bp) elif user_input == "2": pass books = database.get_all_books(connection) # for book in books: print(book) # elif user_input == "3": pass teideal = input("Cuir isteach teideal leabhair a ba mhaith leat: ") books = database.get_books_by_teideal(connection, teideal) for book in books: print(book) # elif user_input == "4": pass # name = input("Cuir isteach nod an leabhair: ") # books = database.get_books_by_nod(connection,nod) # # for book in books: # print(book) # # for book in books: # print(book) # elif user_input == "5": id = input("Cuir isteach an id: ") book = database.delete_item(connection, id) else: print("Invalid input please try again")
def item(): if request.method == "POST": item = json.loads(request.data) db_item = db.add_item(name=item["ItemName"], room=item["Room"], owner=item["Owner"], value=item["Value"], quant=item["Quantity"], size=item["Size"], priority=item["Priority"], fragile=item["Fragile"], owned=item["Owned"], moved=item["Moved"], keeping=item["Keeping"], notes=item["Notes"]) return json.dumps(db_item), 201, json_content elif request.method == "GET": items = db.get_items() return json.dumps(items), 200, json_content elif request.methos == "DELETE": item = json.loads(request.data) db_item = db.delete_item(item["ItemName"]) return json.dumps(db_item), json_content
def delete_item(): identity = request.form["identity"] database.delete_item(identity) return redirect(url_for("mainpage", i=identity))
def test_delete_item(self): with mock.patch('database.sqlite3') as mocksql: conn = mocksql.connect() database.delete_item(conn, 'Club', 1) mocksql.connect().execute.assert_called_with( sql.delete_item(), ('Club', 1))