Exemplo n.º 1
0
def review(id):
    user_aux = current_user.current_profile()
    book = Book.query.get_or_404(id)
    if not (user_aux.doneReading):
        flash('No se puede escribir una reseña de un libro que no leiste',
              'danger')
        return redirect(url_for('main.book', id=id))
    saveBookHistory(name=book.full_name(), entryType='Book', id=id)
    aux = current_user.current_profile().reviews
    isreviewed = False
    for each in aux:
        if each.book_id == book.id:
            isreviewed = True
            break
    if (isreviewed):
        flash('Solo se puede escribir una reseña por libro', 'danger')
        return redirect(url_for('main.book', id=id))
    form = ReviewForm()
    if form.validate_on_submit():
        review = Review(writer=user_aux,
                        book=book,
                        score=form.score.data,
                        text=form.text.data)
        db.session.add(review)
        db.session.commit()
        flash('Se ha publicado la reseña', 'success')
        return redirect(url_for('main.book', id=id))
    return render_template('review.html', form=form, legend="Reseña")
Exemplo n.º 2
0
def chapter(chapter_id):
    theChapter = Chapter.query.get_or_404(chapter_id)
    theBook = Book.query.get_or_404(theChapter.book_id)
    theName = theBook.full_name() + ' - ' + theChapter.full_name()
    if (current_user.accountType != 'Admin' and theBook.public == False):
        flash('Este libro todavia no esta disponible.', 'info')
        return redirect(url_for('main.home'))
    saveBookHistory(name=theName, entryType='Chapter', id=chapter_id)

    lastChapter = Chapter.query.filter_by(book_id=theBook.id).order_by(
        Chapter.chapterNumber.desc()).first()
    if (lastChapter == theChapter):
        current_user.current_profile().markAsRead(theBook)
    return render_template('chapter.html', book=theBook, chapter=theChapter)
Exemplo n.º 3
0
def update_profile():
    form = ProfileUpdateForm()
    if form.validate_on_submit():
        current_user.current_profile().name = form.name.data
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
        else:
            picture_file = "default.png"
        current_user.current_profile().image_file = picture_file
        db.session.commit()
        flash('Los datos de la cuenta se guardaron!', 'success')
        return redirect(url_for('main.home'))
    elif request.method == 'GET':
        form.name.data = current_user.current_profile().name
    return render_template('update_profile.html', form=form, profile =  current_user.current_profile(), title= 'Editar perfil', legend= 'Editar perfil')
Exemplo n.º 4
0
def saveBookHistory(name, entryType, id):
    entry = NavigationHistoryEntry(entryType=entryType,
                                   item_id=id,
                                   entryName=name,
                                   owner=current_user.current_profile())
    db.session.add(entry)
    db.session.commit()
Exemplo n.º 5
0
def delete_favourite(id):

    bookF = Book.query.get_or_404(id)

    profile = current_user.current_profile()
    profile.favourites.remove(bookF)
    db.session.commit()
    flash('{} ha sido eliminado de Favoritos.'.format(bookF.full_name()), 'info')
    return redirect (url_for('users.favourites'))
Exemplo n.º 6
0
def book(id):
    theBook = Book.query.get_or_404(id)
    if (current_user.accountType != 'Admin' and theBook.public == False):
        flash('Este libro todavia no esta disponible.', 'info')
        return redirect(url_for('main.home'))

    saveBookHistory(name=theBook.full_name(), entryType='Book', id=id)
    aux = current_user.current_profile().reviews
    isreviewed = False
    for each in aux:
        if each.book_id == theBook.id:
            isreviewed = True
            break
    return render_template(
        'book.html',
        book=theBook,
        alreadyRead=(theBook in current_user.current_profile().doneReading),
        isreviewed=isreviewed)
Exemplo n.º 7
0
def add_favourite(id):

    bookF = Book.query.get_or_404(id)

    profile = current_user.current_profile()
    if bookF not in profile.favourites:
        profile.favourites.append(bookF)
        db.session.commit()
        flash('{} ha sido agregado a Favoritos.'.format(bookF.full_name()), 'success')
    else:
        flash('{} ya está en Favoritos.'.format(bookF.full_name()), 'danger')

    return redirect(url_for('main.book', id=id))
Exemplo n.º 8
0
        def decorator(*args, **kwargs):
            #user must be logged in
            if not current_user.is_authenticated:
                return current_app.login_manager.unauthorized()

            #user must have selected a profile
            if (not current_user.current_profile()):
                # Redirect to the unauthorized page
                flash('Please choose a profile before accessing the app.', 'info')
                return redirect(url_for('main.profiles')) #lo que sea que llamen la funcion de la ruta para elegir perfil

            # It's OK to call the view
            return view_function(*args, **kwargs)
Exemplo n.º 9
0
def unread(id):
    theBook = Book.query.get_or_404(id)
    profile = current_user.current_profile()
    profile.unread(theBook)
    flash('El libro ya no esta marcado como leido.', 'info')
    return redirect(url_for('main.book', id=id))
Exemplo n.º 10
0
def favourites():
    favs = current_user.current_profile().favourites
    return render_template('favs.html', favs=favs, profile=current_user.current_profile())
Exemplo n.º 11
0
def history():
    nav_history = NavigationHistoryEntry.query.filter_by(owner=current_user.current_profile()).order_by(NavigationHistoryEntry.date_posted).all()
    return render_template('history.html', nav_history=nav_history, title='Historial', legend='Historial' )