Ejemplo n.º 1
0
def upload():
    """ Create a new badge in the system """

    # TODO: some data validation wouldn't hurt.
    if request.method == 'POST':
        upload_source_path = sourcefiles.save(request.files['rawfile'])
        sourcefile = SourceFile(upload_source_path)
        db.session.add(sourcefile)
        db.session.commit()

    return render_template('home/index.jade')
Ejemplo n.º 2
0
def upload():
    """ Create a new badge in the system """
    #require.badge.create()

    # TODO: some data validation wouldn't hurt.
    if request.method == 'POST':
        upload_source_path = sourcefiles.save(request.files['rawfile'])
        sourcefile = SourceFile(upload_source_path)
        db.session.add(sourcefile)
        db.session.commit()

    return render_template('home/index.jade')
Ejemplo n.º 3
0
        #return jsonify({"errors":["You must enter a data name " + str(e)]})

    #verify that name is unique and URL is real
    #model = {'source': source}
    schema = source_schema(ValidationState(sourceapi))
    try:
        data = schema.deserialize(sourceapi)
    except Invalid, e:
        #print message in thefuture
        return jsonify({"errors":["Invalid field " + str(e)]})

    basesource = dataset.source


    if len(request.files) == 1:
        upload_source_path = sourcefiles.save(request.files['sourcefile'])


        sourcefile = SourceFile(rawfile = upload_source_path)
        db.session.add(sourcefile)
        oroperations = None

        if basesource:
            if basesource.rawfile:
                basesource.rawfile.delete()
            basesource.rawfile = sourcefile
            source = basesource
            oroperations = source.getORInstructions()
            source.reload_openrefine()
        else:
            source = Source(dataset=dataset, name=data['name'], url=None, rawfile=sourcefile)
Ejemplo n.º 4
0
        sourceapi['name'] = dataset.name
        #return jsonify({"errors":["You must enter a data name " + str(e)]})

    #verify that name is unique and URL is real
    #model = {'source': source}
    schema = source_schema(ValidationState(sourceapi))
    try:
        data = schema.deserialize(sourceapi)
    except Invalid, e:
        #print message in thefuture
        return jsonify({"errors": ["Invalid field " + str(e)]})

    basesource = dataset.source

    if len(request.files) == 1:
        upload_source_path = sourcefiles.save(request.files['sourcefile'])

        sourcefile = SourceFile(rawfile=upload_source_path)
        db.session.add(sourcefile)

        if basesource:
            if basesource.rawfile:
                basesource.rawfile.delete()
            basesource.rawfile = sourcefile
            source = basesource
            source.reload_openrefine()
        else:
            source = Source(dataset=dataset,
                            name=data['name'],
                            url=None,
                            rawfile=sourcefile)
Ejemplo n.º 5
0
        #convert to a file:///name
        #create a source file
        try:

            filename = sourcejson['fields']['downloadedFile'].replace(
                "rawdata/", "")

            #copy file over to another folder and open it
            #copyfile(os.path.join(file_dir, filename), os.path.join(UPLOADED_FILES_DEST, filename))

            orig_filepath = os.path.join(file_dir, filename)

            with codecs.open(orig_filepath, 'rb') as fh:
                wuezfile = FileStorage(stream=fh)
                #upload_source_path = sourcefiles.save(wuezfile, name=filename, folder=UPLOADED_FILES_DEST)
                upload_source_path = sourcefiles.save(wuezfile, name=filename)
                sourcefile = SourceFile(rawfile=upload_source_path)
                db.session.add(sourcefile)
        except Exception, e:
            print "!!!!!Error failed", e
            return (None, False)
        try:
            print sourcefile
            source = Source(dataset=dataset,
                            name=dataset.name,
                            url=None,
                            rawfile=sourcefile)
        except Exception, e:
            traceback.print_exc(e)
            print "Could not load source rawfile", e
            return (None, False)
Ejemplo n.º 6
0
    if sourcejson['fields']['downloadedFile'] and file_dir and not sourcejson['fields']['webservice']:
        #convert to a file:///name
        #create a source file
        try:

            filename = sourcejson['fields']['downloadedFile'].replace("rawdata/", "")

            #copy file over to another folder and open it
            #copyfile(os.path.join(file_dir, filename), os.path.join(UPLOADED_FILES_DEST, filename))

            orig_filepath = os.path.join(file_dir, filename)

            with codecs.open(orig_filepath, 'rb') as fh:
                wuezfile = FileStorage(stream=fh)
                #upload_source_path = sourcefiles.save(wuezfile, name=filename, folder=UPLOADED_FILES_DEST)
                upload_source_path = sourcefiles.save(wuezfile, name=filename)
                sourcefile = SourceFile(rawfile = upload_source_path)
                db.session.add(sourcefile)
        except Exception ,e:
            print "!!!!!Error failed", e
            return (None, False)
        try:
            print sourcefile
            source = Source(dataset=dataset, name=dataset.name, url=None, rawfile=sourcefile)
        except Exception, e:
            traceback.print_exc(e)
            print "Could not load source rawfile", e
            return(None, False)

    else:
        try: