Beispiel #1
0
    def dimensions_update(self, dataset, format='html'):
        self._get_dataset(dataset)

        require.dataset.update(c.dataset)
        if len(c.dataset):
            abort(400, _("You cannot edit the dimensions model when "
                         "data is loaded for the dataset."))

        errors, mapping, saved = {}, None, False
        try:
            mapping = json.loads(request.params.get('mapping'))
            model = c.dataset.model
            model['mapping'] = mapping
            schema = mapping_schema(ValidationState(model))
            new_mapping = schema.deserialize(mapping)
            c.dataset.data['mapping'] = new_mapping
            c.dataset.drop()
            c.dataset._load_model()
            c.dataset.generate()
            db.session.commit()
            # h.flash_success(_("The mapping has been updated."))
            saved = True
        except (ValueError, TypeError, AttributeError):
            abort(400, _("The mapping data could not be decoded as JSON!"))
        except Invalid as i:
            errors = i.asdict()
        return self.dimensions_edit(dataset, errors=errors,
                                    mapping=mapping, saved=saved)
Beispiel #2
0
    def dimensions_update(self, dataset, format='html'):
        dry_run = False

        self._get_dataset(dataset)

        operation = request.params.get('operation', 'Save')
        if operation == 'Verify':
            dry_run = True

        require.dataset.update(c.dataset)
        if len(c.dataset):
            abort(400, _("You cannot edit the dimensions model when " \
                    "data is loaded for the dataset."))

        errors, mapping = {}, None
        try:
            mapping = json.loads(request.params.get('mapping'))
            model = c.dataset.model
            model['mapping'] = mapping
            schema = mapping_schema(ValidationState(model))
            new_mapping =  schema.deserialize(mapping)
            if not dry_run:
            # erm...
                c.dataset.data['mapping'] = new_mapping
                c.dataset.drop()
                c.dataset._load_model()
                c.dataset.generate()
                db.session.commit()
                h.flash_success(_("The mapping has been updated."))
            else:
                h.flash_success(_("The mapping has been validated successfully."))
        except (ValueError, TypeError, AttributeError):
            abort(400, _("The mapping data could not be decoded as JSON!"))
        except Invalid, i:
            errors = i.asdict()
Beispiel #3
0
    def dimensions_update(self, dataset, format='html'):
        self._get_dataset(dataset)

        require.dataset.update(c.dataset)
        if len(c.dataset):
            abort(400, _("You cannot edit the dimensions model when " \
                    "data is loaded for the dataset."))

        errors, mapping, saved = {}, None, False
        try:
            mapping = json.loads(request.params.get('mapping'))
            model = c.dataset.model
            model['mapping'] = mapping
            schema = mapping_schema(ValidationState(model))
            new_mapping = schema.deserialize(mapping)
            c.dataset.data['mapping'] = new_mapping
            c.dataset.drop()
            c.dataset._load_model()
            c.dataset.generate()
            db.session.commit()
            #h.flash_success(_("The mapping has been updated."))
            saved = True
        except (ValueError, TypeError, AttributeError):
            abort(400, _("The mapping data could not be decoded as JSON!"))
        except Invalid, i:
            errors = i.asdict()
 def test_entry_overlap(self):
     ms = self.model['mapping'].copy()
     ms['entry_id'] = ms['function']
     model = self.model.copy()
     model['mapping'] = ms
     state = ValidationState(model)
     schema = mapping_schema(state)
     schema.deserialize(ms)
 def test_basic_validate(self):
     try:
         in_ = self.model['mapping']
         schema = mapping_schema(self.state)
         out = schema.deserialize(in_)
         assert len(out)==len(in_), out
     except Invalid, i:
         assert False, i.asdict()
 def test_requires_one_key_column(self):
     ms = self.model['mapping'].copy()
     del ms['function']['key']
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
 def test_no_label(self):
     ms = self.model['mapping'].copy()
     del ms['function']['label']
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
 def test_invalid_name(self):
     ms = self.model['mapping']
     ms['ba nana'] = ms['function']
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
 def test_to_is_compound(self):
     ms = self.model['mapping']
     ms['to'] = ms['transaction_id']
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
 def test_from_is_compound(self):
     ms = self.model['mapping']
     ms['from'] = ms['cofinance']
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
 def test_date_data_type(self):
     ms = self.model['mapping'].copy()
     ms['time']['datatype'] = 'id'
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
 def test_compound_field_name_not_datatype_id(self):
     ms = self.model['mapping'].copy()
     ms['function']['attributes']['name']['datatype'] = 'string'
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
 def test_compound_field_invalid_datatype(self):
     ms = self.model['mapping'].copy()
     ms['function']['attributes']['description']['datatype'] = 'banana'
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
 def test_compound_field_has_column(self):
     ms = self.model['mapping'].copy()
     del ms['function']['attributes']['description']['column']
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
 def test_compound_field_reserved_name(self):
     ms = self.model['mapping'].copy()
     ms['function']['attributes']['id'] = ms['function']['attributes']['description']
     del ms['function']['attributes']['description']
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
 def test_attribute_data_type(self):
     ms = self.model['mapping'].copy()
     ms['transaction_id']['datatype'] = 'banana'
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
 def test_attribute_has_column(self):
     ms = self.model['mapping'].copy()
     del ms['transaction_id']['column']
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
 def test_requires_amount(self):
     ms = self.model['mapping'].copy()
     del ms['amount']
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
 def test_requires_amount_float_datatype(self):
     ms = self.model['mapping'].copy()
     ms['amount']['datatype'] = 'string'
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
Beispiel #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
 def test_compound_field_label_not_datatype_string(self):
     ms = self.model['mapping'].copy()
     ms['function']['attributes']['label']['datatype'] = 'float'
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
 def test_date_has_column(self):
     ms = self.model['mapping'].copy()
     del ms['time']['column']
     schema = mapping_schema(self.state)
     schema.deserialize(ms)
Beispiel #23
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
 def test_compound_must_have_label(self):
     ms = self.model['mapping'].copy()
     del ms['function']['attributes']['label']
     schema = mapping_schema(self.state)
     schema.deserialize(ms)