def __location_shapefiles(self): """For all the combinations of contractor and measurement type in this project, check if the shapefile exists, and if so return its path and the measurement type and contractor.""" for mtype in models.MeasurementType.objects.filter( project=self.project): for contractor in Contractor.objects.filter(project=self.project): if has_access(self.user, self.project, contractor): shapefile_path = directories.location_shapefile_path( self.project, contractor, mtype.mtype) if os.path.exists(shapefile_path + ".shp"): yield shapefile_path, contractor, mtype
def __save_uploaded_files(self, request, contractor, amtype): shapefilepath = directories.location_shapefile_path( self.project, contractor, amtype) with open(shapefilepath + '.shp', 'wb+') as dest: for chunk in request.FILES['shp'].chunks(): dest.write(chunk) with open(shapefilepath + '.dbf', 'wb+') as dest: for chunk in request.FILES['dbf'].chunks(): dest.write(chunk) with open(shapefilepath + '.shx', 'wb+') as dest: for chunk in request.FILES['shx'].chunks(): dest.write(chunk) return shapefilepath + '.shp'