Beispiel #1
0
def model(datasetname):
    #if not sourcename then we are saving the defaults for dataset
    
    dataset = get_dataset(datasetname)
    if not dataset.source:
        #then create one
        dataset_source = Source.by_source_name(dataset.name)
        if not dataset_source:
            dataset_source = Source(name=dataset.name, dataset=dataset)
            db.session.add(dataset_source)
        else:
            dataset_source.dataset = dataset
        db.session.commit()

        #figure out what they need over there?
    return jsonify(dataset.source)
Beispiel #2
0
def model(datasetname):
    #if not sourcename then we are saving the defaults for dataset

    dataset = get_dataset(datasetname)
    if not dataset.source:
        #then create one
        dataset_source = Source.by_source_name(dataset.name)
        if not dataset_source:
            dataset_source = Source(name=dataset.name, dataset=dataset)
            db.session.add(dataset_source)
        else:
            dataset_source.dataset = dataset
        db.session.commit()

        #figure out what they need over there?
    return jsonify(dataset.source)
Beispiel #3
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)]})
Beispiel #4
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)]})
Beispiel #5
0
def get_source(sourcename):
    source = obj_or_404(Source.by_source_name(sourcename))
    #require.dataset.read(dataset)
    return source
Beispiel #6
0
def get_source(sourcename):
    source = obj_or_404(Source.by_source_name(sourcename))
    #require.dataset.read(dataset)
    return source