Exemplo n.º 1
0
def filter_search():
    """
    Filters last search result by whatever was checked
    (done from search page)
    """
    if g.uid:
        # show search results
        if request.method == "POST":
            uid = g.uid
            if session.get("search") is not None:
                last_search = session.get("search")
                input_fields = request.form.getlist("fields")
                # retrieve notes from the database that match the search term
                db_search_results = get_search_notes(uid, last_search,
                                                     input_fields)
                note_data = process_note_results(db_search_results)
                num_results = len(note_data)
                # show the checked fields
                return render_template("search.html",
                                       menu_item="logout",
                                       data=note_data,
                                       num=num_results,
                                       term=last_search,
                                       filters=input_fields)
            else:
                return redirect("/search")
        else:
            return redirect("/search")
    return redirect("/")
Exemplo n.º 2
0
def search():
    """
    Handle search (available only if logged in)
    """
    if g.uid:
        # show search results
        if request.method == "POST":
            uid = g.uid
            # get the search term
            input_term = request.form["search"]
            # store the current search term
            session["search"] = input_term.lower()
            # retrieve notes from the database that match the search term
            db_search_results = get_search_notes(uid, input_term)
            note_data = process_note_results(db_search_results)
            num_results = len(note_data)
            # default filters
            def_filters = ["title", "tags", "content"]
            return render_template("search.html",
                                   menu_item="logout",
                                   data=note_data,
                                   num=num_results,
                                   term=input_term,
                                   filters=def_filters)
        # show empty search page
        else:
            # clear the search term last stored
            session.pop("search", None)
            return render_template(
                "search.html",
                menu_item="logout",
                data={},
                num=0,
                term="(none, please use the search in the menu)")
    return redirect("/")
Exemplo n.º 3
0
def dashboard():
    """
    Dashboard - shows notes for the user
    """
    if g.uid:
        session_user = g.username
        uid = g.uid
        # get the notes associated with the user
        db_user_results = get_notes_by_user(uid)
        note_data = process_note_results(db_user_results)
        # create the welcome message
        msg = create_welcome_message(session_user)
        return render_template("dashboard.html",
                               msg=msg,
                               menu_item="logout",
                               data=note_data)
    return redirect("/")
Exemplo n.º 4
0
def download():
    """
    Download as plain text file the contents of the note
    """
    if g.uid:
        uid = g.uid
        # get the note id from the query string param
        requested_note_id = request.args.get("id")
        # retrieve note from the database
        db_note_results = get_note_by_id(uid, requested_note_id)
        note_data = reformat_for_export(
            process_note_results(db_note_results)[0])
        file_name = "note_" + str(requested_note_id) + ".txt"
        return Response(note_data,
                        mimetype="text/plain",
                        headers={
                            "Content-Disposition":
                            "attachment;filename=" + file_name
                        })
    return redirect("/")
Exemplo n.º 5
0
def view():
    """
    Shows a note based on its id in single note view
    """
    if g.uid:
        uid = g.uid
        # get the note id from the query string param
        if request.args.get("id"):
            # requested_note_id = request.args.get("id")
            session["last_note_id"] = request.args.get("id")
        # if the request didn't include a note id, check the last one
        requested_note_id = session.get("last_note_id")
        # retrieve note from the database
        db_note_results = get_note_by_id(uid, requested_note_id)
        note_data = process_note_results(db_note_results)
        # if the list is empty, redirect!
        if not note_data:
            # add warning in the menu bar
            flash("note not found", "error")
            return redirect("/dashboard")
        return render_template("view.html",
                               menu_item="logout",
                               data=note_data[0])
    return redirect("/")