def edit_post(id=0): label = db.query(Label).get(id) if not label: return "label {} not found".format(id) if access.access(label) < access.EDIT: return "access forbidden to {}".format(id) try: action = get_arg("action") if action == "set_name": label.name = get_arg("name") db.commit() return "success: name set" elif action == "delete": label.labels.clear() db.delete(label) db.commit() return "success: deleted" else: return "nothing done" except Exception as e: print("===== labels =====") print(e) print("==================") db.rollback() return str(e)
def add(): if "q" in request.args: words = extended_split(request.args.get("q")) key, url, search = (words + 3 * [""])[:3] print("=======q=", [request.args.get("q"), key, url, search]) return redirect(url_for("search.add", key=key, url=url, search=search)) elif "key" in request.args and request.args.get("url"): key = request.args.get("key") # why to control key? #if not key.replace(" ","").replace("_","").replace("-","").isalnum(): # return "Invalid key." url = request.args.get("url") engine = db.query(SearchEngine).filter_by( key=key, author=current_user).one_or_none() if engine: force = request.args.get("force") if not force == "True": return render_template( "add.html", caption="{key} already points at {url}".format( key=key, url=engine.search if engine.search else engine.url), key=request.args.get("key", ""), url=request.args.get("url", ""), search=request.args.get("search", ""), force="True", button="Override") else: print("===========editing==to==", url) engine.url = url engine.search = request.args.get("search") db.commit() else: engine = SearchEngine( url=url, key=key, search=request.args.get("search"), ) db.add(engine) db.commit() return """ <b>{key}</b> -> {url} <br/> added <br/> <a href="{url}">back</a> """.format(key=key, url=engine.url) else: return render_template( "add.html", caption="example search: https://www.google.com/search?q={query}", key=request.args.get("key", ""), url=request.args.get("url", ""), search=request.args.get("search", ""), force="", button="Submit")
def load_or_write(key): item = db.query(Sensitive).get(key) if not item: value = input("Enter " + key + ":") db.add(Sensitive(key=key,value=value)) db.commit() else: value = item.value return value
def add_user(name, pasw): salt = crypto.get_random_iid() pasw = hash(pasw + salt) user = User( name=name, pasw=pasw, salt=salt ) db.add(user) db.commit() return user
def internal_add(name, url, author, lbls=[], t=None): if t == None: t = int(time.time()) bm = Bookmark(name=name, url=url, created_timestamp=t, updated_timestamp=t, author=author) for label in lbls: bm.labels.append(label) print("======", bm.to_dict()) print("======", type(bm.labels)) db.add(bm) db.commit() return bm
def get_self_access_policy(): ap = AccessPolicy( secret=crypto.get_random_secret(), with_secret_can=NOTHING, public_can=NOTHING ) db.add(ap) db.commit() ua = UserAccess( user_id=current_user.id, access_policy_id=ap.id, user_can=ADMIN ) ap.individuals.append(ua) db.add(ua) db.commit() return ap
def internal_add(name, author, labels=[], t=None): if t == None: t = int(time.time()) if db.query(Label).filter_by(name=name, author=author).all(): label = db.query(Label).filter_by(name=name, author=author).first() else: label = Label(name=name, author=author, created_timestamp=t, updated_timestamp=t) db.add(label) for l in labels: if not l in label.labels: label.labels.append(l) db.commit() return label
def append(id=0): note = db.query(Note).get(id) if not note: flash("Note {} not found.".format(id)) return redirect(url_for('notes.index')) if access.access(note) < access.EDIT: return access.forbidden_page() line = request.args.get('line') if line == None: flash("`line` arg required.") return redirect(url_for('notes.index')) note.text += " \n" + line db.commit() flash("<i>{}</i> appended to {}.".format(line, note.name)) return redirect(url_for("notes.view", id=id))
def edit_post(id=0): bm = db.query(Bookmark).get(id) if not bm: flash("Bookmark {} not found.".format(id)) return redirect(url_for('labels.index')) if access.access(bm) < access.EDIT: return access.forbidden_page() try: action = get_arg("action") if action == "set_name": bm.name = get_arg("name") db.commit() return "success: name set" elif action == "set_url": bm.url = get_arg("url") db.commit() return "success: url set" elif action == "delete": bm.labels.clear() db.delete(bm) db.commit() return "success: deleted" else: return "nothing done" except Exception as e: print("===== bookmarks =====") print(e) print("==================") db.rollback() return str(e)
def edit(id=0): note = db.query(Note).get(id) if not note: flash("Note {} not found.".format(id)) return redirect(url_for('notes.index')) if access.access(note) < access.EDIT: return access.forbidden_page() if request.args.get("action") == "view": note.text = request.args.get("text") note.name = request.args.get("name") db.commit() flash("{} saved.".format(note.name)) return redirect(url_for("notes.view", id=id)) elif request.args.get("action") == "save": note.text = request.args.get("text") note.name = request.args.get("name") db.commit() flash("{} saved.".format(note.name)) return redirect(url_for("notes.edit", id=id)) elif request.args.get("action") == "delete": note.labels.clear() db.delete(note) db.commit() flash("{} deleted.".format(note.name)) return redirect(url_for('notes.index')) else: return render_template( 'edit_note.html', note=note, )
def edit_post(id=0): node = db.query(Node).get(id) if not node: return "node {} not found".format(id) if access.access(node) < access.EDIT: return "access forbidden to node {}".format(id) try: action = get_arg("action") if action == "remove_label": label_name = get_arg("label_name") label = db.query(Label).filter_by( author=current_user, name=label_name, ).one_or_none() node.labels.remove(label) db.commit() return "success: label removed" elif action == "add_label": label_name = get_arg("label_name") label = db.query(Label).filter_by( author=current_user, name=label_name, ).one_or_none() if not label: label = Label(name=name) db.add(label) db.commit() node.labels.append(label) db.commit() return "success: label added" else: return "nothing done" except Exception as e: print("===== nodes =====") print(e) print("==================") db.rollback() return str(e)
import json from chuml.auth import auth from chuml.search import bookmarks from chuml.search import labels from chuml.utils import db from chuml.search import search #db.db_path = "../../db" author = db.query(auth.User).filter_by(name="agi").first() with open("/home/agi/backups/engines-2020-12-26.json") as file: engines = json.load(file) for key, data in engines.items(): e = search.SearchEngine(key=key, author=author) if "search" in data: e.search = data["search"] if "url" in data: e.url = data["url"] else: print("engine without url", key) db.add(e) db.commit() print(key)
def log(text): db.add(Log(text=text, time=int(time.time()))) db.commit()
def create(): note = Note(text=request.args.get("text"), name=request.args.get("name")) db.add(note) db.commit() return redirect(url_for("notes.edit", id=note.id))