Skip to content

Commit

Permalink
Add ftod(fields to download) parameter management
Browse files Browse the repository at this point in the history
  • Loading branch information
wlorenzetti committed Oct 11, 2023
1 parent d430836 commit cef719e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions g3w-admin/qdjango/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cef719e

Please sign in to comment.