def testJ(self): # Temporary data new_title = "Test" new_description = "Test" db.edit( getVideoId(), new_title, new_description, tests.image, tests.video, tests.category_id) self.assertNotEqual(new_title, tests.title)
def editvideo(): if request.method == 'POST': form = request.form videoid = form['video_id'] title = form['title'] description = form['description'] img_source = form['image'] video_source = form['video'] category_id = form['category_id'] try: # Getting username user_name = db.getLogin() # Edit video information in the database db.edit(videoid, title, description, img_source, video_source, category_id) return redirect('/{}'.format(user_name)) except: return redirect('/')
def post(self): TYPE=self.get_argument('TYPE','') ID=self.get_argument('ID','') subject = self.get_argument('subject','') tags = self.get_argument('tags','') markdown = self.get_argument('markdown','') Category = self.get_argument('Category','') if TYPE=='DEL': Category = Category[0:-1] SQL = "DELETE FROM Category WHERE ID IN (%s)" % Category self.write(db.exe(SQL)) elif TYPE=='NEW': SQL = "INSERT INTO Category (Category) VALUES ('%s')" % Category self.write(db.exe(SQL)) elif None or "" in (subject,tags,markdown): self.write(u"主题、标签、类别及内容均不可为空!") else: if db.edit(TYPE,subject.encode("utf-8"),tags.encode("utf-8"),markdown.encode("utf-8"),Category.encode("utf-8"),ID): tohtml.html().ALL() self.write(u'OK,文章已成功发布!') else: self.write(u'Error!')
import db while True: choice = input("1. Add \n2. Remove \n3. View all \n4. Edit\n5. Quit\n") if choice != "1" and choice != "2" and choice != "3" and choice != "4" and choice != "5": print("That wasn't a valid option, please try again.\n") elif choice == "1": name = input("Name?\n") country = input("Country?\n") catches = input("Catches?\n") db.add_juggler(name, country, catches) elif choice == "2": name = input("Name?\n") db.remove_juggler(name) elif choice == "3": db.view_all() # Assuming we are updating the highest number of catches elif choice == "4": name = input("Name?\n") catches = input("New high score?\n") db.edit(name, catches) elif choice == "5": break
def long_pool(): last_uid = 0 first_step = True worker_flag = False edit_flag_1 = False edit_flag_11 = False edit_flag_12 = False edit_flag_13 = False worker_user_id = 0 worker_chat_id = 0 edit_user_id = 0 edit_chat_id = 0 requested_doc = {} while True: if first_step: obj_ = get_last_obj() else: obj_ = get_last_obj(current_uid + 1) if not obj_: continue current_uid = obj_['update_id'] if current_uid != last_uid: last_uid = current_uid if first_step: first_step = False if edit_flag_11 or edit_flag_12 or edit_flag_13: response_edit_message_obj = command_message_handler( obj_, 'response_edit') if response_edit_message_obj: text = response_edit_message_obj['text'] answer_text = '' if edit_flag_11 or edit_flag_12: try: text = json.loads(text) if isinstance(text, dict): if text.get('position'): for value in list(text.values()): if not isinstance(value, str): raise ValueError if edit_flag_11: if not db.insert(text): time.sleep(1.5) if not db.insert(text): answer_text = 'Ошибка ' +\ 'добавления, ' +\ 'попробуйте ещё раз' else: answer_text = 'Добавление ' +\ 'прошло успешно' else: answer_text = 'Добавление ' +\ 'прошло успешно' elif edit_flag_12: if not db.edit(text['position'], text): time.sleep(1.5) if not db.edit( text['position'], text): answer_text = 'Ошибка ' +\ 'изменения, попробуйте ' +\ 'ещё раз' else: answer_text = 'Изменение ' +\ 'прошло успешно' else: answer_text = 'Изменение ' +\ 'прошло успешно' else: answer_text = 'Некорректный ввод' else: answer_text = 'Некорректный ввод' except ValueError: answer_text = 'Некорректный ввод' elif edit_flag_13: if text: if not db.remove(text): time.sleep(1.5) if not db.remove(text): answer_text = 'Ошибка удаления, ' +\ 'попробуйте ещё раз' else: answer_text = 'Удаление прошло успешно' else: answer_text = 'Удаление прошло успешно' bot_request( 'sendMessage', 'chat_id=' + str(edit_chat_id), 'parse_mode=HTML', 'text=' + answer_text, 'reply_to_message_id=' + str(edit_message_obj['message_id'])) worker_flag = False edit_flag_1 = False edit_flag_11 = False edit_flag_12 = False edit_flag_13 = False edit_user_id = 0 edit_chat_id = 0 elif edit_flag_1: edit_message_obj = command_message_handler(obj_, 'edit') if edit_message_obj: if edit_user_id == edit_message_obj['user_id'] \ and edit_chat_id == edit_message_obj['chat_id']: sub_edit_flag_11 = False sub_edit_flag_12 = False sub_edit_flag_13 = False if edit_message_obj['text'] == 'Вставить': response = '<b>Введите данные в формате ' +\ 'json-словаря.</b>\nШаблон: \n' + \ '{\n' + \ '\t"position": "Поле должности ' +\ 'является обязательным",\n' + \ '\t"office": "A 101",\n' + \ '\t"surname": "Иванов",\n' + \ '\t"name": "Иван",\n' + \ '\t"middle_name": "Иванович",\n' + \ '\t"email": "*****@*****.**",\n' + \ '\t"phone": "8 (423) 212 34 55"\n' + \ '}' sub_edit_flag_11 = True elif edit_message_obj['text'] == 'Изменить': response = '<b>Введите новые данные в формате ' +\ 'json-словаря.</b>\nШаблон: \n' + \ '{\n' + \ '\t"position": "Поле должности ' +\ 'является обязательным",\n' + \ '\t"office": "A 101",\n' + \ '\t"surname": "Иванов",\n' + \ '\t"name": "Иван",\n' + \ '\t"middle_name": "Иванович",\n' + \ '\t"email": "*****@*****.**",\n' + \ '\t"phone": "8 (423) 212 34 55"\n' + \ '}' sub_edit_flag_12 = True elif edit_message_obj['text'] == 'Удалить': response = '<b>Введите должность, данные по ' +\ 'которой хотите удалить.</b>' sub_edit_flag_13 = True else: continue bot_request( 'sendMessage', 'chat_id=' + str(edit_chat_id), 'parse_mode=HTML', 'text=' + str(response), 'reply_to_message_id=' + str(edit_message_obj['message_id'])) worker_flag = False edit_flag_1 = False if sub_edit_flag_11: edit_flag_11 = True if sub_edit_flag_12: edit_flag_12 = True if sub_edit_flag_13: edit_flag_13 = True edit_user_id = message_obj['user_id'] edit_chat_id = message_obj['chat_id'] else: worker_flag = False edit_flag_1 = False edit_flag_11 = False edit_flag_12 = False edit_flag_13 = False edit_user_id = 0 edit_chat_id = 0 elif worker_flag: worker_message_obj = command_message_handler(obj_, 'worker') if worker_message_obj: if worker_user_id == worker_message_obj['user_id'] \ and worker_chat_id == worker_message_obj[ 'chat_id']: if worker_message_obj['text'] == 'Только ФИО': response = str( '<b>Фамилия</b>: ' + f'{requested_doc.get("surname")}\n' + '<b>Имя</b>: ' + f'{requested_doc.get("name")}\n' + '<b>Отчество</b>: ' + f'{requested_doc.get("middle_name")}\n') elif worker_message_obj['text'] == 'Всё': response = '' for key, val in requested_doc.items(): if key == 'position': key = 'Должность' elif key == 'office': key = 'Кабинет' elif key == 'surname': key = 'Фамилия' elif key == 'name': key = 'Имя' elif key == 'middle_name': key = 'Отчество' elif key == 'email': key = 'Почта' elif key == 'phone': key = 'Телефон' else: continue response += f'<b>{str(key)}</b>: {val}\n' if not response: response = None else: continue bot_request( 'sendMessage', 'chat_id=' + str(worker_chat_id), 'parse_mode=HTML', 'text=' + str(response), 'reply_to_message_id=' + str(worker_message_obj['message_id'])) worker_flag = False edit_flag_1 = False worker_user_id = 0 worker_chat_id = 0 else: worker_flag = False edit_flag_1 = False edit_flag_11 = False edit_flag_12 = False edit_flag_13 = False edit_user_id = 0 edit_chat_id = 0 else: message_obj = message_handler(obj_) if message_obj: if message_obj['edit']: if not show_edit_keyboard(message_obj): continue edit_flag_1 = True edit_user_id = message_obj['user_id'] edit_chat_id = message_obj['chat_id'] if message_obj['list']: data = list(db.collection.find({})) text = '<b>Список имеющихся должностей:</b>\n' if data: for doc in data: text += str(doc['position'] + ';\n') bot_request( 'sendMessage', 'chat_id=' + str(message_obj['chat_id']), 'parse_mode=HTML', 'text=' + text, 'reply_to_message_id=' + str(message_obj['message_id'])) else: data = list(db.collection.find({})) requested_doc = None if data: for doc in data: position = doc['position'].lower().strip() if position == message_obj['text']: requested_doc = doc break if requested_doc: show_worker_keyboard(message_obj) worker_flag = True worker_user_id = message_obj['user_id'] worker_chat_id = message_obj['chat_id']