Beispiel #1
0
def upload(req): 
    r = HttpResponse()
    f = req.FILES["file"]
    id_ensemble = req.GET["id_ensemble"]
    id_source = req.GET["id_source"]
    id_folder = req.GET.get("id_folder", None)
    uid = UR.getUserId(req);
    logging.info("upload uid=%s, id_source=%s, id_ensemble=%s, id_folder=%s" %  (uid,id_source,id_ensemble,id_folder))
    url = "http://%s:%s/%s?id_ensemble=%s" %("localhost", "8080",f.name, id_ensemble)
    payload = {"url": url, "id_source": id_source, "id_folder": id_folder }
    if auth.canInsertFile(uid, id_ensemble, id_folder):
        #the followong data will be deleted in utils_pdf if an PDF error happens later...
        annotations.createSource(uid, payload)
        annotations.addOwnership(id_source, id_ensemble, id_folder)
        REPOSITORY_DIR = "%s/%s" % (settings.HTTPD_MEDIA, "/pdf/repository")
        f2 = open("%s/%s" % (REPOSITORY_DIR, id_source,),"wb")    
        f2.write(f.read())
        f2.close()
        basedir = dirname(dirname(abspath(__file__)))
        #do the rest in the background, so server remains responsive                
        cmd = "(cd %s; python -m upload.jobs file_img %s >/tmp/uploadscript_%s.log 2>&1 &)" %(basedir, id_source,  id_log )
        logging.info(cmd)
        os.system(cmd)
        r.content =  UR.prepare_response({})
    else: 
        r.content =  UR.prepare_response({}, 1, "NOT ALLOWED to insert a file to this group")
    return r
Beispiel #2
0
def upload(req): 
    r = HttpResponse()
    f = req.FILES["file"]
    id_ensemble = req.GET["id_ensemble"]
    id_source = req.GET["id_source"]
    id_folder = req.GET.get("id_folder", None)
    uid = UR.getUserId(req);
    logging.info("upload uid=%s, id_source=%s, id_ensemble=%s, id_folder=%s" %  (uid,id_source,id_ensemble,id_folder))
    url = "http://%s:%s/%s?id_ensemble=%s" %("localhost", "8080",f.name, id_ensemble)
    payload = {"url": url, "id_source": id_source, "id_folder": id_folder }
    if auth.canInsertFile(uid, id_ensemble, id_folder):
        #the followong data will be deleted in utils_pdf if an PDF error happens later...
        annotations.createSource(uid, payload)
        annotations.addOwnership(id_source, id_ensemble, id_folder)
        REPOSITORY_DIR = "%s/%s" % (settings.HTTPD_MEDIA, "/pdf/repository")
        f2 = open("%s/%s" % (REPOSITORY_DIR, id_source,),"wb")    
        f2.write(f.read())
        f2.close()
        basedir = dirname(dirname(abspath(__file__)))
        #do the rest in the background, so server remains responsive                
        cmd = "(cd %s; python -m upload.jobs file_img %s >/tmp/uploadscript_%s.log 2>&1 &)" %(basedir, id_source,  id_log )
        logging.info(cmd)
        os.system(cmd)
        r.content =  UR.prepare_response({})
    else: 
        r.content =  UR.prepare_response({}, 1, "NOT ALLOWED to insert a file to this group")
    return r
Beispiel #3
0
def upload(req):
    try:
        r = HttpResponse()
        f = req.FILES["file"]
        id_ensemble = req.GET["id_ensemble"]
        id_source = req.GET["id_source"]
        id_folder = req.GET.get("id_folder", None)
        uid = UR.getUserId(req)
    except UnreadablePostError:
        #most likely a canceled upload
        r.content = UR.prepare_response({}, 1, "unreadable post")
        return r
    except MultiValueDictKeyError:
        #most likely no file submitted
        r.content = UR.prepare_response({}, 1, "no file submitted")
        return r
    logging.info("upload uid=%s, id_source=%s, id_ensemble=%s, id_folder=%s" %
                 (uid, id_source, id_ensemble, id_folder))
    url = "http://%s:%s/%s?id_ensemble=%s" % ("localhost", "8000", f.name,
                                              id_ensemble)
    payload = {"url": url, "id_source": id_source, "id_folder": id_folder}
    if auth.canInsertFile(uid, id_ensemble, id_folder):
        #the followong data will be deleted in utils_pdf if an PDF error happens later...
        annotations.createSource(uid, payload)
        ownership = annotations.addOwnership(id_source, id_ensemble, id_folder)
        source = ownership.source
        #bug? before it was %s/%s which produced //
        REPOSITORY_DIR = "%s%s" % (settings.HTTPD_MEDIA, "/pdf/repository")
        print REPOSITORY_DIR
        f2 = open("%s/%s" % (
            REPOSITORY_DIR,
            id_source,
        ), "wb")
        f2.write(f.read())
        f2.close()
        if insert_pdf_metadata(id_source, REPOSITORY_DIR):
            V = {
                "reply_to": settings.SMTP_REPLY_TO,
                "email": source.submittedby.email,
                "title": source.title,
                "submitted": ownership.published,
                "protocol": settings.PROTOCOL,
                "hostname": settings.HOSTNAME,
                "id_source": id_source,
                "firstname": source.submittedby.firstname
            }
            msg = render_to_string("email/msg_pdfdone", V)
            email = EmailMessage(
                "The PDF file that you've submitted is now ready on NB.", msg,
                settings.EMAIL_FROM, (V["email"], settings.SMTP_CC_USER),
                (settings.EMAIL_BCC, ))
            email.send()
        else:
            #send email that stg didn't work and remove that document.
            V = {
                "reply_to": settings.SMTP_REPLY_TO,
                "email": source.submittedby.email,
                "source_id": id_source,
                "title": source.title,
                "submitted": ownership.published,
                "support": settings.SUPPORT_LINK,
                "contact_email": settings.NBTEAM_EMAIL,
                "firstname": source.submittedby.firstname
            }
            ownership.delete()
            source.delete()
            msg = render_to_string("email/msg_pdferror", V)
            email = EmailMessage(
                "NB was unable to read a PDF file that you've submitted", msg,
                settings.EMAIL_FROM, (V["email"], settings.SMTP_CC_PDFERROR),
                (settings.EMAIL_BCC, ))
            email.send()
        r.content = UR.prepare_response({})
    else:
        r.content = UR.prepare_response(
            {}, 1, "NOT ALLOWED to insert a file to this group")
    return r
Beispiel #4
0
def upload(req): 
    try:
        r = HttpResponse()
        f = req.FILES["file"]
        id_ensemble = req.GET["id_ensemble"]
        id_source = req.GET["id_source"]
        id_folder = req.GET.get("id_folder", None)
        uid = UR.getUserId(req);
    except UnreadablePostError:
        #most likely a canceled upload
        r.content =  UR.prepare_response({},1,"unreadable post")
        return r
    except MultiValueDictKeyError:
        #most likely no file submitted
        r.content =  UR.prepare_response({},1,"no file submitted")
        return r
    logging.info("upload uid=%s, id_source=%s, id_ensemble=%s, id_folder=%s" %  (uid,id_source,id_ensemble,id_folder))
    url = "http://%s:%s/%s?id_ensemble=%s" %("localhost", "8000",f.name, id_ensemble)
    payload = {"url": url, "id_source": id_source, "id_folder": id_folder }
    if auth.canInsertFile(uid, id_ensemble, id_folder):
        #the followong data will be deleted in utils_pdf if an PDF error happens later...
        annotations.createSource(uid, payload)
        ownership = annotations.addOwnership(id_source, id_ensemble, id_folder)
        source = ownership.source
        #bug? before it was %s/%s which produced //
        REPOSITORY_DIR = "%s%s" % (settings.HTTPD_MEDIA, "/pdf/repository")
        print REPOSITORY_DIR
        f2 = open("%s/%s" % (REPOSITORY_DIR, id_source,),"wb")    
        f2.write(f.read())
        f2.close()                 
        if insert_pdf_metadata(id_source,  REPOSITORY_DIR):
            V = {"reply_to": settings.SMTP_REPLY_TO,
             "email": source.submittedby.email,
             "title": source.title,  
             "submitted": ownership.published, 
             "protocol": settings.PROTOCOL, 
             "hostname": settings.HOSTNAME, 
             "id_source": id_source, 
             "firstname": source.submittedby.firstname
             }
            msg = render_to_string("email/msg_pdfdone",V)
            email = EmailMessage(
                "The PDF file that you've submitted is now ready on NB.", 
                msg,
                settings.EMAIL_FROM,
                (V["email"], settings.SMTP_CC_USER ), 
                (settings.EMAIL_BCC, ))
            email.send()
        else:
            #send email that stg didn't work and remove that document.         
            V = {"reply_to": settings.SMTP_REPLY_TO,
                     "email": source.submittedby.email,
                     "source_id": id_source,
                     "title": source.title, 
                     "submitted": ownership.published, 
                     "support":  settings.SUPPORT_LINK,
                     "contact_email": settings.NBTEAM_EMAIL,
                     "firstname": source.submittedby.firstname
                     }
            ownership.delete()
            source.delete()
            msg = render_to_string("email/msg_pdferror",V)
            email = EmailMessage(
                "NB was unable to read a PDF file that you've submitted", 
                msg,  
                settings.EMAIL_FROM,
                (V["email"], settings.SMTP_CC_PDFERROR ), (settings.EMAIL_BCC, ))
            email.send()
        r.content =  UR.prepare_response({})
    else: 
        r.content =  UR.prepare_response({}, 1, "NOT ALLOWED to insert a file to this group")
    return r