def validate_date(isbn): set_db() complete = Book.is_complete(isbn) if complete: book = Book.find_by_isbn(isbn) today = dt.datetime.now()#.strfstrftime("%Y-%m-%d") if book is None: caps = Book.allChapter(isbn) for cap in caps: if cap['available_to'] is not None and today > cap['available_to']: print("Se encontro un capitulo vencido") return False if cap['available_from'] is not None and today < cap['available_from']: print("Se encontro un capitulo no disponible") return False print("Ningun Capitulo se vencio") return True else: if book['available_to'] is not None and today > book['available_to']: print("El libro esta vencido") return False if book['available_from'] is not None and today < book['available_from']: print("El libro aun no esta disponible") return False else: print("El libro no esta vencido") return True else: print("Aun no se cargo el libro") return False
def open_cap_menu(isbn): set_db() capitulos = Book.allChapter(isbn) today = dt.datetime.now() noDisponibles = list(map(lambda cap: cap['available_from'] > today, capitulos)) vencidos = list(map(lambda cap: ((cap['available_to'] is not None) and cap['available_to'] < today), capitulos)) titulo = Book.find_meta_by_isbn(isbn)['titulo'] return render_template('books/abrir_cap_menu.html',isbn=isbn, capitulos=capitulos, noDisponibles=noDisponibles, vencidos=vencidos, titulo=titulo)
def new(isbn): set_db() if validate_book_isbn(isbn): caps = Book.allChapter(isbn) if(caps==()): titulo = Book.find_meta_by_isbn(isbn)['titulo'] today = dt.datetime.now().strftime("%Y-%m-%d") return render_template('books/new.html', isbn=isbn, titulo=titulo, today=today) else: flash("Ya se han cargado capitulos") else: flash("Ya hay un libro cargado") return redirect(url_for("book_menu"))
def search(): def filter_by(criteria, name, book): return name in book[criteria].lower() set_db() books = Book.allMeta() criteria = request.form.get('busqueda') name = request.form.get('nombre').lower() print(name) selected = list(filter(lambda book: filter_by(criteria, name, book), books)) print(selected) venc = list(map(lambda meta: validate_date(meta['isbn']), selected)) hasChapters = list(map(lambda meta: Book.allChapter(meta['isbn'])!=(), selected)) i = int(request.args.get('i',0)) Configuracion.db = get_db() pag=Configuracion.get_page_size() if (i == -1): i=0 elif (i*pag >= len(books)): i = i - 1 adm = "configuracion_usarInhabilitado" in session['permisos'] #Permiso que solo tiene un administrador return render_template('books/menu.html', books=selected, i=i, pag=pag, adm=adm, canReadBook=venc, hasChapters=hasChapters)
def render_menu(): set_db() book_for={} book_type = request.args.get('type','all') book_for['all'] = Book.allMeta book_for['search_by'] = search_by if request.form.get('nombre') is not None else Book.allMeta book_for['history'] = history books = book_for[book_type]() venc = list(map(lambda meta: validate_date(meta['isbn']), books)) hasChapters = list(map(lambda meta: Book.allChapter(meta['isbn'])!=(), books)) print("Lista de tiene capitulos") print(hasChapters) i = int(request.args.get('i',0)) Configuracion.db = get_db() pag=Configuracion.get_page_size() if (i == -1): i=0 elif (i*pag >= len(books)): i = i - 1 adm = "configuracion_usarInhabilitado" in session['permisos'] #Permiso que solo tiene un administrador return render_template('books/menu.html', books=books, i=i, pag=pag, adm=adm, canReadBook=venc, hasChapters=hasChapters)
def date_menu(isbn): set_db() capitulos = Book.allChapter(isbn) libro = Book.find_by_isbn(isbn) return render_template('books/modificar_menu.html', isbn=isbn, capitulos=capitulos, libro=libro)
def render_delete_menu(isbn): set_db() chaps = Book.allChapter(isbn) return render_template('books/eliminar_menu.html', isbn=isbn, capitulos=chaps)