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
qprocessing/forms.py ADDED
@@ -0,0 +1,133 @@
1
+ # coding=utf-8
2
+ """" QProcessing forms
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.forms.models import ModelForm, ValidationError
15
+ from django.utils.translation import gettext_lazy as _
16
+ from crispy_forms.helper import FormHelper
17
+ from crispy_forms.layout import Layout, Div, HTML, Field
18
+ from django_bleach.forms import BleachField
19
+ from django_file_form.forms import FileFormMixin, UploadedFileField
20
+ from usersmanage.forms import G3WACLForm
21
+ from usersmanage.utils import crispyBoxACL
22
+ #from usersmanage.configs import G3W_EDITOR1
23
+ from core.mixins.forms import G3WRequestFormMixin, G3WFormMixin
24
+ from .models import QProcessingProject
25
+ from .utils.data import QProcessingModel
26
+ from .utils.exceptions import (
27
+ QProcessingInputException,
28
+ QProcessingOutputException)
29
+ import os
30
+
31
+
32
+
33
+ class QProcessingProjectForm(FileFormMixin, G3WFormMixin, G3WACLForm, G3WRequestFormMixin, ModelForm):
34
+ """
35
+ Form for QprocessingPro model.
36
+ """
37
+
38
+ # TODO: add ACL
39
+
40
+ note = BleachField(required=False)
41
+
42
+ class Meta:
43
+ model = QProcessingProject
44
+ fields = '__all__'
45
+ field_classes = dict(
46
+ model=UploadedFileField
47
+ )
48
+
49
+ def __init__(self, *args, **kwargs):
50
+ super().__init__(*args, **kwargs)
51
+
52
+ self.helper = FormHelper(self)
53
+ self.helper.form_tag = False
54
+ self.helper.layout = Layout(
55
+ Div(
56
+ Div(
57
+ Div(
58
+ Div(
59
+ HTML("<h3 class='box-title'><i class='fa fa-file'></i> {}</h3>".format(
60
+ _('Project'))),
61
+ css_class='box-header with-border'
62
+ ),
63
+ Div(
64
+ Field('projects', css_class='select2'),
65
+ 'model',
66
+ 'model-uploads',
67
+ 'form_id',
68
+ 'upload_url',
69
+ Field('note', css_class='wys5'),
70
+ css_class='box-body',
71
+ ),
72
+ css_class='box box-success'
73
+ ),
74
+ css_class='col-md-8'
75
+ ),
76
+ crispyBoxACL(self,
77
+ editor_field_required=False,
78
+ editor2_field_required=False,
79
+ editor_groups_field_required=False,
80
+ boxCssClass='col-md-4'),
81
+ css_class='row'
82
+ ),
83
+ )
84
+
85
+ def clean_model(self):
86
+ """
87
+ Validate .model3 uploaded
88
+ """
89
+
90
+ model = self.cleaned_data['model']
91
+
92
+ # Validate file extension
93
+ file_extension = os.path.splitext(model.name)[1]
94
+ if file_extension.lower() not in ('.model3', ):
95
+ raise ValidationError(_("File must have '.model3' extension"))
96
+
97
+ if hasattr(self.cleaned_data['model'], 'path'):
98
+ model_file = model.path
99
+
100
+ # Case UploadedFileWithId
101
+ elif hasattr(model, 'file'):
102
+ if hasattr(model.file, 'path'):
103
+ model_file = model.file.path
104
+ else:
105
+ model_file = model.file.name
106
+
107
+ # Validate the model
108
+ try:
109
+ is_valid, errors = QProcessingModel(model_file).validate()
110
+ except QProcessingInputException as e:
111
+ raise ValidationError(e)
112
+ except QProcessingOutputException as e:
113
+ raise ValidationError(e)
114
+
115
+ if not is_valid:
116
+ raise ValidationError(_(f'[Model Validation Errors] - {"; ".join(errors)}'))
117
+
118
+ return model
119
+
120
+ def save(self, commit=True):
121
+ instance = super().save(commit=commit)
122
+
123
+ # set permissions to editor1 and editor2
124
+ self.instance.setPermissionToEditor()
125
+
126
+ # set permissions to editor user groups
127
+ self.instance.set_permissions_to_editor_user_groups()
128
+
129
+ self._ACLPolicy()
130
+
131
+ return instance
132
+
133
+
@@ -0,0 +1,24 @@
1
+ # Generated by Django 3.2.19 on 2023-05-11 15:57
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ initial = True
9
+
10
+ dependencies = [
11
+ ('qdjango', '0107_auto_20230516_0806'),
12
+ ]
13
+
14
+ operations = [
15
+ migrations.CreateModel(
16
+ name='QProcessingProject',
17
+ fields=[
18
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19
+ ('model', models.FileField(upload_to='qprocessing', verbose_name='QGIS processing model file (.model3)')),
20
+ ('note', models.TextField(blank=True, null=True, verbose_name='Note')),
21
+ ('projects', models.ManyToManyField(to='qdjango.Project')),
22
+ ],
23
+ ),
24
+ ]
@@ -0,0 +1,23 @@
1
+ # Generated by Django 3.2.19 on 2023-06-15 16:09
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ dependencies = [
9
+ ('qdjango', '0107_auto_20230516_0806'),
10
+ ('qprocessing', '0001_initial'),
11
+ ]
12
+
13
+ operations = [
14
+ migrations.AlterModelOptions(
15
+ name='qprocessingproject',
16
+ options={'permissions': (('run_model', 'Can run a QGIS processing model'),)},
17
+ ),
18
+ migrations.AlterField(
19
+ model_name='qprocessingproject',
20
+ name='projects',
21
+ field=models.ManyToManyField(help_text='Select one of more projects to link to this QGIS processing model', to='qdjango.Project'),
22
+ ),
23
+ ]
@@ -0,0 +1,32 @@
1
+ # Generated by Django 3.2.20 on 2023-08-09 09:08
2
+
3
+ from django.conf import settings
4
+ from django.db import migrations, models
5
+ import django.db.models.deletion
6
+ import django.utils.timezone
7
+ import model_utils.fields
8
+ import uuid
9
+
10
+
11
+ class Migration(migrations.Migration):
12
+
13
+ dependencies = [
14
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
15
+ ('qprocessing', '0002_auto_20230615_1609'),
16
+ ]
17
+
18
+ operations = [
19
+ migrations.CreateModel(
20
+ name='QProcessingInputUpload',
21
+ fields=[
22
+ ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
23
+ ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
24
+ ('name', models.TextField()),
25
+ ('uuid', model_utils.fields.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
26
+ ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
27
+ ],
28
+ options={
29
+ 'abstract': False,
30
+ },
31
+ ),
32
+ ]
@@ -0,0 +1,26 @@
1
+ # Generated by Django 3.2.20 on 2023-08-09 09:20
2
+
3
+ from django.db import migrations, models
4
+ import django.db.models.deletion
5
+
6
+
7
+ class Migration(migrations.Migration):
8
+
9
+ dependencies = [
10
+ ('qprocessing', '0003_qprocessinginputupload'),
11
+ ]
12
+
13
+ operations = [
14
+ migrations.AddField(
15
+ model_name='qprocessinginputupload',
16
+ name='input_name',
17
+ field=models.CharField(max_length=400),
18
+ preserve_default=False,
19
+ ),
20
+ migrations.AddField(
21
+ model_name='qprocessinginputupload',
22
+ name='qpp',
23
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='qprocessing.qprocessingproject'),
24
+ preserve_default=False,
25
+ ),
26
+ ]
@@ -0,0 +1,21 @@
1
+ # Generated by Django 3.2.20 on 2023-08-09 14:49
2
+
3
+ from django.conf import settings
4
+ from django.db import migrations, models
5
+ import django.db.models.deletion
6
+
7
+
8
+ class Migration(migrations.Migration):
9
+
10
+ dependencies = [
11
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
12
+ ('qprocessing', '0004_auto_20230809_0920'),
13
+ ]
14
+
15
+ operations = [
16
+ migrations.AlterField(
17
+ model_name='qprocessinginputupload',
18
+ name='user',
19
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
20
+ ),
21
+ ]
File without changes
qprocessing/models.py ADDED
@@ -0,0 +1,143 @@
1
+ # coding=utf-8
2
+ """ Qprocessing django urls 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-09'
10
+ __copyright__ = 'Copyright 2015 - 2023, Gis3w'
11
+ __license__ = 'MPL 2.0'
12
+
13
+
14
+ from django.db import models
15
+ from django.utils.translation import gettext_lazy as _
16
+ from qdjango.models import Project
17
+ from model_utils.models import TimeStampedModel
18
+ from model_utils.fields import UUIDField
19
+ from usersmanage.utils import get_users_for_object, get_groups_for_object, setPermissionUserObject
20
+ from usersmanage.configs import G3W_VIEWER1, G3W_VIEWER2, G3W_EDITOR2, G3W_EDITOR1
21
+ from usersmanage.models import User, Group as AuthGroup
22
+ from .utils.data import QProcessingModel
23
+
24
+
25
+ class QProcessingProject(models.Model):
26
+ """
27
+ Model to stor relation between QGIS processing model (.model3) and Qdjango Projects objects
28
+ """
29
+
30
+ class Meta:
31
+ permissions = (
32
+ ('run_model', 'Can run a QGIS processing model'),
33
+ )
34
+
35
+
36
+ #TODO: add new permission type, `can_run_model`
37
+
38
+ model = models.FileField(_('QGIS processing model file (.model3)'), upload_to='qprocessing')
39
+ projects = models.ManyToManyField(Project, help_text=_('Select one of more projects to link to this QGIS processing model'))
40
+ note = models.TextField(_('Note'), null=True, blank=True)
41
+
42
+ def get_qprocessingmodel(self):
43
+ """
44
+ Return an instance of QProcessingModel utility object by self instance
45
+ """
46
+
47
+ if not self.model:
48
+ return None
49
+
50
+ return QProcessingModel(str(self.model.file))
51
+
52
+ def get_qdjango_project(self, project_pk:int):
53
+ """
54
+ Give a Qdjango project pk return qdjango.Project model instance
55
+ """
56
+
57
+ return self.projects.get(pk=project_pk)
58
+
59
+ # ACL
60
+ # ---------------------------------------------
61
+ def setPermissionToEditor(self):
62
+ """ Check and give or remove permission to editor level 1 and editor level 2"""
63
+
64
+ currentEditor = set()
65
+ for project in self.projects.all():
66
+ ce = get_users_for_object(project, 'change_project', [G3W_EDITOR1, G3W_EDITOR2],
67
+ with_anonymous=False)
68
+ currentEditor = currentEditor.union(set(ce))
69
+
70
+ currentEditorPermission = get_users_for_object(self, 'run_model', [G3W_EDITOR1, G3W_EDITOR2],
71
+ with_anonymous=False)
72
+ permissionEditorToRemove = list(set(currentEditorPermission) - currentEditor)
73
+
74
+ if len(currentEditor) > 0 :
75
+ for ce in currentEditor:
76
+ setPermissionUserObject(ce, self, ['run_model'])
77
+ if len(permissionEditorToRemove):
78
+ for per in permissionEditorToRemove:
79
+ setPermissionUserObject(per, self, ['run_model'], mode='remove')
80
+
81
+ def set_permissions_to_editor_user_groups(self):
82
+ """ Check and giv or remove permission to editor groups """
83
+
84
+ # current editor user groups with change permission on project
85
+ currentEditorGroup = set()
86
+ for project in self.projects.all():
87
+ ceg = get_groups_for_object(project, 'change_project', grouprole='editor')
88
+
89
+ currentEditorGroup = currentEditorGroup.union(ceg)
90
+
91
+ currentEditorGroupPermission = get_groups_for_object(self, 'run_model', grouprole='editor')
92
+ permissionEditorGroupToRemove = list(set(currentEditorGroupPermission) - currentEditorGroup)
93
+
94
+ if len(currentEditorGroup) > 0 :
95
+ for ceg in currentEditorGroup:
96
+ setPermissionUserObject(ceg, self, ['run_model'])
97
+ if len(permissionEditorGroupToRemove):
98
+ for pegr in permissionEditorGroupToRemove:
99
+ setPermissionUserObject(pegr, self, permissions=['run_model'],
100
+ mode='remove')
101
+
102
+ def addPermissionsToViewers(self, users_id):
103
+
104
+ for user_id in users_id:
105
+ setPermissionUserObject(User.objects.get(pk=user_id), self,
106
+ permissions='qprocessing.run_model')
107
+
108
+ def removePermissionsToViewers(self, users_id=None):
109
+
110
+ for user_id in users_id:
111
+ setPermissionUserObject(User.objects.get(pk=user_id), self,
112
+ permissions='run_model', mode='remove')
113
+
114
+ def add_permissions_to_viewer_user_groups(self, groups_id):
115
+ self._permissions_to_user_groups_viewer(groups_id=groups_id)
116
+
117
+ def remove_permissions_to_viewer_user_groups(self, groups_id):
118
+ self._permissions_to_user_groups_viewer(groups_id=groups_id, mode='remove')
119
+
120
+ def _permissions_to_user_groups_viewer(self, groups_id, mode='add'):
121
+
122
+ for group_id in groups_id:
123
+ auth_group = AuthGroup.objects.get(pk=group_id)
124
+ setPermissionUserObject(auth_group, self, permissions=['run_model'],
125
+ mode=mode)
126
+
127
+
128
+
129
+
130
+ class QProcessingInputUpload(TimeStampedModel):
131
+ """
132
+ Model to save information about files uploaded for processing inputs.
133
+ """
134
+
135
+ name = models.TextField()
136
+ user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
137
+ uuid = UUIDField(editable=True)
138
+ input_name = models.CharField(max_length=400)
139
+ qpp = models.ForeignKey(QProcessingProject, on_delete=models.CASCADE)
140
+
141
+
142
+
143
+
@@ -0,0 +1,100 @@
1
+ # coding=utf-8
2
+ """" QProcessing receiver signals.
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
+ from django.conf import settings
14
+ from django.dispatch import receiver
15
+ from django.db.models.signals import post_delete
16
+ from django.core.files.storage import FileSystemStorage
17
+ from guardian.shortcuts import get_objects_for_user
18
+ from core.signals import initconfig_plugin_start
19
+ from .models import QProcessingProject, QProcessingInputUpload
20
+ from .utils.data import QProcessingModel
21
+ from .configs import __BASE_RUN_MODEL_URL, __BASE_TASK_INFO_URL, __BASE_ACTION_URL, __BASE_UPLOAD_URL
22
+ from importlib.metadata import version as get_version
23
+
24
+ import os
25
+
26
+ @receiver(initconfig_plugin_start)
27
+ def set_initconfig_value(sender, **kwargs):
28
+ """
29
+ Set base qprocessing data for initconfig
30
+ """
31
+
32
+ # Check if project has QGIS processing models linked.
33
+ # Get QProcessingProject instances by ACL
34
+ qpprojects = get_objects_for_user(sender.request.user, 'run_model', QProcessingProject).\
35
+ filter(projects__pk=kwargs['project'])
36
+
37
+ if len(qpprojects) == 0:
38
+ return None
39
+
40
+ return {
41
+ 'qprocessing': {
42
+ 'version': get_version('qprocessing'),
43
+ 'gid': f"{kwargs['projectType']}:{kwargs['project']}",
44
+ 'async': settings.QPROCESSING_ASYNC_RUN,
45
+ 'urls': {
46
+ 'run': f'/qprocessing{__BASE_RUN_MODEL_URL}',
47
+ 'taskinfo': f'/qprocessing{__BASE_TASK_INFO_URL}',
48
+ 'fields': f'/qprocessing{__BASE_ACTION_URL}fields/',
49
+ 'upload': f'/qprocessing{__BASE_UPLOAD_URL}',
50
+ },
51
+ 'models': [{
52
+ **QProcessingModel(str(qpp.model.file)).render2dict(),
53
+ 'id': qpp.pk,
54
+ 'results': [],
55
+ # TODO: move the following into render2dict? (converts [admin] model inputs into [client] form inputs)
56
+ 'inputs': [{
57
+ **input,
58
+ 'visible': True,
59
+ 'validate': {
60
+ 'empty': True,
61
+ 'message': None,
62
+ 'required': True,
63
+ 'unique': False,
64
+ 'valid': False,
65
+ '_valid': False,
66
+ **input['validate'],
67
+ },
68
+ 'get_default_value': True,
69
+ } for input in QProcessingModel(str(qpp.model.file)).inputs.values()],
70
+ } for qpp in qpprojects],
71
+ 'sidebar': {
72
+ 'id': 'qprocessing',
73
+ 'title': 'plugins.qprocessing.title',
74
+ 'collapsible': True,
75
+ 'open': False,
76
+ 'isolate': False,
77
+ 'iconColor': 'green',
78
+ 'icon': 'tools',
79
+ 'mobile': True,
80
+ 'sidebarOptions': {
81
+ 'position': "spatialbookmarks" # can be a number or a string
82
+ }
83
+ }
84
+ }
85
+ }
86
+
87
+ @receiver(post_delete, sender=QProcessingInputUpload)
88
+ def delete_input_upload_file(sender, **kwargs):
89
+
90
+ base_url = f"{kwargs['instance'].user.pk}/" if kwargs['instance'].user else f"nouser/"
91
+ base_url += "uploads/"
92
+ storage = FileSystemStorage(location=settings.QPROCESSING_INPUT_UPLOAD_PATH)
93
+ if os.path.splitext(kwargs['instance'].name)[-1][1:].lower() == 'shp':
94
+
95
+ # Delete every shapefile files
96
+ for ext in settings.QPROCESSING_INPUT_SHP_EXTS + ['qix', 'cpg']:
97
+ fname = f"{os.path.splitext(kwargs['instance'].name)[0]}.{ext}"
98
+ storage.delete(f"{base_url}{fname}")
99
+ else:
100
+ storage.delete(f"{base_url}{kwargs['instance'].name}")
@@ -0,0 +1,31 @@
1
+ from sitetree.utils import item
2
+ from core.utils.tree import G3Wtree
3
+
4
+ # Be sure you defined `sitetrees` in your module.
5
+ sitetrees = (
6
+ # Define a tree with `tree` function.
7
+ G3Wtree('qprocessing', title='QProcessing', module='qprocessing', items=[
8
+ # Then define items and their children with `item` function.
9
+ item('PROCESSING', '#', type_header=True),
10
+ item('Modelli', 'qprocessing-project-list', icon_css_class='fa fa-list', children=[
11
+ item('Aggiungi modello', 'qprocessing-project-add', url_as_pattern=True, icon_css_class='fa fa-plus',
12
+ access_by_perms=['qprocessing.add_qprocessingproject']),
13
+ item('Lista Modelli', 'qprocessing-project-list', url_as_pattern=True, icon_css_class='fa fa-list'),
14
+ item('Agg. Modello {{ object.pk }}', 'qprocessing-project-update object.pk', url_as_pattern=True,
15
+ icon_css_class='fa fa-edit', in_menu=False),
16
+ ])
17
+ ]),
18
+
19
+ G3Wtree('qprocessing_en', title='QProcessing', module='qprocessing', items=[
20
+ # Then define items and their children with `item` function.
21
+ item('PROCESSING', '#', type_header=True),
22
+ item('Models', 'qprocessing-project-list', icon_css_class='fa fa-list', children=[
23
+ item('Add model', 'qprocessing-project-add', url_as_pattern=True, icon_css_class='fa fa-plus',
24
+ access_by_perms=['qprocessing.add_qprocessingproject']),
25
+ item('Models list', 'qprocessing-project-list', url_as_pattern=True, icon_css_class='fa fa-list'),
26
+ ])
27
+ ]),
28
+
29
+
30
+ )
31
+