Ejemplo n.º 1
0
def new_mediatype():
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())
    else:
        mediatypes = dbmanager.find_all_mediatypes()
        if mediatypes is None:
            return render_template("create_mediatype.html",
                                   pagename="Create Media Type",
                                   search_form=SearchForm(),
                                   logon_user=session['username'],
                                   mediatypeform=MediaTypeForm())
        else:
            mediatype_list = []
            for m in mediatypes:
                if m.parent == 0:
                    mediatype_list.append({
                        "id": m.id,
                        "name": m.name,
                        "parent_name": "None",
                        "parent_id": 0
                    })
                else:
                    p_type = dbmanager.find_mediatype_by_id(m.parent)
                    mediatype_list.append({
                        "id": m.id,
                        "name": m.name,
                        "parent_name": p_type.name,
                        "parent_id": p_type.id
                    })

        return render_template("create_mediatype.html",
                               pagename="Create Media Type",
                               search_form=SearchForm(),
                               logon_user=session['username'],
                               mediatypeform=MediaTypeForm())
Ejemplo n.º 2
0
def update_mediatype(mediatype_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    cur_mediatype = dbmanager.find_mediatype_by_id(mediatype_id)
    mediatypeform = MediaTypeForm()
    if mediatypeform.validate_on_submit():
        mediatype = dbmanager.find_mediatype_by_name(
            mediatypeform.name.data.strip())
        if len(mediatype) == 0:
            logger.info("Update new media type to db.")
            op_result = dbmanager.update_mediatype(
                mediatype_id, mediatypeform.name.data.strip(),
                mediatypeform.parent.data)
            logger.info("Update new media type complete, status: %s." %
                        op_result["op_status"])
            return redirect("/mediatype/all")
        else:
            logger.info("Media type is existed.")
            mediatypeform.name.errors.append("Media Type is existed.")
            return render_template("edit_mediatype.html",
                                   pagename="Edit Media Type",
                                   search_form=SearchForm(),
                                   logon_user=session['username'],
                                   mediatypeform=mediatypeform,
                                   cur_mediatype=cur_mediatype)
    else:
        return render_template("edit_mediatype.html",
                               pagename="Edit Media Type",
                               search_form=SearchForm(),
                               logon_user=session['username'],
                               mediatypeform=mediatypeform,
                               cur_mediatype=cur_mediatype)
Ejemplo n.º 3
0
def create_storage():
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    storageform = StorageForm()
    if storageform.validate_on_submit():
        storage = dbmanager.find_storage_by_name(storageform.name.data.strip())
        if len(storage) == 0:
            logger.info("Saving new media type to db.")
            op_result = dbmanager.save_storage(storageform.name.data.strip(),
                                               storageform.mediatype.data,
                                               float(storageform.size.data))
            logger.info("Save new storage complete, status: %s." %
                        op_result["op_status"])
            return redirect("/storage/all")
        else:
            logger.info("The storage with name %s is existed." %
                        storageform.name.data.strip())
            storageform.name.errors.append(
                "Storage with name '%s' is existed." %
                storageform.name.data.strip())
            return render_template("create_storage.html",
                                   pagename="Create Storage",
                                   search_form=SearchForm(),
                                   logon_user=session['username'],
                                   storageform=storageform)

    logger.error("Create new storage fail.")
    return render_template("create_storage.html",
                           pagename="Create Storage",
                           search_form=SearchForm(),
                           logon_user=session['username'],
                           storageform=storageform)
Ejemplo n.º 4
0
def storage_index():
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())
    else:
        storages = dbmanager.find_all_storages()
        if storages is None:
            return render_template("storages.html",
                                   pagename="Storages",
                                   search_form=SearchForm(),
                                   logon_user=session['username'])
        else:
            storage_list = []
            for s in storages:
                mediatype = dbmanager.find_mediatype_by_id(s.mediatype)
                storage_list.append({
                    "id": s.id,
                    "name": s.name,
                    "mediatype": mediatype.name,
                    "size": s.size
                })

            return render_template("storages.html",
                                   pagename="Storage List",
                                   search_form=SearchForm(),
                                   logon_user=session['username'],
                                   storage_list=storage_list)
Ejemplo n.º 5
0
def create_mediatype():
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    mediatypeform = MediaTypeForm()
    if mediatypeform.validate_on_submit():
        mediatype = dbmanager.find_mediatype_by_name(
            mediatypeform.name.data.strip())
        if len(mediatype) == 0:
            logger.info("Saving new media type to db.")
            op_result = dbmanager.save_mediatype(
                mediatypeform.name.data.strip(), mediatypeform.parent.data)
            logger.info("Save new media type complete, status: %s." %
                        op_result["op_status"])
            #return render_template("mediatypes.html", pagename="Media Type", logon_user=session['username'], mediatype_list=mediatype_list)
            return redirect("/mediatype/all")
        else:
            logger.info("Media type is existed.")
            mediatypeform.name.errors.append("Media Type is existed.")
            return render_template("create_mediatype.html",
                                   pagename="Create Media Type",
                                   search_form=SearchForm(),
                                   logon_user=session['username'],
                                   mediatypeform=mediatypeform)

    return render_template("create_mediatype.html",
                           pagename="Create Media Type",
                           search_form=SearchForm(),
                           logon_user=session['username'],
                           mediatypeform=mediatypeform)
Ejemplo n.º 6
0
def update_storage(storage_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    cur_storage = dbmanager.find_storage_by_id(storage_id)
    storageform = StorageForm()
    if storageform.validate_on_submit():
        storages = dbmanager.find_storage_by_name(
            storageform.name.data.strip())
        if len(storages) == 0:
            logger.info("Update new storage to db.")
            op_result = dbmanager.update_storage(storage_id,
                                                 storageform.name.data.strip(),
                                                 storageform.mediatype.data,
                                                 float(storageform.size.data))
            logger.info("Update new storage complete, status: %s." %
                        op_result["op_status"])
            return redirect("/storage/all")
        else:
            logger.info("Storage %s is existed." %
                        storageform.name.data.strip())
            storageform.name.errors.append("Storage is existed.")
            return render_template("edit_storage.html",
                                   pagename="Edit Storage",
                                   search_form=SearchForm(),
                                   logon_user=session['username'],
                                   storageform=storageform,
                                   cur_storage=cur_storage)
    else:
        return render_template("edit_storage.html",
                               pagename="Edit Storage",
                               search_form=SearchForm(),
                               logon_user=session['username'],
                               storageform=storageform,
                               cur_storage=cur_storage)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
def new_actor():
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    actorform = ActorForm()
    return render_template("create_actor.html",
                           pagename="New Actor",
                           search_form=SearchForm(),
                           logon_ueer=session['username'],
                           actorform=actorform)
Ejemplo n.º 10
0
def new_storage():
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    storageform = StorageForm()
    return render_template("create_storage.html",
                           pagename="New Storage",
                           search_form=SearchForm(),
                           logon_ueer=session['username'],
                           storageform=storageform)
Ejemplo n.º 11
0
def edit_ebook(ebook_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    db_ebook = dbmanager.find_ebook_by_id(ebook_id)
    if db_ebook is None:
        logger.error("There is not any ebook match id %d." % ebook_id)
        return redirect("/ebook/all/1")
    else:
        ebookform = eBookForm(name=db_ebook.name, actors=db_ebook.actors, storage_path=db_ebook.file_path)
        return render_template("edit_ebook.html", pagename="Edit eBook", search_form=SearchForm(), logon_user=session['username'], ebookform=ebookform, ebook_id=ebook_id)
Ejemplo n.º 12
0
def new_movie(movie_type):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    if movie_type == "adult":
        movieform = MovieAdultForm()
        return render_template("create_movie.html",
                               pagename="New Movie",
                               search_form=SearchForm(),
                               logon_ueer=session['username'],
                               movieform=movieform,
                               movie_type=movie_type)

    if movie_type == "regular":
        movieform = MovieRegularForm()
        return render_template("create_movie.html",
                               pagename="New Movie",
                               search_form=SearchForm(),
                               logon_ueer=session['username'],
                               movieform=movieform,
                               movie_type=movie_type)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
def delete_confirm(mediatype_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    mediatype = dbmanager.find_mediatype_by_id(mediatype_id)
    if mediatype is None:
        logger.error("There is not any media type match id %d." % mediatype_id)
        return redirect("/mediatype/all")
    else:
        return render_template("delete_mediatype_confirm.html",
                               pagename="Delete Media Type Confirm",
                               search_form=SearchForm(),
                               logon_user=session['username'],
                               cur_mediatype=mediatype)
Ejemplo n.º 15
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())
Ejemplo n.º 16
0
def edit_mediatype(mediatype_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    mediatype = dbmanager.find_mediatype_by_id(mediatype_id)
    if mediatype is None:
        logger.error("There is not any media type match id %d." % mediatype_id)
        return redirect("/mediatype/all")
    else:
        mediatypeform = MediaTypeForm()
        return render_template("edit_mediatype.html",
                               pagename="Edit Media Type",
                               search_form=SearchForm(),
                               logon_user=session['username'],
                               mediatypeform=mediatypeform,
                               cur_mediatype=mediatype)
Ejemplo n.º 17
0
def delete_confirm(storage_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    storage = dbmanager.find_storage_by_id(storage_id)
    if storage is None:
        logger.error("There is not any storage match id %d." % storage_id)
        return redirect("/storage/all")
    else:
        mediatype = dbmanager.find_mediatype_by_id(storage.mediatype)
        cur_storage = {
            "id": storage.id,
            "name": storage.name,
            "mediatype_name": mediatype.name,
            "size": storage.size
        }
        return render_template("delete_storage_confirm.html",
                               pagename="Delete Storage Confirm",
                               search_form=SearchForm(),
                               logon_user=session['username'],
                               cur_storage=cur_storage)
Ejemplo n.º 18
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)
Ejemplo n.º 19
0
def update_ebook(ebook_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    db_ebook = dbmanager.find_ebook_by_id(ebook_id)
    ebookform = eBookForm(name=db_ebook.name, actors=db_ebook.actors, storage_path=db_ebook.file_path)
    ebookform.set_is_not_edit(False)
    if ebookform.validate_on_submit():
        logger.info("Prepare to update info of eBook with id %d to db." % ebook_id)
        if ebookform.name.data.strip() != db_ebook.name:
            new_name = ebookform.name.data.strip()
        else:
            new_name = db_ebook.name

        if ebookform.actors.data.strip() != db_ebook.actors:
            new_actors = ebookform.actors.data.strip()
        else:
            new_actors = db_ebook.actors
            
        if ebookform.storage_path.data.strip() != db_ebook.file_path:
            new_path = ebookform.storage_path.data.strip()
        else:
            new_path = db_ebook.file_path

        new_types = combineIntegerToStr(ebookform.types.data)
        # Clear the ebook type mapping
        for e_type in dbmanager.find_ebook_type_by_ebook_id(ebook_id):
            op_delete_e_type = dbmanager.delete_ebook_type(e_type.id)
        # Save new type
        for new_e_type in ebookform.types.data:
            ob_update_e_type = dbmanager.save_ebook_type(ebook_id, new_e_type)

        new_storage = ebookform.storage.data

        op_ebook_resp = dbmanager.update_ebook(id=ebook_id, name=new_name, actors=new_actors, mediatype=new_types, storage=new_storage, file_path=new_path)
        logger.info("Update ebook with new data complete, status: %s." % op_ebook_resp["op_status"])
        return redirect("/ebook/all/1")
    else:
        return render_template("edit_ebook.html", pagename="Edit eBook", search_form=SearchForm(), logon_user=session['username'], ebookform=ebookform, ebook_id=ebook_id)
Ejemplo n.º 20
0
def search_result():
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())
    else:
        search_form = SearchForm()
        if search_form.validate_on_submit():
            search_key = search_form.name.data.strip()

            results = []

            actors_search_result = dbmanager.find_actor_by_name_for_search(
                search_key)
            if len(actors_search_result) > 0:
                for actor in actors_search_result:
                    results.append({
                        "name": actor.name,
                        "name_url": "/actor/detail/%d" % actor.id,
                        "category": "Actor",
                        "category_url": "/actor/all/1"
                    })
            else:
                pass

            movies_search_result = dbmanager.find_movie_by_name_for_search(
                search_key)
            if len(movies_search_result) > 0:
                for movie in movies_search_result:
                    results.append({
                        "name": movie.name,
                        "name_url": "/movie/detail/%d" % movie.id,
                        "category": "Movie",
                        "category_url": "/movie/all/1"
                    })
            else:
                pass

            ebooks_search_result = dbmanager.find_ebook_by_name_for_search(
                search_key)
            if len(ebooks_search_result) > 0:
                for ebook in ebooks_search_result:
                    results.append({
                        "name": ebook.name,
                        "name_url": "#",
                        "category": "EBook",
                        "category_url": "/ebook/all/1"
                    })
            else:
                pass

            return render_template("results.html",
                                   pagename="Search Result Page",
                                   search_for="Search Result of %s" %
                                   search_key,
                                   search_form=search_form,
                                   logon_user=session['username'],
                                   search_result=results)
        else:
            return render_template("results.html",
                                   pagename="Search Result Page",
                                   search_for="Search Result of %s" %
                                   "Nothing",
                                   search_form=search_form,
                                   logon_user=session['username'])
Ejemplo n.º 21
0
def confirm_delete_ebook(ebook_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    db_ebook = dbmanager.find_ebook_by_id(ebook_id)

    if db_ebook is None:
        logger.errof("There is not any ebook matching id %d found." % ebook_id)
        return redirect("/ebook/all/1")
    else:
        types_list = []
        for e_type in dbmanager.find_ebook_type_by_ebook_id(db_ebook.id):
            tmp_type = dbmanager.find_mediatype_by_id(e_type.type_id)
            types_list.append(tmp_type.name)
        types = ", ".join(types_list)
        storage = dbmanager.find_storage_by_id(db_ebook.storage)
        cur_ebook = {"id": db_ebook.id,
                     "name": db_ebook.name,
                     "type": types,
                     "actors": db_ebook.actors,
                     "storage": storage.name,
                     "path": db_ebook.file_path}
        return render_template("delete_ebook_confirm.html", pagename="Delete eBook Confirm", search_form=SearchForm(), logon_user=session['username'], cur_ebook=cur_ebook)
Ejemplo n.º 22
0
def movie_index(ebook_type, page_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())
    else:
        ebooks = None
        if ebook_type == "all":
            count_ebooks = dbmanager.get_count_of_all_ebooks()
            if count_ebooks < EBOOK_PER_PAGE:
                ebooks = dbmanager.find_all_ebooks_by_page(per_page=count_ebooks, page=page_id)
            else:
                ebooks = dbmanager.find_all_ebooks_by_page(per_page=EBOOK_PER_PAGE, page=page_id)

        if ebook_type == "development":
            count_ebooks = dbmanager.get_count_of_all_ebooks_with_type(EBOOK_TYPE["DEVELOPMENT"])
            if count_ebooks < EBOOK_PER_PAGE:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["DEVELOPMENT"], per_page=count_ebooks, page=page_id)
            else:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["DEVELOPMENT"], per_page=EBOOK_PER_PAGE, page=page_id)

        if ebook_type == "entertainment":
            count_ebooks = dbmanager.get_count_of_all_ebooks_with_type(EBOOK_TYPE["ENTERTAINMENT"])
            if count_ebooks < EBOOK_PER_PAGE:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["ENTERTAINMENT"], per_page=count_ebooks, page=page_id)
            else:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["ENTERTAINMENT"], per_page=EBOOK_PER_PAGE, page=page_id)

        if ebook_type == "python":
            count_ebooks = dbmanager.get_count_of_all_ebooks_with_type(EBOOK_TYPE["PYTHON"])
            if count_ebooks < EBOOK_PER_PAGE:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["PYTHON"], per_page=count_ebooks, page=page_id)
            else:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["PYTHON"], per_page=EBOOK_PER_PAGE, page=page_id)

        if ebook_type == "golang":
            count_ebooks = dbmanager.get_count_of_all_ebooks_with_type(EBOOK_TYPE["GOLANG"])
            if count_ebooks < EBOOK_PER_PAGE:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["GOLANG"], per_page=count_ebooks, page=page_id)
            else:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["GOLANG"], per_page=EBOOK_PER_PAGE, page=page_id)

        if ebook_type == "kubernetes":
            count_ebooks = dbmanager.get_count_of_all_ebooks_with_type(EBOOK_TYPE["KUBERNETES"])
            if count_ebooks < EBOOK_PER_PAGE:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["KUBERNETES"], per_page=count_ebooks, page=page_id)
            else:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["KUBERNETES"], per_page=EBOOK_PER_PAGE, page=page_id)

        if ebook_type == "database":
            count_ebooks = dbmanager.get_count_of_all_ebooks_with_type(EBOOK_TYPE["DATABASE"])
            if count_ebooks < EBOOK_PER_PAGE:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["DATABASE"], per_page=count_ebooks, page=page_id)
            else:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["DATABASE"], per_page=EBOOK_PER_PAGE, page=page_id)

        if ebook_type == "devops":
            count_ebooks = dbmanager.get_count_of_all_ebooks_with_type(EBOOK_TYPE["DEVOPS"])
            if count_ebooks < EBOOK_PER_PAGE:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["DEVOPS"], per_page=count_ebooks, page=page_id)
            else:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["DEVOPS"], per_page=EBOOK_PER_PAGE, page=page_id)

        if ebook_type == "system":
            count_ebooks = dbmanager.get_count_of_all_ebooks_with_type(EBOOK_TYPE["SYSTEM"])
            if count_ebooks < EBOOK_PER_PAGE:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["SYSTEM"], per_page=count_ebooks, page=page_id)
            else:
                ebooks = dbmanager.find_all_ebooks_with_type_by_page(EBOOK_TYPE["SYSTEM"], per_page=EBOOK_PER_PAGE, page=page_id)

        if ebooks is None:
            return render_template("ebooks.html", pagename="eBooks", search_form=SearchForm(), logon_user=session['username'])
        else:
            min_item = (page_id - 1) * EBOOK_PER_PAGE + 1
            if page_id * EBOOK_PER_PAGE >= count_ebooks:
                max_item = count_ebooks
            else:
                max_item = page_id * EBOOK_PER_PAGE

            ebooks_list = []
            for b in ebooks.items:
                types_list = []
                for e_type in dbmanager.find_ebook_type_by_ebook_id(b.id):
                    tmp_type = dbmanager.find_mediatype_by_id(e_type.type_id)
                    types_list.append(tmp_type.name)
                types = ", ".join(types_list)
                actors = b.actors
                storage = dbmanager.find_storage_by_id(b.storage)
                tmp_book = {"id": b.id, "name": b.name, "type": types, "actors": actors, "storage": storage.name, "path": b.file_path}
                ebooks_list.append(tmp_book)

            return render_template("ebooks.html",
                                   pagename="%s eBooks" % ebook_type.title(),
                                   logon_user=session['username'],
                                   ebooks=ebooks_list,
                                   count_movies=count_ebooks,
                                   min_item=min_item,
                                   max_item=max_item,
                                   has_prev=ebooks.has_prev,
                                   has_next=ebooks.has_next,
                                   prev_num=ebooks.prev_num,
                                   page=ebooks.page,
                                   pages=ebooks.pages,
                                   next_num=ebooks.next_num,
                                   search_form=SearchForm())
Ejemplo n.º 23
0
def crate_ebook():
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    ebookform = eBookForm()
    if ebookform.validate_on_submit():
        new_name = ebookform.name.data.strip()
        if ebookform.actors.data.strip() == "":
            new_actors = "Anonymous Writer"
        else:
            new_actors = ebookform.actors.data.strip()
        new_types = combineIntegerToStr(ebookform.types.data)
        new_storage = ebookform.storage.data
        new_path = ebookform.storage_path.data.strip()
        
        op_save_ebook = dbmanager.save_ebook(name=new_name, actors=new_actors, mediatype=new_types, storage=new_storage, file_path=new_path)
        for type_id in ebookform.types.data:
            op_save_e_type = dbmanager.save_ebook_type(op_save_ebook["new_id"], type_id)

        if op_save_ebook["op_status"]:
            logger.info("Save new ebook success, new id is: %d" % op_save_ebook["new_id"])
            return redirect("/ebook/all/1")
        else:
            logger.error("There is some issue for saving new ebook.")
            return render_template("create_ebook.html", pagename="New eBook", search_form=SearchForm(), logon_ueer=session['username'], ebookform=ebookform)
    else:
        return render_template("create_ebook.html", pagename="New eBook", search_form=SearchForm(), logon_ueer=session['username'], ebookform=ebookform)
Ejemplo n.º 24
0
def new_ebook():
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    ebookform = eBookForm()
    return render_template("create_ebook.html", pagename="New eBook", search_form=SearchForm(), logon_ueer=session['username'], ebookform=ebookform)
Ejemplo n.º 25
0
def actor_index(actor_type, page_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())
    else:
        actors = None
        if actor_type == "all":
            count_actor = dbmanager.get_count_of_all_actors()
            if count_actor < ACTOR_PER_PAGE:
                actors = dbmanager.find_all_actors_by_page(
                    per_page=count_actor, page=page_id)
            else:
                actors = dbmanager.find_all_actors_by_page(
                    per_page=ACTOR_PER_PAGE, page=page_id)

        if actor_type == "regular":
            count_actor = dbmanager.get_count_of_all_actors_with_type(
                ACTOR_TYPE["REGULAR"])
            if count_actor < ACTOR_PER_PAGE:
                actors = dbmanager.find_all_actors_with_type_by_page(
                    actor_type=ACTOR_TYPE["REGULAR"],
                    per_page=count_actor,
                    page=page_id)
            else:
                actors = dbmanager.find_all_actors_with_type_by_page(
                    actor_type=ACTOR_TYPE["REGULAR"],
                    per_page=ACTOR_PER_PAGE,
                    page=page_id)

        if actor_type == "adult":
            count_actor = dbmanager.get_count_of_all_actors_with_type(
                ACTOR_TYPE["ADULT"])
            if count_actor < ACTOR_PER_PAGE:
                actors = dbmanager.find_all_actors_with_type_by_page(
                    actor_type=ACTOR_TYPE["ADULT"],
                    per_page=count_actor,
                    page=page_id)
            else:
                actors = dbmanager.find_all_actors_with_type_by_page(
                    actor_type=ACTOR_TYPE["ADULT"],
                    per_page=ACTOR_PER_PAGE,
                    page=page_id)

        if actors is None:
            return render_template("actors.html",
                                   pagename="Actors",
                                   search_form=SearchForm(),
                                   logon_user=session['username'])
        else:
            min_item = (page_id - 1) * ACTOR_PER_PAGE + 1
            if page_id * ACTOR_PER_PAGE >= count_actor:
                max_item = count_actor
            else:
                max_item = page_id * ACTOR_PER_PAGE

            actor_list = []
            for a in actors.items:
                if a.sex == 0:
                    cur_sex = "Male"
                else:
                    cur_sex = "Female"

                actor_list.append({
                    "id": a.id,
                    "name": a.name,
                    "sex": cur_sex,
                    "country": a.country,
                    "description": a.description
                })

            return render_template("actors.html",
                                   pagename="Actors",
                                   logon_user=session['username'],
                                   actor_list=actor_list,
                                   has_prev=actors.has_prev,
                                   has_next=actors.has_next,
                                   page=actors.page,
                                   pages=actors.pages,
                                   prev_num=actors.prev_num,
                                   next_num=actors.next_num,
                                   min_item=min_item,
                                   max_item=max_item,
                                   count_actors=count_actor,
                                   search_form=SearchForm())
Ejemplo n.º 26
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)
Ejemplo n.º 27
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())
Ejemplo n.º 28
0
def create_movie(movie_type):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())

    if movie_type == "regular":
        movieform = MovieRegularForm()

    if movie_type == "adult":
        movieform = MovieAdultForm()

    if movieform.validate_on_submit():
        cur_movie = dbmanager.find_movie_by_name(movieform.name.data.strip())
        if len(cur_movie) == 0:
            logger.info("Saving new movie to db.")
            new_name = movieform.name.data.strip()

            if movieform.provider.data.strip() == "":
                new_provider = "Default Provider"
            else:
                new_provider = movieform.provider.data.strip()

            new_actor_list = combineIntegerToStr(movieform.actors.data)
            new_storage = movieform.storage.data
            new_filepath = movieform.storage_path.data.strip()
            # Save the cover file
            if movieform.cover.data.filename == '':
                op_cover_save = dbmanager.save_photo_with_string(
                    "nopic", ".jpg", PHOTO_TYPE["COVER"], "")
            else:
                cover_file = movieform.cover.data.filename
                logger.info("Upload file %s" % cover_file)
                upload_filename = os.path.splitext(cover_file)[0]
                upload_suffix = os.path.splitext(cover_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
                logger.info("Save path is %s" % save_path)
                movieform.cover.data.save(save_path)
                op_cover_save = dbmanager.save_photo_with_string(
                    save_filename, upload_suffix, PHOTO_TYPE["COVER"],
                    MEDIA_URL + save_fullfilename)
            # end of saving cover file
            # Save snapshot files
            snapshot_list = request.files.getlist('snapshots')
            op_snapshots = []
            for snapshot in snapshot_list:
                # Save the snapshot file
                snapshot_file = snapshot.filename
                logger.info("Upload file %s" % snapshot_file)
                snapshot_filename = os.path.splitext(snapshot_file)[0]
                snapshot_suffix = os.path.splitext(snapshot_file)[1]
                snapshot_filename = str(
                    uuid.uuid3(uuid.NAMESPACE_URL,
                               snapshot_filename.encode('utf-8')))
                snapshot_fullfilename = snapshot_filename + snapshot_suffix
                snapshot_path = MEDIA_LOCAL_PATH + snapshot_fullfilename
                logger.info("Save path is %s" % snapshot_path)
                snapshot.save(snapshot_path)
                op_snapshot_save = dbmanager.save_photo_with_string(
                    snapshot_filename, snapshot_suffix, PHOTO_TYPE["SNAPSHOT"],
                    MEDIA_URL + snapshot_fullfilename)
                op_snapshots.append(op_snapshot_save["new_id"])
                # end of saving cover file
            op_movie_save = dbmanager.save_movie(
                name=new_name,
                actors=new_actor_list,
                snapshots=combineIntegerToStr(op_snapshots),
                cover=op_cover_save["new_id"],
                types=MOVIE_TYPE[movie_type.upper()],
                provider=new_provider,
                storage=new_storage,
                file_path=new_filepath)

            # Save the mapping between Movie and snapshots
            for s_id in op_snapshots:
                ob_map_m_s = dbmanager.save_movie_photo(
                    op_movie_save["new_id"], s_id)

            # Save the mapping between Movie and actors
            for a_id in movieform.actors.data:
                ob_map_m_a = dbmanager.save_movie_actor(
                    op_movie_save["new_id"], a_id)

            # Save the mapping between Movie and type
            op_map_m_t = dbmanager.save_movie_type(
                op_movie_save["new_id"], MOVIE_TYPE[movie_type.upper()])

            return redirect("/movie/all/1")
        else:
            logger.info("The movie with name %s seems existed." %
                        movieform.name.data.strip())
            return render_template("create_movie.html",
                                   pagename="New Movie",
                                   search_form=SearchForm(),
                                   loggon_user=session['username'],
                                   movieform=movieform,
                                   movie_type=movie_type)
    else:
        return render_template("create_movie.html",
                               pagename="New Movie",
                               search_form=SearchForm(),
                               logon_ueer=session['username'],
                               movieform=movieform,
                               movie_type=movie_type)
Ejemplo n.º 29
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)
Ejemplo n.º 30
0
def photo_index_with_type(photo_type, page_id):
    if 'username' not in session:
        return render_template('login.html', form=LoginForm())
    else:
        if photo_type == "all":
            count_photos = dbmanager.get_count_of_all_photos()
            if count_photos < PHOTO_PER_PAGE:
                photos = dbmanager.find_all_photo_by_page(
                    per_page=count_photos, page=page_id)
            else:
                photos = dbmanager.find_all_photo_by_page(
                    per_page=PHOTO_PER_PAGE, page=page_id)

        if photo_type == "regular":
            count_photos = dbmanager.get_count_of_all_photos_with_type(
                PHOTO_TYPE["NORMAL"])
            if count_photos < PHOTO_PER_PAGE:
                photos = dbmanager.find_all_photo_with_type_by_page(
                    PHOTO_TYPE["NORMAL"], per_page=count_photos, page=page_id)
            else:
                photos = dbmanager.find_all_photo_with_type_by_page(
                    PHOTO_TYPE["NORMAL"],
                    per_page=PHOTO_PER_PAGE,
                    page=page_id)

        if photo_type == "cover":
            count_photos = dbmanager.get_count_of_all_photos_with_type(
                PHOTO_TYPE["COVER"])
            if count_photos < PHOTO_PER_PAGE:
                photos = dbmanager.find_all_photo_with_type_by_page(
                    PHOTO_TYPE["COVER"], per_page=count_photos, page=page_id)
            else:
                photos = dbmanager.find_all_photo_with_type_by_page(
                    PHOTO_TYPE["COVER"], per_page=PHOTO_PER_PAGE, page=page_id)

        if photo_type == "snap":
            count_photos = dbmanager.get_count_of_all_photos_with_type(
                PHOTO_TYPE["SNAPSHOT"])
            if count_photos < PHOTO_PER_PAGE:
                photos = dbmanager.find_all_photo_with_type_by_page(
                    PHOTO_TYPE["SNAPSHOT"],
                    per_page=count_photos,
                    page=page_id)
            else:
                photos = dbmanager.find_all_photo_with_type_by_page(
                    PHOTO_TYPE["SNAPSHOT"],
                    per_page=PHOTO_PER_PAGE,
                    page=page_id)

        if photos is None:
            return render_template("photoes.html",
                                   pagename="Photos",
                                   search_form=SearchForm(),
                                   logon_user=session['username'])
        else:
            min_item = (page_id - 1) * PHOTO_PER_PAGE + 1
            if page_id * PHOTO_PER_PAGE >= count_photos:
                max_item = count_photos
            else:
                max_item = page_id * PHOTO_PER_PAGE

            return render_template("photoes.html",
                                   pagename="%s Photos" % photo_type.title(),
                                   search_form=SearchForm(),
                                   logon_user=session['username'],
                                   photos=photos,
                                   count_photos=count_photos,
                                   min_item=min_item,
                                   max_item=max_item)