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)
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)
def editNote(payload, req): uid = UR.getUserId(req) if not auth.canEdit(uid, payload["id_comment"]): return UR.prepare_response({}, 1, "NOT ALLOWED") else: edited_loc = annotations.editNote(payload) tags = {} tags.update(annotations.getTagsByComment(payload["id_comment"])) #no need to worry about threadmarks: they can't be changed from an "edit-mode" editor retval = {"comments": [annotations.getComment(payload["id_comment"], uid)], "tags": tags, "cid": payload["id_comment"]} if not edited_loc == None: retval["edit_location"] = edited_loc return UR.prepare_response(retval)
def editNote(payload, req): uid = UR.getUserId(req) if not auth.canEdit(uid, payload["id_comment"]): return UR.prepare_response({}, 1, "NOT ALLOWED") else: edited_loc = annotations.editNote(payload) tags = {} tags.update(annotations.getTagsByComment(payload["id_comment"])) #no need to worry about threadmarks: they can't be changed from an "edit-mode" editor retval = { "comments": [annotations.getComment(payload["id_comment"], uid)], "tags": tags, "cid": payload["id_comment"] } if not edited_loc == None: retval["edit_location"] = edited_loc return UR.prepare_response(retval)