def review(book_title): if 'username' not in session: abort(401) error = None if request.method == 'POST': if not request.form['rating']: error = 'Please give this book a rating from 1 - 10' else: # update rating for book book = Book.query.filter_by(title=book_title).first() old_rating = book.rating if old_rating == 0: book.rating = request.form['rating'] book.num_ratings = 1 else: book.rating = round( ((old_rating * book.num_ratings) + int(request.form['rating'])) / (book.num_ratings + 1), 1) book.num_ratings += 1 db.session.add( Update('review', session['username'], book_title, request.form['content'], request.form['rating'], time.time())) db.session.commit() db.session.flush() flash("Submission successful") return redirect(url_for('timeline')) return render_template('review.html', book=Book.query.filter_by(title=book_title).first(), error=error)
def add_update(): name = request.args.get('name') message = request.args.get('message') try: update = Update(name=name, message=message) db.session.add(update) db.session.commit() return "Update added. Update id={}".format(update.id) except Exception as e: return (str(e))
def create_update(): if request.method == "POST": name = request.form.get('name') message = request.form.get('message') try: update = Update(name=name, message=message) db.session.add(update) db.session.commit() add_msg = "{}'s update was added! Id: {}".format( update.name, update.id) return redirect(url_for('hello')) except Exception as e: return (str(e)) return render_template("add_update.html")
def begin(book_title): if 'username' not in session: abort(401) error = None user = User.query.filter_by(username=session['username']).first() book = Book.query.filter_by(title=book_title).first() if not user: abort(404) user.reading = book_title db.session.add( Update('reading', session['username'], book_title, None, None, time.time())) db.session.commit() db.session.flush() flash('Enjoy \"' + book_title + '\"!') return redirect(url_for('timeline'))
def submit(): """ Process the form and persist the filtered dates to the database """ form = MyForm() if form.validate_on_submit(): filtered_dates = process_form(form) for filtered_date in filtered_dates: update = Update.query.filter_by(date=filtered_date).filter_by(room_type = (form.room_type.data == 'double')).first() if update: update.price = form.price.data else: update = Update(form.price.data,form.availability.data,filtered_date,form.room_type.data == 'double') db.session.add(update) db.session.commit() return redirect('/success') return render_template('submit.html', title='Update',form=form)
def get_updates(self): scraper = cloudscraper.create_scraper() url = self.url + 'updates' updates_raw = BeautifulSoup(scraper.get(url).content, 'lxml') updates_html = updates_raw.select('li.novel-item > a') updates = [] for item in updates_html: title = item.find('h4').text.strip() latest = item.find('h5').text.strip() last_update = item.select('div.novel-stats > span')[0].text.strip() rank = item.select('div.novel-stats > span')[1].text.strip() updates.append(Update(title, latest, last_update, rank)) return updates
def add_rating(self, user_id, movie_id, value): self.send_update(Update(user_id, movie_id, value))
def sermon_needs_update(self, request): # The 1 is the number it is within the request message. Not sure why it is one indexed? update = Update() update.needs_update = updates.get_last_sermon_time() > DateTimeField(1).value_from_message(request) return update