Ejemplo n.º 1
0
def set_location_section(P, req):
    uid = UR.getUserId(req)
    if not auth.canAdministrateLocation(uid, P["id_location"]):
        return UR.prepare_response({}, 1, "NOT ALLOWED")
    result = annotations.setLocationSection(P["id_location"], P["id_section"])
    locations, html5locations = annotations.getLocation(result.pk)
    return UR.prepare_response(locations)
Ejemplo n.º 2
0
def set_location_section(P, req):
    uid = UR.getUserId(req)
    if not auth.canAdministrateLocation(uid, P["id_location"]):
        return UR.prepare_response({}, 1, "NOT ALLOWED")
    result = annotations.setLocationSection(P["id_location"], P["id_section"])
    locations, html5locations = annotations.getLocation(result.pk)
    return UR.prepare_response( locations )
Ejemplo n.º 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)
    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)
Ejemplo n.º 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)
    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)
Ejemplo n.º 5
0
def get_location_info(payload, req): 
    id = payload["id"]
    uid = UR.getUserId(req);
    #SACHA TODO: check I'm allowed to know this
    retval={}
    retval["locations"], retval["html5locations"] = annotations.getLocation(id)
    if "org" in payload:
        annotations.logDirectURL(uid, id, payload["org"])
    return UR.prepare_response(retval)
Ejemplo n.º 6
0
def get_location_info(payload, req): 
    id = payload["id"]
    uid = UR.getUserId(req);
    #SACHA TODO: check I'm allowed to know this
    retval={}
    retval["locations"], retval["html5locations"] = annotations.getLocation(id)
    if "org" in payload:
        annotations.logDirectURL(uid, id, payload["org"])
    return UR.prepare_response(retval)
Ejemplo n.º 7
0
def markNote(payload, req):
    uid = UR.getUserId(req)
    id_comment =  payload["id_comment"]
    if not auth.canMark(uid,id_comment ):
        return UR.prepare_response({}, 1,  "NOT ALLOWED")
    else: 
        annotations.markNote(uid, payload);        
        comments = annotations.getComment(id_comment,uid)
        p = {"locations":annotations.getLocation(comments[int(id_comment)]["ID_location"]), "marks": annotations.getMark(uid, payload), "comments": comments}
        return UR.prepare_response(p)
Ejemplo n.º 8
0
def markNote(payload, req):
    uid = UR.getUserId(req)
    id_comment =  payload["id_comment"]
    if not auth.canMark(uid,id_comment ):
        return UR.prepare_response({}, 1,  "NOT ALLOWED")
    else: 
        annotations.markNote(uid, payload);        
        comments = annotations.getComment(id_comment,uid)
        p = {"locations":annotations.getLocation(comments[int(id_comment)]["ID_location"]), "marks": annotations.getMark(uid, payload), "comments": comments}
        return UR.prepare_response(p)
Ejemplo n.º 9
0
def get_comment_info(payload, req): 
    id = int(payload["id"])
    uid = UR.getUserId(req);
    #SACHA TODO: check I'm allowed to know this
    retval={}
    comments = annotations.getComment(id, uid)
    id_location = comments[id]["ID_location"]
    retval["comments"] = {id: {"ID": id, "ID_location": id_location}} #share only what's needed
    #print retval["comments"]
    retval["locations"] , retval["html5locations"] = annotations.getLocation( id_location)
    if "org" in payload:
        annotations.logDirectURL(uid, id, payload["org"])
    return UR.prepare_response(retval)
Ejemplo n.º 10
0
def get_comment_info(payload, req): 
    id = int(payload["id"])
    uid = UR.getUserId(req);
    #SACHA TODO: check I'm allowed to know this
    retval={}
    comments = annotations.getComment(id, uid)
    id_location = comments[id]["ID_location"]
    retval["comments"] = {id: {"ID": id, "ID_location": id_location}} #share only what's needed
    #print retval["comments"]
    retval["locations"] , retval["html5locations"] = annotations.getLocation( id_location)
    if "org" in payload:
        annotations.logDirectURL(uid, id, payload["org"])
    return UR.prepare_response(retval)
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
def promote_location_by_copy(P, req):
    uid = UR.getUserId(req)
    if not auth.canAdministrateLocation(uid, P["id_location"]):
        return UR.prepare_response({}, 1, "NOT ALLOWED")
    location_ids, comment_ids = annotations.promoteLocationByCopy(P["id_location"])
    retval = {}
    retval["comments"] = {}
    for cid in comment_ids:
        retval["comments"].update(annotations.getComment(cid, uid))
    retval["locations"] = {}
    retval["html5locations"] = {}
    for lid in location_ids:
        locations, html5locations = annotations.getLocation(lid)
        retval["locations"].update(locations)
        if not html5locations:
            retval["html5locations"].update(html5locations)

    # clear out html5locations if none exist
    if retval["html5locations"]:
        del retval["html5locations"]
    return UR.prepare_response( retval )
Ejemplo n.º 14
0
def promote_location_by_copy(P, req):
    uid = UR.getUserId(req)
    if not auth.canAdministrateLocation(uid, P["id_location"]):
        return UR.prepare_response({}, 1, "NOT ALLOWED")
    location_ids, comment_ids = annotations.promoteLocationByCopy(
        P["id_location"])
    retval = {}
    retval["comments"] = {}
    for cid in comment_ids:
        retval["comments"].update(annotations.getComment(cid, uid))
    retval["locations"] = {}
    retval["html5locations"] = {}
    for lid in location_ids:
        locations, html5locations = annotations.getLocation(lid)
        retval["locations"].update(locations)
        if not html5locations:
            retval["html5locations"].update(html5locations)

    # clear out html5locations if none exist
    if retval["html5locations"]:
        del retval["html5locations"]
    return UR.prepare_response(retval)
Ejemplo n.º 15
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)