コード例 #1
0
def video_update(video_id, bookmark=None):
    if not bookmark:
        video = Bookmark.query.get_or_404(video_id)

    form = VideoUpdateForm()

    if form.validate_on_submit():
        video.header = form.header.data
        video.URL = form.URL.data
        video.timestamp = timestamp_parser(form.timestamp.data)
        video.comment = form.comment.data
        video.read_status = form.read_status.data

        try:
            db.session().commit()
        except IntegrityError:
            db.session.rollback()
            return render_template("update/video/edit.html",
                                   form=form,
                                   video_id=video_id)

        return redirect(url_for("get_bookmark", bookmark_id=video_id))

    form.header.data = video.header
    form.comment.data = video.comment
    form.URL.data = video.URL
    form.timestamp.data = video.timestamp
    form.read_status.data = video.read_status
    return render_template("bookmarks/video/edit.html",
                           form=form,
                           video_id=video_id)
コード例 #2
0
def video_create():
    form = VideoForm()

    if request.method == "GET":
        return render_template("bookmarks/video/new.html", form=form)

    if not form.header.data:
        try:
            title = get_video_title(form.URL.data)
            form.header.data = title
            flash('Title updated')
            return render_template("bookmarks/video/new.html", form=form)
        except RuntimeError:
            flash('Check the link')
            return render_template("bookmarks/video/new.html", form=form)

    if form.validate_on_submit():
        video = Video(header=form.header.data,
                      comment=form.comment.data,
                      URL=form.URL.data,
                      timestamp=timestamp_parser(form.timestamp.data))
        db.session().add(video)
        try:
            db.session().commit()
        except IntegrityError:
            db.session.rollback()
            return render_template("/bookmarks/video/new.html")
        return redirect(url_for("get_bookmark", bookmark_id=video.id))

    return render_template("bookmarks/video/new.html", form=form)
コード例 #3
0
ファイル: book.py プロジェクト: otahontas/tuho
def book_update(book_id, bookmark=None):
    if not bookmark:
        bookmark = Bookmark.query.get_or_404(book_id)

    form = BookUpdateForm()

    if form.validate_on_submit():
        bookmark.header = form.header.data
        bookmark.writer = form.writer.data
        bookmark.comment = form.comment.data
        bookmark.image = form.image.data
        bookmark.ISBN = form.ISBN.data
        bookmark.read_status = form.read_status.data

        try:
            db.session().commit()
        except IntegrityError:
            db.session.rollback()
            return render_template("bookmarks/book/edit.html",
                                   form=form,
                                   bookmark_id=book_id,
                                   ISBN_taken=True)

        return redirect(url_for("get_bookmark", bookmark_id=book_id))

    form.header.data = bookmark.header
    form.comment.data = bookmark.comment
    form.writer.data = bookmark.writer
    form.ISBN.data = bookmark.ISBN
    form.image.data = bookmark.image
    form.read_status.data = bookmark.read_status
    return render_template("bookmarks/book/edit.html",
                           form=form,
                           bookmark_id=book_id)
コード例 #4
0
def update_timestamp(bookmark_id):
    video = Video.query.get_or_404(bookmark_id)
    form = UpdateTimestampForm()

    if form.validate_on_submit():
        video.timestamp = timestamp_parser(form.timestamp.data)
        try:
            db.session().commit()
        except IntegrityError:
            db.session.rollback()

    return redirect(url_for("get_bookmark", bookmark_id=bookmark_id))
コード例 #5
0
ファイル: views.py プロジェクト: otahontas/tuho
def update_comment(bookmark_id):
    bookmark = Bookmark.query.get_or_404(bookmark_id)
    form = UpdateCommentForm()

    if form.validate_on_submit():
        bookmark.comment = form.comment.data
        try:
            db.session().commit()
        except IntegrityError:
            db.session.rollback()

    return redirect(url_for("get_bookmark", bookmark_id=bookmark_id))
コード例 #6
0
ファイル: book.py プロジェクト: otahontas/tuho
def book_create():
    form = BookForm()

    if request.method == "GET":
        return render_template("bookmarks/book/new.html", form=form)

    prefilled = request.args.get('prefilled')
    form.ISBN.data = re.sub(r'[^\d]*', '', form.ISBN.data)

    if is_valid_isbn(form.ISBN.data):
        if not prefilled:
            try:
                book_details = resolve_book_details(form.ISBN.data)
                form.header.data = book_details.get("title")
                form.writer.data = book_details.get("author")
                form.image.data = book_details.get("image")
                flash('Name and writer resolved successfully, ' +
                      'please check that details are correct')
                return render_template("/bookmarks/book/new.html",
                                       form=form,
                                       prefilled=True)
            except (RuntimeError):
                flash(
                    'Book fetch failed, please give name and title for book yourself'
                )
                return render_template("/bookmarks/book/new.html",
                                       form=form,
                                       prefilled=True)
        else:
            book = Book(header=form.header.data,
                        writer=form.writer.data,
                        comment=form.comment.data,
                        ISBN=form.ISBN.data,
                        image=form.image.data)
    else:
        flash('ISBN given was not valid, please give a valid ISBN instead')
        return render_template("/bookmarks/book/new.html", form=form)

    if form.validate_on_submit():
        db.session().add(book)
        try:
            db.session().commit()
        except IntegrityError:
            db.session.rollback()
            flash('Book with given ISBN was already in the database')
            return render_template("/bookmarks/book/new.html", form=form)

        flash('Book succefully added')
        return redirect(url_for("get_bookmark", bookmark_id=book.id))
    else:
        return render_template("bookmarks/book/new.html", form=form)