Пример #1
0
def edit(ID):
    from psycopg2 import DatabaseError
    if not allowed_knowl_id.match(ID):
        flask.flash("""Oops, knowl id '%s' is not allowed.
                  It must consist of lowercase characters,
                  no spaces, numbers or '.', '_' and '-'.""" % ID, "error")
        return flask.redirect(url_for(".index"))
    knowl = Knowl(ID)

    lock = None
    if request.args.get("lock", "") != 'ignore':
        try:
            lock = knowldb.is_locked(knowl.id)
        except DatabaseError as e:
            logger.info("Oops, failed to get the lock. Error: %s" %e)
    author_edits = lock and lock['who'] == current_user.get_id()
    logger.debug(author_edits)
    if author_edits:
        lock = None
    if not lock:
        try:
            knowldb.set_locked(knowl, current_user.get_id())
        except DatabaseError as e:
            logger.info("Oops, failed to set the lock. Error: %s" %e)

    b = get_bread([("Edit '%s'" % ID, url_for('.edit', ID=ID))])
    return render_template("knowl-edit.html",
                           title="Edit Knowl '%s'" % ID,
                           k=knowl,
                           bread=b,
                           lock=lock)
Пример #2
0
def edit(ID):
    from pymongo.errors import OperationFailure 
    if not allowed_knowl_id.match(ID):
        flask.flash("""Oops, knowl id '%s' is not allowed.
                  It must consist of lowercase characters,
                  no spaces, numbers or '.', '_' and '-'.""" % ID, "error")
        return flask.redirect(url_for(".index"))
    knowl = Knowl(ID)

    from knowl import is_locked, set_locked
    lock = False
    if request.args.get("lock", "") != 'ignore':
        try:
            lock = is_locked(knowl.id)
        except OperationFailure as e:
            logger.info("Oops, failed to get the lock. Error: %s" %e)
            pass;
    # lock, if either lock is false or (lock is active), current user is editing again
    author_edits = lock and lock['who'] == current_user.get_id()
    logger.debug(author_edits)
    if not lock or author_edits:
        try:
            set_locked(knowl, current_user.get_id())
        except OperationFailure as e:
            logger.info("Oops, failed to set the lock. Error: %s" %e)
            pass;
    if author_edits:
        lock = False

    b = get_bread([("Edit '%s'" % ID, url_for('.edit', ID=ID))])
    return render_template("knowl-edit.html",
                           title="Edit Knowl '%s'" % ID,
                           k=knowl,
                           bread=b,
                           lock=lock)
Пример #3
0
def edit(ID):
    from psycopg2 import DatabaseError
    if not allowed_knowl_id.match(ID):
        flask.flash(
            """Oops, knowl id '%s' is not allowed.
                  It must consist of lowercase characters,
                  no spaces, numbers or '.', '_' and '-'.""" % ID, "error")
        return flask.redirect(url_for(".index"))
    knowl = Knowl(ID)

    lock = None
    if request.args.get("lock", "") != 'ignore':
        try:
            lock = knowldb.is_locked(knowl.id)
        except DatabaseError as e:
            logger.info("Oops, failed to get the lock. Error: %s" % e)
    author_edits = lock and lock['who'] == current_user.get_id()
    logger.debug(author_edits)
    if author_edits:
        lock = None
    if not lock:
        try:
            knowldb.set_locked(knowl, current_user.get_id())
        except DatabaseError as e:
            logger.info("Oops, failed to set the lock. Error: %s" % e)

    b = get_bread([("Edit '%s'" % ID, url_for('.edit', ID=ID))])
    return render_template("knowl-edit.html",
                           title="Edit Knowl '%s'" % ID,
                           k=knowl,
                           bread=b,
                           lock=lock)
Пример #4
0
def edit(ID):
    from pymongo.errors import OperationFailure 
    if not allowed_knowl_id.match(ID):
        flask.flash("""Oops, knowl id '%s' is not allowed.
                  It must consist of lowercase characters,
                  no spaces, numbers or '.', '_' and '-'.""" % ID, "error")
        return flask.redirect(url_for(".index"))
    knowl = Knowl(ID)

    from knowl import is_locked, set_locked
    lock = False
    if request.args.get("lock", "") != 'ignore':
        try:
            lock = is_locked(knowl.id)
        except OperationFailure as e:
            logger.info("Oops, failed to get the lock. Error: %s" %e)
            pass;
    # lock, if either lock is false or (lock is active), current user is editing again
    author_edits = lock and lock['who'] == current_user.get_id()
    logger.debug(author_edits)
    if not lock or author_edits:
        try:
            set_locked(knowl, current_user.get_id())
        except OperationFailure as e:
            logger.info("Oops, failed to set the lock. Error: %s" %e)
            pass;
    if author_edits:
        lock = False

    b = get_bread([("Edit '%s'" % ID, url_for('.edit', ID=ID))])
    return render_template("knowl-edit.html",
                           title="Edit Knowl '%s'" % ID,
                           k=knowl,
                           bread=b,
                           lock=lock)
Пример #5
0
def test():
    """
    just a test page
    """
    logger.info("test")
    return render_template(
        "knowl-test.html", bread=get_bread([("Test", url_for(".test"))]), title="Knowledge Test", k1=Knowl("k1")
    )
Пример #6
0
def test():
    """
    just a test page
    """
    logger.info("test")
    return render_template("knowl-test.html",
                           bread=get_bread([("Test", url_for(".test"))]),
                           title="Knowledge Test",
                           k1=Knowl("k1"))
Пример #7
0
def edit(ID):
    from psycopg2 import DatabaseError
    if not allowed_id(ID):
        return redirect(url_for(".index"))
    knowl = Knowl(ID, editing=True)
    for elt in knowl.edit_history:
        # We will be printing these within a javascript ` ` string
        # so need to escape backticks
        elt['content'] = json.dumps(elt['content'])
    author = knowl._last_author
    # Existing comments can only be edited by admins and the author
    if knowl.type == -2 and author and not (current_user.is_admin() or
                                            current_user.get_id() == author):
        flash_error("You can only edit your own comments")
        return redirect(url_for(".show", ID=knowl.source))

    lock = None
    if request.args.get("lock", "") != 'ignore':
        try:
            lock = knowldb.is_locked(knowl.id)
        except DatabaseError as e:
            logger.info("Oops, failed to get the lock. Error: %s" % e)
    author_edits = lock and lock['username'] == current_user.get_id()
    logger.debug(author_edits)
    if author_edits:
        lock = None
    if not lock:
        try:
            knowldb.set_locked(knowl, current_user.get_id())
        except DatabaseError as e:
            logger.info("Oops, failed to set the lock. Error: %s" % e)

    b = get_bread([("Edit '%s'" % ID, url_for('.edit', ID=ID))])
    if knowl.type == -2:
        title = "Comment on '%s'" % knowl.source
    elif knowl.type == 0:
        title = "Edit Knowl '%s'" % ID
    elif knowl.type == 2:
        pieces = ID.split(".")
        title = f"Edit column information for '{pieces[2]}' in '{pieces[1]}'"
        knowl.title = f"Column {pieces[2]} of table {pieces[1]}"
        from lmfdb import db
        if pieces[1] in db.tablenames:
            knowl.coltype = db[pieces[1]].col_type.get(pieces[2], "DEFUNCT")
        else:
            knowl.coltype = "DEFUNCT"
    else:
        ann_type = 'Top' if knowl.type == 1 else 'Bottom'
        title = 'Edit %s Knowl for <a href="/%s">%s</a>' % (
            ann_type, knowl.source, knowl.source_name)
    return render_template("knowl-edit.html",
                           title=title,
                           k=knowl,
                           bread=b,
                           lock=lock)
Пример #8
0
def edit(ID):
    from psycopg2 import DatabaseError
    if not allowed_id(ID):
        return redirect(url_for(".index"))
    knowl = Knowl(ID, editing=True)
    for elt in knowl.edit_history:
        # We will be printing these within a javascript ` ` string
        # so need to escape backticks
        elt['content'] = json.dumps(elt['content'])
    author = knowl._last_author
    # Existing comments can only be edited by admins and the author
    if knowl.type == -2 and author and not (current_user.is_admin() or current_user.get_id() == author):
        flash("You can only edit your own comments", "error")
        return redirect(url_for(".show", ID=knowl.source))

    lock = None
    if request.args.get("lock", "") != 'ignore':
        try:
            lock = knowldb.is_locked(knowl.id)
        except DatabaseError as e:
            logger.info("Oops, failed to get the lock. Error: %s" %e)
    author_edits = lock and lock['username'] == current_user.get_id()
    logger.debug(author_edits)
    if author_edits:
        lock = None
    if not lock:
        try:
            knowldb.set_locked(knowl, current_user.get_id())
        except DatabaseError as e:
            logger.info("Oops, failed to set the lock. Error: %s" %e)

    b = get_bread([("Edit '%s'" % ID, url_for('.edit', ID=ID))])
    if knowl.type == -2:
        title = "Comment on '%s'" % knowl.source
    elif knowl.type == 0:
        title = "Edit Knowl '%s'" % ID
    else:
        ann_type = 'Top' if knowl.type == 1 else 'Bottom'
        title = 'Edit %s Knowl for <a href="/%s">%s</a>' % (ann_type, knowl.source, knowl.source_name)
    return render_template("knowl-edit.html",
                           title=title,
                           k=knowl,
                           bread=b,
                           lock=lock)