コード例 #1
0
ファイル: dataset.py プロジェクト: nathanhilbert/FPA_Core
def field_polling_post(datasetname, columnkey):
    """
    post to check to verify that the column is good
    """

    #print request.get_json().get('columnval', None)
    ORcolumn = request.get_json().get('columnval', None)
    if not ORcolumn:
        return jsonify({"errors":["could not find the column name"]})

    dataset = get_dataset(datasetname)

    if not require.dataset.update(dataset):
        return jsonify({"errors":["Permission denied"]})

    try:
        columnsettings = api_form_data()

        #use this later if async run is necessary
        #runop = Run(columnsettings['columnval'], dataset, source)
        #db.session.add(runop)
        #db.session.commit()

        #check_column.apply_async(args=[source.id, columnkey, columnsettings['columnval'], runop.id], countdown=1)
        resultval = check_column(dataset.source.id, columnkey, columnsettings['columnval'])

        if len(resultval['errors']) == 0:
            return jsonify({"success":True})
        else:
            return jsonify(resultval)
    except Exception, e:
        print "here is my error", e
        return jsonify({"errors":['Unknown Error has occurred']})
コード例 #2
0
ファイル: dataview.py プロジェクト: fucc1/FPA_Core
def create():
    """
    This takes a json format post with label, name, description
    and creates a private dataset to put sources in
    The json_errors return a json object
    """

    # if not require.dataview.create():
    #     return jsonify({"errors":["Can not create new dataset.  Permission denied"]})

    try:
        dataview_form = api_form_data()
        #make checks here for various secuirty and validation
        if dataview_form['urlhash']:
            dataview = Dataview.by_urlhash(dataview_form['urlhash'])
            dataview.update(dataview_form)
        else:
            dataview = Dataview(dataview_form)
            db.session.add(dataview)

        db.session.commit()
        return jsonify(dataview)
    except Exception, e:
        ex_type, ex, tb = sys.exc_info()
        print traceback.print_tb(tb)
        return jsonify({"errors": ['Unknown Error has occurred: ' + str(e)]})
コード例 #3
0
def field_polling_post(datasetname, columnkey):
    """
    post to check to verify that the column is good
    """

    #print request.get_json().get('columnval', None)
    ORcolumn = request.get_json().get('columnval', None)
    if not ORcolumn:
        return jsonify({"errors": ["could not find the column name"]})

    dataset = get_dataset(datasetname)

    if not require.dataset.update(dataset):
        return jsonify({"errors": ["Permission denied"]})

    try:
        columnsettings = api_form_data()

        #use this later if async run is necessary
        #runop = Run(columnsettings['columnval'], dataset, source)
        #db.session.add(runop)
        #db.session.commit()

        #check_column.apply_async(args=[source.id, columnkey, columnsettings['columnval'], runop.id], countdown=1)
        resultval = check_column(dataset.source.id, columnkey,
                                 columnsettings['columnval'])

        if len(resultval['errors']) == 0:
            return jsonify({"success": True})
        else:
            return jsonify(resultval)
    except Exception, e:
        print "here is my error", e
        return jsonify({"errors": ['Unknown Error has occurred']})
コード例 #4
0
ファイル: dataset.py プロジェクト: govtmirror/FPA_Core
def update(name):
    """
    Update a dataset with a json object and name from the dataset form
    """
    try:
        dataset = get_dataset(name)
        schema = dataset_schema(ValidationState(dataset))
        data = schema.deserialize(api_form_data())

        dataset.update(data)
        db.session.commit()
        #clear_index_cache()
        return jsonify({"success": True})
    except Exception, e:
        print e
        return jsonify({"errors": ['Unknown Error has occurred']})
コード例 #5
0
def create():
    """
    This takes a json format post with label, name, description
    and creates a private dataset to put sources in
    The json_errors return a json object
    """

    if not require.dataset.create():
        return jsonify(
            {"errors": ["Can not create new dataset.  Permission denied"]})

    try:
        dataset = api_form_data()
        if not dataset.get("dataorg", None):
            return jsonify(
                {"errors": ["You must select the data source organization"]})
        model = {'data': dataset}
        schema = dataset_schema(ValidationState(model))
        data = schema.deserialize(dataset)

        #should have a better place for sluggify
        if (data.get('name', None)):
            tempname = slugify(str(data.get('name')), max_length=50)
        else:
            tempname = slugify(str(data.get('label')), max_length=50)

        if Dataset.by_name(tempname) is not None:
            return jsonify(
                {"errors": ["A dataset with this name already exists "]})

        dataset = Dataset(data=data)
        dataset.managers.append(current_user)
        db.session.add(dataset)

        dataset_source = Source.by_source_name(dataset.name)
        if not dataset_source:
            dataset_source = Source(dataset=dataset, name=dataset.name)
            db.session.add(dataset_source)
        else:
            dataset_source.dataset = dataset
        #creating a new dataset so we have to create a source as well
        db.session.commit()
        return jsonify({"success": True, "dataset": dataset.name})
    except Exception, e:
        ex_type, ex, tb = sys.exc_info()
        print traceback.print_tb(tb)
        return jsonify({"errors": ['Unknown Error has occurred: ' + str(e)]})
コード例 #6
0
ファイル: dataset.py プロジェクト: nathanhilbert/FPA_Core
def update(name):
    """
    Update a dataset with a json object and name from the dataset form
    """
    try:
        dataset = get_dataset(name)
        require.dataset.update(dataset)
        schema = dataset_schema(ValidationState(dataset))
        data = schema.deserialize(api_form_data())

        dataset.update(data)
        db.session.commit()
        #clear_index_cache()
        return jsonify({"success":True})
    except Exception, e:
        print e
        return jsonify({"errors":['Unknown Error has occurred']}) 
コード例 #7
0
ファイル: dataset.py プロジェクト: nathanhilbert/FPA_Core
def create():
    """
    This takes a json format post with label, name, description
    and creates a private dataset to put sources in
    The json_errors return a json object
    """

    if not require.dataset.create():
        return jsonify({"errors":["Can not create new dataset.  Permission denied"]})

    try:
        dataset = api_form_data()
        if not dataset.get("dataorg", None):
            return jsonify({"errors":["You must select the data source organization"]}) 
        model = {'data': dataset}
        schema = dataset_schema(ValidationState(model))
        data = schema.deserialize(dataset)

        #should have a better place for sluggify
        if (data.get('name', None)):
            tempname = slugify(str(data.get('name')), max_length=50)
        else:
            tempname = slugify(str(data.get('label')), max_length=50)

        if Dataset.by_name(tempname) is not None:
            return jsonify({"errors":["A dataset with this name already exists "]})

        dataset = Dataset(data=data)
        dataset.managers.append(current_user)
        db.session.add(dataset)
        
        dataset_source = Source.by_source_name(dataset.name)
        if not dataset_source:
            dataset_source = Source(dataset=dataset, name=dataset.name)
            db.session.add(dataset_source)
        else:
            dataset_source.dataset = dataset
        #creating a new dataset so we have to create a source as well
        db.session.commit()
        return jsonify({"success":True, "dataset":dataset.name})
    except Exception, e:
        ex_type, ex, tb = sys.exc_info()
        print traceback.print_tb(tb)
        return jsonify({"errors":['Unknown Error has occurred: ' + str(e)]})
コード例 #8
0
def update_model_createnew(datasetname):
    #refactor to include the update

    dataset = get_dataset(datasetname)

    #source will have name and URL
    sourceapi = api_form_data()

    if not sourceapi['name']:
        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)]})
コード例 #9
0
ファイル: dataset.py プロジェクト: nathanhilbert/FPA_Core
def update_model_createnew(datasetname):
    #refactor to include the update

    dataset = get_dataset(datasetname)


    #source will have name and URL
    sourceapi = api_form_data()

    if not sourceapi['name']:
        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)]})