Esempio n. 1
0
def import_csv(dataset, url, args):
    """
    Import the csv data into the dataset
    """

    csv_data_url, source_url = url 
    source = Source(dataset, shell_account(), 
                    csv_data_url)
    # Analyse the csv data and add it to the source
    # If we don't analyse it we'll be left with a weird message
    source.analysis = analyze_csv(csv_data_url)
    # Check to see if the dataset already has this source
    for source_ in dataset.sources:
        if source_.url == csv_data_url:
            source = source_
            break
    db.session.add(source)
    db.session.commit()
    
    dataset.generate()
    importer = CSVImporter(source)
    importer.run(**vars(args))

    # Check if imported from the file system (source and data url differ)
    if csv_data_url != source_url:
        # If we did, then we must update the source url based on the
        # sources in the dataset model (so we need to fetch the source again
        # or else we'll add a new one)
        source = Source.by_id(source.id)
        source.url = source_url
        db.session.commit()
Esempio n. 2
0
def import_csv(dataset, url, args):
    """
    Import the csv data into the dataset
    """

    csv_data_url, source_url = url
    source = Source(dataset, shell_account(), csv_data_url)
    # Analyse the csv data and add it to the source
    # If we don't analyse it we'll be left with a weird message
    source.analysis = analyze_csv(csv_data_url)
    # Check to see if the dataset already has this source
    for source_ in dataset.sources:
        if source_.url == csv_data_url:
            source = source_
            break
    db.session.add(source)
    db.session.commit()

    dataset.generate()
    importer = CSVImporter(source)
    importer.run(**vars(args))

    # Check if imported from the file system (source and data url differ)
    if csv_data_url != source_url:
        # If we did, then we must update the source url based on the
        # sources in the dataset model (so we need to fetch the source again
        # or else we'll add a new one)
        source = Source.by_id(source.id)
        source.url = source_url
        db.session.commit()
Esempio n. 3
0
 def test_dimensions_edit_mask_with_data(self):
     cra = Dataset.by_name('cra')
     src = Source(cra, self.user, 'file:///dev/null')
     src.analysis = {'columns': ['amount', 'etc']}
     db.session.add(src)
     db.session.commit()
     response = self.app.get(url(controller='editor',
                                 action='dimensions_edit', dataset='cra'),
                             extra_environ={'REMOTE_USER': '******'})
     assert 'cannot edit dimensions' in response.body
     assert '"amount"' not in response.body
     assert 'Update' not in response.body
Esempio n. 4
0
 def test_dimensions_edit_mask_with_data(self):
     cra = Dataset.by_name('cra')
     src = Source(cra, self.user, 'file:///dev/null')
     src.analysis = {'columns': ['amount', 'etc']}
     db.session.add(src)
     db.session.commit()
     response = self.app.get(url(controller='editor', 
         action='dimensions_edit', dataset='cra'),
         extra_environ={'REMOTE_USER': '******'})
     assert 'cannot edit dimensions' in response.body
     assert '"amount"' not in response.body
     assert 'Update' not in response.body