コード例 #1
0
def edit_bookmark(username: str, url_uuid: UUID) -> flask.Response:
    owner = get_user_or_fail(db.session, username)
    require_access_or_fail(
        BookmarkAccessObject(user_uuid=owner.user_uuid, url_uuid=url_uuid),
        Access.WRITE,
    )
    form = flask.request.form
    existing_bookmark = get_bookmark_by_url_uuid(db.session, owner.user_uuid,
                                                 url_uuid)
    if existing_bookmark is None:
        raise exc.NotFound()

    updated_bookmark = Bookmark(
        url=existing_bookmark.url,
        created=existing_bookmark.created,
        title=form["title"],
        description=form["description"],
        unread="unread" in form,
        deleted="deleted" in form,
        updated=datetime.utcnow().replace(tzinfo=timezone.utc),
        tag_triples=tag_triples_from_form(
            form, current=existing_bookmark.tag_triples),
    )

    merged_bookmark = updated_bookmark.merge(existing_bookmark)

    set_bookmark(db.session, get_cache(), owner.user_uuid, merged_bookmark)
    db.session.commit()
    flask.flash("Edited: %s" % merged_bookmark.title)
    return flask.make_response("ok")
コード例 #2
0
ファイル: blueprint.py プロジェクト: RQuintin/quarchive
def edit_bookmark_form(url_uuid: UUID) -> flask.Response:
    bookmark = get_bookmark_by_url_uuid(
        db.session, get_current_user().user_uuid, url_uuid
    )
    if bookmark is None:
        # FIXME: er, write a test for this
        flask.abort(404, description="bookmark not found")

    # Step one, load the template kwargs from the bookmark
    template_kwargs: Dict[str, Any] = dict(
        url=bookmark.url.to_string(),
        title=bookmark.title,
        description=bookmark.description,
        page_title="Edit %s" % bookmark.title,
        url_uuid=url_uuid,
        tags=bookmark.current_tags(),
    )
    if bookmark.unread:
        template_kwargs["unread"] = "on"

    # Then update it from the querystring
    template_kwargs.update(form_fields_from_querystring(flask.request.args))

    template_kwargs["tags_with_count"] = tags_with_count(db.session, get_current_user())
    template_kwargs["deleted"] = bookmark.deleted

    return flask.make_response(
        flask.render_template("edit_bookmark.html", **template_kwargs)
    )
コード例 #3
0
def get_bookmark_by_url_uuid_or_fail(session: Session, user_uuid: UUID,
                                     url_uuid: UUID) -> Bookmark:
    bookmark = get_bookmark_by_url_uuid(session, user_uuid, url_uuid)
    if bookmark is None:
        flask.abort(404, description="bookmark not found")
    else:
        return bookmark
コード例 #4
0
def test_quick_add_tag(session, cache, signed_in_client, test_user):
    bm = make_bookmark()
    set_bookmark(session, cache, test_user.user_uuid, bm)

    response = signed_in_client.post(
        flask.url_for(
            "quarchive.quick_add_tag",
            username=test_user.username,
            url_uuid=bm.url.url_uuid,
        ),
        data={"tag": "test-tag"},
    )
    assert response.status_code == 303

    new_bm = get_bookmark_by_url_uuid(session, test_user.user_uuid,
                                      bm.url.url_uuid)
    assert new_bm is not None
    assert "test-tag" in new_bm.current_tags()