def delete(): form = DeleteForm() if form.validate_on_submit(): Employee.query.filter_by(id=form.bartender_id.data).delete() db.session.commit() return redirect(url_for('index')) return render_template('delete.html', form=form)
def delete_test(): form = DeleteForm() if form.validate_on_submit(): print(form.fields.data) else: print(form.errors) return render_template('DeleteTest.html', form=form)
def delete(): form = DeleteForm() context = dict() context['pagename'] = 'Удаление ссылки' context['form'] = form if form.validate_on_submit(): if form.alias.data in path.values(): flash('Нельзя удалить ссылку, необходимую для работы сайта', 'danger') return render_template('delete.html', context=context) cur = g.db.execute('select password from entries where alias = (?)', (form.alias.data, )) try: password = str(cur.fetchall()[0][0]) if password == form.password.data: g.db.execute('delete from entries where alias = (?)', (form.alias.data, )) cur_seq = g.db.execute('select seq from sqlite_sequence') ids = int(cur_seq.fetchall()[0][0]) - 1 g.db.execute('update sqlite_sequence set seq = (?)', (ids, )) g.db.commit() flash('Успешное удаление', 'success') return render_template('delete.html', context=context) else: flash('Неверный пароль', 'danger') return render_template('delete.html', context=context) except IndexError: flash('Несуществующая ссылка', 'danger') return render_template('delete.html', context=context) return render_template('delete.html', context=context)
def delete(): form = DeleteForm() if form.validate_on_submit(): employee = db.session.query(Employee).filter_by( id=form.id.data).first() db.session.delete(employee) db.session.commit() flash('Congratulations, you deleted an employee!') return redirect(url_for('index')) return render_template('delete.html', title='Delete', form=form)
def delete(): form = DeleteForm() data = form.data if form.validate_on_submit(): id_ = data.pop('id') redis.delete_men([id_]) return redirect(url_for('index', message='Пользователь успешно удалён')) else: flash('Введены некорректные данные') return render_template('delete_form.html', form=form)
def delete(): form = DeleteForm() if form.validate_on_submit(): collections = Collection.query.filter_by(user_id=current_user.id, numb=form.numb.data, name=form.name.data).first() if collections is None: flash('Not found') else: db.session.delete(collections) db.session.commit() flash('Congratulations, you deleted deal "'+str(form.name.data) + '" planed on '+form.numb.data.strftime('%d.%m.%Y')+'!') return render_template('delete.html', title='Delete', form=form) return render_template('delete.html', title='Delete', form=form)
def delete(address_id): address = Address.query.filter_by(id=address_id).first_or_404() form = DeleteForm(current_user.username) if form.validate_on_submit(): g.db.execute('delete from address where id = address_id', [request.form['address']]) db.session.commit() flash(_('Your changes have been saved.')) return render_template('edit_address.html', title=_('Edit Address'), form=form, address=address)
def delete(cid, name): if current_user.permissions == 'delete' or 'crud': form = DeleteForm() coisa = Coisa.query.filter_by(id=cid, name=name, user_id=current_user.id).first_or_404() if form.validate_on_submit(): db.session.delete(coisa) db.session.commit() flash('{} Excluido.'.format(name)) return redirect(url_for('read')) return render_template('delete_date.html', form=form, coisas=coisa)
def delete_myuser(myuser): form = DeleteForm() if form.validate_on_submit() and current_user.permissions == 'admin': u = User.query.filter_by(username=myuser).first() c = Coisa.query.filter_by(user_id=u.id) db.session.delete(u) c.delete() db.session.commit() flash('Usuário excluido com sucesso.') return redirect(url_for('index')) elif form.validate_on_submit() and current_user.permissions != 'admin': user_id = int(current_user.id) u = User.query.filter_by(id=user_id).first() db.session.delete(u) db.session.commit() flash('Usuário excluido com sucesso.') return redirect(url_for('logout')) return render_template('delete_myuser.html', title='Excluir perfil', form=form, user=myuser)
def delete_student(): form = DeleteForm() if form.validate_on_submit(): id_number = form.id_number.data if Student_Profile().student_exist(id_number): Student_Profile().delete_students(id_number) flash('Student deleted Successfully!') redirect(url_for('delete_student')) else: flash('Student with id number {} do not exist!'.format(id_number)) redirect(url_for('delete_student')) return render_template('delete_student.html', form=form, title='Delete')
def delete_confirm(record_id): # auth process if current_user.is_authenticated is True: account = get_account_info_by_account_id(current_user.account_id) else: return redirect(url_for('auth.login_view')) # process end form = DeleteForm() # Get record info record_url = 'http://' + Config.DB_OPS_URL + \ '/api/gas/document/rid/' + str(record_id) result = requests.get(record_url) # Functional Part if form.validate_on_submit(): if result.status_code == 200: user_id = get_api_info(result)[0]['employee_no'] # check user's authentication by account_id in url whether match current_user.account_id # Mention!! Type of current_user.account_id is not string! if str(current_user.account_id) != str(user_id): # back to detail viewing page flash('试图删除不属于自己的数据', 'danger') return redirect( url_for('auth.home_view', account_id=current_user.account_id)) # main function process below delete_url = 'http://' + Config.DB_OPS_URL + \ '/api/gas/document/' + str(record_id) requests.delete(delete_url) flash('数据删除成功', 'success') return redirect( url_for('auth.home_view', account_id=current_user.account_id)) # View Part else: if result.status_code == 200: user_id = get_api_info(result)[0]['employee_no'] # check user's authentication by account_id in url whether match current_user.account_id # Mention!! Type of current_user.account_id is not string! if str(current_user.account_id) != str(user_id): # back to detail viewing page return redirect( url_for('auth.home_view', account_id=current_user.account_id)) # main function process below competition = get_api_info(result)[0] return render_template('recordDelete.html', form=form, account=account)
def del_products(): form = DeleteForm() if form.validate_on_submit(): id = form.id.data product_name = Product.query.get(id) product_description = Product.query.get(id) db.session.delete(product_name) db.session.delete(product_description) db.session.commit() return redirect(url_for('list_products')) return render_template('delete.html', form=form)
def admin(): #if current_user.get_id() == '1' or current_user.get_id() == '2': if current_user.role == 'admin': #if 0 == 0 : form = RegistrationForm() if form.validate_on_submit(): user = User(username=form.username.data, role=form.role.data) # email=form.email.data) user.set_password(form.password.data) db.session.add(user) db.session.commit() flash('Congratulations, you are now a registered user!') return redirect(url_for('admin')) form2 = DeleteForm() if form2.validate_on_submit(): user = User(username=form2.username.data) # email=form.email.data) mystring = str(user) ########## keyword = '>' before_keyword, keyword, after_keyword = mystring.partition( keyword) mystring = before_keyword keyword = '<User ' before_keyword, keyword, after_keyword = mystring.partition( keyword) mystring = after_keyword print(mystring) ############ conn = sqlite3.connect(sqlite_file) c = conn.cursor() c.execute( 'DELETE FROM user WHERE username ="******" '.format(mystring)) conn.commit() conn.close() flash('Congratulations, you are delete user!') return redirect(url_for('admin')) conn = sqlite3.connect(sqlite_file) c = conn.cursor() #c.execute("SELECT * FROM user") c.execute("SELECT id, username, role FROM user") rows = c.fetchall() return render_template('admin.html', title='Admin', form=form, form2=form2, rows=rows) else: pass
def delete(): form = DeleteForm() if form.validate_on_submit(): substance = Substance.query.filter_by(title=form.title.data.title).first_or_404() filename = secure_filename(str(substance.id) + '.pdf') try: os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filename)) except Exception as ex: app.logger.error("Подобного файла в базе нет", ex) flash("Карточки вещества в базе не оказалось") db.session.delete(substance) db.session.commit() flash('Вещество удалено') return redirect(url_for('delete')) return render_template('delete.html', title='Удалить вещества', form=form)
def asset_delete(asset_id=None): form = DeleteForm() asset = assets.GetAsset(a.GetAssetRequest(_id=asset_id)) if form.validate_on_submit(): deleted = assets.DeleteAsset(a.DeleteAssetRequest(_id=asset_id)) if deleted and deleted.name and not deleted._id: flash('Asset deleted: {}'.format(deleted.name)) return redirect('/assets') else: flash('Failed to delete asset: {}'.format(deleted)) logging.error('Failed to delete asset: {}'.format(deleted)) asset = 'error' return render_template('delete.html', form=form, view='delete', obj_type='Asset', obj=None, name='deleted?') return render_template('delete.html', form=form, view='delete', obj_type='Asset', obj=asset, name=asset.name)
def delete_record(): form = DeleteForm() if form.validate_on_submit(): # Query DB for matching record (we'll grab the first record in case # there's more than one). to_delete = db.session.query(City).filter_by(city = form.city.data).first() # If record is found delete from DB table and commit changes if to_delete is not None: db.session.delete(to_delete) db.session.commit() form.city.data = '' # Redirect to the view_all route (view function) return redirect(url_for('view_cities')) return render_template('delete.html', form=form)
def delete_snippet(snippet_uuid): """Route lets the owner of a snippet delete the snippet""" snippet = get_snippet_by_uuid(snippet_uuid) if current_user != snippet.user: message = "You are not authorized to edit this snippet." return render_template('errorpages/401.html', message=message), 401 form = DeleteForm() if form.validate_on_submit(): db.session.delete(snippet) db.session.commit() return redirect( url_for('user.snippets', username=current_user.username)) return render_template('snippets/delete.html', form=form, snippet=snippet)
def deleteGame(game_id): ''' This route function lets the owner of a game post delete the game''' if 'credentials' not in login_session: return "Must be logged in to delete a game." # Throw 404 if game_id in URL not in DB try: game = db.session.query(Game).filter_by(id=game_id).one() except: abort(404) # Check if user is owner of the game if login_session['user_id'] != game.user_id: return "You do not have permission to delete this game." form = DeleteForm() if form.validate_on_submit(): db.session.delete(game) db.session.commit() return redirect(url_for('home')) return render_template('deleteGame.html', game=game, form=form)
def deleteGame(game_id): ''' This route function lets the owner of a game post delete the game''' if 'credentials' not in login_session: return "Must be logged in to delete a game." # Throw 404 if game_id in URL not in DB try: game = db.session.query(Game).filter_by(id=game_id).one() except: abort(404) # Check if user is owner of the game if login_session['user_id'] != game.user_id: return "You do not have permission to delete this game." form = DeleteForm() if form.validate_on_submit(): db.session.delete(game) db.session.commit() return redirect(url_for('home')) return render_template('deleteGame.html', game=game, form=form)
def delete_record(): # Verifying that user is an admin if is_admin(): form = DeleteForm() if form.validate_on_submit(): # Query DB for matching record (we'll grab the first record in case # there's more than one). to_delete = db.session.query(City).filter_by( city=form.city.data).first() # If record is found delete from DB table and commit changes if to_delete is not None: db.session.delete(to_delete) db.session.commit() form.city.data = '' # Redirect to the view_all route (view function) return redirect(url_for('view')) return render_template('delete.html', form=form) # Tell non-admin user they're not authorized to access route. else: return render_template('unauthorized.html')
def view(): add_form = AddForm() delete_form = DeleteForm() if add_form.validate_on_submit(): # Valid AddForm request book_records = session['book_records'] book_record = {} book_record['brn'] = add_form.brn.data book_record['title'] = add_form.title.data book_record['author'] = add_form.author.data book_record['classification'] = add_form.classification.data book_records.append(book_record) book_records = sorted(book_records, key=itemgetter('classification', 'title')) session['book_records'] = book_records db_update_book_records(book_records, session['identifier']) return redirect('/view') if delete_form.validate_on_submit(): #Valid DeleteForm request if not 1 <= delete_form.number.data <= len(session['book_records']): return redirect('/view') book_records = session['book_records'] book_records.pop(delete_form.number.data - 1) session['book_records'] = book_records db_update_book_records(book_records, session['identifier']) return redirect('/view') book_records = session['book_records'] or \ sorted(db_retrieve_book_records(session['identifier']), key=itemgetter('classification', 'title')) session['book_records'] = book_records split_book_records = book_records_by_classification(book_records) return render_template('view.html', add_form=add_form, delete_form=delete_form, split_book_records=split_book_records)
def delete(): form = DeleteForm() imgs = get_imgs_name(app.config['UPLOADED_PHOTOS_DEST']) if request.method == 'POST': if form.validate_on_submit(): short_name = form.name.data full_name = '' for f_name in imgs: if f_name.split('@')[0] == short_name: full_name = f_name f_path = os.path.join(app.config['UPLOADED_PHOTOS_DEST'], full_name) ret = os.system(f"rm {f_path}") if ret: flash("Something gone worry...Havn't deleted...") else: flash(f"you have f*****g delete the {short_name}.") return redirect('delete') else: return render_template('delete.html', title='Delete', form=form, images=imgs)
def index(): users = User.query.all() register_form = RegistrationForm() delete_form = DeleteForm() if register_form.validate_on_submit(): username = register_form.username.data email = register_form.email.data password = register_form.password.data new_user = User(username=username, email=email, password_hash=User.set_password(password)) db.session.add(new_user) db.session.commit() flash('You register new user: "******".'.format(username)) return redirect(url_for('index')) elif delete_form.validate_on_submit(): user = User.query.filter_by( username=delete_form.name_del_user.data).first() if user is None: flash('Invalid username or password') redirect(url_for('index')) elif user.username == 'admin': flash("You can't delete the admin page!") redirect(url_for('index')) else: db.session.delete(user) db.session.commit() flash('You delete user: "******".'.format(user.username)) return redirect(url_for('index')) return render_template('index.html', title='User Page', users=users, form1=register_form, form2=delete_form)