Beispiel #1
0
def search_results(searchVariable):
    letter = searchVariable.replace("%", "")
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    check = len(letter)
    animes = None
    animes2 = None
    if searchVariable == "TopRated" or searchVariable == "NewAdded":
        defaultAnimeList = AnimeSeries.query.all()
        count2 = len(defaultAnimeList)
        animes, animes2 = AnimeSortQuery(count2)
        if searchVariable == "TopRated":
            searchAnime = animes
            searchTitle = "Top Rated"
        elif searchVariable == "NewAdded":
            searchAnime = animes2
            searchTitle = "Newest Added"
    elif searchVariable in ('A%','B%','C%','D%','E%','F%','G%','H%','I%','J%','K%','L%','M%',
                      'N%','O%','P%','Q%','R%','S%','T%','U%','V%','W%','X%','Y%','Z%'):
        searchTitle = "Anime starting with "
        searchAnime = AnimeSeries.query.filter(AnimeSeries.animeTitle.like(searchVariable))
    else:
        searchTitle = "Anime containing "
        searchAnime = AnimeSeries.query.filter(AnimeSeries.animeTitle.like("%" + searchVariable + "%"))
        
    return render_template('search_results.html', image_file=image_file, suggestedAnime=suggestedAnime, searchVariable=searchVariable, posts=posts, searchAnime=searchAnime, letter=letter, searchTitle=searchTitle, check=check, animes=animes, animes2=animes2)
Beispiel #2
0
def mediapage(media):
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    tempObject = Media.query.filter(Media.media == media).first()
    animeList = getAnime(tempObject)
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
            
    return render_template('mediapage.html', animeList=animeList, image_file=image_file, media=media, suggestedAnime=suggestedAnime, posts=posts)
Beispiel #3
0
def studiopage(studio):
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    tempObject = Studio.query.filter(Studio.studio == studio).first()
    animeList = getAnime(tempObject)
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
            
    return render_template('studiopage.html', animeList=animeList, image_file=image_file, studio=studio, suggestedAnime=suggestedAnime, posts=posts)
Beispiel #4
0
def home():
    suggestedAnime = SuggestedContent(current_user)
    count2 = 4
    animes, animes2 = AnimeSortQuery(count2)
    randomAnimeChoice = randomAnime()
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    return render_template('home.html', animes=animes, animes2=animes2, image_file=image_file, post=post, suggestedAnime=suggestedAnime, posts=posts, randomAnimeChoice=randomAnimeChoice)
Beispiel #5
0
def genrepage(genre):
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    tempObject = Genre.query.filter(Genre.genre == genre).first()
    animeList = getAnime(tempObject)
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
            
    return render_template('genrepage.html', animeList=animeList, image_file=image_file, genre=genre, suggestedAnime=suggestedAnime, posts=posts)
Beispiel #6
0
def producerpage(producer):
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    tempObject = Producer.query.filter(Producer.producer == producer).first()
    animeList = getAnime(tempObject)
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
            
    return render_template('producerpage.html', animeList=animeList, image_file=image_file, producer=producer, suggestedAnime=suggestedAnime, posts=posts)
Beispiel #7
0
def results(searchVariable):
    try:
        if current_user.admin != 'y':
            abort(403)
    except:
        abort(403)
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    result = User.query.filter_by(username=searchVariable).first()
    return render_template('results.html', image_file=image_file, suggestedAnime=suggestedAnime, searchVariable=searchVariable, result=result, posts=posts)
Beispiel #8
0
def search():

    form = SearchAnimeForm()
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    if form.validate_on_submit():
        searchVariable = form.searchVar.data
        return redirect(url_for('search_results', searchVariable=searchVariable))
    
    return render_template('search.html', image_file=image_file, suggestedAnime=suggestedAnime, posts=posts, form=form)
Beispiel #9
0
def anime():
    try:
        if current_user.admin != 'y':
            abort(403)
    except:
        abort(403)
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    form = AnimeForm()
    if form.validate_on_submit():
        animeTitle = form.animeTitle.data
        anime = AnimeSeries(animeTitle=form.animeTitle.data, content=form.content.data, premiered=form.premiered.data, 
                            episodes=form.episodes.data, scored=form.scored.data, scoredBy=form.scoredBy.data, thumbnail=animeTitle, 
                            pic1=animeTitle, pic2=animeTitle, briefContent=form.content.data[0:200])
        db.session.add(anime)
        db.session.commit()
        
        item = form.genre.data
        item = item.split(",")
        for i in item:
            genreTemp = AnimeGenre(animeseries_id=anime.id, genre_id=i)
            db.session.add(genreTemp)
            db.session.commit()
        item = form.media.data
        item = item.split(",")
        for i in item:
            mediaTemp = AnimeMedia(animeseries_id=anime.id, media_id=i)
            db.session.add(mediaTemp)
            db.session.commit()
        item = form.studio.data
        item = item.split(",")
        for i in item:
            studioTemp = AnimeStudio(animeseries_id=anime.id, studio_id=i)
            db.session.add(studioTemp)
            db.session.commit()
        item = form.producer.data
        item = item.split(",")
        for i in item:
            producerTemp = AnimeProducer(animeseries_id=anime.id, producer_id=i)
            db.session.add(producerTemp)
            db.session.commit()

        if form.picture.data:
            picture_file = save_thumbnail(animeTitle, form.picture.data)
            current_user.image_file = picture_file
            anime.thumbnail = picture_file
            db.session.commit()
        
        flash('Anime added!', 'success')
        return redirect(url_for('home'))
    return render_template('anime.html', title='Anime', form=form, legend='New Anime', suggestedAnime=suggestedAnime, image_file=image_file, posts=posts)
Beispiel #10
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)
Beispiel #11
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)
Beispiel #12
0
def login():
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(url_for('home'))
        else:
            flash('Login Unsuccessful. Please check email and or password', 'danger')
    return render_template('login.html', title='Login', form=form, suggestedAnime=suggestedAnime, image_file=image_file, posts=posts)
Beispiel #13
0
def register():
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        admin = 'n'
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password, admin=admin)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form, suggestedAnime=suggestedAnime, image_file=image_file, posts=posts)
Beispiel #14
0
def user_posts(searchVariable):
    try:
        if current_user.admin != 'y':
            abort(403)
    except:
        abort(403)
    form = DeletePostForm()
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    user = User.query.filter_by(username=searchVariable).first()
    result = Post.query.filter_by(user_id=user.id).all()
    
    if form.validate_on_submit():
        post_id = form.searchVar.data
        return redirect(url_for('delete_post', post_id=post_id))

    return render_template('user_posts.html', image_file=image_file, suggestedAnime=suggestedAnime, searchVariable=searchVariable, result=result, posts=posts, form=form)
Beispiel #15
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)
Beispiel #16
0
def admintools():
    try:
        if current_user.admin != 'y':
            abort(403)
    except:
        abort(403)
    result = ""
    searchVariable = ""
    form = SearchUserForm()
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    
    if form.validate_on_submit():
        searchVariable = form.searchVar.data
        return redirect(url_for('results', searchVariable=searchVariable))
        
    return render_template('admintools.html', image_file=image_file, form=form, suggestedAnime=suggestedAnime, result=result, searchVariable=searchVariable, posts=posts)
Beispiel #17
0
def register_user():
    try:
        if current_user.admin != 'y':
            abort(403)
    except:
        abort(403)
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    form = RegisterUserForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password, admin=form.admin.data)
        db.session.add(user)
        db.session.commit()
        flash('Account has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('registeruser.html', title='Register User', form=form, legend='Register User', suggestedAnime=suggestedAnime, image_file=image_file, posts=posts)
Beispiel #18
0
def account():
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.user_name = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file2 = url_for('static', filename='profile_pics/' + current_user.image_file)
    return render_template('account.html', title='Account', image_file=image_file, image_file2=image_file2, form=form, suggestedAnime=suggestedAnime, posts=posts)
Beispiel #19
0
def 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)
    return render_template('post.html', title=post.title, post=post, suggestedAnime=suggestedAnime, image_file=image_file, posts=posts)
Beispiel #20
0
def about():
    posts = recentPost()
    image_file = url_for('static', filename='anime_thumbnail/downloads/')
    suggestedAnime = SuggestedContent(current_user)
    return render_template('about.html', title='About', suggestedAnime=suggestedAnime, image_file=image_file, posts=posts)