def edit_sale(id): sale = Sale.find(id) if request.method == 'GET': return render_template('edit_sale.html', sale=sale, categories=Category.all()) elif request.method == 'POST': sale.name = request.form['name'] sale.model = request.form['model'] sale.condition = request.form['condition'] sale.price = request.form['price'] sale.mileage = request.form['mileage'] sale.year = request.form['year'] sale.horsepower = request.form['horsepower'] sale.category = Category.find(request.form['category_id']) images = request.files.getlist("file") shutil.rmtree(sale.file_path) letters = string.ascii_lowercase direc_path = random.choice(letters) direc = request.form['model'] os.mkdir("static/images/" + direc + User.find_by_id(session['USERNAME']) + direc_path) for img in images: img_path = 'static/images/' + direc + User.find_by_id( session['USERNAME']) + direc_path + "/" img.save(img_path + img.filename) sale.file_path = img_path sale.save() logging.info('%s with id: %s edited sale %s', User.find_by_id(session['USERNAME']), session['USERNAME'], sale.id) return redirect(url_for('show_sale', id=sale.id))
def show_sale(id): sale = Sale.find(id) images = os.listdir(sale.file_path) sale.file_path = '/' + sale.file_path username = session['USERNAME'] return render_template('sale.html', sale=sale, images=images, username=username)
def del_comment(id): Comment.delete(id) sale = Sale.find(request.form['sale_id']) logging.info('%s with id: %s deleted comment on sale %s', User.find_by_id(session['USERNAME']), session['USERNAME'], sale.id) return redirect(url_for('show_sale', id=sale.id))
def del_comment(id): Comment.delete(id) sale = Sale.find(request.form['sale_id']) text = "user id: " + str( session['USERNAME']) + "with username: "******"edited a comment" i_logger(text) return redirect(url_for('show_sale', id=sale.id))
def delete_sale(id): sale = Sale.find(id) shutil.rmtree(sale.file_path) with DB() as db: db.execute('DELETE FROM comments WHERE sale_id = ?', (sale.id, )) sale.delete() logging.info('%s with id: %s deleted sale %s', User.find_by_id(session['USERNAME']), session['USERNAME'], sale.id) return redirect('/')
def edit_comment(id): if not request.form['message']: Comment.delete(id) else: Comment.save(request.form['message'], id) sale = Sale.find(request.form['sale_id']) logging.info('%s with id: %s edited comment on sale %s with: %s', User.find_by_id(session['USERNAME']), session['USERNAME'], sale.id, request.form['message']) return redirect(url_for('show_sale', id=sale.id))
def delete_sale(id): sale = Sale.find(id) shutil.rmtree(sale.file_path) with DB() as db: db.execute('DELETE FROM comments WHERE sale_id = ?', (sale.id, )) sale.delete() text = "user id: " + str( session['USERNAME']) + "with username: "******"deleted a post" i_logger(text) return redirect('/')
def show_sale(id): sale = Sale.find(id) images = os.listdir(sale.file_path) sale.file_path = '/' + sale.file_path user_id = session['USERNAME'] username = User.find_by_id(sale.user_id) user = User.find_by_username(username) email = user.email return render_template('sale.html', sale=sale, images=images, user_id=user_id, username=username, email=email)
def new_comment(): if request.method == 'POST': sale = Sale.find(request.form['sale_id']) user_id = session['USERNAME'] username = User.find_by_id(user_id) if not request.form['message']: flash('You entered empty comment!') return redirect(url_for('show_sale', id=sale.id)) else: values = (None, sale, request.form['message'], user_id, username) Comment(*values).create() logging.info('%s with id: %s commented %s on sale %s', User.find_by_id(session['USERNAME']), session['USERNAME'], request.form['message'], sale.id) return redirect(url_for('show_sale', id=sale.id))
def edit_sale(id): sale = Sale.find(id) if request.method == 'GET': return render_template('edit_sale.html', sale=sale, categories=Category.all()) elif request.method == 'POST': sale.name = request.form['name'] sale.model = request.form['model'] sale.condition = request.form['condition'] sale.price = request.form['price'] sale.mileage = request.form['mileage'] sale.year = request.form['year'] sale.horsepower = request.form['horsepower'] sale.category = Category.find(request.form['category_id']) if request.files['file'].filename == '': flash('You forgot to upload in image!') return redirect(url_for('edit_sale', id=sale.id)) images = request.files.getlist("file") shutil.rmtree(sale.file_path) letters = string.ascii_lowercase direc_path = random.choice(letters) direc = request.form['model'] os.mkdir("static/images/" + direc + User.find_by_id(session['USERNAME']) + direc_path) for img in images: img_path = 'static/images/' + direc + User.find_by_id( session['USERNAME']) + direc_path + "/" img.save(img_path + img.filename) sale.file_path = img_path sale.save() text = "user id: " + str( session['USERNAME']) + "with username: "******"edited a post" i_logger(text) return redirect(url_for('show_sale', id=sale.id))
def new_comment(): if request.method == 'POST': sale = Sale.find(request.form['sale_id']) user_id = session['USERNAME'] username = User.find_by_id(user_id) if not request.form['message']: flash('You entered empty comment!') text = "user id: " + str( session['USERNAME']) + "with username: "******"tried to comment unsuccessfully" w_logger(text) return redirect(url_for('show_sale', id=sale.id)) else: values = (None, sale, request.form['message'], user_id, username) Comment(*values).create() text = "user id: " + str( session['USERNAME']) + "with username: "******"commented successfully" i_logger(text) return redirect(url_for('show_sale', id=sale.id))