def delete_body(path, d, m, env): parent = model.parent(path) if parent: model.delete(path) return "\n", parent else: raise restlite.Status, '403 Forbidden'
def remove_reservation(): if 'user_id' in session: if 'user_admin' not in session or session['user_admin'] is False: return redirect(url_for('status')) else: return redirect(url_for('admin')) if request.method == 'POST': data = request.form.to_dict(flat=True) model.delete(model.Reservation, data['reservation_id']) return router['remove_reservation'](['success'], data=model.reservations()) return router['remove_reservation']([], data=model.reservations())
def take_action(locations: Dict[str, str], args: Namespace) -> GoAction: if args.new: return Update(m.new(locations, args.new.name, args.new.path)) elif args.delete: return Update(m.delete(locations, args.delete)) elif args.rename: return Update(m.rename(locations, args.rename.old_name, args.rename.new_name)) elif args.copy: return Update(m.copy(locations, args.copy.old_name, args.copy.new_name)) elif args.name is None: return Display("Available locations:", locations, 0) else: p = m.lookup(locations, args.name) if isinstance(p, str): return Navigate(expand(p)) elif isinstance(p, m.NoMatchError): return Display( f"Couldn’t find {args.name} – available locations are:", locations, 1 ) elif isinstance(p, m.AmbiguousPrefixError): if args.name in p.matches: return Navigate(expand(p.matches[args.name])) else: return Display( f"Got more than one match for {args.name}:", p.matches, 2 ) else: return Display("Got an unknown error.", {}, 3)
def test_delete(): game = json.dumps({ 'ID': None, 'kind': 'game', 'name': 'Game3', 'company': 'Company1', 'minPlayers': 1, 'maxPlayers': 4, 'age': 10, 'length': 30, 'link': 'www.example.com', 'image': None, 'notes': 'Fun!' }) mini = json.dumps({ 'ID': None, 'kind': 'mini', 'name': 'Mini3', 'army': 'Orcs and Goblins', 'type': 'core', 'system': 'WFB', 'company': 'Company1', 'quantity': 10, 'status': 'painted', 'link': 'www.example.com', 'image': None, 'notes': 'Fun!' }) paint = json.dumps({ 'ID': None, 'kind': 'paint', 'name': 'Paint3', 'color': 'green', 'type': 'matte', 'company': 'Company1', 'quantity': 1, 'link': 'www.example.com', 'notes': 'Fun!' }) assert model.delete(game) == '1' assert model.view(game) == 'null' assert model.delete(mini) == '1' assert model.view(mini) == 'null' assert model.delete(paint) == '1' assert model.view(paint) == 'null'
def test_delete(): game = json.dumps({'ID': None, 'kind': 'game', 'name': 'Game3', 'company': 'Company1', 'minPlayers': 1, 'maxPlayers': 4, 'age': 10, 'length': 30, 'link': 'www.example.com', 'image': None, 'notes': 'Fun!'}) mini = json.dumps({'ID': None, 'kind': 'mini', 'name': 'Mini3', 'army': 'Orcs and Goblins', 'type': 'core', 'system': 'WFB', 'company': 'Company1', 'quantity': 10, 'status': 'painted', 'link': 'www.example.com', 'image': None, 'notes': 'Fun!'}) paint = json.dumps({'ID': None, 'kind': 'paint', 'name': 'Paint3', 'color': 'green', 'type': 'matte', 'company': 'Company1', 'quantity': 1, 'link': 'www.example.com', 'notes': 'Fun!'}) assert model.delete(game) == '1' assert model.view(game) == 'null' assert model.delete(mini) == '1' assert model.view(mini) == 'null' assert model.delete(paint) == '1' assert model.view(paint) == 'null'
def delete_from_table(table_num): table = tables[table_num] table_columns = columns[table] while True: print("Choose column to delete by:") view.table_columns_names(table_num) chosen_column_num = input() if re.match(r'^[1-{}]{}$'.format(len(table_columns), "{1}"), chosen_column_num): chosen_column = table_columns[int(chosen_column_num) - 1] print("Input value: ") print("DELETE FROM {} WHERE {} = ...".format(table, chosen_column)) value = "'" + input() + "'" print("DELETE FROM {} WHERE {} = {}".format( table, chosen_column, value)) where = " WHERE {} = {}".format(chosen_column, value) res = model.delete(table, where) return res elif chosen_column_num == '0': return else: print("No such option. Check your input")
def main(args): r""" >>> import model, control, rest >>> rest.load_props() >>> from bs4 import BeautifulSoup as BS >>> docs = [{"id":"1","name":"Mike","email":"[email protected]"}] >>> model.find = lambda bookmark=None: {"docs":docs} >>> res = control.main({"__ow_method":"get"}) >>> html = BS(res["body"], "lxml") >>> print(html.find("tbody")) <tbody> <tr> <td scope="row"> <input name="id" type="radio" value="1"/> </td> <td>Mike</td> <td>[email protected]</td> <td></td> </tr> </tbody> >>> res = control.main({"__ow_method":"get", "op":"new"}) >>> inp = BS(res["body"], "lxml").find_all("input") >>> print(*inp, sep="\n") <input class="form-control" id="photo" name="photo" type="file"/> <input class="form-control" id="name" name="name" type="text" value=""/> <input class="form-control" id="email" name="email" type="email" value=""/> >>> res = control.main({"__ow_method":"get", "op":"edit", "id":"1"}) >>> inp = BS(res["body"], "lxml").find_all("input") >>> print(*inp, sep="\n") <input name="id" type="hidden" value="1"/> <input class="form-control" id="photo" name="photo" type="file"/> <input class="form-control" id="name" name="name" type="text" value="Mike"/> <input class="form-control" id="email" name="email" type="email" value="[email protected]"/> >>> model.insert = control.inspect >>> ctype = "multipart/form-data; boundary=------------------------ff26122a2a4ed25b" >>> body = "LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS1mZjI2MTIyYTJhNGVkMjViDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7IG5hbWU9Im5hbWUiDQoNCmhlbGxvDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLWZmMjYxMjJhMmE0ZWQyNWINCkNvbnRlbnQtRGlzcG9zaXRpb246IGZvcm0tZGF0YTsgbmFtZT0iZW1haWwiDQoNCmhAbC5vDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLWZmMjYxMjJhMmE0ZWQyNWItLQ0K" >>> args = {"__ow_method":"post", "__ow_body":body, "__ow_headers": {"content-type": ctype} } >>> _ = control.main(args) >>> print(control.spy) {'name': 'hello', 'email': '[email protected]'} >>> model.update = control.inspect >>> ctype = "multipart/form-data; boundary=------------------------7a256bc140953925" >>> body = "LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS03YTI1NmJjMTQwOTUzOTI1DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7IG5hbWU9Im5hbWUiDQoNCm1pa2UNCi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tN2EyNTZiYzE0MDk1MzkyNQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJlbWFpbCINCg0KbUBzLmMNCi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tN2EyNTZiYzE0MDk1MzkyNQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJpZCINCg0KMTIzDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTdhMjU2YmMxNDA5NTM5MjUtLQ0K" >>> args = {"__ow_method":"post", "__ow_body":body, "__ow_headers": {"content-type": ctype} } >>> x = control.main(args) >>> print(control.spy) {'id': '123', 'name': 'mike', 'email': '[email protected]'} """ # extract photo if "__ow_path" in args: path = args["__ow_path"] if len(path) > 1: doc = model.find(path[1:])["docs"][0] return { "body": doc["photo"], "headers": { "Content-Type": doc["photo_mime"] } } # post data if "__ow_body" in args: fields, files = form_parse(args) filled = fill(fields, files) if "id" in fields: model.update(filled) else: model.insert(filled) # handle other ops op = "" if args["__ow_method"] == "get": op = args.get("op") if op == "new": body = view.form(fill({}, {})) return {"body": view.wrap(body)} if op == "edit" and "id" in args: res = model.find(args["id"]) rec = res["docs"][0] body = view.form(rec) return {"body": view.wrap(body)} if op == "delete" and "id" in args: model.delete(args["id"]) # paginated rendering curr = args.get("bookmark") query = model.find(bookmark=curr) data = query["docs"] next = "" if len(data) == model.find_limit: next = query.get("bookmark") body = view.table(data, next, model.last_error) if model.last_error: model.last_error = None return {"body": view.wrap(body)}
def delete(): id_del = request.form["id"] model.delete(id_del) return redirect("/admin")
def delete(self, name): model.delete(name) return '', 204
def delete(table): query = view.multiple_input( table, 'Enter requirement of row to be deleted:') model.delete(table, query) display_secondary_menu(table, 'Deletion was made successfully')
def main(args): r""" >>> import model >>> import control >>> from bs4 import BeautifulSoup as BS >>> docs = [{"id":"1","name":"Mike","email":"[email protected]"}] >>> model.find = lambda x=None: {"docs":docs} >>> res = control.main({}) >>> html = BS(res["body"], "lxml") >>> print(html.find("tbody")) <tbody> <tr> <td scope="row"> <input name="id" type="radio" value="1"/> </td> <td>Mike</td> <td>[email protected]</td> </tr> </tbody> >>> res = control.main({"op":"new"}) >>> inp = BS(res["body"], "lxml").find_all("input") >>> print(*inp, sep="\n") <input name="op" type="hidden" value="save"/> <input class="form-control" id="name" name="name" type="text" value=""/> <input class="form-control" id="email" name="email" type="email" value=""/> >>> res = control.main({"op":"edit", "id":"1"}) >>> inp = BS(res["body"], "lxml").find_all("input") >>> print(*inp, sep="\n") <input name="id" type="hidden" value="1"/> <input name="op" type="hidden" value="save"/> <input class="form-control" id="name" name="name" type="text" value="Mike"/> <input class="form-control" id="email" name="email" type="email" value="[email protected]"/> >>> model.insert = control.inspect >>> args = {"op":"save", "name":"Miri","email":"[email protected]"} >>> x = control.main(args) >>> print(control.spy) {'name': 'Miri', 'email': '[email protected]'} >>> model.update = control.inspect >>> args = {"op":"save", "id": "1", "name":"Mike","email":"[email protected]"} >>> x = control.main(args) >>> print(control.spy) {'id': '1', 'name': 'Mike', 'email': '[email protected]'} """ op = args.get("op") if op == "new": body = view.form(fill({})) return {"body": view.wrap(body)} if op == "edit" and "id" in args: res = model.find(args["id"]) rec = res["docs"][0] body = view.form(rec) return {"body": view.wrap(body)} if op == "save": if "id" in args: model.update(fill(args)) else: model.insert(fill(args)) if op == "delete" and "id" in args: model.delete(args["id"]) data = model.find()["docs"] body = view.table(data) return {"body": view.wrap(body)}
def remove(subject): return model.delete(subject)
def POST(self, id): id = int(id) model.delete(id) raise web.seeother(web.ctx.env.get('HTTP_REFERER','/'))
def delete(tname): query = reader.multiple_input(tname, 'Enter requirement of row to be deleted:') model.delete(tname, query) show_table_menu(tname, 'Deletion was made successfully')
def redo(self, model): model.delete(len(self.char))
def test_delete_missing(): assert True == model.add({'id': '0', 'msg': 'test-0'}) model.delete('1') assert ([{'id': '0', 'msg': 'test-0'}], True) == model.getTasks()
import model import time while True: menu_item = view.main_menu() print(menu_item) if menu_item == '1': attrs = view.insert_menu() try: getattr(model, f'insert_{attrs[0]}')(attrs[1].split(',')) except: print("Oops, table doesn't exists") elif menu_item == '2': attrs = view.delete_menu() model.delete(*attrs) elif menu_item == '3': attrs = view.update_menu() model.update(*attrs) elif menu_item == '4': attrs = view.random_menu() try: view.show_random_query( getattr(model, f'random_{attrs[0]}')(int(attrs[1]))) except: print("Oops, table doesn't exists") elif menu_item == '5': attrs = view.select_menu() f_name = [ 'student_grade', 'teacher_subject', 'student_teacher_subject' ][int(attrs[0]) - 1]
) for row in range(len(rows)): print("Serviço: {} | Usuário: {} | Senha: {} | ID: {} ". format(rows[row][1], rows[row][2], rows[row][3], rows[row][0])) print( "--------------------------------------------------------------------------------------------" ) #Update ------------------------------------------------------------ if option == "u": db.update() #Delete ------------------------------------------------------------ if option == "d": db.delete() #Exit ------------------------------------------------------------ if option == "e": for i in range(1, 4): os.system("clear") print("Exiting sistem... ", i) time.sleep(1) os.system("clear") break input("PRESS ENTER TO CONTINUE...") else: print("Wrong password") time.sleep(1)
def POST(self): index= web.data() id=json.loads(index)['id'] res = model.delete(id) return res