Exemplo n.º 1
0
def update(id):
    form = request.form
    new = {}
    old_tags = {}
    old_data = qu.query_byid(MarkNote, id).first()
    for key in form.keys():
        new[key] = form[key]
    new["tags"] = new["tags"].replace(' ', '')
    new["tags"] = new["tags"].strip(',')
    if new["title"] == '':
        new["title"] = "untitle"
    if new["tags"] == '':
        new["tags"] = "untag"

    print("update:" + str(new))
    print new["tags"].split(',')
    for tag in old_data.tags.split(','):
        if tag == '':
            print("blank")
            continue
        old_tags[tag] = True

    for tag in new["tags"].split(','):
        if tag == '':
            continue
        if tag in old_tags.keys():
            old_tags[tag] = False
        else:
            rel = Relate()
            check_tag = qu.query_bytitle(Tag, tag).first()
            if check_tag == None:
                new_tag = Tag(tag, 1)
                new_tag.relates += [rel]
                new_tag.add()
            else:
                check_tag.relates += [rel]
                qu.query_update(Tag, check_tag.id,
                                {"count": check_tag.count + 1})

            old_data.relates += [rel]
            old_tags[tag] = False

    for tag in old_tags.keys():
        if old_tags[tag]:
            qu.delete_rel(id, qu.query_bytitle(Tag, tag))

    #new["last_time"] = datetime.now()
    qu.query_update(MarkNote, id, new)

    next_url = request.args.get("next")
    return redirect(next_url)
Exemplo n.º 2
0
def update(id):
    form = request.form
    new = {}
    old_tags = {}
    old_data = qu.query_byid(MarkNote,id).first()
    for key in form.keys():
        new[key] = form[key]
    new["tags"] = new["tags"].replace(' ','')
    new["tags"] = new["tags"].strip(',')
    if new["title"] == '':
        new["title"] = "untitle"
    if new["tags"] == '':
        new["tags"] = "untag"
    
    print("update:"+str(new))
    print new["tags"].split(',')
    for tag in old_data.tags.split(','):
        if tag == '':
            print("blank")
            continue
        old_tags[tag] = True

    for tag in new["tags"].split(','):
        if tag == '':
            continue
        if tag in old_tags.keys():
            old_tags[tag] = False
        else:
            rel = Relate()
            check_tag = qu.query_bytitle(Tag,tag).first()
            if check_tag == None:
                new_tag = Tag(tag,1)
                new_tag.relates += [rel]
                new_tag.add()
            else:
                check_tag.relates += [rel]
                qu.query_update(Tag,check_tag.id,{"count":check_tag.count+1})
            
            old_data.relates += [rel]
            old_tags[tag] = False

    for tag in old_tags.keys():
        if old_tags[tag]:
            qu.delete_rel(id,qu.query_bytitle(Tag,tag))
    
    #new["last_time"] = datetime.now()
    qu.query_update(MarkNote,id,new)

    next_url = request.args.get("next")
    return redirect(next_url)
Exemplo n.º 3
0
def add(title, link, tags, note, time):
    tags = tags.replace(' ', '')
    tags = tags.strip(',')
    if title == '':
        title = "untitle"
    if tags == '':
        tags = "untag"
    new_data = MarkNote(title, link, tags, note, time)
    add_tags = {}
    for t in tags.split(','):
        if t == '':
            continue
        add_tags[t] = True

    for tag in tags.split(','):
        if tag == '':
            continue
        rel = Relate()
        t = qu.query_bytitle(Tag, tag).first()
        if t == None:
            print("new tag:" + tag)
            new_tag = Tag(tag, 1)

            new_data.relates += [rel]
            new_tag.relates += [rel]

            new_tag.add()
            add_tags[tag] = False

        elif add_tags[tag]:
            new_data.relates += [rel]
            t.relates += [rel]
            qu.query_update(Tag, t.id, {"count": t.count + 1})

        add_tags[tag] = False

    new_data.add()
    print("add new marknote:\n" + str(new_data))
Exemplo n.º 4
0
def add(title,link,tags,note,time):
    tags = tags.replace(' ','')
    tags = tags.strip(',')
    if title=='':
        title = "untitle"
    if tags=='':
        tags = "untag"
    new_data = MarkNote(title,link,tags,note,time)
    add_tags = {}
    for t in tags.split(','):
        if t == '':
            continue
        add_tags[t] = True
    
    for tag in tags.split(','):
        if tag == '':
            continue
        rel = Relate()
        t = qu.query_bytitle(Tag,tag).first()
        if t == None:
            print("new tag:"+tag)
            new_tag = Tag(tag,1)

            new_data.relates += [rel]
            new_tag.relates += [rel]

            new_tag.add()
            add_tags[tag] = False

        elif add_tags[tag]:
            new_data.relates += [rel]
            t.relates += [rel]
            qu.query_update(Tag,t.id,{"count":t.count+1})

        add_tags[tag] = False
    
    new_data.add()
    print("add new marknote:\n"+str(new_data))