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)
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)
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)
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)
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")
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)
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)
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())
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)
def delete_confirm(user_id): if 'username' not in session: return render_template('login.html', form=LoginForm()) user = dbmanager.find_user_by_id(user_id) if user is None: return render_template('delete_actor_confirm.html', pagename="User Delete Confirm", logon_user=session['username']) else: return render_template('delete_actor_confirm.html', pagename="User Delete Confirm", logon_user=session['username'], user=user)
def edit_user(user_id): if 'username' not in session: return render_template('login.html', form=LoginForm()) user = dbmanager.find_user_by_id(user_id) if user is None: return render_template('user_edit.html', pagename="Edit User", logon_user=session['username']) else: return render_template('user_edit.html', pagename="Edit User", logon_user=session['username'], user=user, usereditform=UserEditForm())
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)
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)
def user_index(): #return render_template("users/users.html", pagename="Users") if 'username' not in session: return render_template('login.html', form=LoginForm()) else: user_list = dbmanager.find_all_users() if user_list is None: return render_template("users.html", pagename="Users", logon_user=session['username']) else: return render_template("users.html", pagename="Users", logon_user=session['username'], users=user_list)
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)
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)
def delete_storge(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: op_result = dbmanager.delete_storage(storage_id) logger.info("Delete the storage with id: %d success." % storage_id) return redirect("/storage/all")
def delete_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: op_result = dbmanager.delete_mediatype(mediatype_id) logger.info("Delete the media type with id: %d success." % mediatype_id) return redirect("/mediatype/all")
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)
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)
def create_user(): if 'username' not in session: return render_template('login.html', form=LoginForm()) userform = UserForm() if userform.validate_on_submit(): dbmanager.save_user(userform.username.data, userform.password.data) user_list = dbmanager.find_all_users() if user_list is None: return render_template("users.html", pagename="Users", logon_user=session['username']) else: return render_template("users.html", pagename="Users", logon_user=session['username'], users=user_list) return render_template("/user_new.html", userform=userform, logon_user=session['username'])
def delete_user(user_id): if 'username' not in session: return render_template('login.html', form=LoginForm()) op_result = dbmanager.delete_user(user_id) if op_result["op_status"]: logger.info(op_result["err_msg"]) else: logger.error(op_result["err_msg"]) user_list = dbmanager.find_all_users() if user_list is None: return render_template("users.html", pagename="Users", logon_user=session['username']) else: return render_template("users.html", pagename="Users", logon_user=session['username'], users=user_list)
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)
def delete_ebook(ebook_id): if 'username' not in session: return render_template('login.html', form=LoginForm()) # Clear the 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) op_result = dbmanager.delete_ebook(ebook_id) if op_result["op_status"]: logger.info("The ebook with id %d has been deleted." % ebook_id) return redirect("/ebook/all/1") else: logger.error("There is some error appeared for deleting ebook with id %d, delete fail." % ebook_id) return redirect("/ebook/all/1")
def delete_movie(movie_id): if 'username' not in session: return render_template('login.html', form=LoginForm()) cur_movie = dbmanager.find_movie_by_id(movie_id) if cur_movie is None: logger.error("There is not any movie match id %d." % movie_id) return redirect("/movie/all/1") else: op_cover_delete = dbmanager.delete_photo(cur_movie.cover) if op_cover_delete["op_status"]: logger.info("Delete cover with id %d is success." % cur_movie.cover) else: logger.error("Delete cover with id %d is fail." % cur_movie.cover) # snapshot_list = splitStrIdToInteger(cur_movie.snapshots) snapshot_list = dbmanager.find_movie_photo_by_movie_id(movie_id) for sid in snapshot_list: op_snapshots_delete = dbmanager.delete_photo(sid.photo_id) if op_snapshots_delete["op_status"]: logger.info("Delete snapshot with id %d is success." % sid.photo_id) else: logger.error("Delete snapshot with id %d is fail." % sid.photo_id) # Clear the mapping between movie and actor for m_a_map in dbmanager.find_movie_actor_by_movie_id(movie_id): op_m_a_result = dbmanager.delete_movie_actor(m_a_map.id) # Clear the mapping between movie and type for m_t_map in dbmanager.find_movie_type_by_movie_id(movie_id): op_m_t_result = dbmanager.delete_movie_type(m_t_map.id) # Clear the mapping between movie and photo for m_p_map in dbmanager.find_movie_photo_by_movie_id(movie_id): op_m_p_result = dbmanager.delete_movie_photo(m_p_map.id) op_movie_delete = dbmanager.delete_movie(movie_id) if op_movie_delete["op_status"]: logger.info("Delete movie with id %d is success." % movie_id) else: logger.error("Delete movie with id %d fail." % movie_id) return redirect("/movie/all/1")
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)
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)
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)
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)
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)