def resource_with_id_and_filename(filename, dataset, obj_id): from mcod.resources.models import Resource full_filename = prepare_file(filename) with open(full_filename, 'rb') as outfile: if is_enabled('S40_new_file_model.be'): res = Resource.objects.create( id=obj_id, title='Local file resource', description='Resource with file', dataset=dataset, data_date=datetime.today(), status='published' ) ResourceFileFactory.create( resource_id=res.pk, file=File(outfile), ) else: Resource.objects.create( id=obj_id, title='Local file resource', description='Resource with file', file=File(outfile), dataset=dataset, data_date=datetime.today(), status='published' )
def no_data_resource(dataset): resource = Resource() resource.title = "No data resource" resource.type = "file" resource.format = 'JPG' if not is_enabled('S40_new_file_model.be'): resource.file = File(open(prepare_file('buzzfeed-logo.jpg'), 'rb')) resource.file.open('rb') resource.dataset = dataset resource.save() if is_enabled('S40_new_file_model.be'): ResourceFile.objects.create(file=File( open(prepare_file('buzzfeed-logo.jpg'), 'rb')), is_main=True, resource=resource, format='JPG') resource = Resource.objects.get(pk=resource.pk) return resource
def table_resource_with_invalid_schema(dataset): resource = Resource() resource.url = "http://smth.smwhere.com" resource.title = "File resource name" resource.type = "file" resource.format = 'XLSX' resource.file = File(open(prepare_file('wrong_schema_table.xlsx'), 'rb')) resource.file.open('rb') resource.dataset = dataset resource.save() return resource
def example_n_triples_file(): # https://www.w3.org/TR/2014/REC-n-triples-20140225/Overview.html return prepare_file('rdf/example_n_triples.nt')
def empty_tar_gz_file(): return prepare_file('empty_file.tar.gz')
def example_binary_netcdf(): return prepare_file('madis-maritime.nc')
def shapefile_trees(): return [prepare_file('iglaste.tar.xz'), prepare_file('iglaste_other.tar.xz')]
def example_trix_file(): # https://www.w3.org/2004/03/trix/ return prepare_file('rdf/example_trix.trix')
def example_grib(): return prepare_file('example_grib.grib')
def single_csv_zip(): return prepare_file('single_csv.zip')
def example_rdf_file(): # https://www.w3.org/TR/REC-rdf-syntax/#example7 return prepare_file('rdf/example_rdf.rdf')
def simple_csv_file(): return prepare_file('simple.csv')
def single_file_pack(): return prepare_file('single_file.tar.gz')
def example_xlsx_file(): return prepare_file('sheet_img.xlsx')
def example_xls_file(): return prepare_file('example_xls_file.xls')
def example_n_quads_file(): # https://www.w3.org/TR/2014/REC-n-quads-20140225/ return prepare_file('rdf/example_n_quads.nq')
def empty_tar_bz2_file(): return prepare_file('empty_file.tar.bz2')
def multi_file_pack(): return prepare_file('multi_file.rar')
def example_ods_file(): return prepare_file('example_ods_file.ods')
def multi_file_zip_pack(): return prepare_file('multi_pdf_xlsx.zip')
def example_trig_file(): # https://www.w3.org/TR/2014/REC-trig-20140225/ return prepare_file('rdf/example_trig.trig')
def shapefile_arch(): return prepare_file('Mexico_and_US_Border.zip')
def example_turtle_file(): # https://www.w3.org/TR/2014/REC-turtle-20140225/examples/example1.ttl return prepare_file('rdf/example_turtle.ttl')
def empty_zip_file(): return prepare_file('empty_file.zip')
def example_hdf_netcdf(): return prepare_file('darwin_2012.nc')
def example_kml_file(): return prepare_file('example_kml.kml')
def shapefile_world(): return [prepare_file('TM_WORLD_BORDERS-0.3.%s' % ext) for ext in ('shp', 'shx', 'prj', 'dbf')]
def empty_7z_file(): return prepare_file('empty_file.7z')
def empty_rar_file(): return prepare_file('empty_file.rar')
def example_n3_file(): # https://w3c.github.io/N3/spec/#simpletriples return prepare_file('rdf/example_n3.n3')