diff --git a/g3w-admin/qdjango/vector.py b/g3w-admin/qdjango/vector.py index 9e47f9d30..eee63a1b0 100644 --- a/g3w-admin/qdjango/vector.py +++ b/g3w-admin/qdjango/vector.py @@ -275,6 +275,11 @@ def initial(self, request, *args, **kwargs): if 'widget_type' in kwargs: self.widget_type = kwargs['widget_type'] + # Get requests_params + if "ftod" in request.query_params: + self.fields_to_download = request.query_params.get("ftod") + + super(LayerVectorView, self).initial(request, *args, **kwargs) def get_forms(self): @@ -589,6 +594,23 @@ def _set_download_attributes(self, save_options): column_to_exclude = [self.metadata_layer.qgis_layer.fields().indexFromName(f) for f in column_to_exclude] save_options.attributes = list(set(self.metadata_layer.qgis_layer.attributeList()) - set(column_to_exclude)) + # Filter by user selection: request parameter `ftod`(fields to download) + if hasattr(self, 'fields_to_download') and self.fields_to_download != '': + try: + + # Parse + fnames = self.fields_to_download.split(',') + + # Get fields index + findexes = [self.metadata_layer.qgis_layer.fields().indexFromName(f) for f in fnames] + + if save_options.attributes and len(save_options.attributes) > 0: + save_options.attributes = list(set(save_options.attributes).intersection(set(findexes))) + else: + save_options.attributes = findexes + except: + pass + def response_shp_mode(self, request): """ Download Shapefile of data