def upload(): form = UploadReceiptForm() if form.validate_on_submit(): post = Post(soft_plastic=form.soft_plastic.data, hard_plastic=form.hard_plastic.data, styrofoam=form.styrofoam.data, author=current_user) post.calculate_points() post.generate_body() db.session.add(post) db.session.commit() flash(_('Thanks for all your effort!')) return redirect(url_for('main.user', username=current_user.username)) return render_template('upload.html', form=form)
def user(username): user = User.query.filter_by(username=username).first_or_404() posts = user.followed_posts() form = LogActivity() form2 = EmptyForm() #posts = current_user.followed_posts().all() if form.validate_on_submit(): post = Post(action=form.action.data, item=form.item.data, body=form.comment.data, author=current_user) post.calculate_points() if form.action.data != 'have something else to share': if post.points == 1: points_str = 'point' else: points_str = 'points' if post.item is None or len(form.item.data) == 0: post.body = ' says: "I {}." They have earned {} {}!'.format( post.action.lower(), str(post.points), points_str) else: post.body = ' says: "I {} {}." They have earned {} points!'.format( post.action.lower(), post.item, str(post.points)) if form.comment.data is not None or len(form.comment.data) > 0: post.body = post.body + '\n' + form.comment.data post.timestamp = datetime.now().strftime("%H:%M:%S %d-%m-%Y ") user.points += post.points db.session.add(post) db.session.commit() form = LogActivity() return redirect(request.url) return render_template("user.html", user=user, posts=posts, form=form, points=user.points)