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.
Files changed (80) hide show
  1. g3w_admin_processing-1.2.1b1.dev1.dist-info/METADATA +258 -0
  2. g3w_admin_processing-1.2.1b1.dev1.dist-info/RECORD +80 -0
  3. g3w_admin_processing-1.2.1b1.dev1.dist-info/WHEEL +5 -0
  4. g3w_admin_processing-1.2.1b1.dev1.dist-info/licenses/LICENSE +373 -0
  5. g3w_admin_processing-1.2.1b1.dev1.dist-info/top_level.txt +1 -0
  6. qprocessing/__init__.py +7 -0
  7. qprocessing/admin.py +21 -0
  8. qprocessing/api/__init__.py +0 -0
  9. qprocessing/api/permissions.py +41 -0
  10. qprocessing/api/views/__init__.py +4 -0
  11. qprocessing/api/views/actions.py +84 -0
  12. qprocessing/api/views/admin.py +76 -0
  13. qprocessing/api/views/models.py +219 -0
  14. qprocessing/api/views/upload.py +177 -0
  15. qprocessing/apiurls.py +64 -0
  16. qprocessing/apps.py +38 -0
  17. qprocessing/configs.py +131 -0
  18. qprocessing/forms.py +133 -0
  19. qprocessing/migrations/0001_initial.py +24 -0
  20. qprocessing/migrations/0002_auto_20230615_1609.py +23 -0
  21. qprocessing/migrations/0003_qprocessinginputupload.py +32 -0
  22. qprocessing/migrations/0004_auto_20230809_0920.py +26 -0
  23. qprocessing/migrations/0005_alter_qprocessinginputupload_user.py +21 -0
  24. qprocessing/migrations/__init__.py +0 -0
  25. qprocessing/models.py +143 -0
  26. qprocessing/receivers.py +100 -0
  27. qprocessing/sitetrees.py +31 -0
  28. qprocessing/static/qprocessing/js/components/DrawInputVectorFeatures.js +180 -0
  29. qprocessing/static/qprocessing/js/components/InputFieldChooser.js +226 -0
  30. qprocessing/static/qprocessing/js/components/InputPrjRasterLayer.js +135 -0
  31. qprocessing/static/qprocessing/js/components/InputPrjVectorLayer.js +415 -0
  32. qprocessing/static/qprocessing/js/components/ModelPanel.js +496 -0
  33. qprocessing/static/qprocessing/js/components/ModelResults.js +73 -0
  34. qprocessing/static/qprocessing/js/components/OutputFile.js +63 -0
  35. qprocessing/static/qprocessing/js/components/OutputRasterLayer.js +63 -0
  36. qprocessing/static/qprocessing/js/components/OutputVectorLayer.js +115 -0
  37. qprocessing/static/qprocessing/js/components/UploadVectorFile.js +53 -0
  38. qprocessing/static/qprocessing/js/i18n/en.js +33 -0
  39. qprocessing/static/qprocessing/js/i18n/index.js +7 -0
  40. qprocessing/static/qprocessing/js/i18n/it.js +33 -0
  41. qprocessing/static/qprocessing/js/plugin.js +122 -0
  42. qprocessing/tasks.py +136 -0
  43. qprocessing/templates/qprocessing/project_form.html +70 -0
  44. qprocessing/templates/qprocessing/projects_list.html +72 -0
  45. qprocessing/tests/__init__.py +0 -0
  46. qprocessing/tests/base.py +104 -0
  47. qprocessing/tests/data/models/qbuffer.model3 +233 -0
  48. qprocessing/tests/data/models/qintersection.model3 +288 -0
  49. qprocessing/tests/data/models/qpointspolygons.model3 +222 -0
  50. qprocessing/tests/data/models/test.model3 +321 -0
  51. qprocessing/tests/data/models/test_buffer_all_inputs.model3 +269 -0
  52. qprocessing/tests/data/models/test_buffer_layer1.model3 +201 -0
  53. qprocessing/tests/data/project_data/buildings.geojson +15 -0
  54. qprocessing/tests/data/project_data/qprocessing.gpkg +0 -0
  55. qprocessing/tests/data/qprocessing_qprocessing.qgs +2813 -0
  56. qprocessing/tests/data/qprocessing_qprocessing_attachments.zip +0 -0
  57. qprocessing/tests/data/test_qgis_328.qgs +954 -0
  58. qprocessing/tests/data/test_qgis_328_attachments.zip +0 -0
  59. qprocessing/tests/data/upload/fail_shp_to_upload.zip +0 -0
  60. qprocessing/tests/data/upload/linestring_to_upload.geojson +9 -0
  61. qprocessing/tests/data/upload/point_to_upload.geojson +10 -0
  62. qprocessing/tests/data/upload/point_to_upload_espg4326.geojson +10 -0
  63. qprocessing/tests/data/upload/point_to_upload_espg4326.qmd +26 -0
  64. qprocessing/tests/data/upload/polygon_to_upload.geojson +9 -0
  65. qprocessing/tests/data/upload/shp_to_upload.cpg +1 -0
  66. qprocessing/tests/data/upload/shp_to_upload.dbf +0 -0
  67. qprocessing/tests/data/upload/shp_to_upload.prj +1 -0
  68. qprocessing/tests/data/upload/shp_to_upload.qix +0 -0
  69. qprocessing/tests/data/upload/shp_to_upload.shp +0 -0
  70. qprocessing/tests/data/upload/shp_to_upload.shx +0 -0
  71. qprocessing/tests/data/upload/shp_to_upload.zip +0 -0
  72. qprocessing/tests/test_algorithm.py +52 -0
  73. qprocessing/tests/test_api.py +173 -0
  74. qprocessing/tests/test_api_models.py +459 -0
  75. qprocessing/urls.py +33 -0
  76. qprocessing/utils/__init__.py +0 -0
  77. qprocessing/utils/data.py +283 -0
  78. qprocessing/utils/exceptions.py +20 -0
  79. qprocessing/utils/formtypes.py +521 -0
  80. qprocessing/views.py +96 -0
@@ -0,0 +1,180 @@
1
+ const { GUI } = g3wsdk.gui;
2
+ const { tPlugin } = g3wsdk.core.i18n;
3
+
4
+ export default ({
5
+
6
+ // language=html
7
+ template: /* html */ `
8
+ <div
9
+ class = "qprocessing-draw-vector-features"
10
+ style = "font-size: 1.3em;"
11
+ >
12
+ <button
13
+ class = "btn skin-background-color"
14
+ style = "height: 100%; margin-right: 0 !important;"
15
+ @click.stop.prevent = "toggled = !toggled"
16
+ >
17
+ <i :class="[g3wtemplate.getFontClass('pencil')]"></i>
18
+ </button>
19
+ </div>
20
+ `,
21
+
22
+ name: "DrawInputVectorFeatures",
23
+ props: {
24
+ datatypes: {
25
+ type: Array, //array of datatypes from input
26
+ default: []
27
+ },
28
+ upload:{
29
+ type: Boolean, //Boolean when file is upload ot not
30
+ }
31
+ },
32
+ data() {
33
+ return {
34
+ toggled: false, //draw button toggled
35
+ drawTool: {
36
+ loading: this.upload,
37
+ disabled: true
38
+ }
39
+ }
40
+ },
41
+ methods: {
42
+ /**
43
+ * handle draw interaction flow
44
+ */
45
+ setDrawInteraction(type=this.drawGeometryTypes[0]){
46
+ GUI.getService('map').disableClickMapControls(true); // avoid click conflicts
47
+ this.drawLayer.getSource().clear(); // clear previous features
48
+ GUI.getService('map').getMap().removeInteraction(this.drawInteraction); // remove previous draw interaction
49
+ this.drawInteraction = new ol.interaction.Draw({ type, source: this.drawLayer.getSource() }); // create draw interaction
50
+ this.drawInteraction.on('drawend', () => this.drawTool.disabled = false); // enable upload button on drawend
51
+ GUI.getService('map').getMap().addInteraction(this.drawInteraction); // add interaction to Map
52
+ },
53
+ clear() {
54
+ this.drawLayer.getSource().clear();
55
+ GUI.getService('map').disableClickMapControls(false);
56
+ GUI.getService('map').getMap().removeInteraction(this.drawInteraction);
57
+ GUI.closeUserMessage();
58
+ },
59
+ },
60
+ watch: {
61
+ //listen toggled button
62
+ toggled(bool){
63
+ if (!bool) {
64
+ this.clear();
65
+ this.$emit('toggled-tool', !bool);
66
+ return;
67
+ }
68
+ //set start interaction
69
+ this.setDrawInteraction();
70
+ //whow tool component
71
+ GUI.showUserMessage({
72
+ title: '', //@TODO add translation title
73
+ type: 'tool',
74
+ size: 'small',
75
+ closable: false,
76
+ hooks: {
77
+ body: {
78
+ template: /* html */`
79
+ <div style="width: 100%; padding: 5px;" v-disabled="state.loading">
80
+ <!-- NB: it makes use of built-in g3w-client directive: "v-select2" -->
81
+ <select
82
+ v-select2 = "'type'"
83
+ :search = "false"
84
+ ref = "select"
85
+ style = "width: 100%">
86
+ <option
87
+ v-for = "type in types"
88
+ :key = "type"
89
+ :value = "type"
90
+ v-t-plugin = "'qprocessing.draw_types.'+type"
91
+ ></option>
92
+ </select>
93
+
94
+ <bar-loader :loading="state.loading"/>
95
+
96
+ <button
97
+ v-disabled="state.disabled"
98
+ class="btn skin-background-color"
99
+ @click.stop.prevent="uploadLayer(type)"
100
+ style="margin: 3px; width: 100%">
101
+ <i :class="[g3wtemplate.getFontClass('cloud-upload')]"></i>
102
+ </button>
103
+
104
+ </div>`,
105
+ data: () => {
106
+ return {
107
+ state: this.drawTool,
108
+ types: this.drawGeometryTypes,
109
+ type: this.drawGeometryTypes[0]
110
+ };
111
+ },
112
+ watch: {
113
+
114
+ /**
115
+ * @listens type change of drawed geometry
116
+ * @fires change-draw-type
117
+ */
118
+ 'type': (type) => {
119
+ this.setDrawInteraction(type);
120
+ },
121
+
122
+ },
123
+ methods: {
124
+ uploadLayer: async (type) => {
125
+ const qprocessing = g3wsdk.core.plugin.PluginsRegistry.getPlugin('qprocessing');
126
+ const features = this.drawLayer.getSource().getFeatures();
127
+ await this.$nextTick();
128
+ //emit event
129
+ this.$emit('add-layer', {
130
+ file: qprocessing.createGeoJSONFile({
131
+ features,
132
+ name: `${tPlugin('qprocessing.draw_filename')}(${tPlugin('qprocessing.draw_types.'+type)})`
133
+ }),
134
+ features,
135
+ type: 'draw'
136
+ });
137
+ }
138
+ },
139
+ }
140
+ }
141
+ });
142
+ this.$emit('toggled-tool', !bool);
143
+ },
144
+ upload(bool){
145
+ //listen upload status. Boolean
146
+ this.drawTool.loading = bool;
147
+ this.drawTool.disabled = !bool;
148
+ if (!bool) {
149
+ this.clear();
150
+ this.toggled = bool;
151
+ }
152
+ }
153
+ },
154
+ created() {
155
+
156
+ //set geometries type
157
+ this.drawGeometryTypes = Object.entries({
158
+ point: 'Point',
159
+ line: 'LineString',
160
+ polygon: 'Polygon'
161
+ }).reduce((accumulator, [type, olGeometry]) => {
162
+ if (this.datatypes.find(datatype => datatype === 'anygeometry')){
163
+ accumulator.push(olGeometry);
164
+ } else {
165
+ this.datatypes.find(datatype => datatype === type) && accumulator.push(olGeometry)
166
+ }
167
+ return accumulator;
168
+ }, []);
169
+
170
+ this.drawInteraction = null;
171
+ this.drawLayer = new ol.layer.Vector({ source: new ol.source.Vector() });
172
+ GUI.getService('map').getMap().addLayer(this.drawLayer);
173
+ },
174
+ beforeDestroy() {
175
+ this.clear();
176
+ GUI.getService('map').getMap().removeLayer(this.drawLayer);
177
+ this.drawLayer = null;
178
+ this.drawInteraction = null;
179
+ }
180
+ });
@@ -0,0 +1,226 @@
1
+ const { selectMixin } = g3wsdk.gui.vue.Mixins;
2
+ const { XHR } = g3wsdk.core.utils;
3
+ const { ProjectsRegistry } = g3wsdk.core.project;
4
+
5
+ export default ({
6
+
7
+ // language=html
8
+ template: /* html */ `
9
+ <div
10
+ v-if = "state.visible"
11
+ class = "form-group field-chooser"
12
+ >
13
+
14
+ <slot name="label">
15
+ <label :for="state.name" v-disabled="!state.editable" class="col-sm-12">
16
+ {{ state.label }}
17
+ <span v-if="state.validate && state.validate.required">*</span>
18
+ </label>
19
+ </slot>
20
+
21
+ <div class="col-sm-12">
22
+
23
+ <slot name="body">
24
+ <bar-loader :loading="loading"/>
25
+ <select
26
+ v-select2 = "'value'"
27
+ :multiple = "state.input.options.multiple"
28
+ :id = "state.name"
29
+ ref = "select"
30
+ style = "width:100%;"
31
+ class = "form-control"
32
+ >
33
+ <option
34
+ v-if = "state.validate.required && !state.input.options.multiple"
35
+ :value = "null"
36
+ >---</option>
37
+ <option
38
+ v-for = "value in state.input.options.values"
39
+ :selected = "state.input.options.default_to_all_fields"
40
+ :key ="value.value"
41
+ :value = "value.value"
42
+ >{{ value.key }}</option>
43
+ </select>
44
+ </slot>
45
+
46
+ <slot name="message">
47
+ <p
48
+ v-if = "notvalid"
49
+ class = "g3w-long-text error-input-message"
50
+ style = "margin: 0"
51
+ v-t-plugin = "state.validate.message"
52
+ ></p>
53
+ <p
54
+ v-else-if = "state.info"
55
+ style = "margin: 0 "
56
+ v-html = "state.info"
57
+ ></p>
58
+ </slot>
59
+
60
+ <div
61
+ v-if = "state.help && this.state.help.visible"
62
+ v-html = "state.help.message"
63
+ class = "g3w_input_help skin-background-color extralighten"
64
+ ></div>
65
+
66
+ </div>
67
+
68
+ </div>
69
+ `,
70
+
71
+ name: "InputFieldChooser",
72
+
73
+ mixins: [selectMixin],
74
+
75
+ props: {
76
+ state: {
77
+ type: Object,
78
+ required: true
79
+ },
80
+
81
+ },
82
+
83
+ data() {
84
+ return {
85
+ loading: false,
86
+ value: this.state.input.options.multiple ? [] : null,
87
+ }
88
+ },
89
+
90
+ computed: {
91
+ notvalid(){
92
+ return this.state.validate.valid === false;
93
+ }
94
+ },
95
+
96
+ watch: {
97
+ //listen change of value (input select)
98
+ 'value'(value) {
99
+ // in case of multiple selection
100
+ if (this.state.input.options.multiple) {
101
+ //set input value as values separate by comma
102
+ this.state.value = value.join(',');
103
+ //check if is required
104
+ if (true === this.state.validate.required) {
105
+ //need to check validation
106
+ this.state.validate.valid = value.length > 0;
107
+ }
108
+ } else {
109
+ //case single value
110
+ this.state.value = value;
111
+ // in case of required input value
112
+ if (true === this.state.validate.required) {
113
+ this.state.validate.valid = "" !== value && null !== value;
114
+ }
115
+ }
116
+ //emit change input
117
+ this.$emit('changeinput', this.state);
118
+ },
119
+ },
120
+
121
+ methods: {
122
+ /**
123
+ * Method to extract fields from project layerId based on options
124
+ *
125
+ * @param layerId
126
+ * @param options: <Object> datatype
127
+ */
128
+ async _getFieldsFromLayer(layerId, params={}) {
129
+ const qprocessing = g3wsdk.core.plugin.PluginsRegistry.getPlugin('qprocessing');
130
+
131
+ // Check if it already fills by layerId
132
+ if (undefined === qprocessing.layerFields[layerId]) {
133
+ qprocessing.layerFields[layerId] = {};
134
+ }
135
+
136
+ // check if it was fill based on params
137
+ const GIVE_ME_A_NAME = qprocessing.layerFields[layerId][JSON.stringify(params)];
138
+
139
+ //check if layerId belong to project layer or is id of temporary upload layer
140
+ if (undefined === GIVE_ME_A_NAME && undefined === ProjectsRegistry.getCurrentProject().getLayers().find(layer => layer.id === layerId)) {
141
+ qprocessing.layerFields[layerId][JSON.stringify(params)] = [];
142
+ } else if (undefined === GIVE_ME_A_NAME) {
143
+ try {
144
+ //do request to api
145
+ const response = await XHR.get({
146
+ url: `${qprocessing.config.urls.fields}${ProjectsRegistry.getCurrentProject().getId()}/${layerId}/`,
147
+ params
148
+ });
149
+ if (true === response.result) {
150
+ qprocessing.layerFields[layerId][JSON.stringify(params)] = response.fields;
151
+ }
152
+ } catch(err) {
153
+ console.warn(err);
154
+ return [];
155
+ }
156
+ }
157
+ return qprocessing.layerFields[layerId][JSON.stringify(params)];
158
+ },
159
+
160
+ /**
161
+ * Get all fields by layers
162
+ * @param layerId
163
+ * @param options
164
+ * @returns {*}
165
+ */
166
+ async getFieldsFromLayer(layerId, options={}){
167
+ this.loading = true;
168
+ const fields = await this._getFieldsFromLayer(layerId, options);
169
+ this.loading = false;
170
+ return fields;
171
+ },
172
+ },
173
+
174
+ created() {
175
+ //set it true at beginning to reactivity
176
+ this.state.validate.valid = true;
177
+ },
178
+
179
+ async mounted() {
180
+ //if required we set message of not valid input
181
+ if (this.state.validate.required) {
182
+ this.state.validate.message = `qprocessing.inputs.fieldchooser.validate.message.${this.state.input.options.multiple ? 'multiple' : 'single'}`
183
+ }
184
+
185
+ await this.$nextTick();
186
+ //set this.select2 element
187
+ this.select2 = $(this.$refs.select);
188
+
189
+ //emit register change input to listen parent input layer value and get related fields
190
+ this.$emit('register-change-input', {
191
+ inputName: this.state.input.options.parent_field,
192
+ handler: async (layerId) => {
193
+ //in case of change parent value change, in case of selectefeature need to get only layerId without featuresid
194
+ layerId = layerId.split(':')[0];
195
+ //set values from Input layer fields
196
+ this.state.input.options.values = await this.getFieldsFromLayer(layerId, {
197
+ datatype: this.state.input.options.datatype,
198
+ })
199
+ //check if multiple
200
+ if (this.state.input.options.multiple) {
201
+ //value is set checking if default_all_fields is true, set all options values by defaults, otherwise empty array
202
+ this.value = this.state.input.options.default_to_all_fields ? this.state.input.options.values.map(({value}) => value) : [];
203
+ } else {
204
+ this.value = null;
205
+ }
206
+ // in case of no value or values set value to null
207
+ if (this.value === null || (Array.isArray(this.value) && this.value.length === 0)) {
208
+ this.select2.val(null).trigger('change');
209
+ }
210
+ }
211
+ })
212
+
213
+ this.state.validate.valid = !this.state.validate.required;
214
+ //emit add input
215
+ this.$emit('addinput', this.state);
216
+ },
217
+ });
218
+
219
+ document.head.insertAdjacentHTML(
220
+ 'beforeend',
221
+ /* css */`
222
+ <style>
223
+ /* Replicate same scoped style in InputBase.vue */
224
+ .field-chooser label { text-align: left !important; padding-top: 0 !important; margin-bottom: 3px; }
225
+ </style>`,
226
+ );
@@ -0,0 +1,135 @@
1
+ const { selectMixin } = g3wsdk.gui.vue.Mixins;
2
+ const { ProjectsRegistry } = g3wsdk.core.project;
3
+
4
+ export default ({
5
+
6
+ // language=html
7
+ template: /* html */ `
8
+ <div
9
+ v-if = "state.visible"
10
+ class = "form-group prj-raster-layer"
11
+ >
12
+
13
+ <slot name="label">
14
+ <label
15
+ :for = "state.name"
16
+ v-disabled = "!state.editable"
17
+ class = "col-sm-12">
18
+ >
19
+ {{ state.label }}
20
+ <span v-if="state.validate && state.validate.required">*</span>
21
+ </label>
22
+ </slot>
23
+
24
+ <div class="col-sm-12">
25
+
26
+ <slot name="body">
27
+ <select
28
+ v-select2 = "'value'"
29
+ :id = "state.name"
30
+ ref = "select"
31
+ style = "width:100%;"
32
+ class = "form-control"
33
+ >
34
+ <option
35
+ v-for = "value in state.input.options.values"
36
+ :key = "value.value"
37
+ :value = "value.value"
38
+ >{{ value.key }}</option>
39
+ </select>
40
+ </slot>
41
+
42
+ <slot name="message">
43
+ <p
44
+ v-if = "notvalid"
45
+ v-html = "state.validate.message"
46
+ class = "g3w-long-text error-input-message"
47
+ style = "margin: 0"
48
+ ></p>
49
+ <p
50
+ v-else-if = "state.info"
51
+ v-html = "state.info"
52
+ style = "margin: 0"
53
+ ></p>
54
+ </slot>
55
+
56
+ <div
57
+ v-if = "state.help && this.state.help.visible"
58
+ v-html = "state.help.message"
59
+ class = "g3w_input_help skin-background-color extralighten"
60
+ ></div>
61
+
62
+ </div>
63
+
64
+ </div>
65
+ `,
66
+
67
+ name: "InputPrjRasterLayer",
68
+ mixins: [selectMixin],
69
+ props: {
70
+ state: {
71
+ type: Object,
72
+ required: true
73
+ }
74
+ },
75
+ data(){
76
+ return {
77
+ value: null,
78
+ }
79
+ },
80
+ computed: {
81
+ //recreate same computed property of input editing
82
+ notvalid() {
83
+ return this.state.validate.valid === false;
84
+ }
85
+ },
86
+ watch: {
87
+ //listen change of value (input select)
88
+ 'value'(value) {
89
+ this.state.value = value;
90
+ this.$emit('changeinput', this.state);
91
+ }
92
+ },
93
+ created() {
94
+
95
+ /**
96
+ * Get all Project Vector Layers that has geometry types
97
+ * @param datatypes <Array> of String
98
+ * 'nogeometry',
99
+ * 'point',
100
+ * 'line',
101
+ * 'polygon',
102
+ * 'anygeometry'
103
+ * return <Array>
104
+ */
105
+ this.state.input.options.values = ProjectsRegistry.getCurrentProject().getLayers()
106
+ //exclude base layer
107
+ .filter(layer => !layer.baselayer && (undefined !== layer.source && layer.source.type === 'gdal'))
108
+ .map(layer => ({
109
+ key: layer.name,
110
+ value: layer.id
111
+ }));
112
+
113
+ if (this.state.input.options.values.length > 0) {
114
+ //set initial value
115
+ this.value = this.state.input.options.values[0].value;
116
+ this.state.validate.valid = true;
117
+ }
118
+
119
+ },
120
+ async mounted(){
121
+ await this.$nextTick();
122
+ //set select2 needed to selectMixin
123
+ this.select2 = $(this.$refs.select);
124
+ this.$emit('addinput', this.state);
125
+ },
126
+ });
127
+
128
+ document.head.insertAdjacentHTML(
129
+ 'beforeend',
130
+ /* css */`
131
+ <style>
132
+ /* Replicate same scoped style in InputBase.vue */
133
+ .prj-raster-layer label { text-align: left !important; padding-top: 0 !important; margin-bottom: 3px; }
134
+ </style>`,
135
+ );