Esempio n. 1
0
 def create(self):
     require.dataset.create()
     try:
         dataset = dict(request.params)
         dataset['territories'] = request.params.getall('territories')
         dataset['languages'] = request.params.getall('languages')
         model = {'dataset': dataset}
         schema = dataset_schema(ValidationState(model))
         data = schema.deserialize(dataset)
         if Dataset.by_name(data['name']) is not None:
             raise Invalid(
                 SchemaNode(String(), name='dataset.name'),
                 _("A dataset with this identifer already exists!"))
         dataset = Dataset({'dataset': data})
         dataset.private = True
         dataset.managers.append(c.account)
         db.session.add(dataset)
         db.session.commit()
         redirect(
             h.url_for(controller='editor',
                       action='index',
                       dataset=dataset.name))
     except Invalid, i:
         errors = i.asdict()
         return self.new(errors)
 def test_basic_validate(self):
     try:
         ds = self.model['dataset']
         schema = dataset_schema(self.state)
         out = schema.deserialize(ds)
         assert sorted(out.keys())==sorted(ds.keys()), [out, ds]
     except Invalid, i:
         assert False, i.asdict()
Esempio n. 3
0
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']})
Esempio n. 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)]})
Esempio n. 5
0
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']}) 
Esempio n. 6
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)]})
Esempio n. 7
0
 def core_update(self, dataset, format='html'):
     self._get_dataset(dataset)
     require.dataset.update(c.dataset)
     errors = {}
     try:
         schema = dataset_schema(ValidationState(c.dataset.model))
         data = dict(request.params)
         data['territories'] = request.params.getall('territories')
         data['languages'] = request.params.getall('languages')
         data = schema.deserialize(data)
         c.dataset.label = data['label']
         c.dataset.currency = data['currency']
         c.dataset.description = data['description']
         c.dataset.territories = data['territories']
         c.dataset.languages = data['languages']
         db.session.commit()
         h.flash_success(_("The dataset has been updated."))
     except Invalid, i:
         errors = i.asdict()
Esempio n. 8
0
 def create(self):
     require.account.create()
     try:
         model = {'dataset': request.params}
         schema = dataset_schema(ValidationState(model))
         data = schema.deserialize(request.params)
         if Dataset.by_name(data['name']):
             raise Invalid(SchemaNode(String(), name='dataset.name'),
                 _("A dataset with this identifer already exists!"))
         dataset = Dataset({'dataset': data})
         dataset.private = True
         dataset.managers.append(c.account)
         db.session.add(dataset)
         db.session.commit()
         redirect(h.url_for(controller='editor', action='index', 
                            dataset=dataset.name))
     except Invalid, i:
         errors = i.asdict()
         return self.new(errors)
Esempio n. 9
0
 def core_update(self, dataset, format='html'):
     self._get_dataset(dataset)
     require.dataset.update(c.dataset)
     errors = {}
     try:
         schema = dataset_schema(ValidationState(c.dataset.model))
         data = dict(request.params)
         data['territories'] = request.params.getall('territories')
         data['languages'] = request.params.getall('languages')
         data = schema.deserialize(data)
         c.dataset.label = data['label']
         c.dataset.currency = data['currency']
         c.dataset.description = data['description']
         c.dataset.territories = data['territories']
         c.dataset.languages = data['languages']
         db.session.commit()
         h.flash_success(_("The dataset has been updated."))
     except Invalid, i:
         errors = i.asdict()
Esempio n. 10
0
 def create(self):
     require.dataset.create()
     try:
         dataset = dict(request.params)
         dataset["territories"] = request.params.getall("territories")
         dataset["languages"] = request.params.getall("languages")
         model = {"dataset": dataset}
         schema = dataset_schema(ValidationState(model))
         data = schema.deserialize(dataset)
         if Dataset.by_name(data["name"]) is not None:
             raise Invalid(
                 SchemaNode(String(), name="dataset.name"), _("A dataset with this identifer already exists!")
             )
         dataset = Dataset({"dataset": data})
         dataset.private = True
         dataset.managers.append(c.account)
         db.session.add(dataset)
         db.session.commit()
         redirect(h.url_for(controller="editor", action="index", dataset=dataset.name))
     except Invalid, i:
         errors = i.asdict()
         return self.new(errors)
 def test_empty_description(self):
     ds = self.model['dataset'].copy()
     ds['description'] = '  '
     schema = dataset_schema(self.state)
     schema.deserialize(ds)
 def test_underscore_validate(self):
     ds = self.model['dataset'].copy()
     ds['name'] = 'test__'
     schema = dataset_schema(self.state)
     schema.deserialize(ds)
 def test_reserved_name_validate(self):
     ds = self.model['dataset'].copy()
     ds['name'] = 'entRY'
     schema = dataset_schema(self.state)
     schema.deserialize(ds)
 def test_invalid_currency(self):
     ds = self.model['dataset'].copy()
     ds['currency'] = 'glass pearls'
     schema = dataset_schema(self.state)
     schema.deserialize(ds)
 def test_invalid_category(self):
     ds = self.model['dataset'].copy()
     ds['category'] = 'giraffes'
     schema = dataset_schema(self.state)
     schema.deserialize(ds)
 def test_invalid_language(self):
     ds = self.model['dataset'].copy()
     ds['languages'].append('esperanto')
     schema = dataset_schema(self.state)
     schema.deserialize(ds)
 def test_empty_label(self):
     ds = self.model['dataset'].copy()
     ds['label'] = '  '
     schema = dataset_schema(self.state)
     schema.deserialize(ds)
 def test_invalid_country(self):
     ds = self.model['dataset'].copy()
     ds['territories'].append('SU')
     schema = dataset_schema(self.state)
     schema.deserialize(ds)
Esempio n. 19
0
def model_schema(state):
    schema = mapping_node('model')
    schema.add(dataset_schema(state))
    schema.add(mapping_schema(state))
    schema.add(views_schema(state))
    return schema
Esempio n. 20
0
def model_schema(state):
    schema = mapping_node('model')
    schema.add(dataset_schema(state))
    schema.add(mapping_schema(state))
    schema.add(views_schema(state))
    return schema