示例#1
0
文件: views.py 项目: papain/nbproject
def saveNote(payload, req):
    uid = UR.getUserId(req)
    if not auth.canAnnotate(uid, payload["id_ensemble"]):
        return UR.prepare_response({}, 1, "NOT ALLOWED")
    payload["id_author"] = uid
    retval = {}
    a = annotations.addNote(payload)
    if len(a) == 0:
        return UR.prepare_response({}, 2, "DUPLICATE")
    tms = {}
    for mark in payload["marks"]:
        tm = M.ThreadMark()
        m_types = [c[0] for c in tm.TYPES if c[1] == mark]
        if len(
                m_types
        ):  #old clients may return types we don't have in DB so ignore them
            tm.type = m_types[0]
            tm.user_id = uid
            tm.comment = a[0]
            tm.location_id = tm.comment.location_id
            tm.save()
            tms[tm.id] = UR.model2dict(tm)
    retval["locations"], html5 = annotations.getLocation(a[0].location_id)
    if (html5 is not None):
        retval["html5locations"] = html5
    retval["comments"] = {}
    retval["tags"] = {}
    for annotation in a:
        retval["comments"].update(annotations.getComment(annotation.id, uid))
        retval["tags"].update(annotations.getTagsByComment(annotation.id))
    retval["threadmarks"] = tms
    return UR.prepare_response(retval)
示例#2
0
def saveNote(payload, req):
    uid = UR.getUserId(req)
    if not auth.canAnnotate(uid,  payload["id_ensemble"]):
        return UR.prepare_response({}, 1,  "NOT ALLOWED")
    payload["id_author"] = uid
    retval = {}
    a = annotations.addNote(payload)
    if len(a) == 0:
        return UR.prepare_response({}, 2,  "DUPLICATE")
    tms = {}
    for mark in payload["marks"]:
        tm = M.ThreadMark()
        m_types = [c[0] for c in tm.TYPES if c[1]==mark]
        if len(m_types): #old clients may return types we don't have in DB so ignore them
            tm.type = m_types[0]
            tm.user_id = uid
            tm.comment=a[0]
            tm.location_id=tm.comment.location_id
            tm.save()
            tms[tm.id] = UR.model2dict(tm)
    retval["locations"], html5 = annotations.getLocation(a[0].location_id)
    if (html5 is not None):
        retval["html5locations"]=html5
    retval["comments"] = {}
    retval["tags"] = {}
    for annotation in a:
        retval["comments"].update(annotations.getComment(annotation.id, uid))
        retval["tags"].update(annotations.getTagsByComment(annotation.id))
    retval["threadmarks"] =  tms
    return UR.prepare_response(retval)
示例#3
0
def saveNote(payload, req): 
    uid = UR.getUserId(req)
    if not auth.canAnnotate(uid,  payload["id_ensemble"]):
        return UR.prepare_response({}, 1,  "NOT ALLOWED")
 
    payload["id_author"] = uid
    retval = {}
    a = annotations.addNote(payload)
    #for mark in payload["marks"]:
    #    annotations.markNote(uid, {"action": payload["marks"][mark], "id_comment": a["id_comment"]})
    if "id_location" in a:
        retval["locations"] = annotations.getLocation(a["id_location"])
    retval["comments"] = annotations.getComment(a["id_comment"], uid)
    retval["marks"] =  annotations.getMark(uid,{"id_comment":  a["id_comment"]})
    return UR.prepare_response(retval)
示例#4
0
def saveNote(payload, req):
    uid = UR.getUserId(req)
    if not auth.canAnnotate(uid, payload["id_ensemble"]):
        return UR.prepare_response({}, 1, "NOT ALLOWED")

    payload["id_author"] = uid
    retval = {}
    a = annotations.addNote(payload)
    #for mark in payload["marks"]:
    #    annotations.markNote(uid, {"action": payload["marks"][mark], "id_comment": a["id_comment"]})
    if "id_location" in a:
        retval["locations"] = annotations.getLocation(a["id_location"])
    retval["comments"] = annotations.getComment(a["id_comment"], uid)
    retval["marks"] = annotations.getMark(uid, {"id_comment": a["id_comment"]})
    return UR.prepare_response(retval)
示例#5
0
def saveNote(payload, req): 
    uid = UR.getUserId(req)
    if not auth.canAnnotate(uid,  payload["id_ensemble"]):
        return UR.prepare_response({}, 1,  "NOT ALLOWED") 
    payload["id_author"] = uid
    retval = {}
    a = annotations.addNote(payload)
    tms = {}
    for mark in payload["marks"]:
        tm = M.ThreadMark()
        m_types = [c[0] for c in tm.TYPES if c[1]==mark]
        if len(m_types): #old clients may return types we don't have in DB so ignore them 
            tm.type = m_types[0]
            tm.user_id = uid         
            tm.comment=a
            tm.location_id=a.location_id
            tm.save()
            tms[tm.id] = UR.model2dict(tm)  
    retval["locations"] = annotations.getLocation(a.location_id)
    retval["comments"] = annotations.getComment(a.id, uid)
    retval["threadmarks"] =  tms
    return UR.prepare_response(retval)