Example #1
0
def movie_info():

    # Check if user is logged in.
    try:
        session["user_id"]
        mycommunities = com.mycommunities()
    except KeyError:
        mycommunities = []

    # Get movie information.
    similar_films = Search.similar_films(request.args.get("imdb_id"))
    actors = Search.movie_actors(request.args.get("imdb_id"))
    full_movie_info = Search.title_info(request.args.get("imdb_id"))

    if request.method == "POST":
        # Add movie to a user list.
        if request.form.get("listadd") == "add":
            Lists.add_item(User.get_list_id(session["username"]),
                           request.args.get("imdb_id"))
            return render_template("movie_information.html",
                                   full_movie_info=full_movie_info,
                                   actors=actors,
                                   similars=similar_films,
                                   movie_select=True,
                                   mycom=mycommunities)

        # Add movie to a community list.
        else:
            Lists.add_item(com.get_list_id(request.form.get("comadd")),
                           request.args.get("imdb_id"))
            return render_template("movie_information.html",
                                   full_movie_info=full_movie_info,
                                   actors=actors,
                                   similars=similar_films,
                                   movie_select=True,
                                   mycom=mycommunities)
    # Show movie info page.
    else:
        return render_template("movie_information.html",
                               full_movie_info=full_movie_info,
                               actors=actors,
                               similars=similar_films,
                               movie_select=True,
                               mycom=mycommunities)
Example #2
0
def community():

    # Gather required information.
    films = Lists.showlist(request.args.get('community'))
    comments = com.community_comments(request.args.get('community'))

    if request.method == "POST":

        # Get changed community description and save it.
        if request.form.get("save"):
            com.change_description(request.form.get("save"),
                                   request.args.get('community'))
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))

        # Lets user join community.
        if request.form.get("comaction") == "join":
            com.join(session["username"], request.args.get('community'))
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))

        # Lets user leave community.
        elif request.form.get("comaction") == "leave":
            com.remove_member(session["username"],
                              request.args.get('community'))
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))

        # Removes item from community list.
        elif request.form.get("comlistremove"):
            Lists.remove_item(Lists.get_listid(request.args.get('community')),
                              request.form.get("comlistremove"))
            films = Lists.showlist(request.args.get('community'))
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))

        # Save comment.
        if request.form.get("commented"):
            username = session["username"]
            com.save_comment(username, request.args.get('community'),
                             request.form.get("comment"))
            comments = com.community_comments(request.args.get('community'))
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))

        # Add item to user list.
        if request.form.get("listadd"):
            Lists.add_item(User.get_list_id(session["username"]),
                           request.form.get("listadd"))
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))

        # Add item to other community list.
        elif request.form.get("comadd"):
            print(request.form.get("comadd") + "fwkogfwkefgjew")
            Lists.add_item(com.get_list_id(request.args.get("community")),
                           request.form.get("comadd"))
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))

        #wrong post request
        else:
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))
    # Render page.
    else:
        return render_template(
            "community.html",
            mycom=com.mycommunities(),
            comments=comments,
            page=com.show(request.args.get('community'))[0],
            members=com.showmembers(request.args.get('community')),
            films=films,
            member=com.member(session["user_id"],
                              request.args.get('community')))