Ejemplo n.º 1
0
def create_note(title, text, source, tags, nid, reminder, queue_schedule):

    #clean the text
    text = utility.text.clean_user_note_text(text)

    if source is not None:
        source = source.strip()

    if (len(text) + len(title)) == 0:
        return

    if tags is not None and len(tags.strip()) > 0:
        tags = " %s " % tags.strip()
    else:
        tags = ""

    pos = None
    if queue_schedule != 1:
        list = _get_priority_list()
        if QueueSchedule(queue_schedule) == QueueSchedule.HEAD:
            pos = 0
        elif QueueSchedule(queue_schedule) == QueueSchedule.FIRST_THIRD:
            pos = int(len(list) / 3.0)
        elif QueueSchedule(queue_schedule) == QueueSchedule.SECOND_THIRD:
            pos = int(2 * len(list) / 3.0)
        elif QueueSchedule(queue_schedule) == QueueSchedule.END:
            pos = len(list)
        elif QueueSchedule(queue_schedule) == QueueSchedule.RANDOM:
            pos = random.randint(0, len(list))
        elif QueueSchedule(queue_schedule) == QueueSchedule.RANDOM_FIRST_THIRD:
            pos = random.randint(0, int(len(list) / 3.0))
        elif QueueSchedule(
                queue_schedule) == QueueSchedule.RANDOM_SECOND_THIRD:
            pos = random.randint(int(len(list) / 3.0),
                                 int(len(list) * 2 / 3.0))
        elif QueueSchedule(queue_schedule) == QueueSchedule.RANDOM_THIRD_THIRD:
            pos = random.randint(int(len(list) * 2 / 3.0),
                                 int(len(list) * 3 / 3.0))

    conn = _get_connection()
    if pos is not None:
        pos_list = [(ix if ix < pos else ix + 1, r[0])
                    for ix, r in enumerate(list)]
        conn.executemany("update notes set position = ? where id = ?",
                         pos_list)

    id = conn.execute(
        """insert into notes (title, text, source, tags, nid, created, modified, reminder, lastscheduled, position)
                values (?,?,?,?,?,datetime('now', 'localtime'),""," ","", ?)""",
        (title, text, source, tags, nid, pos)).lastrowid
    conn.commit()
    conn.close()
    index = get_index()
    if index is not None:
        index.add_user_note((id, title, text, source, tags, nid, ""))
Ejemplo n.º 2
0
def update_note(id, title, text, source, tags, reminder, queue_schedule):

    text = utility.text.clean_user_note_text(text)
    tags = " %s " % tags.strip()
    conn = _get_connection()
    sql = """
        update notes set title=?, text=?, source=?, tags=?, modified=datetime('now', 'localtime') where id=?
    """

    pos = None
    orig_prio_list = _get_priority_list()
    note_had_position = False
    list = []
    for li in orig_prio_list:
        if li[0] == id:
            note_had_position = True
        else:
            list.append(li)
    if queue_schedule != 1:
        if QueueSchedule(queue_schedule) == QueueSchedule.HEAD:
            pos = 0
        elif QueueSchedule(queue_schedule) == QueueSchedule.FIRST_THIRD:
            pos = int(len(list) / 3.0)
        elif QueueSchedule(queue_schedule) == QueueSchedule.SECOND_THIRD:
            pos = int(2 * len(list) / 3.0)
        elif QueueSchedule(queue_schedule) == QueueSchedule.END:
            pos = len(list)
        elif QueueSchedule(queue_schedule) == QueueSchedule.RANDOM:
            pos = random.randint(0, len(list))
        elif QueueSchedule(queue_schedule) == QueueSchedule.RANDOM_FIRST_THIRD:
            pos = random.randint(0, int(len(list) / 3.0))
        elif QueueSchedule(
                queue_schedule) == QueueSchedule.RANDOM_SECOND_THIRD:
            pos = random.randint(int(len(list) / 3.0),
                                 int(len(list) * 2 / 3.0))
        elif QueueSchedule(queue_schedule) == QueueSchedule.RANDOM_THIRD_THIRD:
            pos = random.randint(int(len(list) * 2 / 3.0),
                                 int(len(list) * 3 / 3.0))
        sql = """
            update notes set title=?, text=?, source=?, tags=?, position=%s, modified=datetime('now', 'localtime') where id=?
        """ % pos
    else:
        if note_had_position:
            sql = "update notes set title=?, text=?, source=?, tags=?, modified=datetime('now', 'localtime') where id=?"
        else:
            sql = "update notes set title=?, text=?, source=?, tags=?, position=null, modified=datetime('now', 'localtime') where id=?"

    conn.execute(sql, (title, text, source, tags, id))

    if pos is not None:
        list.insert(pos, (id, ))
        pos_list = [(ix, r[0]) for ix, r in enumerate(list)]
        conn.executemany("update notes set position = ? where id = ?",
                         pos_list)
    conn.commit()
    conn.close()
    index = get_index()
    if index is not None:
        index.update_user_note((id, title, text, source, tags, -1, ""))
Ejemplo n.º 3
0
def create_note(title, text, source, tags, nid, reminder, queue_schedule):

    #clean the text
    text = utility.text.clean_user_note_text(text)

    if source is not None:
        source = source.strip()
    if (len(text) + len(title)) == 0:
        return
    if tags is not None and len(tags.strip()) > 0:
        tags = " %s " % tags.strip()
    else: 
        tags = ""

    conn = _get_connection()
    id = conn.execute("""insert into notes (title, text, source, tags, nid, created, modified, reminder, lastscheduled, position)
                values (?,?,?,?,?,datetime('now', 'localtime'),""," ","", NULL)""", (title, text, source, tags, nid)).lastrowid
    conn.commit()
    conn.close()
    if queue_schedule != QueueSchedule.NOT_ADD:
        update_priority_list(id, queue_schedule)
    index = get_index()
    if index is not None:
        index.add_user_note((id, title, text, source, tags, nid, ""))
Ejemplo n.º 4
0
def update_note(id, title, text, source, tags, reminder, queue_schedule):

    text = utility.text.clean_user_note_text(text)
    tags = " %s " % tags.strip()
    mod = _date_now_str()
    sql = f"update notes set title=?, text=?, source=?, tags=?, modified='{mod}' where id=?"
    conn = _get_connection()
    conn.execute(sql, (title, text, source, tags, id))
    conn.commit()
    conn.close()
    # if schedule is NOT_ADD/keep priority, don't recalc queue
    if queue_schedule != QueueSchedule.NOT_ADD.value:
        update_priority_list(id, queue_schedule)
    index = get_index()
    if index is not None:
        index.update_user_note((id, title, text, source, tags, -1, ""))