g3w-admin-processing 1.2.1b1.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- g3w_admin_processing-1.2.1b1.dev1.dist-info/METADATA +258 -0
- g3w_admin_processing-1.2.1b1.dev1.dist-info/RECORD +80 -0
- g3w_admin_processing-1.2.1b1.dev1.dist-info/WHEEL +5 -0
- g3w_admin_processing-1.2.1b1.dev1.dist-info/licenses/LICENSE +373 -0
- g3w_admin_processing-1.2.1b1.dev1.dist-info/top_level.txt +1 -0
- qprocessing/__init__.py +7 -0
- qprocessing/admin.py +21 -0
- qprocessing/api/__init__.py +0 -0
- qprocessing/api/permissions.py +41 -0
- qprocessing/api/views/__init__.py +4 -0
- qprocessing/api/views/actions.py +84 -0
- qprocessing/api/views/admin.py +76 -0
- qprocessing/api/views/models.py +219 -0
- qprocessing/api/views/upload.py +177 -0
- qprocessing/apiurls.py +64 -0
- qprocessing/apps.py +38 -0
- qprocessing/configs.py +131 -0
- qprocessing/forms.py +133 -0
- qprocessing/migrations/0001_initial.py +24 -0
- qprocessing/migrations/0002_auto_20230615_1609.py +23 -0
- qprocessing/migrations/0003_qprocessinginputupload.py +32 -0
- qprocessing/migrations/0004_auto_20230809_0920.py +26 -0
- qprocessing/migrations/0005_alter_qprocessinginputupload_user.py +21 -0
- qprocessing/migrations/__init__.py +0 -0
- qprocessing/models.py +143 -0
- qprocessing/receivers.py +100 -0
- qprocessing/sitetrees.py +31 -0
- qprocessing/static/qprocessing/js/components/DrawInputVectorFeatures.js +180 -0
- qprocessing/static/qprocessing/js/components/InputFieldChooser.js +226 -0
- qprocessing/static/qprocessing/js/components/InputPrjRasterLayer.js +135 -0
- qprocessing/static/qprocessing/js/components/InputPrjVectorLayer.js +415 -0
- qprocessing/static/qprocessing/js/components/ModelPanel.js +496 -0
- qprocessing/static/qprocessing/js/components/ModelResults.js +73 -0
- qprocessing/static/qprocessing/js/components/OutputFile.js +63 -0
- qprocessing/static/qprocessing/js/components/OutputRasterLayer.js +63 -0
- qprocessing/static/qprocessing/js/components/OutputVectorLayer.js +115 -0
- qprocessing/static/qprocessing/js/components/UploadVectorFile.js +53 -0
- qprocessing/static/qprocessing/js/i18n/en.js +33 -0
- qprocessing/static/qprocessing/js/i18n/index.js +7 -0
- qprocessing/static/qprocessing/js/i18n/it.js +33 -0
- qprocessing/static/qprocessing/js/plugin.js +122 -0
- qprocessing/tasks.py +136 -0
- qprocessing/templates/qprocessing/project_form.html +70 -0
- qprocessing/templates/qprocessing/projects_list.html +72 -0
- qprocessing/tests/__init__.py +0 -0
- qprocessing/tests/base.py +104 -0
- qprocessing/tests/data/models/qbuffer.model3 +233 -0
- qprocessing/tests/data/models/qintersection.model3 +288 -0
- qprocessing/tests/data/models/qpointspolygons.model3 +222 -0
- qprocessing/tests/data/models/test.model3 +321 -0
- qprocessing/tests/data/models/test_buffer_all_inputs.model3 +269 -0
- qprocessing/tests/data/models/test_buffer_layer1.model3 +201 -0
- qprocessing/tests/data/project_data/buildings.geojson +15 -0
- qprocessing/tests/data/project_data/qprocessing.gpkg +0 -0
- qprocessing/tests/data/qprocessing_qprocessing.qgs +2813 -0
- qprocessing/tests/data/qprocessing_qprocessing_attachments.zip +0 -0
- qprocessing/tests/data/test_qgis_328.qgs +954 -0
- qprocessing/tests/data/test_qgis_328_attachments.zip +0 -0
- qprocessing/tests/data/upload/fail_shp_to_upload.zip +0 -0
- qprocessing/tests/data/upload/linestring_to_upload.geojson +9 -0
- qprocessing/tests/data/upload/point_to_upload.geojson +10 -0
- qprocessing/tests/data/upload/point_to_upload_espg4326.geojson +10 -0
- qprocessing/tests/data/upload/point_to_upload_espg4326.qmd +26 -0
- qprocessing/tests/data/upload/polygon_to_upload.geojson +9 -0
- qprocessing/tests/data/upload/shp_to_upload.cpg +1 -0
- qprocessing/tests/data/upload/shp_to_upload.dbf +0 -0
- qprocessing/tests/data/upload/shp_to_upload.prj +1 -0
- qprocessing/tests/data/upload/shp_to_upload.qix +0 -0
- qprocessing/tests/data/upload/shp_to_upload.shp +0 -0
- qprocessing/tests/data/upload/shp_to_upload.shx +0 -0
- qprocessing/tests/data/upload/shp_to_upload.zip +0 -0
- qprocessing/tests/test_algorithm.py +52 -0
- qprocessing/tests/test_api.py +173 -0
- qprocessing/tests/test_api_models.py +459 -0
- qprocessing/urls.py +33 -0
- qprocessing/utils/__init__.py +0 -0
- qprocessing/utils/data.py +283 -0
- qprocessing/utils/exceptions.py +20 -0
- qprocessing/utils/formtypes.py +521 -0
- qprocessing/views.py +96 -0
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""" Module to build config options for Qprocessing client form building.
|
|
3
|
+
.. note:: This program is free software; you can redistribute it and/or modify
|
|
4
|
+
it under the terms of the Mozilla Public License 2.0.
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__author__ = 'lorenzetti@gis3w.it'
|
|
9
|
+
__date__ = '2023-06-07'
|
|
10
|
+
__copyright__ = 'Copyright 2015 - 2023, Gis3w'
|
|
11
|
+
__license__ = 'MPL 2.0'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
from django.conf import settings
|
|
15
|
+
from django.utils.text import slugify
|
|
16
|
+
from core.utils.structure import \
|
|
17
|
+
FORM_FIELD_TYPE_CHECK, \
|
|
18
|
+
FORM_FIELD_TYPE_SELECT
|
|
19
|
+
|
|
20
|
+
from qdjango.utils.edittype import \
|
|
21
|
+
FORM_FIELD_TYPE_QGIS_RANGE
|
|
22
|
+
|
|
23
|
+
# Processing input types
|
|
24
|
+
# ---------------------------------------
|
|
25
|
+
from qgis.core import \
|
|
26
|
+
(QgsProcessingParameterDistance, \
|
|
27
|
+
QgsProcessingParameterVectorLayer, \
|
|
28
|
+
QgsProcessingParameterField, \
|
|
29
|
+
QgsProcessingParameterFeatureSource, \
|
|
30
|
+
QgsProcessingParameterBand, \
|
|
31
|
+
QgsProcessingParameterBoolean, \
|
|
32
|
+
QgsProcessingParameterAggregate, \
|
|
33
|
+
QgsProcessingParameterColor, \
|
|
34
|
+
QgsProcessingParameterEnum, \
|
|
35
|
+
QgsProcessingParameterExpression, \
|
|
36
|
+
QgsProcessingParameterExtent, \
|
|
37
|
+
QgsProcessingParameterDuration, \
|
|
38
|
+
QgsProcessingParameterField, \
|
|
39
|
+
QgsProcessingParameterFile, \
|
|
40
|
+
QgsProcessingParameterGeometry, \
|
|
41
|
+
QgsProcessingParameterNumber, \
|
|
42
|
+
QgsProcessingParameterPoint, \
|
|
43
|
+
QgsProcessingParameterRange, \
|
|
44
|
+
QgsProcessingParameterScale, \
|
|
45
|
+
QgsProcessingParameterAnnotationLayer, \
|
|
46
|
+
QgsProcessingParameterCrs, \
|
|
47
|
+
QgsProcessingParameterString, \
|
|
48
|
+
QgsProcessingParameterDateTime, \
|
|
49
|
+
QgsProcessingParameterCoordinateOperation, \
|
|
50
|
+
QgsProcessingParameterRasterLayer, \
|
|
51
|
+
QgsProcessingOutputVectorLayer, \
|
|
52
|
+
QgsProcessingOutputRasterLayer, \
|
|
53
|
+
QgsProcessingOutputFile, \
|
|
54
|
+
QgsProcessingOutputHtml, \
|
|
55
|
+
QgsWkbTypes,
|
|
56
|
+
QgsProcessingFeatureSourceDefinition,
|
|
57
|
+
QgsVectorLayer)
|
|
58
|
+
|
|
59
|
+
# Processing ouput types
|
|
60
|
+
# ---------------------------------------
|
|
61
|
+
from qgis.core import \
|
|
62
|
+
QgsProcessingOutputVectorLayer
|
|
63
|
+
from core.utils import structure
|
|
64
|
+
from core.utils.qgisapi import get_layer_fids_from_server_fids
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
import datetime
|
|
68
|
+
import os
|
|
69
|
+
|
|
70
|
+
# Mapping qprocessing parameters type
|
|
71
|
+
MAPPING_PROCESSING_PARAMS_FORM_TYPE = {
|
|
72
|
+
# Inputs
|
|
73
|
+
QgsProcessingParameterDistance('').type(): structure.FIELD_TYPE_FLOAT,
|
|
74
|
+
QgsProcessingParameterDateTime('').type(): structure.FIELD_TYPE_DATETIME,
|
|
75
|
+
QgsProcessingParameterBoolean('').type(): structure.FIELD_TYPE_BOOLEAN,
|
|
76
|
+
QgsProcessingParameterRasterLayer('').type(): structure.FIELD_TYPE_VARCHAR,
|
|
77
|
+
QgsProcessingParameterVectorLayer('').type(): structure.FIELD_TYPE_VARCHAR,
|
|
78
|
+
QgsProcessingParameterRange('').type(): structure.FIELD_TYPE_INTEGER,
|
|
79
|
+
QgsProcessingParameterNumber('').type(): structure.FIELD_TYPE_INTEGER,
|
|
80
|
+
QgsProcessingParameterExtent('').type(): structure.FIELD_TYPE_VARCHAR,
|
|
81
|
+
QgsProcessingParameterFeatureSource('').type(): structure.FIELD_TYPE_VARCHAR,
|
|
82
|
+
QgsProcessingParameterField('').type(): structure.FIELD_TYPE_VARCHAR,
|
|
83
|
+
#TODO: add other QgsProcessingParamenter* type
|
|
84
|
+
# Outputs
|
|
85
|
+
QgsProcessingOutputVectorLayer('').type(): structure.FIELD_TYPE_VARCHAR,
|
|
86
|
+
QgsProcessingOutputRasterLayer('').type(): structure.FIELD_TYPE_VARCHAR,
|
|
87
|
+
QgsProcessingOutputFile('').type(): structure.FIELD_TYPE_VARCHAR,
|
|
88
|
+
QgsProcessingOutputHtml('').type(): structure.FIELD_TYPE_VARCHAR,
|
|
89
|
+
#TODO: add other QgsProcessingOutput* type
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
# Specific Form Field Types for QProcessing client forms
|
|
93
|
+
# ------------------------------------------------------
|
|
94
|
+
FORM_FIELD_TYPE_VECTORLAYER = 'vectorlayer' # A vector data layer which can be uploaded
|
|
95
|
+
FORM_FIELD_TYPE_PRJVECTORLAYER = 'prjvectorlayer' # A vector layer belonging to the project
|
|
96
|
+
FORM_FIELD_TYPE_RASTERLAYER = 'rasterlayer' # A raster data layer which can be uploaded
|
|
97
|
+
FORM_FIELD_TYPE_PRJRASTERLAYER = 'prjrasterlayer' # A raster layer belonging to the project
|
|
98
|
+
FORM_FIELD_TYPE_EXTENT = 'extent' # Type to get extent values form layer, map, bookmarks or by hand
|
|
99
|
+
FORM_FIELD_TYPE_FEATURESOURCE = 'prjvectorlayerfeature' # A vector layer belonging to the project or feature selected
|
|
100
|
+
FORM_FIELD_TYPE_FIELDCHOOSER = 'fieldchooser' # A select with multiple choosen or not belonging from other vectorlayer or prjvectorlayer field
|
|
101
|
+
|
|
102
|
+
# For outputs
|
|
103
|
+
FORM_FIELD_TYPE_OUTPUT_VECTORLAYER = 'outputvectorlayer' # Type to get outputvector type
|
|
104
|
+
FORM_FIELD_TYPE_OUTPUT_RASTERLAYER = 'outputrasterlayer' # Type to get outputraster type
|
|
105
|
+
FORM_FIELD_TYPE_OUTPUT_FILE = 'outputfile' # Type to get outputfile type
|
|
106
|
+
FORM_FIELD_TYPE_OUTPUT_HTML = 'outputhtml' # Type to get outputfile type
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class QProcessingFormTypeException(Exception):
|
|
110
|
+
pass
|
|
111
|
+
|
|
112
|
+
class QProcessingFormType(object):
|
|
113
|
+
"""
|
|
114
|
+
Base class to render form config structure for g3w-client
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
def __init__(self, **qprocessingparams):
|
|
118
|
+
"""
|
|
119
|
+
:param qprocessingparams: QgsProcessingParameterDefinition.toVariantMap results
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
for key, value in list(qprocessingparams.items()):
|
|
123
|
+
setattr(self, key, value)
|
|
124
|
+
|
|
125
|
+
@property
|
|
126
|
+
def input_form(self):
|
|
127
|
+
return dict()
|
|
128
|
+
|
|
129
|
+
@staticmethod
|
|
130
|
+
def update_model_params(qgs_project, parameter=None, output=None,**kwargs):
|
|
131
|
+
'''
|
|
132
|
+
Method to make parameters for running model.
|
|
133
|
+
:params qgs_project: qdjango.model.Project instance.
|
|
134
|
+
:params parameter: POST data coming from g3w-client.
|
|
135
|
+
:params output: Dict about outputs model.
|
|
136
|
+
:return: Str, Object, ... for model running.
|
|
137
|
+
'''
|
|
138
|
+
|
|
139
|
+
if parameter and output:
|
|
140
|
+
return output
|
|
141
|
+
else:
|
|
142
|
+
return parameter
|
|
143
|
+
|
|
144
|
+
def validate_type(self, file_path):
|
|
145
|
+
"""
|
|
146
|
+
Validate input type
|
|
147
|
+
"""
|
|
148
|
+
pass
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class QProcessingFormTypeDistance(QProcessingFormType):
|
|
152
|
+
"""
|
|
153
|
+
FormType QProcessing class for type `distance` (QgsProcessingParameterDistance)
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
field_type = structure.FORM_FIELD_TYPE_FLOAT
|
|
157
|
+
|
|
158
|
+
@property
|
|
159
|
+
def input_form(self):
|
|
160
|
+
return {
|
|
161
|
+
'input': {
|
|
162
|
+
'type': FORM_FIELD_TYPE_QGIS_RANGE,
|
|
163
|
+
'options': {
|
|
164
|
+
'default': self.default,
|
|
165
|
+
'values': [
|
|
166
|
+
{
|
|
167
|
+
'min': self.min,
|
|
168
|
+
'max': self.max,
|
|
169
|
+
'step': 1
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
]
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
class QProcessingFormTypeNumber(QProcessingFormType):
|
|
178
|
+
"""
|
|
179
|
+
FormType QProcessing class for type `number` (QgsProcessingParameterNUmber)
|
|
180
|
+
"""
|
|
181
|
+
|
|
182
|
+
@property
|
|
183
|
+
def input_form(self):
|
|
184
|
+
return {
|
|
185
|
+
'input': {
|
|
186
|
+
'type': FORM_FIELD_TYPE_QGIS_RANGE,
|
|
187
|
+
'options': {
|
|
188
|
+
'default': self.default,
|
|
189
|
+
'values': [
|
|
190
|
+
{
|
|
191
|
+
'min': self.min,
|
|
192
|
+
'max': self.max,
|
|
193
|
+
'step': 1
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
class QProcessingFormTypeVectorLayer(QProcessingFormType):
|
|
202
|
+
"""
|
|
203
|
+
FormType QProcessing class for type `vector` (QgsProcessingParameterVectorLayer)
|
|
204
|
+
"""
|
|
205
|
+
|
|
206
|
+
field_type = FORM_FIELD_TYPE_PRJVECTORLAYER
|
|
207
|
+
TYPES = {
|
|
208
|
+
5: 'nogeometry',
|
|
209
|
+
0: 'point',
|
|
210
|
+
1: 'line',
|
|
211
|
+
2: 'polygon',
|
|
212
|
+
-1: 'anygeometry'
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
@staticmethod
|
|
216
|
+
def update_model_params(qgs_project, parameter):
|
|
217
|
+
|
|
218
|
+
# Case uploaded input file
|
|
219
|
+
# --------------------------------------------
|
|
220
|
+
# Split by `:`
|
|
221
|
+
subparams = parameter.split(":")
|
|
222
|
+
if len(subparams) == 1:
|
|
223
|
+
return qgs_project.mapLayer(parameter).source()
|
|
224
|
+
|
|
225
|
+
# Build path to file
|
|
226
|
+
from qprocessing.models import QProcessingInputUpload
|
|
227
|
+
try:
|
|
228
|
+
qpiu = QProcessingInputUpload.objects.get(uuid=subparams[1])
|
|
229
|
+
base_path = settings.QPROCESSING_INPUT_UPLOAD_PATH
|
|
230
|
+
base_path += f"{qpiu.user.pk}/" if qpiu.user else f"nouser/"
|
|
231
|
+
base_path += f"uploads/{qpiu.name}"
|
|
232
|
+
|
|
233
|
+
return base_path
|
|
234
|
+
except:
|
|
235
|
+
return None
|
|
236
|
+
|
|
237
|
+
def validate_type(self, file_path):
|
|
238
|
+
"""
|
|
239
|
+
Check for correct geometry
|
|
240
|
+
"""
|
|
241
|
+
|
|
242
|
+
vlayer = QgsVectorLayer(file_path)
|
|
243
|
+
if not vlayer.isValid():
|
|
244
|
+
raise QProcessingFormTypeException(f'{file_path} is no valid')
|
|
245
|
+
|
|
246
|
+
# If self.data_types contain -1 (anygeometry), return True
|
|
247
|
+
if -1 in self.data_types:
|
|
248
|
+
return True
|
|
249
|
+
|
|
250
|
+
if vlayer.geometryType() not in self.data_types:
|
|
251
|
+
raise QProcessingFormTypeException(f"Input file {file_path} must have a geometry type of:"
|
|
252
|
+
f" {','.join([self.TYPES[t] for t in self.data_types])}")
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
@property
|
|
256
|
+
def input_form(self):
|
|
257
|
+
return {
|
|
258
|
+
'input': {
|
|
259
|
+
'type': self.field_type,
|
|
260
|
+
'options': {
|
|
261
|
+
'datatypes': [self.TYPES[t] for t in self.data_types],
|
|
262
|
+
'values': []
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
class QProcessingFormTypeRasterLayer(QProcessingFormType):
|
|
268
|
+
"""
|
|
269
|
+
FormType QProcessing class for type `raster` (QgsProcessingParameterRasterLayer)
|
|
270
|
+
"""
|
|
271
|
+
|
|
272
|
+
field_type = FORM_FIELD_TYPE_PRJRASTERLAYER
|
|
273
|
+
|
|
274
|
+
@staticmethod
|
|
275
|
+
def update_model_params(qgs_project, parameter):
|
|
276
|
+
return qgs_project.mapLayer(parameter).source()
|
|
277
|
+
|
|
278
|
+
@property
|
|
279
|
+
def input_form(self):
|
|
280
|
+
return {
|
|
281
|
+
'input': {
|
|
282
|
+
'type': self.field_type,
|
|
283
|
+
'options': {
|
|
284
|
+
'values': []
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
class QProcessingFormTypeExtent(QProcessingFormType):
|
|
290
|
+
"""
|
|
291
|
+
FormType QProcessing class for type `extent` (QgsProcessingParameterExtent)
|
|
292
|
+
"""
|
|
293
|
+
|
|
294
|
+
field_type = FORM_FIELD_TYPE_EXTENT
|
|
295
|
+
|
|
296
|
+
@property
|
|
297
|
+
def input_form(self):
|
|
298
|
+
return {
|
|
299
|
+
'input': {
|
|
300
|
+
'type': self.field_type,
|
|
301
|
+
'options': {
|
|
302
|
+
'default': self.default
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
class QProcessingFormTypeBoolean(QProcessingFormType):
|
|
309
|
+
"""
|
|
310
|
+
FormType QProcessing class for type `boolean` (QgsProcessingParameterBoolean)
|
|
311
|
+
"""
|
|
312
|
+
|
|
313
|
+
field_type = FORM_FIELD_TYPE_CHECK
|
|
314
|
+
|
|
315
|
+
@staticmethod
|
|
316
|
+
def update_model_params(qgs_project, parameter):
|
|
317
|
+
return True if parameter.lower() == 'true' else False
|
|
318
|
+
|
|
319
|
+
@property
|
|
320
|
+
def input_form(self):
|
|
321
|
+
return {
|
|
322
|
+
'input': {
|
|
323
|
+
'type': self.field_type,
|
|
324
|
+
'options': {
|
|
325
|
+
'default': self.default,
|
|
326
|
+
'values': [
|
|
327
|
+
{'value': 'True', 'checked': True},
|
|
328
|
+
{'value': 'False', 'checked': False},
|
|
329
|
+
]
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
class QProcessingFormTypeField(QProcessingFormType):
|
|
336
|
+
"""
|
|
337
|
+
FormType QProcessing class for type `field` (QgsProcessingParameterField)
|
|
338
|
+
"""
|
|
339
|
+
|
|
340
|
+
field_type = FORM_FIELD_TYPE_FIELDCHOOSER
|
|
341
|
+
TYPES = {
|
|
342
|
+
QgsProcessingParameterField.String: 'string',
|
|
343
|
+
QgsProcessingParameterField.Numeric: 'numeric',
|
|
344
|
+
QgsProcessingParameterField.DateTime: 'datetime',
|
|
345
|
+
QgsProcessingParameterField.Any: 'any'
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
@staticmethod
|
|
349
|
+
def update_model_params(qgs_project, parameter):
|
|
350
|
+
return parameter.split(',')
|
|
351
|
+
|
|
352
|
+
@property
|
|
353
|
+
def input_form(self):
|
|
354
|
+
return {
|
|
355
|
+
'input': {
|
|
356
|
+
'type': self.field_type,
|
|
357
|
+
'options': {
|
|
358
|
+
'default': self.default,
|
|
359
|
+
'multiple': self.allow_multiple,
|
|
360
|
+
'parent_field': self.parent_layer,
|
|
361
|
+
'datatype': self.TYPES[self.data_type],
|
|
362
|
+
'default_to_all_fields': self.default_to_all_fields,
|
|
363
|
+
'values': []
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
class QProcessingFormTypeFeatureSource(QProcessingFormTypeVectorLayer):
|
|
369
|
+
"""
|
|
370
|
+
FormType QProcessing class for type `vector` (QgsProcessingParameterVectorLayer)
|
|
371
|
+
"""
|
|
372
|
+
|
|
373
|
+
field_type = FORM_FIELD_TYPE_FEATURESOURCE
|
|
374
|
+
|
|
375
|
+
@staticmethod
|
|
376
|
+
def update_model_params(qgs_project, parameter):
|
|
377
|
+
# Split by `:`
|
|
378
|
+
subparams = parameter.split(':')
|
|
379
|
+
qgs_layer = qgs_project.mapLayer(subparams[0])
|
|
380
|
+
if len(subparams) == 1:
|
|
381
|
+
return QgsProcessingFeatureSourceDefinition(qgs_layer.source())
|
|
382
|
+
else:
|
|
383
|
+
if subparams[0] == 'file':
|
|
384
|
+
from qprocessing.models import QProcessingInputUpload
|
|
385
|
+
try:
|
|
386
|
+
qpiu = QProcessingInputUpload.objects.get(uuid=subparams[1])
|
|
387
|
+
base_path = settings.QPROCESSING_INPUT_UPLOAD_PATH
|
|
388
|
+
base_path += f"{qpiu.user.pk}/" if qpiu.user else f"nouser/"
|
|
389
|
+
base_path += f"uploads/{qpiu.name}"
|
|
390
|
+
|
|
391
|
+
return base_path
|
|
392
|
+
except:
|
|
393
|
+
return None
|
|
394
|
+
else:
|
|
395
|
+
qgs_layer.selectByIds(get_layer_fids_from_server_fids(subparams[1].split(','), qgs_layer))
|
|
396
|
+
return QgsProcessingFeatureSourceDefinition(qgs_layer.source(), selectedFeaturesOnly=True)
|
|
397
|
+
|
|
398
|
+
# OUTPUT PROCESSING
|
|
399
|
+
# -------------------------------------------------------------
|
|
400
|
+
class QProcessingFormTypeOutputRaster(QProcessingFormType):
|
|
401
|
+
"""
|
|
402
|
+
FormType QProcessing class for type `outputraster` (QgsProcessingOutputRasterLayer)
|
|
403
|
+
"""
|
|
404
|
+
|
|
405
|
+
field_type = FORM_FIELD_TYPE_OUTPUT_RASTERLAYER
|
|
406
|
+
|
|
407
|
+
@staticmethod
|
|
408
|
+
def update_model_params(qgs_project, parameter=None, output=None, **kwargs):
|
|
409
|
+
name = f"{output['label']}-{datetime.datetime.now()}"
|
|
410
|
+
vector_formats = [f['value'] for f in settings.QPROCESSING_OUTPUT_RASTER_FORMATS]
|
|
411
|
+
ext = parameter if parameter in vector_formats else settings.QPROCESSING_OUTPUT_RASTER_FORMAT_DEFAULT
|
|
412
|
+
|
|
413
|
+
return f"{kwargs['save_path']}{slugify(name)}.{ext}"
|
|
414
|
+
|
|
415
|
+
@property
|
|
416
|
+
def input_form(self):
|
|
417
|
+
return {
|
|
418
|
+
'input': {
|
|
419
|
+
'type': self.field_type,
|
|
420
|
+
'options': {
|
|
421
|
+
'values': settings.QPROCESSING_OUTPUT_RASTER_FORMATS
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
class QProcessingFormTypeOutputFile(QProcessingFormType):
|
|
427
|
+
"""
|
|
428
|
+
FormType QProcessing class for type `outputfile` (QgsProcessingOutputFile)
|
|
429
|
+
"""
|
|
430
|
+
|
|
431
|
+
field_type = FORM_FIELD_TYPE_OUTPUT_FILE
|
|
432
|
+
|
|
433
|
+
@staticmethod
|
|
434
|
+
def update_model_params(qgs_project, parameter=None, output=None, **kwargs):
|
|
435
|
+
name = f"{output['label']}-{datetime.datetime.now()}"
|
|
436
|
+
vector_formats = [f['value'] for f in settings.QPROCESSING_OUTPUT_FILE_FORMATS]
|
|
437
|
+
ext = parameter if parameter in vector_formats else settings.QPROCESSING_OUTPUT_FILE_FORMAT_DEFAULT
|
|
438
|
+
|
|
439
|
+
return f"{kwargs['save_path']}{slugify(name)}.{ext}"
|
|
440
|
+
|
|
441
|
+
@property
|
|
442
|
+
def input_form(self):
|
|
443
|
+
return {
|
|
444
|
+
'input': {
|
|
445
|
+
'type': self.field_type,
|
|
446
|
+
'options': {
|
|
447
|
+
'values': settings.QPROCESSING_OUTPUT_FILE_FORMATS
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
class QProcessingFormTypeOutputHtml(QProcessingFormType):
|
|
453
|
+
"""
|
|
454
|
+
FormType QProcessing class for type `outputhtml` (QgsProcessingOutputhtml)
|
|
455
|
+
"""
|
|
456
|
+
|
|
457
|
+
field_type = FORM_FIELD_TYPE_OUTPUT_HTML
|
|
458
|
+
|
|
459
|
+
@staticmethod
|
|
460
|
+
def update_model_params(qgs_project, parameter=None, output=None, **kwargs):
|
|
461
|
+
name = f"{output['label']}-{datetime.datetime.now()}"
|
|
462
|
+
vector_formats = [f['value'] for f in settings.QPROCESSING_OUTPUT_HTML_FORMATS]
|
|
463
|
+
ext = parameter if parameter in vector_formats else settings.QPROCESSING_OUTPUT_HTML_FORMAT_DEFAULT
|
|
464
|
+
|
|
465
|
+
return f"{kwargs['save_path']}{slugify(name)}.{ext}"
|
|
466
|
+
|
|
467
|
+
@property
|
|
468
|
+
def input_form(self):
|
|
469
|
+
return {
|
|
470
|
+
'input': {
|
|
471
|
+
'type': self.field_type,
|
|
472
|
+
'options': {
|
|
473
|
+
'values': settings.QPROCESSING_OUTPUT_HTML_FORMATS
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
class QProcessingFormTypeOutputVector(QProcessingFormType):
|
|
479
|
+
"""
|
|
480
|
+
FormType QProcessing class for type `outputvector` (QgsProcessingOutputVectorLayer)
|
|
481
|
+
"""
|
|
482
|
+
|
|
483
|
+
field_type = FORM_FIELD_TYPE_OUTPUT_VECTORLAYER
|
|
484
|
+
|
|
485
|
+
@staticmethod
|
|
486
|
+
def update_model_params(qgs_project, parameter=None, output=None, **kwargs):
|
|
487
|
+
|
|
488
|
+
name = f"{output['label']}-{datetime.datetime.now()}"
|
|
489
|
+
vector_formats = [f['value'] for f in settings.QPROCESSING_OUTPUT_VECTOR_FORMATS]
|
|
490
|
+
ext = parameter if parameter in vector_formats else settings.QPROCESSING_OUTPUT_VECTOR_FORMAT_DEFAULT
|
|
491
|
+
|
|
492
|
+
return f"{kwargs['save_path']}{slugify(name)}.{ext}"
|
|
493
|
+
|
|
494
|
+
@property
|
|
495
|
+
def input_form(self):
|
|
496
|
+
return {
|
|
497
|
+
'input': {
|
|
498
|
+
'type': self.field_type,
|
|
499
|
+
'options': {
|
|
500
|
+
'values': settings.QPROCESSING_OUTPUT_VECTOR_FORMATS
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
MAPPING_QPROCESSINGTYPE_FORMTYPE = {
|
|
507
|
+
# Inputs
|
|
508
|
+
QgsProcessingParameterDistance('').type(): QProcessingFormTypeDistance,
|
|
509
|
+
QgsProcessingParameterNumber('').type(): QProcessingFormTypeNumber,
|
|
510
|
+
QgsProcessingParameterVectorLayer('').type(): QProcessingFormTypeVectorLayer,
|
|
511
|
+
QgsProcessingParameterRasterLayer('').type(): QProcessingFormTypeRasterLayer,
|
|
512
|
+
QgsProcessingParameterExtent('').type(): QProcessingFormTypeExtent,
|
|
513
|
+
QgsProcessingParameterFeatureSource('').type(): QProcessingFormTypeFeatureSource,
|
|
514
|
+
QgsProcessingParameterBoolean('').type(): QProcessingFormTypeBoolean,
|
|
515
|
+
QgsProcessingParameterField('').type(): QProcessingFormTypeField,
|
|
516
|
+
# Outputs
|
|
517
|
+
QgsProcessingOutputVectorLayer('').type(): QProcessingFormTypeOutputVector,
|
|
518
|
+
QgsProcessingOutputRasterLayer('').type(): QProcessingFormTypeOutputRaster,
|
|
519
|
+
QgsProcessingOutputFile('').type(): QProcessingFormTypeOutputFile,
|
|
520
|
+
QgsProcessingOutputHtml('').type(): QProcessingFormTypeOutputHtml,
|
|
521
|
+
}
|
qprocessing/views.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""" Main views module
|
|
3
|
+
.. note:: This program is free software; you can redistribute it and/or modify
|
|
4
|
+
it under the terms of the Mozilla Public License 2.0.
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__author__ = 'lorenzetti@gis3w.it'
|
|
9
|
+
__date__ = '2023-05-18'
|
|
10
|
+
__copyright__ = 'Copyright 2015 - 2023, Gis3w'
|
|
11
|
+
__license__ = 'MPL 2.0'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
from django.views.generic import ListView, CreateView, UpdateView, View
|
|
15
|
+
from django.views.generic.detail import SingleObjectMixin
|
|
16
|
+
from django.utils.decorators import method_decorator
|
|
17
|
+
from django.urls import reverse_lazy
|
|
18
|
+
from guardian.decorators import permission_required
|
|
19
|
+
from usersmanage.utils import get_viewers_for_object, get_users_for_object, get_user_groups_for_object
|
|
20
|
+
from core.mixins.views import G3WRequestViewMixin, G3WAjaxDeleteViewMixin
|
|
21
|
+
from .models import QProcessingProject
|
|
22
|
+
from .forms import QProcessingProjectForm
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
import json
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class QProcessingProjectsListView(ListView):
|
|
30
|
+
"""List simple qprocessing projects view."""
|
|
31
|
+
|
|
32
|
+
template_name = 'qprocessing/projects_list.html'
|
|
33
|
+
model = QProcessingProject
|
|
34
|
+
|
|
35
|
+
@method_decorator(permission_required('qprocessing.add_qprocessingproject', return_403=True))
|
|
36
|
+
def dispatch(self, *args, **kwargs):
|
|
37
|
+
return super().dispatch(*args, **kwargs)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class QProcessingProjectAddView(G3WRequestViewMixin, CreateView):
|
|
42
|
+
"""
|
|
43
|
+
Create view for QProcessingProject model
|
|
44
|
+
"""
|
|
45
|
+
form_class = QProcessingProjectForm
|
|
46
|
+
template_name = 'qprocessing/project_form.html'
|
|
47
|
+
success_url = reverse_lazy('qprocessing-project-list')
|
|
48
|
+
|
|
49
|
+
@method_decorator(permission_required('qprocessing.add_qprocessingproject', return_403=True))
|
|
50
|
+
def dispatch(self, *args, **kwargs):
|
|
51
|
+
return super().dispatch(*args, **kwargs)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class QProcessingProjectUpdateView(G3WRequestViewMixin, UpdateView):
|
|
55
|
+
"""
|
|
56
|
+
Update view for QProcessingProject model instance
|
|
57
|
+
"""
|
|
58
|
+
model = QProcessingProject
|
|
59
|
+
form_class = QProcessingProjectForm
|
|
60
|
+
template_name = 'qprocessing/project_form.html'
|
|
61
|
+
success_url = reverse_lazy('qprocessing-project-list')
|
|
62
|
+
|
|
63
|
+
@method_decorator(
|
|
64
|
+
permission_required('qprocessing.change_qprocessingproject', (QProcessingProject, 'pk', 'pk'), return_403=True))
|
|
65
|
+
def dispatch(self, *args, **kwargs):
|
|
66
|
+
return super().dispatch(*args, **kwargs)
|
|
67
|
+
|
|
68
|
+
def get_form_kwargs(self):
|
|
69
|
+
"""
|
|
70
|
+
Returns the keyword arguments for instantiating the form.
|
|
71
|
+
"""
|
|
72
|
+
self.get_object()
|
|
73
|
+
kwargs = super().get_form_kwargs()
|
|
74
|
+
kwargs.update({'instance': self.object})
|
|
75
|
+
|
|
76
|
+
# give initial viewer users and viewer user groups
|
|
77
|
+
viewers = get_viewers_for_object(self.object, self.request.user, 'run_model')
|
|
78
|
+
kwargs['initial']['viewer_users'] = [o.id for o in viewers]
|
|
79
|
+
viewer_groups = get_user_groups_for_object(self.object, self.request.user, 'run_model', 'viewer')
|
|
80
|
+
kwargs['initial']['viewer_user_groups'] = [o.id for o in viewer_groups]
|
|
81
|
+
|
|
82
|
+
return kwargs
|
|
83
|
+
|
|
84
|
+
class QProcessingProjectDeleteView(G3WAjaxDeleteViewMixin, SingleObjectMixin, View):
|
|
85
|
+
"""
|
|
86
|
+
Delete SISPIWorkSiteProject model Ajax view
|
|
87
|
+
"""
|
|
88
|
+
model = QProcessingProject
|
|
89
|
+
@method_decorator(
|
|
90
|
+
permission_required('qprocessing.delete_qprocessingproject', (QProcessingProject, 'pk', 'pk'), return_403=True))
|
|
91
|
+
def dispatch(self, *args, **kwargs):
|
|
92
|
+
return super().dispatch(*args, **kwargs)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|