示例#1
0
def log_history(payload, req):
    uid =  UR.getUserInfo(req, True).id
    if uid is None: 
        #SACHA TODO: LOG this.
        return UR.prepare_response({}, 1,  "NOT ALLOWED")
    cid = UR.CID
    if cid == 0:        
        return  UR.prepare_response({}, 1, "CID MOST BE NONZERO")
    session, previous_activity = annotations.markActivity(cid)
    if session is None: 
        return  UR.prepare_response({}, 1, "SESSION NOT FOUND")
    id_session = session.id
    output={}
    if "seen" in payload and cid != 0: 
        annotations.markCommentSeen(uid, id_session, payload["seen"])
    if "page" in payload and cid != 0: 
        annotations.markPageSeen(uid, id_session,  payload["page"])
    if "idle" in payload and cid != 0: 
        annotations.markIdle(uid,  id_session, payload["idle"]) 
    if "scrolling" in payload and cid != 0:         
        logger = logging.getLogger("scrolling")
        logger.info("%s|%s"%(id_session, payload["scrolling"]));
    if "__return" in payload and cid != 0:
        R = payload["__return"]
        if R["type"] == "newNotesOnFile": 
            id_source = R["a"]["id_source"]
            if auth.canReadFile(uid, id_source):
                output["locations"], output["html5locations"], output["comments"], output["threadmarks"] = annotations.getCommentsByFile(id_source, uid, previous_activity)
        elif R["type"] == "newPending":
            #for now, we retrieve all the pending stuff. 
            output = annotations.getPending(uid, payload)
    return UR.prepare_response(output)
示例#2
0
def log_history(payload, req):
    uid =  UR.getUserInfo(req, True).id
    if uid is None: 
        #SACHA TODO: LOG this.
        return UR.prepare_response({}, 1,  "NOT ALLOWED")
    cid = UR.CID
    if cid == 0:        
        return  UR.prepare_response({}, 1, "CID MOST BE NONZERO")
    session, previous_activity = annotations.markActivity(cid)
    if session is None: 
        return  UR.prepare_response({}, 1, "SESSION NOT FOUND")
    id_session = session.id
    output={}
    if "seen" in payload and cid != 0: 
        annotations.markCommentSeen(uid, id_session, payload["seen"])
    if "page" in payload and cid != 0: 
        annotations.markPageSeen(uid, id_session,  payload["page"])
    if "idle" in payload and cid != 0: 
        annotations.markIdle(uid,  id_session, payload["idle"]) 
    if "scrolling" in payload and cid != 0:         
        logger = logging.getLogger("scrolling")
        logger.info("%s|%s"%(id_session, payload["scrolling"]));
    if "__return" in payload and cid != 0:
        R = payload["__return"]
        if R["type"] == "newNotesOnFile": 
            id_source = R["a"]["id_source"]
            if auth.canReadFile(uid, id_source):
                output["locations"], output["html5locations"], output["comments"], output["threadmarks"] = annotations.getCommentsByFile(id_source, uid, previous_activity)
        elif R["type"] == "newPending":
            #for now, we retrieve all the pending stuff. 
            output = annotations.getPending(uid, payload)
    return UR.prepare_response(output)
示例#3
0
def serve_img(req, res, scale, id_source):
    #print "img request of page %s of file %s at res %s and scale %s w/ invite_key=%s and req=%s" % (req.GET["page"], id_file, res, scale, req.GET["invite_key"], req  )
    #TODO: check permissions.
    uid = UR.getUserId(req)
    if not auth.canReadFile(uid, id_source):
        return HttpResponse(
            "Error: You don't have credentials to see this file %s " %
            (id_source, ))
    page = int(req.GET["page"]) - 1
    page_str = settings.IMG_FMT_STRING % (page, )
    filename = req.META["PATH_INFO"].rstrip('/')
    filename = "%s_%s.png" % (filename, page_str)
    response = None
    try:
        response = serve(req, filename, settings.HTTPD_MEDIA_CACHE)
        return response
    except Http404:
        #let's generate on demand
        try:
            pdf_dir = "%s/%s" % (settings.HTTPD_MEDIA, settings.REPOSITORY_DIR)
            img_dir = "%s/%s" % (settings.HTTPD_MEDIA_CACHE,
                                 settings.CACHE_DIR)
            process_page(id_source, page, res, scale, pdf_dir, img_dir,
                         settings.IMG_FMT_STRING)
            response = serve(req, filename, settings.HTTPD_MEDIA_CACHE)
            return response
        except Http404:
            basedir = dirname(dirname(dirname(abspath(__file__))))
            #TODO: would be better to do a redirect to the not_available page
            f = open("%s/content/data/icons/png/not_available.png" % basedir)
            s = f.read()
            f.close()
        return HttpResponse(s)
示例#4
0
def log_history(payload, req):
    uid =  UR.getUserInfo(req, True).id
    if uid is None: 
        #SACHA TODO: LOG this.
        return UR.prepare_response({}, 1,  "NOT ALLOWED")
    cid = UR.CID
    if cid == 0:        
        return  UR.prepare_response({}, 1, "CID MOST BE NONZERO")
    session, previous_activity = annotations.markActivity(cid)
    if session is None: 
        return  UR.prepare_response({}, 1, "SESSION NOT FOUND")
    id_session = session.id
    output={}
    if "seen" in payload and cid != 0: 
        annotations.markCommentSeen(uid, id_session, payload["seen"])
    if "page" in payload and cid != 0: 
        annotations.markPageSeen(uid, id_session,  payload["page"])
    if "idle" in payload and cid != 0: 
        annotations.markIdle(uid,  id_session, payload["idle"])        
    if "__return" in payload and cid != 0:
        R = payload["__return"]
        if R["type"] == "newNotesOnFile": 
            id_source = R["a"]["id_source"]
            if auth.canReadFile(uid, id_source):
                output["locations"], output["comments"] = annotations.getCommentsByFile(id_source, uid, previous_activity)             
    return UR.prepare_response(output)
示例#5
0
def serve_img(req, res, scale, id_source):
    #print "img request of page %s of file %s at res %s and scale %s w/ invite_key=%s and req=%s" % (req.GET["page"], id_file, res, scale, req.GET["invite_key"], req  )
    #TODO: check permissions. 
    uid = UR.getUserId(req);
    if not auth.canReadFile(uid, id_source): 
        return HttpResponse("Error: You don't have credentials to see this file %s " % (id_source,))
    page = int(req.GET["page"])-1
    page_str =  settings.IMG_FMT_STRING %  (page,)
    filename = req.META["PATH_INFO"].rstrip('/')
    filename = "%s_%s.png" % (filename, page_str)
    response = None
    try: 
        response = serve(req, filename,settings.HTTPD_MEDIA_CACHE)
        return response
    except Http404: 
        #let's generate on demand
        try: 
            pdf_dir =  "%s/%s" % (settings.HTTPD_MEDIA,settings.REPOSITORY_DIR)
            img_dir =  "%s/%s" % (settings.HTTPD_MEDIA_CACHE,settings.CACHE_DIR)
            process_page(id_source, page,  res, scale, pdf_dir, img_dir, settings.IMG_FMT_STRING)
            response = serve(req, filename,settings.HTTPD_MEDIA_CACHE)
            return response
        except Http404:             
            basedir = dirname(dirname(dirname(abspath(__file__))))
            #TODO: would be better to do a redirect to the not_available page
            f = open("%s/content/data/icons/png/not_available.png" % basedir)
            s = f.read()
            f.close()
        return HttpResponse(s)
示例#6
0
def log_history(payload, req):
    uid = UR.getUserInfo(req, True).id
    if uid is None:
        #SACHA TODO: LOG this.
        return UR.prepare_response({}, 1, "NOT ALLOWED")
    cid = UR.CID
    if cid == 0:
        return UR.prepare_response({}, 1, "CID MOST BE NONZERO")
    session, previous_activity = annotations.markActivity(cid)
    if session is None:
        return UR.prepare_response({}, 1, "SESSION NOT FOUND")
    id_session = session.id
    output = {}
    if "seen" in payload and cid != 0:
        annotations.markCommentSeen(uid, id_session, payload["seen"])
    if "page" in payload and cid != 0:
        annotations.markPageSeen(uid, id_session, payload["page"])
    if "idle" in payload and cid != 0:
        annotations.markIdle(uid, id_session, payload["idle"])
    if "__return" in payload and cid != 0:
        R = payload["__return"]
        if R["type"] == "newNotesOnFile":
            id_source = R["a"]["id_source"]
            if auth.canReadFile(uid, id_source):
                output["locations"], output[
                    "comments"] = annotations.getCommentsByFile(
                        id_source, uid, previous_activity)
    return UR.prepare_response(output)
示例#7
0
def getNotes(payload, req):
    uid = UR.getUserId(req)
    output = {}
    if "file" in payload: #access by file
        after = payload.get("after", None)
        id_source = payload["file"]
        if auth.canReadFile(uid, id_source, req):
            #output["notes"] = annotations.getNotesByFile(id_source, uid)
            output["file"] = id_source
            output["locations"], output["html5locations"], output["comments"], output["threadmarks"] = annotations.getCommentsByFile(id_source, uid, after)
            #TODO: 
            #output["links"] = annotations.get_links(uid, {"id_source": id_source})
            output["seen"] = annotations.getSeenByFile(id_source, uid)
        else:
            return UR.prepare_response({}, 1, "NOT ALLOWED")
    return UR.prepare_response(output)
示例#8
0
def getNotes(payload, req):
    uid = UR.getUserId(req)
    output = {}
    if "file" in payload: #access by file
        after = payload.get("after", None)
        id_source = payload["file"]
        if auth.canReadFile(uid, id_source, req):
            #output["notes"] = annotations.getNotesByFile(id_source, uid)
            output["file"] = id_source
            output["locations"], output["html5locations"], output["comments"], output["threadmarks"] = annotations.getCommentsByFile(id_source, uid, after)
            #TODO: 
            #output["links"] = annotations.get_links(uid, {"id_source": id_source})
            output["seen"] = annotations.getSeenByFile(id_source, uid)
        else:
            return UR.prepare_response({}, 1, "NOT ALLOWED")
    return UR.prepare_response(output)
示例#9
0
def serve_img(req, res, scale, id_source):
    # print "img request of page %s of file %s at res %s and scale %s w/ invite_key=%s and req=%s" % (req.GET["page"], id_file, res, scale, req.GET["invite_key"], req  )
    # TODO: check permissions.
    uid = UR.getUserId(req)
    if not auth.canReadFile(uid, id_source):
        return HttpResponse("Error: You don't have credentials to see this file %s " % (id_source,))
    page_str = settings.IMG_FMT_STRING % (int(req.GET["page"]) - 1,)
    filename = req.META["PATH_INFO"].rstrip("/")
    filename = "%s_%s.png" % (filename, page_str)
    response = None
    try:
        response = serve(req, filename, settings.HTTPD_MEDIA)
        return response
    except Http404:
        logging.info("missing " + filename)
        basedir = dirname(dirname(dirname(abspath(__file__))))
        # basedir =  sys.modules["servers"].__path__[0].rpartition("/")[0]
        # TODO: would be better to do a redirect to the not_available page
        f = open("%s/data/icons/png/not_available.png" % basedir)
        s = f.read()
        f.close()
        return HttpResponse(s)
示例#10
0
def serve_img(req, res, scale, id_source):
    #print "img request of page %s of file %s at res %s and scale %s w/ invite_key=%s and req=%s" % (req.GET["page"], id_file, res, scale, req.GET["invite_key"], req  )
    #TODO: check permissions. 
    uid = UR.getUserId(req);
    if not auth.canReadFile(uid, id_source): 
        return HttpResponse("Error: You don't have credentials to see this file %s " % (id_source,))
    page_str =  settings.IMG_FMT_STRING %  (int(req.GET["page"])-1,)
    filename = req.META["PATH_INFO"].rstrip('/')
    filename = "%s_%s.png" % (filename, page_str)
    response = None
    try: 
        response = serve(req, filename,settings.HTTPD_MEDIA)
        return response
    except Http404: 
        logging.info("missing "+filename)
        basedir = dirname(dirname(dirname(abspath(__file__))))
        #basedir =  sys.modules["servers"].__path__[0].rpartition("/")[0]
        #TODO: would be better to do a redirect to the not_available page
        f = open("%s/data/icons/png/not_available.png" % basedir)
        s = f.read()
        f.close()
        return HttpResponse(s)