Ejemplo n.º 1
0
    def load(self, dataset, id):
        """
        Load the dataset into the database. If a url parameter 'sample' 
        is provided then its value is converted into a boolean. If the value
        equals true we only perform a sample run, else we do a full load.
        """

        # Get our source (and dataset)
        self._get_source(dataset, id)

        # We require that the user can update the dataset
        require.dataset.update(c.dataset)

        # If the source is already running we flash an error declaring that
        # we're already running this source
        if c.source.is_running:
            h.flash_error(_("Already running!"))
        # If the source isn't already running we try to load it (or sample it)
        else:
            try:
                sample = asbool(request.params.get('sample', 'false'))
                load_source.delay(c.source.id, sample)
                # Let the user know we're loading the source
                h.flash_success(_("Now loading..."))
            except Exception, e:
                abort(400, e)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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()
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
    def load(self, dataset, id):
        """
        Load the dataset into the database. If a url parameter 'sample'
        is provided then its value is converted into a boolean. If the value
        equals true we only perform a sample run, else we do a full load.
        """

        # Get our source (and dataset)
        self._get_source(dataset, id)

        # We require that the user can update the dataset
        require.dataset.update(c.dataset)

        # If the source is already running we flash an error declaring that
        # we're already running this source
        if c.source.is_running:
            h.flash_error(_("Already running!"))
        # If the source isn't already running we try to load it (or sample it)
        else:
            try:
                sample = asbool(request.params.get('sample', 'false'))
                load_source.delay(c.source.id, sample)
                # Let the user know we're loading the source
                h.flash_success(_("Now loading..."))
            except Exception as e:
                abort(400, e)

        # Send the user to the editor index page for this dataset
        redirect(
            h.url_for(controller='editor',
                      action='index',
                      dataset=c.dataset.name))
Ejemplo n.º 6
0
 def load(self, dataset, id):
     self._get_source(dataset, id)
     require.dataset.update(c.dataset)
     try:
         sample = asbool(request.params.get('sample', 'false'))
         load_source.delay(c.source.id, sample)
     except Exception, e:
         abort(400, e)
Ejemplo n.º 7
0
 def load(self, dataset, id):
     self._get_source(dataset, id)
     require.dataset.update(c.dataset)
     try:
         sample = asbool(request.params.get('sample', 'false'))
         load_source.delay(c.source.id, sample)
     except Exception, e:
         abort(400, e)
Ejemplo n.º 8
0
 def _get_run(self, dataset, source, id):
     self._get_dataset(dataset)
     require.dataset.update(c.dataset)
     c.source = Source.by_id(source)
     if c.source is None or c.source.dataset != c.dataset:
         abort(404, _("There is no source '%s'") % source)
     c.run = Run.by_id(id)
     if c.run is None or c.run.source != c.source:
         abort(404, _("There is no run '%s'") % id)
Ejemplo n.º 9
0
 def _get_run(self, dataset, source, id):
     self._get_dataset(dataset)
     require.dataset.update(c.dataset)
     c.source = Source.by_id(source)
     if c.source is None or c.source.dataset != c.dataset:
         abort(404, _("There is no source '%s'") % source)
     c.run = Run.by_id(id)
     if c.run is None or c.run.source != c.source:
         abort(404, _("There is no run '%s'") % id)
Ejemplo n.º 10
0
 def retract(self, dataset):
     self._get_dataset(dataset)
     require.dataset.update(c.dataset)
     if c.dataset.private:
         abort(400, _("This dataset is already private!"))
     c.dataset.private = True
     AggregationCache(c.dataset).invalidate()
     db.session.commit()
     h.flash_success(_("The dataset has been retracted. " \
             "It is no longer visible to others."))
     redirect(h.url_for(controller='editor', action='index', 
                        dataset=c.dataset.name))
Ejemplo n.º 11
0
 def retract(self, dataset):
     self._get_dataset(dataset)
     require.dataset.update(c.dataset)
     if c.dataset.private:
         abort(400, _("This dataset is already private!"))
     c.dataset.private = True
     AggregationCache(c.dataset).invalidate()
     db.session.commit()
     h.flash_success(_("The dataset has been retracted. " \
             "It is no longer visible to others."))
     redirect(h.url_for(controller='editor', action='index', 
                        dataset=c.dataset.name))
Ejemplo n.º 12
0
 def publish(self, dataset):
     self._get_dataset(dataset)
     require.dataset.update(c.dataset)
     if not c.dataset.private:
         abort(400, _("This dataset is already public!"))
     c.dataset.private = False
     db.session.commit()
     public_url = h.url_for(controller='dataset', action='view', 
                        dataset=c.dataset.name, qualified=True)
     h.flash_success(_("Congratulations, the dataset has been " \
             "published. It is now available at: %s") % public_url)
     redirect(h.url_for(controller='editor', action='index', 
                        dataset=c.dataset.name))
Ejemplo n.º 13
0
 def publish(self, dataset):
     self._get_dataset(dataset)
     require.dataset.update(c.dataset)
     if not c.dataset.private:
         abort(400, _("This dataset is already public!"))
     c.dataset.private = False
     db.session.commit()
     public_url = h.url_for(controller='dataset', action='view', 
                        dataset=c.dataset.name, qualified=True)
     h.flash_success(_("Congratulations, the dataset has been " \
             "published. It is now available at: %s") % public_url)
     redirect(h.url_for(controller='editor', action='index', 
                        dataset=c.dataset.name))
Ejemplo n.º 14
0
 def views_update(self, dataset, format='html'):
     self._get_dataset(dataset)
     require.dataset.update(c.dataset)
     errors, views = {}, None
     try:
         views = json.loads(request.params.get('views'))
         schema = views_schema(ValidationState(c.dataset.model))
         c.dataset.data['views'] = schema.deserialize(views)
         db.session.commit()
         h.flash_success(_("The views have been updated."))
     except (ValueError, TypeError):
         abort(400, _("The views could not be decoded as JSON!"))
     except Invalid, i:
         errors = i.asdict()
Ejemplo n.º 15
0
 def views_update(self, dataset, format='html'):
     self._get_dataset(dataset)
     require.dataset.update(c.dataset)
     errors, views = {}, None
     try:
         views = json.loads(request.params.get('views'))
         schema = views_schema(ValidationState(c.dataset.model))
         c.dataset.data['views'] = schema.deserialize(views)
         db.session.commit()
         h.flash_success(_("The views have been updated."))
     except (ValueError, TypeError):
         abort(400, _("The views could not be decoded as JSON!"))
     except Invalid, i:
         errors = i.asdict()
Ejemplo n.º 16
0
    def dimensions_edit(self, dataset, errors={}, mapping=None, 
            format='html', mode='visual'):

        assert mode in ['visual', 'source']
        self._get_dataset(dataset)
        require.dataset.update(c.dataset)
        # TODO: really split up dimensions and mapping editor.
        c.source = c.dataset.sources.first()
        if c.source is None:
            abort(400, _("You cannot edit the dimensions model before "\
                          "defining a data source"))
        mapping = mapping or c.dataset.data.get('mapping', {})
        if not len(mapping) and c.source and 'mapping' in c.source.analysis:
            mapping = c.source.analysis['mapping']
        c.fill = {'mapping': json.dumps(mapping, indent=2)}
        c.errors = errors
        c.can_edit = not len(c.dataset)

        template = {'visual': 'editor/dimensions.html',
                    'source': 'editor/dimensions_source.html'}[mode]

        return render(template, form_fill=c.fill)
Ejemplo n.º 17
0
    def dimensions_edit(self, dataset, errors={}, mapping=None, 
            format='html', mode='visual'):

        assert mode in ['visual', 'source']
        self._get_dataset(dataset)
        require.dataset.update(c.dataset)
        # TODO: really split up dimensions and mapping editor.
        c.source = c.dataset.sources.first()
        if c.source is None:
            abort(400, _("You cannot edit the dimensions model before "\
                          "defining a data source"))
        mapping = mapping or c.dataset.data.get('mapping', {})
        if not len(mapping) and c.source and 'mapping' in c.source.analysis:
            mapping = c.source.analysis['mapping']
        c.fill = {'mapping': json.dumps(mapping, indent=2)}
        c.errors = errors
        c.can_edit = not len(c.dataset)

        template = {'visual': 'editor/dimensions.html',
                    'source': 'editor/dimensions_source.html'}[mode]

        return render(template, form_fill=c.fill)
Ejemplo n.º 18
0
 def _get_source(self, dataset, id):
     self._get_dataset(dataset)
     c.source = Source.by_id(id)
     if c.source is None or c.source.dataset != c.dataset:
         abort(404, _("There is no source '%s'") % id)
Ejemplo n.º 19
0
 def not_found(self):
     abort(404, "Custom 404 error message")
Ejemplo n.º 20
0
 def server_error(self):
     abort(500, "Custom 500 error message")
Ejemplo n.º 21
0
 def not_authorised(self):
     abort(403, "Custom 403 error message")
Ejemplo n.º 22
0
 def not_authorised(self):
     abort(403, "Custom 403 error message")
Ejemplo n.º 23
0
 def _get_source(self, dataset, id):
     self._get_dataset(dataset)
     c.source = Source.by_id(id)
     if c.source is None or c.source.dataset != c.dataset:
         abort(404, _("There is no source '%s'") % id)
Ejemplo n.º 24
0
 def server_error(self):
     abort(500, "Custom 500 error message")
Ejemplo n.º 25
0
 def not_found(self):
     abort(404, "Custom 404 error message")