Exemplo n.º 1
0
def movie_works(actor_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())
    else:
        movies = []
        movie_actor_list = dbmanager.find_movie_actor_by_actor_id(actor_id)
        for m_a in movie_actor_list:
            movie = dbmanager.find_movie_by_id(m_a.movie_id)
            if movie is None:
                pass
            else:
                movies.append(movie)

        if len(movies) == 0:
            return render_template("movies.html",
                                   pagename="Movie",
                                   search_form=SearchForm(),
                                   logon_user=session['username'])
        else:

            movies_list = []
            for m in movies:

                types_list = []
                for m_type in dbmanager.find_movie_type_by_movie_id(m.id):
                    tmp_type = dbmanager.find_mediatype_by_id(m_type.type_id)
                    types_list.append(tmp_type.name)
                types = ", ".join(types_list)

                actors_list = []
                for m_actor in dbmanager.find_movie_actor_by_movie_id(m.id):
                    tmp_actor = dbmanager.find_actor_by_id(m_actor.actor_id)
                    actors_list.append(tmp_actor.name)
                actors = ", ".join(actors_list)

                storage = dbmanager.find_storage_by_id(m.storage)
                tmp_movie = {
                    "id": m.id,
                    "name": m.name,
                    "provider": m.provider,
                    "type": types,
                    "actors": actors,
                    "storage": storage.name
                }
                movies_list.append(tmp_movie)

                actor = dbmanager.find_actor_by_id(actor_id)

            return render_template("movies.html",
                                   pagename="Movie Works of %s" %
                                   actor.name.title(),
                                   search_form=SearchForm(),
                                   logon_user=session['username'],
                                   movies=movies_list)
Exemplo n.º 2
0
def search_result(statistics_type):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())
    else:
        statistics_result = []
        result_number = 0
        if statistics_type == "movieofactor":
            db_all_actor_with_movie = dbmanager.get_all_actor_by_movie()
            for actor_id, movies in db_all_actor_with_movie:
                result_number = result_number + 1
                actor = dbmanager.find_actor_by_id(actor_id)
                statistics_result.append({
                    "result_number": result_number,
                    "name": actor.name,
                    "name_url": "/actor/detail/%d" % actor_id,
                    "count": movies
                })

        if statistics_type == "ebookoftype":
            db_all_ebook_with_type = dbmanager.get_all_ebook_by_type()
            for ebook_type_id, ebooks in db_all_ebook_with_type:
                result_number = result_number + 1
                m_type = dbmanager.find_mediatype_by_id(ebook_type_id)
                statistics_result.append({
                    "result_number": result_number,
                    "name": m_type.name,
                    "name_url": "#",
                    "count": ebooks
                })

        return render_template("statistics_result.html",
                               pagename="Statistics Page",
                               search_form=SearchForm(),
                               logon_user=session['username'],
                               statistics_result=statistics_result)
Exemplo n.º 3
0
def delete_actor(actor_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    cur_actor = dbmanager.find_actor_by_id(actor_id)
    if cur_actor is None:
        logger.error("There is not any actor match id %d." % actor_id)
        return redirect("/actor/all/1")
    else:
        op_photo_delete = dbmanager.delete_photo(cur_actor.thumb)
        if op_photo_delete["op_status"]:
            logger.info("Delete photo with id %d is success." %
                        cur_actor.thumb)
        else:
            logger.error("Delete photo with id %d is fail." % cur_actor.thumb)

        for map_id in dbmanager.find_actor_type_by_actor_id(actor_id):
            op_mapping_delete = dbmanager.delete_actor_type(map_id.id)
            if op_mapping_delete["op_status"]:
                logger.info("Delete mapping with id %d is success." %
                            map_id.id)
            else:
                logger.error("Delete mapping with id %d is fail." % map_id.id)

        op_actor_delete = dbmanager.delete_actor(actor_id)
        if op_actor_delete["op_status"]:
            logger.info("Delete actor with id %d is success." % actor_id)
        else:
            logger.error("Delete actor with id %d fail." % actor_id)
    return redirect("/actor/all/1")
Exemplo n.º 4
0
def delete_confirm(actor_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    cur_actor = dbmanager.find_actor_by_id(actor_id)
    if cur_actor is None:
        logger.error("There is not any actor match id %d." % actor_id)
        return redirect("/actor/all/1")
    else:
        if cur_actor.sex == 0:
            sex = "Male"
        else:
            sex = 'Female'

        # int_list = splitStrIdToInteger(cur_actor.type)
        # str_list = []
        # for i_type in int_list:
        #     db_mediatype = dbmanager.find_mediatype_by_id(i_type)
        #     str_list.append(db_mediatype.name)
        # type_list = ", ".join(str_list)
        str_list = []
        for i_type in dbmanager.find_actor_type_by_actor_id(actor_id):
            db_mediatype = dbmanager.find_mediatype_by_id(i_type.type_id)
            str_list.append(db_mediatype.name)
        type_list = ", ".join(str_list)

        if cur_actor.description == "":
            description = "The author is lazy, there is nothing for this actor yet, you can edit and add some description for her(him)."
        else:
            description = cur_actor.description

        db_thumb = dbmanager.find_photo_by_id(cur_actor.thumb)
        if db_thumb.path == "":
            thumb = MEDIA_URL + db_thumb.name + db_thumb.ext
        else:
            thumb = db_thumb.path

        actor = {
            "id": actor_id,
            "name": cur_actor.name,
            "sex": sex,
            "country": cur_actor.country,
            "description": description,
            "type_list": type_list,
            "thumb": thumb
        }
        return render_template("delete_actor_confirm.html",
                               pagename="Actor Delete Confirm",
                               search_form=SearchForm(),
                               logon_user=session["username"],
                               actor=actor)
Exemplo n.º 5
0
def index():
    if 'username' in session:
        ebook_count = dbmanager.get_count_of_all_ebooks()
        actor_count = dbmanager.get_count_of_all_actors()
        photo_count = dbmanager.get_count_of_all_photos()
        movie_count = dbmanager.get_count_of_all_movies()

        r_movie_count = dbmanager.get_count_of_all_movie_type_with_type(
            MOVIE_TYPE["REGULAR"])
        a_movie_count = dbmanager.get_count_of_all_movie_type_with_type(
            MOVIE_TYPE["ADULT"])

        top5_actor_with_movie = []
        db_top5_actor_with_movie = dbmanager.get_top5_actor_by_movie()
        for actor_id, movies in db_top5_actor_with_movie:
            actor = dbmanager.find_actor_by_id(actor_id)
            top5_actor_with_movie.append({"name": actor.name, "count": movies})

        top5_ebook_with_type = []
        db_top5_ebook_with_type = dbmanager.get_top5_ebook_by_type()
        for ebook_type_id, ebooks in db_top5_ebook_with_type:
            m_type = dbmanager.find_mediatype_by_id(ebook_type_id)
            top5_ebook_with_type.append({"name": m_type.name, "count": ebooks})

        dash = {
            "ebook_count":
            ebook_count,
            "actor_count":
            actor_count,
            "photo_count":
            photo_count,
            "movie_count":
            movie_count,
            "r_movie_percent":
            round(float(r_movie_count) / float(movie_count), 3) * 100,
            "a_movie_percent":
            round(float(a_movie_count) / float(movie_count), 3) * 100,
            "top5_actor":
            top5_actor_with_movie,
            "top5_ebook":
            top5_ebook_with_type
        }

        return render_template('index.html',
                               search_form=SearchForm(),
                               logon_user=session['username'],
                               dash=dash)
    else:
        return render_template('login.html', form=LoginForm())
Exemplo n.º 6
0
def edit_actor(actor_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    db_actor = dbmanager.find_actor_by_id(actor_id)
    if db_actor is None:
        logger.error("There is not any actor match id %d." % actor_id)
        return redirect("/actor/all/1")
    else:
        db_photo = dbmanager.find_photo_by_id(db_actor.thumb)
        actorform = ActorForm(name=db_actor.name,
                              country=db_actor.country,
                              sex=db_actor.sex,
                              thumb_path=db_photo.path,
                              description=db_actor.description)
        return render_template("edit_actor.html",
                               pagename="Edit Actor",
                               search_form=SearchForm(),
                               logon_user=session['username'],
                               actorform=actorform,
                               actor_id=actor_id)
Exemplo n.º 7
0
def delete_movie_confirm(movie_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    db_movie = dbmanager.find_movie_by_id(movie_id)

    if db_movie is None:
        logger.error("There is not any movie with id %d is existed" % movie_id)
        return redirect("/movie/all/1")
    else:
        snapshot_list = []
        for sid in dbmanager.find_movie_photo_by_movie_id(db_movie.id):
            tmp_snapshot = dbmanager.find_photo_by_id(sid.photo_id)
            if tmp_snapshot is None:
                logger.error("The snapshot with id %d is not existed." %
                             sid.photo_id)
                continue
            else:
                if os.path.exists(
                        os.path.join(MEDIA_LOCAL_PATH,
                                     tmp_snapshot.name + tmp_snapshot.ext)):
                    snapshot_list.append({
                        "id": tmp_snapshot.id,
                        "url": tmp_snapshot.path
                    })
                else:
                    snapshot_list.append({
                        "id": tmp_snapshot.id,
                        "url": MOVIE_DEFAULT_SNAP_URL
                    })

        types_list = []
        type_list = dbmanager.find_movie_type_by_movie_id(db_movie.id)
        for tid in type_list:
            tmp_type = dbmanager.find_mediatype_by_id(tid.type_id)
            types_list.append(tmp_type.name)
        types = ", ".join(types_list)

        actors_list = []
        for aid in dbmanager.find_movie_actor_by_movie_id(db_movie.id):
            tmp_actor = dbmanager.find_actor_by_id(aid.actor_id)
            actors_list.append(tmp_actor.name)
        actors = ", ".join(actors_list)

        storage = dbmanager.find_storage_by_id(db_movie.storage)

        cur_cover = dbmanager.find_photo_by_id(db_movie.cover)
        if cur_cover.path == "":
            logger.error("The snapshot with id %d is not existed." % sid)
            cover = MOVIE_DEFAULT_COVER_URL
        else:
            if os.path.exists(
                    os.path.join(MEDIA_LOCAL_PATH,
                                 cur_cover.name + cur_cover.ext)):
                cover = cur_cover.path
            else:
                cover = MOVIE_DEFAULT_COVER_URL

        movie = {
            "id": db_movie.id,
            "name": db_movie.name,
            "type": types,
            "provider": db_movie.provider,
            "actors": actors,
            "storage": storage.name,
            "filepath": db_movie.file_path,
            "cover": cover,
            "snapshots": snapshot_list
        }
        return render_template("delete_movie_confirm.html",
                               pagename="Movie Delete Confirm",
                               search_form=SearchForm(),
                               logon_user=session["username"],
                               movie=movie)
Exemplo n.º 8
0
def movie_index(movie_type, page_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())
    else:
        movies = None
        if movie_type == "all":
            count_movies = dbmanager.get_count_of_all_movies()
            if count_movies < MOVIE_PER_PAGE:
                movies = dbmanager.find_all_movie_by_page(
                    per_page=count_movies, page=page_id)
            else:
                movies = dbmanager.find_all_movie_by_page(
                    per_page=MOVIE_PER_PAGE, page=page_id)

        if movie_type == "regular":
            count_movies = dbmanager.get_count_of_all_movies_with_type(
                MOVIE_TYPE["REGULAR"])
            if count_movies < MOVIE_PER_PAGE:
                movies = dbmanager.find_all_movie_with_type_by_page(
                    MOVIE_TYPE["REGULAR"], per_page=count_movies, page=page_id)
            else:
                movies = dbmanager.find_all_movie_with_type_by_page(
                    MOVIE_TYPE["REGULAR"],
                    per_page=MOVIE_PER_PAGE,
                    page=page_id)

        if movie_type == "adult":
            count_movies = dbmanager.get_count_of_all_movies_with_type(
                MOVIE_TYPE["ADULT"])
            if count_movies < MOVIE_PER_PAGE:
                movies = dbmanager.find_all_movie_with_type_by_page(
                    MOVIE_TYPE["ADULT"], per_page=count_movies, page=page_id)
            else:
                movies = dbmanager.find_all_movie_with_type_by_page(
                    MOVIE_TYPE["ADULT"], per_page=MOVIE_PER_PAGE, page=page_id)

        if movies is None:
            return render_template("movies.html",
                                   pagename="Movie",
                                   search_form=SearchForm(),
                                   logon_user=session['username'])
        else:
            min_item = (page_id - 1) * MOVIE_PER_PAGE + 1
            if page_id * MOVIE_PER_PAGE >= count_movies:
                max_item = count_movies
            else:
                max_item = page_id * MOVIE_PER_PAGE

            movies_list = []
            for m in movies.items:

                types_list = []
                for m_type in dbmanager.find_movie_type_by_movie_id(m.id):
                    tmp_type = dbmanager.find_mediatype_by_id(m_type.type_id)
                    types_list.append(tmp_type.name)
                types = ", ".join(types_list)

                actors_list = []
                for m_actor in dbmanager.find_movie_actor_by_movie_id(m.id):
                    tmp_actor = dbmanager.find_actor_by_id(m_actor.actor_id)
                    actors_list.append(tmp_actor.name)
                actors = ", ".join(actors_list)

                storage = dbmanager.find_storage_by_id(m.storage)
                tmp_movie = {
                    "id": m.id,
                    "name": m.name,
                    "provider": m.provider,
                    "type": types,
                    "actors": actors,
                    "storage": storage.name
                }
                movies_list.append(tmp_movie)

            return render_template("movies.html",
                                   pagename="%s Movies" % movie_type.title(),
                                   logon_user=session['username'],
                                   movies=movies_list,
                                   count_movies=count_movies,
                                   min_item=min_item,
                                   max_item=max_item,
                                   has_prev=movies.has_prev,
                                   has_next=movies.has_next,
                                   prev_num=movies.prev_num,
                                   page=movies.page,
                                   pages=movies.pages,
                                   next_num=movies.next_num,
                                   search_form=SearchForm())
Exemplo n.º 9
0
def update_actor(actor_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    cur_actor = dbmanager.find_actor_by_id(actor_id)
    actorform = ActorForm(name=cur_actor.name)
    actorform.set_is_not_edit(False)
    if actorform.validate_on_submit():
        logger.info("Prepare to update info of actor with id %d to db." %
                    actor_id)
        if actorform.country.data.strip() != cur_actor.country:
            new_country = actorform.country.data.strip()
        else:
            new_country = cur_actor.country

        if actorform.sex.data != cur_actor.sex:
            new_sex = actorform.sex
        else:
            new_sex = cur_actor.sex

        if actorform.description.data.strip() != cur_actor.description:
            new_description = actorform.description.data.strip()
        else:
            new_description = cur_actor.description

        new_type_list = combineIntegerToStr(actorform.types.data)
        # Clear the original mapping
        for origin_map in dbmanager.find_actor_type_by_actor_id(actor_id):
            op_origin_map_result = dbmanager.delete_actor_type(origin_map.id)
        # Save mapping with new one
        for new_type_id in actorform.types.data:
            op_new_map_result = dbmanager.save_actor_type(
                actor_id, new_type_id)

        # Process the photo update.
        if actorform.thumb.data.filename.strip() == "":
            new_thumb = cur_actor.thumb
        else:
            if MEDIA_SAVE_TO_DB:
                pass
            else:
                upload_file = actorform.thumb.data.filename
                logger.info("Upload file %s" % upload_file)
                upload_filename = os.path.splitext(upload_file)[0]
                upload_suffix = os.path.splitext(upload_file)[1]
                save_filename = str(
                    uuid.uuid3(uuid.NAMESPACE_URL,
                               upload_filename.encode('utf-8')))
                save_fullfilename = save_filename + upload_suffix
                save_path = MEDIA_LOCAL_PATH + save_fullfilename
                print(MEDIA_LOCAL_PATH, save_fullfilename)
                logger.info("Save path is %s" % save_path)
                actorform.thumb.data.save(save_path)
                op_photo_result = dbmanager.save_photo_with_string(
                    save_filename, upload_suffix, PHOTO_TYPE["NORMAL"])
                new_thumb = op_photo_result["new_id"]

        if new_thumb == cur_actor.thumb and actorform.thumb_path.data.strip(
        ) != "":
            thumb_url = actorform.thumb_path.data.strip()
            logger.info("Upload file path is %s" % thumb_url)
            thumb_url_name = os.path.splitext(thumb_url.split("/")[-1])[0]
            thumb_url_suffix = os.path.splitext(thumb_url.split("/")[-1])[1]
            op_photo_result = dbmanager.save_photo_with_string(
                thumb_url_name, thumb_url_suffix, PHOTO_TYPE["NORMAL"],
                thumb_url)
            new_thumb = op_photo_result["new_id"]

        op_result = dbmanager.update_actor(id=actor_id,
                                           name=cur_actor.name,
                                           country=new_country,
                                           sex=new_sex,
                                           types=new_type_list,
                                           description=new_description,
                                           thumb=new_thumb)
        logger.info("Update actor with new data complete, status: %s." %
                    op_result["op_status"])
        return redirect("/actor/all/1")
    else:
        return render_template("edit_actor.html",
                               pagename="Edit Actor",
                               search_form=SearchForm(),
                               logon_user=session['username'],
                               actorform=actorform,
                               actor_id=actor_id)