Example #1
0
def logout():

    if db.getLogin():
        message = {
            "message_type": "success",
            "message_info": "{0} has logged out!".format(db.getLogin())
        }

        #Clean the Login Variable
        db.setLogin('')
        return render_template('login.html', message=message)

    else:
        return redirect('/')
Example #2
0
def addvideo():

    # Video's original creator
    origin = "true"

    if request.method == 'POST':
        form = request.form
        userid = form['user_id']
        title = form['title']
        description = form['description']
        image = form['image']
        video = form['video']
        category = form['category_id']

    try:
        # Get username
        user_name = db.getLogin()

        # Add the Video to the database
        db.addVideo(userid, title, description, image, video, category, origin)

        return redirect('/{}'.format(user_name))

    except:
        return redirect('/')
Example #3
0
def edit(videoid):

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Getting categories list
        categories = db.getCategories()

        # Getting playlists by id
        video = db.getVideoById(videoid)

        # Checks to make sure video belongs to the user editing the video.
        if int(userid) == int(video['user_id']):
            return render_template('edit-video.html',
                                   video=video,
                                   categories=categories)

        else:
            return redirect('/profile')

    except:
        return redirect('/')
Example #4
0
def videos():

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Getting original videos created by other users
        videos = db.getOtherVideos(userid)

        # Getting the vote information
        votes = db.getAllVotes()

        return render_template('videos.html',
                               videos=videos,
                               username=user_name,
                               votes=votes,
                               userid=userid,
                               get_votes=db.calcVotes,
                               check_voted=db.checkVote)

    except:
        return redirect('/')
Example #5
0
def orderuser(user_name):

    try:
        # Getting my username
        my_username = db.getLogin()

        # Getting my user id
        my_id = db.getUserId(my_username)

        # Getting user id to search
        users_id = db.getUserId(user_name)

        #Getting vote information
        votes = db.getAllVotes()

        # Getting videos ordered by user name
        ordered = db.orderByUser(users_id, my_id)

        return render_template('videos.html',
                               videos=ordered,
                               username=my_username,
                               votes=votes,
                               userid=my_id,
                               get_votes=db.calcVotes,
                               check_voted=db.checkVote)

    except:
        return redirect('/')
Example #6
0
def dashboard(username):

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Getting list of my videos
        videos = db.getMyVideos(userid)

        # If user has no videos redirect to welcome screen
        if not videos:
            return redirect('/welcome')

        # Getting the vote information
        votes = db.getAllVotes()

        return render_template('dashboard.html',
                               username=username,
                               videos=videos,
                               votes=votes,
                               get_votes=db.calcVotes)

    except:
        return redirect('/')
Example #7
0
def ordercategory(category_name):

    # Not my videos or profile page
    profile = False

    try:
        # Getting user name
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Getting categories by name and ordering
        category_id = db.getCategoryIdByName(category_name)

        # Getting vote information
        votes = db.getAllVotes()

        # Getting video list ordered by category name
        ordered = db.orderByCategory(category_id, userid, profile)

        return render_template('videos.html',
                               videos=ordered,
                               username=user_name,
                               votes=votes,
                               userid=userid,
                               get_votes=db.calcVotes,
                               check_voted=db.checkVote)

    except:
        return redirect('/')
Example #8
0
def orderprofilecategory(category_name):

    # My videos and profile
    profile = True

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Getting category by category name and ordering
        category_id = db.getCategoryIdByName(category_name)

        # Getting vote information
        votes = db.getAllVotes()

        # Getting profile video list ordered by category name
        ordered = db.orderByCategory(category_id, userid, profile)

        return render_template('dashboard.html',
                               videos=ordered,
                               username=user_name,
                               votes=votes,
                               get_votes=db.calcVotes)

    except:
        return redirect('/')
Example #9
0
def repost(videoid):

    # Video's original creator
    origin = "false"

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Get playlist by id
        video = db.getVideoById(videoid)

        # Setting variables with copied video data
        title = video['title']
        description = video['description']
        img_source = video['img_source']
        video_source = video['video_source']
        category_id = video['category_id']

        # Adding video to database
        db.addVideo(userid, title, description, img_source, video_source,
                    category_id, origin)

        return redirect('/{}'.format(user_name))

    except:
        return redirect('/')
Example #10
0
def downvote(videoid):

    # Set vote value
    vote = -1

    # Calculating the votes for video
    total_votes = db.calcVotes(videoid)

    if total_votes == None:
        total_votes = 0

    # This deletes a video if it has a total score of -5
    if total_votes > -4:
        try:
            # Getting username
            user_name = db.getLogin()

            # Getting user id
            userid = db.getUserId(user_name)

            # Make vote
            db.vote(videoid, userid, vote)
            return redirect('/videos')

        except:
            redirect('/')

    else:
        db.delete(videoid)
        return redirect('/videos')
Example #11
0
def profile():

    try:
        # Get Username
        user_name = db.getLogin()
        return redirect('/{}'.format(user_name))

    except:
        return redirect('/')
Example #12
0
def welcome():

    try:
        username = db.getLogin()
        if username:
            return render_template('welcome.html', username=username)
        else:
            return redirect('/')

    except:
        return redirect('/')
Example #13
0
def newplaylist():

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Getting list of categories
        categories = db.getCategories()

        return render_template('new-video.html',
                               user_name=user_name,
                               userid=userid,
                               categories=categories)

    except:
        return redirect('/')
Example #14
0
def upvote(videoid):

    # Set vote value
    vote = 1

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Make vote
        db.vote(videoid, userid, vote)

        return redirect('/videos')

    except:
        redirect('/')
Example #15
0
def editvideo():

    if request.method == 'POST':
        form = request.form
        videoid = form['video_id']
        title = form['title']
        description = form['description']
        img_source = form['image']
        video_source = form['video']
        category_id = form['category_id']

    try:
        # Getting username
        user_name = db.getLogin()

        # Edit video information in the database
        db.edit(videoid, title, description, img_source, video_source,
                category_id)
        return redirect('/{}'.format(user_name))

    except:
        return redirect('/')
Example #16
0
def delete(videoid):

    try:
        # Get username
        user_name = db.getLogin()

        # Getting playlists by id
        video = db.getVideoById(videoid)

        # Getting user id
        userid = db.getUserId(user_name)

        # Checks to make sure video belongs to the user deleting the video via the url.
        if int(userid) == int(video['user_id']):
            # Delete the video
            db.delete(videoid)
            return redirect('/{}'.format(user_name))

        else:
            return redirect('/profile')

    except:
        return redirect('/')
Example #17
0
def ordersaved(status):

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Getting vote information
        votes = db.getAllVotes()

        # Getting profile video list ordered by original and reposted
        ordered = db.orderBySaved(userid, status)

        return render_template('dashboard.html',
                               videos=ordered,
                               username=user_name,
                               votes=votes,
                               get_votes=db.calcVotes)

    except:
        return redirect('/')