Example #1
0
def home():
    postForm = PostForm()
    if postForm.validate_on_submit():
        append_client_history(postForm.number.data)
        for ind, val in enumerate(session['guess']):
            update_physic(physics[ind], val, postForm.number.data)
        clear_physic_guess()
    return render_template('index.html', physics=physics, postForm=postForm)
Example #2
0
def new_post():
	form = PostForm()
	if form.validate_on_submit():
		post = Post(title=form.title.data, content=form.content.data, author=current_user)
		db.session.add(post)
		db.session.commit()
		flash('Your post has been created!', 'success')
		return redirect(url_for('home'))
	return render_template('create_post.html', title='New Post', form=form, legend='New Post')
Example #3
0
def new_post():
  form = PostForm()
  if form.validate_on_submit():
    post = Post(title=form.title.data, content=form.content.data, author=current_user)
    db.session.add(post)
    db.session.commit()
    flash('Kirjoituksesi on lisäty!', 'success')
    return redirect(url_for('home'))
  return render_template('create_post.html', title='Uusi kirjoitus', form=form)
Example #4
0
def animepage(animeTitle):
    posts = recentPost()
    suggestedAnime = SuggestedContent(current_user)
    form = PostForm()
    postValidation = ""
    animes = AnimeSeries.query.filter(AnimeSeries.animeTitle == animeTitle).first()
    userRating = UserRating.query.filter(UserRating.animeseries_id == animes.id).all()
    
    animeRating = animes.scored
    
    try:
        if form.validate_on_submit():
            post = Post(animeseries_id=animes.id, title=form.title.data, content=form.content.data, author=current_user)
            fav = UserRating(user_id=current_user.id, animeseries_id=animes.id, rating=form.rating.data)
            try:
                rating=int(form.rating.data)
                if rating >= 8:
                    animes.favorites.append(current_user)
                elif rating < 8:
                    meh = UserPassList(user_id=current_user.id, animeseries_id=animes.id)
                    db.session.add(meh)
                scored, scoredBy, rating = float(animes.scored), float(animes.scoredBy), float(rating)
                scored, scoredBy = RatingCalculation(rating, scored, scoredBy)
                scored, scoredBy = str(round(scored, 2)), str(scoredBy)
                animes.scored, animes.scoredBy = scored, scoredBy
            except:
                print("error2")
            db.session.add(post)
            db.session.add(fav)
            db.session.commit()
            flash('Your post has been created!', 'success')
            return redirect(url_for('animepage', animeTitle=animeTitle))
    except:
        print("error")

    posts2 = Post.query.filter_by(animeseries_id = animes.id).all()
    try:
        for post in posts2:
            if post.user_id == current_user.id:
                postValidation = "exists"
    except:
        print("No user ID found")
    genreList = getGenre(animes)
    mediaList = getMedia(animes)
    producerList = getProducer(animes)
    studioList = getStudio(animes)
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    image_file2 = url_for('static', filename='gallery_thumbnail/')

    return render_template('animepage.html', animes=animes, image_file=image_file, image_file2=image_file2, posts=posts, genreList=genreList, mediaList=mediaList, producerList=producerList, studioList=studioList, form=form, animeRating=animeRating, postValidation=postValidation, userRating=userRating, suggestedAnime=suggestedAnime, posts2=posts2)
Example #5
0
def post(post_id):
    post = Post.query.get_or_404(post_id)
    post_form = PostForm()
    if post_form.validate_on_submit():
        if post_form.title.data and post_form.content.data:
            post.title = post_form.title.data
            post.content = post_form.content.data
            db.session.commit()
            flash('Your post has been updated', 'success')
            return redirect(url_for('home'))
    elif request.method == 'GET':
        post_form.title.data = post.title
        post_form.content.data = post.content
    return render_template('post.html',title='Update post',post = post,form=post_form,legend='Update post')
Example #6
0
def update_post(post_id):
    post = Post.query.get_or_404(post_id)
    if post.author != current_user:
        abort(403)
    form = PostForm()
    if form.validate_on_submit():
        post.title = form.title.data
        post.content = form.content.data
        db.session.commit()
        flash('Your post has been updated!', 'success')
        return redirect(url_for('post', post_id=post.id))
    elif request.method =='GET':
      form.title.data = post.title
      form.content.data = post.content
    return render_template('create_post.html', title='Update Post', form = form, legend='Update Post')
Example #7
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        media = save_media(form.media.data, 'media')
        post = Post(content=form.content.data,
                    media=media,
                    author=current_user)
        db.session.add(post)
        db.session.commit()
        flash("Posted successfully", 'success')
        return redirect(url_for('home'))
    return render_template("new_post.html",
                           title="Instaclone",
                           form=form,
                           get_file_url=get_file_url)
Example #8
0
def new_post():
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    form = PostForm()
    try:
        if form.validate_on_submit():
            post = Post(animeseries_id=form.animeseries_id.data, title=form.title.data, content=form.content.data, author=current_user)
            db.session.add(post)
            db.session.commit()
            flash('Your post has been created!', 'success')
            return redirect(url_for('home'))
    except:
        print("error")
    return render_template('create_post.html', title='New post', form=form, legend='New Post', suggestedAnime=suggestedAnime, image_file=image_file, posts=posts)
Example #9
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        if form.picture.data:
            image_file = save_picture_post(form.picture.data)
            image_file = url_for('static', filename='mile_pics/' + image_file)
        post = Post(title=form.title.data,
                    content=form.content.data,
                    author=current_user,
                    image_file=form.picture.data)
        db.session.add(post)
        db.session.commit()
        flash('Your post has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('create_post.html',
                           title='New Post',
                           form=form,
                           legend='New Post')
Example #10
0
def update_post(post_id):
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    post = Post.query.get_or_404(post_id)
    if post.author != current_user:
        abort(403)
    form = PostForm()
    if form.validate_on_submit():
        post.title = form.title.data
        post.content = form.content.data
        db.session.commit()
        flash('Your post has been updated!', 'success')
        return redirect(url_for('post', post_id=post.id))
    elif request.method == 'GET':   
        form.title.data = post.title
        form.content.data = post.content
    return render_template('create_post.html', title='Update post', form=form, legend='Update Post', suggestedAnime=suggestedAnime, image_file=image_file, posts=posts)