g3w-admin-qplotly 0.0.1__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_qplotly-0.0.1.dist-info/METADATA +52 -0
- g3w_admin_qplotly-0.0.1.dist-info/RECORD +139 -0
- g3w_admin_qplotly-0.0.1.dist-info/WHEEL +5 -0
- g3w_admin_qplotly-0.0.1.dist-info/licenses/LICENSE +373 -0
- g3w_admin_qplotly-0.0.1.dist-info/top_level.txt +1 -0
- qplotly/__init__.py +1 -0
- qplotly/admin.py +34 -0
- qplotly/api/__init__.py +0 -0
- qplotly/api/plots/__init__.py +0 -0
- qplotly/api/plots/views.py +211 -0
- qplotly/api/widgets/__init__.py +0 -0
- qplotly/api/widgets/permissions.py +79 -0
- qplotly/api/widgets/serializers.py +109 -0
- qplotly/api/widgets/views.py +287 -0
- qplotly/apiurls.py +132 -0
- qplotly/apps.py +11 -0
- qplotly/locale/bg/LC_MESSAGES/django.mo +0 -0
- qplotly/locale/bg/LC_MESSAGES/django.po +162 -0
- qplotly/locale/de/LC_MESSAGES/django.mo +0 -0
- qplotly/locale/de/LC_MESSAGES/django.po +126 -0
- qplotly/locale/de/LC_MESSAGES/djangojs.mo +0 -0
- qplotly/locale/de/LC_MESSAGES/djangojs.po +221 -0
- qplotly/locale/es/LC_MESSAGES/django.mo +0 -0
- qplotly/locale/es/LC_MESSAGES/django.po +151 -0
- qplotly/locale/es/LC_MESSAGES/djangojs.mo +0 -0
- qplotly/locale/es/LC_MESSAGES/djangojs.po +232 -0
- qplotly/locale/fi/LC_MESSAGES/django.mo +0 -0
- qplotly/locale/fi/LC_MESSAGES/django.po +126 -0
- qplotly/locale/fi/LC_MESSAGES/djangojs.mo +0 -0
- qplotly/locale/fi/LC_MESSAGES/djangojs.po +222 -0
- qplotly/locale/fr/LC_MESSAGES/django.mo +0 -0
- qplotly/locale/fr/LC_MESSAGES/django.po +160 -0
- qplotly/locale/fr/LC_MESSAGES/djangojs.mo +0 -0
- qplotly/locale/fr/LC_MESSAGES/djangojs.po +222 -0
- qplotly/locale/it/LC_MESSAGES/django.mo +0 -0
- qplotly/locale/it/LC_MESSAGES/django.po +163 -0
- qplotly/locale/it/LC_MESSAGES/djangojs.mo +0 -0
- qplotly/locale/it/LC_MESSAGES/djangojs.po +220 -0
- qplotly/locale/pl/LC_MESSAGES/django.mo +0 -0
- qplotly/locale/pl/LC_MESSAGES/django.po +129 -0
- qplotly/locale/pl/LC_MESSAGES/djangojs.mo +0 -0
- qplotly/locale/pl/LC_MESSAGES/djangojs.po +217 -0
- qplotly/locale/pt/LC_MESSAGES/django.mo +0 -0
- qplotly/locale/pt/LC_MESSAGES/django.po +160 -0
- qplotly/locale/ro/LC_MESSAGES/django.mo +0 -0
- qplotly/locale/ro/LC_MESSAGES/django.po +128 -0
- qplotly/locale/ro/LC_MESSAGES/djangojs.mo +0 -0
- qplotly/locale/ro/LC_MESSAGES/djangojs.po +222 -0
- qplotly/locale/se/LC_MESSAGES/django.mo +0 -0
- qplotly/locale/se/LC_MESSAGES/django.po +126 -0
- qplotly/locale/se/LC_MESSAGES/djangojs.mo +0 -0
- qplotly/locale/se/LC_MESSAGES/djangojs.po +222 -0
- qplotly/migrations/0001_initial.py +26 -0
- qplotly/migrations/0002_qplotlywidget_type.py +18 -0
- qplotly/migrations/0003_auto_20200925_0838.py +18 -0
- qplotly/migrations/0004_auto_20200925_1535.py +25 -0
- qplotly/migrations/0005_qplotlywidget_show_on_start_client.py +18 -0
- qplotly/migrations/0006_alter_qplotlywidget_options_qplotlywidget_order.py +23 -0
- qplotly/migrations/0007_alter_qplotlywidget_options_and_more.py +22 -0
- qplotly/migrations/0008_alter_qplotlywidget_order.py +18 -0
- qplotly/migrations/0009_qplotlywidget_show_in_sidebar.py +18 -0
- qplotly/migrations/0010_remove_qplotlywidget_show_in_sidebar_and_more.py +22 -0
- qplotly/migrations/0011_rename_show_poistion_qplotlywidget_show_position.py +18 -0
- qplotly/migrations/0012_qplotlywidgetrelation_qplotlywidget_related_widgets.py +34 -0
- qplotly/migrations/0013_alter_qplotlywidgetrelation_source_and_more.py +24 -0
- qplotly/migrations/0014_alter_qplotlywidgetrelation_source_and_more.py +24 -0
- qplotly/migrations/0015_qplotlywidgetrelation_project.py +34 -0
- qplotly/migrations/0016_remove_qplotlywidget_project.py +17 -0
- qplotly/migrations/__init__.py +0 -0
- qplotly/models.py +142 -0
- qplotly/receivers.py +356 -0
- qplotly/requirements.txt +1 -0
- qplotly/server_filters/__init__.py +1 -0
- qplotly/server_filters/relations.py +32 -0
- qplotly/static/qplotly/icons/2dhistogram.svg +2048 -0
- qplotly/static/qplotly/icons/barplot.svg +2048 -0
- qplotly/static/qplotly/icons/boxplot.svg +2048 -0
- qplotly/static/qplotly/icons/contour.svg +2056 -0
- qplotly/static/qplotly/icons/histogram.svg +2048 -0
- qplotly/static/qplotly/icons/pie.svg +2048 -0
- qplotly/static/qplotly/icons/polar.svg +2055 -0
- qplotly/static/qplotly/icons/scatterplot.svg +2048 -0
- qplotly/static/qplotly/icons/scatterternary.svg +2055 -0
- qplotly/static/qplotly/icons/violin.svg +2878 -0
- qplotly/static/qplotly/js/data-widget-qplotlyWidgetList.js +373 -0
- qplotly/static/qplotly/js/i18n/bg.js +19 -0
- qplotly/static/qplotly/js/i18n/de.js +19 -0
- qplotly/static/qplotly/js/i18n/en.js +19 -0
- qplotly/static/qplotly/js/i18n/fi.js +19 -0
- qplotly/static/qplotly/js/i18n/fr.js +19 -0
- qplotly/static/qplotly/js/i18n/index.js +19 -0
- qplotly/static/qplotly/js/i18n/it.js +19 -0
- qplotly/static/qplotly/js/i18n/ro.js +19 -0
- qplotly/static/qplotly/js/i18n/se.js +19 -0
- qplotly/static/qplotly/js/i18n/uk.js +19 -0
- qplotly/static/qplotly/js/plugin.js +927 -0
- qplotly/static/qplotly/js/sidebar.js +373 -0
- qplotly/static/qplotly/js/widget.js +9 -0
- qplotly/static/qplotly/plotly-1.52.2.min.js +7 -0
- qplotly/static/qplotly/polyfill.min.js +3 -0
- qplotly/templates/qplotly/include/plot_type_icon.html +52 -0
- qplotly/templates/qplotly/layer_action.html +13 -0
- qplotly/templates/qplotly/plots_list_order.html +68 -0
- qplotly/templates/qplotly/plots_list_order_action.html +14 -0
- qplotly/templatetags/__init__.py +0 -0
- qplotly/templatetags/qplotly_tags.py +28 -0
- qplotly/urls.py +52 -0
- qplotly/utils/__init__.py +13 -0
- qplotly/utils/models.py +86 -0
- qplotly/utils/qplotly_factory.py +699 -0
- qplotly/utils/qplotly_settings.py +37 -0
- qplotly/vendor/DataPlotly/__init__.py +0 -0
- qplotly/vendor/DataPlotly/core/__init__.py +0 -0
- qplotly/vendor/DataPlotly/core/plot_factory.py +843 -0
- qplotly/vendor/DataPlotly/core/plot_settings.py +322 -0
- qplotly/vendor/DataPlotly/core/plot_types/__init__.py +20 -0
- qplotly/vendor/DataPlotly/core/plot_types/bar_plot.py +83 -0
- qplotly/vendor/DataPlotly/core/plot_types/box.py +56 -0
- qplotly/vendor/DataPlotly/core/plot_types/contour.py +43 -0
- qplotly/vendor/DataPlotly/core/plot_types/histogram.py +66 -0
- qplotly/vendor/DataPlotly/core/plot_types/histogram2d.py +39 -0
- qplotly/vendor/DataPlotly/core/plot_types/icons/2dhistogram.svg +2048 -0
- qplotly/vendor/DataPlotly/core/plot_types/icons/barplot.svg +2048 -0
- qplotly/vendor/DataPlotly/core/plot_types/icons/boxplot.svg +2048 -0
- qplotly/vendor/DataPlotly/core/plot_types/icons/contour.svg +2056 -0
- qplotly/vendor/DataPlotly/core/plot_types/icons/histogram.svg +2048 -0
- qplotly/vendor/DataPlotly/core/plot_types/icons/pie.svg +2048 -0
- qplotly/vendor/DataPlotly/core/plot_types/icons/polar.svg +2055 -0
- qplotly/vendor/DataPlotly/core/plot_types/icons/scatterplot.svg +2048 -0
- qplotly/vendor/DataPlotly/core/plot_types/icons/scatterternary.svg +2055 -0
- qplotly/vendor/DataPlotly/core/plot_types/icons/violin.svg +2878 -0
- qplotly/vendor/DataPlotly/core/plot_types/pie.py +60 -0
- qplotly/vendor/DataPlotly/core/plot_types/plot_type.py +170 -0
- qplotly/vendor/DataPlotly/core/plot_types/polar.py +63 -0
- qplotly/vendor/DataPlotly/core/plot_types/scatter.py +74 -0
- qplotly/vendor/DataPlotly/core/plot_types/ternary.py +129 -0
- qplotly/vendor/DataPlotly/core/plot_types/violin.py +62 -0
- qplotly/vendor/__init__.py +0 -0
- qplotly/views.py +148 -0
qplotly/receivers.py
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
""""Django signal receivers
|
|
3
|
+
|
|
4
|
+
.. note:: This program is free software; you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the Mozilla Public License 2.0.
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__author__ = 'lorenzetti@gis3w.it'
|
|
10
|
+
__date__ = '2020-09-16'
|
|
11
|
+
__copyright__ = 'Copyright 2015 - 2020, Gis3w'
|
|
12
|
+
|
|
13
|
+
from django.conf import settings as g3wsettings
|
|
14
|
+
from django.dispatch import receiver
|
|
15
|
+
from django.apps import apps
|
|
16
|
+
from django.db.models.signals import post_save, post_delete, pre_delete
|
|
17
|
+
from django.templatetags.static import static
|
|
18
|
+
from django.template import loader
|
|
19
|
+
from core.signals import (
|
|
20
|
+
load_layer_actions,
|
|
21
|
+
load_js_modules,
|
|
22
|
+
load_project_layers_actions
|
|
23
|
+
)
|
|
24
|
+
from qdjango.signals import (
|
|
25
|
+
load_qdjango_project_file,
|
|
26
|
+
post_save_qdjango_project_file
|
|
27
|
+
)
|
|
28
|
+
from qdjango.utils.data import QgisProject
|
|
29
|
+
from qdjango.models import Layer
|
|
30
|
+
|
|
31
|
+
from qgis.PyQt.QtXml import QDomDocument
|
|
32
|
+
from qgis.PyQt.QtCore import QFile
|
|
33
|
+
|
|
34
|
+
from core.signals import initconfig_plugin_start
|
|
35
|
+
from base.version import get_version
|
|
36
|
+
|
|
37
|
+
from .utils.qplotly_settings import QplotlySettings
|
|
38
|
+
from .utils.qplotly_factory import QplotlyFactoring
|
|
39
|
+
from .utils.models import get_qplotlywidgets4project
|
|
40
|
+
from .models import (
|
|
41
|
+
QplotlyWidget,
|
|
42
|
+
QplotlyWidgetRelation
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
import plotly
|
|
46
|
+
import plotly.graph_objects as go
|
|
47
|
+
|
|
48
|
+
import logging
|
|
49
|
+
|
|
50
|
+
logger = logging.getLogger('django.request')
|
|
51
|
+
|
|
52
|
+
def make_qplotlywidget_for_config(qplotly_widget, qgs_layer_id, project=None) :
|
|
53
|
+
"""
|
|
54
|
+
Generate a qplotly widget configuration dictionary for initialization.
|
|
55
|
+
This function creates a configuration dictionary for a qplotly widget by loading
|
|
56
|
+
its settings from the database and building the necessary layout information.
|
|
57
|
+
If the widget has related widgets, it returns a multiplot configuration instead.
|
|
58
|
+
Args:
|
|
59
|
+
qplotly_widget: The qplotly widget model instance to configure.
|
|
60
|
+
qgs_layer_id: The QGIS layer ID associated with this widget.
|
|
61
|
+
project (optional): The project instance. Used only at the first level to check
|
|
62
|
+
for related widgets. Defaults to None.
|
|
63
|
+
Returns:
|
|
64
|
+
dict: A configuration dictionary containing:
|
|
65
|
+
- For single plots: id, type ('singleplot'), qgs_layer_id, selected_features_only,
|
|
66
|
+
visible_features_only, show_on_start, show_position, label, and plot_type.
|
|
67
|
+
- For multi plots: id, qgs_layer_id, selected_features_only, visible_features_only,
|
|
68
|
+
show_on_start, show_position, label, type ('multiplot'), and plots list.
|
|
69
|
+
None: If settings cannot be read from the widget model.
|
|
70
|
+
Note:
|
|
71
|
+
When related widgets are found, they are processed recursively in reverse order
|
|
72
|
+
('desc') for correct logical alignment with project-level chart ordering.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
# Load settings from db
|
|
76
|
+
settings = QplotlySettings()
|
|
77
|
+
if not settings.read_from_model(qplotly_widget):
|
|
78
|
+
return
|
|
79
|
+
|
|
80
|
+
# Instace QplotlyFactory
|
|
81
|
+
factory = QplotlyFactoring(settings, request=None, layer=None)
|
|
82
|
+
factory.build_layout()
|
|
83
|
+
|
|
84
|
+
fig = go.Figure(layout=factory.layout)
|
|
85
|
+
layout = fig.to_dict()['layout']
|
|
86
|
+
|
|
87
|
+
toret = {
|
|
88
|
+
'id': qplotly_widget.pk,
|
|
89
|
+
'type': 'singleplot',
|
|
90
|
+
'qgs_layer_id': qgs_layer_id,
|
|
91
|
+
'selected_features_only': qplotly_widget.selected_features_only,
|
|
92
|
+
'visible_features_only': qplotly_widget.visible_features_only,
|
|
93
|
+
'show_on_start': qplotly_widget.show_on_start_client,
|
|
94
|
+
'show_position': qplotly_widget.show_position,
|
|
95
|
+
'label': layout.get('title', {}).get('text', f"Plot id [{qplotly_widget.pk}]"),
|
|
96
|
+
'type': settings.plot_type,
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
# Check if is has related per project
|
|
100
|
+
# Only at first levet pass project
|
|
101
|
+
related_widgets = qplotly_widget.related(project, order='asc')
|
|
102
|
+
if len(related_widgets) > 0:
|
|
103
|
+
logger.warning(f"Widget {qplotly_widget.pk} has related widgets, but related widgets are not supported for initconfig. Widget will be ignored.")
|
|
104
|
+
|
|
105
|
+
multiplots = [
|
|
106
|
+
toret if plot.pk == qplotly_widget.pk else make_qplotlywidget_for_config(plot, qgs_layer_id)
|
|
107
|
+
for plot in related_widgets
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
'id': qplotly_widget.pk,
|
|
112
|
+
'qgs_layer_id': qgs_layer_id,
|
|
113
|
+
'selected_features_only': qplotly_widget.selected_features_only,
|
|
114
|
+
'visible_features_only': qplotly_widget.visible_features_only,
|
|
115
|
+
'show_on_start': qplotly_widget.show_on_start_client,
|
|
116
|
+
'show_position': qplotly_widget.show_position,
|
|
117
|
+
'label': multiplots[0]['label'],
|
|
118
|
+
'type': 'multiplot',
|
|
119
|
+
'plots': multiplots
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return toret
|
|
123
|
+
|
|
124
|
+
@receiver(load_qdjango_project_file)
|
|
125
|
+
def load_dataplotly_project_settings(sender, **kwargs):
|
|
126
|
+
"""Load from qgis project dom document DatPlotly settings
|
|
127
|
+
and put data into sender(QgisProject instance)"""
|
|
128
|
+
|
|
129
|
+
if not isinstance(sender, QgisProject) or not g3wsettings.LOAD_QPLOTLY_FROM_PROJECT:
|
|
130
|
+
return
|
|
131
|
+
|
|
132
|
+
# to avoid multithreading load xml file.
|
|
133
|
+
doc = QDomDocument('QgsProject')
|
|
134
|
+
file = QFile(sender.qgs_project.fileName())
|
|
135
|
+
doc.setContent(file)
|
|
136
|
+
|
|
137
|
+
# Deprecated only for tests
|
|
138
|
+
settings = QplotlySettings()
|
|
139
|
+
read = settings.read_from_project(doc)
|
|
140
|
+
|
|
141
|
+
file.close()
|
|
142
|
+
|
|
143
|
+
if not read or settings.source_layer_id is None:
|
|
144
|
+
logger.info('DataPlotly settings not found into project dom document.')
|
|
145
|
+
return
|
|
146
|
+
|
|
147
|
+
sender.qplotly = {
|
|
148
|
+
'qgs_layer_id': settings.source_layer_id,
|
|
149
|
+
'type': settings.plot_type,
|
|
150
|
+
'title': settings.layout['title'],
|
|
151
|
+
'selected_features_only': settings.properties['selected_features_only'],
|
|
152
|
+
'visible_features_only': settings.properties['visible_features_only'],
|
|
153
|
+
'xml': settings.write_xml_db().toString()
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@receiver(post_save_qdjango_project_file)
|
|
158
|
+
def save_dataplotly_project_settings(sender, **kwargs):
|
|
159
|
+
"""Save qplotly settings into db"""
|
|
160
|
+
|
|
161
|
+
if not isinstance(sender, QgisProject):
|
|
162
|
+
return
|
|
163
|
+
|
|
164
|
+
if hasattr(sender, 'qplotly'):
|
|
165
|
+
|
|
166
|
+
layer = sender.instance.layer_set.get(qgs_layer_id=sender.qplotly['qgs_layer_id'])
|
|
167
|
+
|
|
168
|
+
qplw = layer.qplotlywidget_set.first()
|
|
169
|
+
if qplw is None:
|
|
170
|
+
qplw = QplotlyWidget()
|
|
171
|
+
|
|
172
|
+
qplw.datasource = layer.datasource
|
|
173
|
+
qplw.type = sender.qplotly['type']
|
|
174
|
+
qplw.title = sender.qplotly['title']
|
|
175
|
+
qplw.xml = sender.qplotly['xml']
|
|
176
|
+
qplw.selected_features_only = sender.qplotly['selected_features_only']
|
|
177
|
+
qplw.visible_features_only = sender.qplotly['visible_features_only']
|
|
178
|
+
qplw.save()
|
|
179
|
+
|
|
180
|
+
if not qplw.layers.filter(pk=layer.pk).exists():
|
|
181
|
+
qplw.layers.add(layer)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
@receiver(post_save, sender=Layer)
|
|
185
|
+
def update_widget(sender, **kwargs):
|
|
186
|
+
"""
|
|
187
|
+
Update Qplotly widget data when layer datasource change
|
|
188
|
+
"""
|
|
189
|
+
|
|
190
|
+
# only for update
|
|
191
|
+
if kwargs['created']:
|
|
192
|
+
return
|
|
193
|
+
|
|
194
|
+
layer = kwargs['instance']
|
|
195
|
+
|
|
196
|
+
# search for widget
|
|
197
|
+
widgets = layer.qplotlywidget_set.all()
|
|
198
|
+
|
|
199
|
+
for widget in widgets:
|
|
200
|
+
if widget.datasource != layer.datasource:
|
|
201
|
+
widget.datasource = layer.datasource
|
|
202
|
+
widget.save()
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
@receiver(initconfig_plugin_start)
|
|
206
|
+
def set_initconfig_value(sender, **kwargs):
|
|
207
|
+
"""Set base editing data for initconfig"""
|
|
208
|
+
|
|
209
|
+
if not hasattr(sender, 'request'):
|
|
210
|
+
return
|
|
211
|
+
|
|
212
|
+
project = apps.get_app_config(kwargs['projectType']).get_model('project').objects.get(pk=kwargs['project'])
|
|
213
|
+
|
|
214
|
+
plots = []
|
|
215
|
+
|
|
216
|
+
qplotly_widgets = get_qplotlywidgets4project(project, sender.request.user, ctx='free+related')
|
|
217
|
+
|
|
218
|
+
for qplotly_widget, qgs_layer_id in qplotly_widgets:
|
|
219
|
+
|
|
220
|
+
plot = make_qplotlywidget_for_config(qplotly_widget, qgs_layer_id, project)
|
|
221
|
+
if plot is not None:
|
|
222
|
+
plots.append(plot)
|
|
223
|
+
|
|
224
|
+
# no plots no 'qplotly' section
|
|
225
|
+
if len(plots) == 0:
|
|
226
|
+
return
|
|
227
|
+
|
|
228
|
+
return {
|
|
229
|
+
'qplotly': {
|
|
230
|
+
'version': get_version(),
|
|
231
|
+
'gid': "{}:{}".format(kwargs['projectType'], kwargs['project']),
|
|
232
|
+
'jsscripts': [
|
|
233
|
+
static('qplotly/polyfill.min.js'),
|
|
234
|
+
static('qplotly/plotly-1.52.2.min.js')
|
|
235
|
+
],
|
|
236
|
+
'plots': plots,
|
|
237
|
+
'sidebar': {
|
|
238
|
+
'id': 'qplotly',
|
|
239
|
+
'title': 'plugins.qplotly.title',
|
|
240
|
+
'open': False,
|
|
241
|
+
'collapsible': True,
|
|
242
|
+
'icon': 'chart-area',
|
|
243
|
+
'iconColor': 'red',
|
|
244
|
+
'mobile': True,
|
|
245
|
+
'sidebarOptions': {
|
|
246
|
+
'position': 1,
|
|
247
|
+
},
|
|
248
|
+
'visible': any('sidebar' in plot.get('show_position', '') for plot in plots),
|
|
249
|
+
},
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
@receiver(load_js_modules)
|
|
255
|
+
def get_js_modules(sender, **kwargs):
|
|
256
|
+
"""Add qplotly js scripts"""
|
|
257
|
+
|
|
258
|
+
try:
|
|
259
|
+
if sender.resolver_match.view_name == 'qdjango-project-layers-list':
|
|
260
|
+
return 'qplotly/js/widget.js'
|
|
261
|
+
except Exception as e:
|
|
262
|
+
logger.error(str(e))
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
@receiver(load_layer_actions)
|
|
266
|
+
def qplottly_layer_action(sender, **kwargs):
|
|
267
|
+
"""
|
|
268
|
+
Return html actions qplotly for project layer.
|
|
269
|
+
"""
|
|
270
|
+
|
|
271
|
+
# only admin and editor1 or editor2:
|
|
272
|
+
if sender.has_perm('change_project', kwargs['layer'].project) and \
|
|
273
|
+
kwargs['layer'].layer_type in (
|
|
274
|
+
Layer.TYPES.postgres,
|
|
275
|
+
Layer.TYPES.spatialite,
|
|
276
|
+
Layer.TYPES.ogr,
|
|
277
|
+
Layer.TYPES.mssql,
|
|
278
|
+
Layer.TYPES.oracle
|
|
279
|
+
):
|
|
280
|
+
|
|
281
|
+
try:
|
|
282
|
+
app_configs = apps.get_app_config(kwargs['app_name']).configs
|
|
283
|
+
except:
|
|
284
|
+
app_configs = object()
|
|
285
|
+
|
|
286
|
+
kwargs['as_col'] = True
|
|
287
|
+
|
|
288
|
+
template = loader.get_template('qplotly/layer_action.html')
|
|
289
|
+
return template.render(kwargs)
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
@receiver(post_save, sender=QplotlyWidget)
|
|
293
|
+
@receiver(pre_delete, sender=QplotlyWidget)
|
|
294
|
+
@receiver(post_save, sender=QplotlyWidgetRelation)
|
|
295
|
+
@receiver(pre_delete, sender=QplotlyWidgetRelation)
|
|
296
|
+
def invalid_prj_cache(**kwargs):
|
|
297
|
+
"""Invalid the possible qdjango project cache"""
|
|
298
|
+
|
|
299
|
+
if kwargs['sender'] == QplotlyWidgetRelation:
|
|
300
|
+
layers = kwargs['instance'].source.layers.all()
|
|
301
|
+
else:
|
|
302
|
+
layers = kwargs['instance'].layers.all()
|
|
303
|
+
|
|
304
|
+
for layer in layers:
|
|
305
|
+
layer.project.invalidate_cache()
|
|
306
|
+
logging.getLogger("g3wadmin.debug").debug(
|
|
307
|
+
f"Qdjango project /api/config invalidate cache after create/update/delete of qplotly widget or relation: "
|
|
308
|
+
f"{layer.project}"
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
@receiver(post_save, sender=QplotlyWidgetRelation)
|
|
313
|
+
def add_source_self_relation(sender, instance, created, **kwargs):
|
|
314
|
+
"""
|
|
315
|
+
When a non-self relation is created, automatically add a self-relation for the
|
|
316
|
+
source widget (source == target) so it appears in the related list for ordering.
|
|
317
|
+
"""
|
|
318
|
+
if not created or instance.source_id == instance.target_id:
|
|
319
|
+
return
|
|
320
|
+
QplotlyWidgetRelation.objects.get_or_create(
|
|
321
|
+
source=instance.source,
|
|
322
|
+
target=instance.source,
|
|
323
|
+
project=instance.project,
|
|
324
|
+
defaults={'order': 0},
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
@receiver(post_delete, sender=QplotlyWidgetRelation)
|
|
329
|
+
def remove_source_self_relation(sender, instance, **kwargs):
|
|
330
|
+
"""
|
|
331
|
+
When the last non-self relation for a source+project is removed,
|
|
332
|
+
automatically delete the self-relation too.
|
|
333
|
+
"""
|
|
334
|
+
if instance.source_id == instance.target_id:
|
|
335
|
+
return
|
|
336
|
+
remaining = QplotlyWidgetRelation.objects.filter(
|
|
337
|
+
source=instance.source,
|
|
338
|
+
project=instance.project,
|
|
339
|
+
).exclude(target=instance.source).exists()
|
|
340
|
+
if not remaining:
|
|
341
|
+
QplotlyWidgetRelation.objects.filter(
|
|
342
|
+
source=instance.source,
|
|
343
|
+
target=instance.source,
|
|
344
|
+
project=instance.project,
|
|
345
|
+
).delete()
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
@receiver(load_project_layers_actions)
|
|
349
|
+
def qplotly_plots_order_actions(sender, **kwargs):
|
|
350
|
+
"""
|
|
351
|
+
Return html actions for order plots by projects.
|
|
352
|
+
"""
|
|
353
|
+
|
|
354
|
+
if (sender.has_perm('change_project', kwargs['project']) and kwargs['app_name'] == 'qdjango'):
|
|
355
|
+
template = loader.get_template('qplotly/plots_list_order_action.html')
|
|
356
|
+
return template.render(kwargs)
|
qplotly/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
plotly==5.20.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .relations import *
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
""""Server filters for relations.
|
|
3
|
+
|
|
4
|
+
.. note:: This program is free software; you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the Mozilla Public License 2.0.
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__author__ = 'lorenzetti@gis3w.it'
|
|
10
|
+
__date__ = '2021-01-15'
|
|
11
|
+
__copyright__ = 'Copyright 2015 - 2021, Gis3w'
|
|
12
|
+
|
|
13
|
+
from core.api.filters import BaseFilterBackend
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ByFatherFeatursFilter(BaseFilterBackend):
|
|
17
|
+
"""A filter backend that applies a QgsExpression to QplotlyFactory"""
|
|
18
|
+
|
|
19
|
+
def apply_filter(self, request, metadata_layer, qgis_feature_request, view=None):
|
|
20
|
+
"""Apply the filter to the QGIS feature request or the layer's subset string
|
|
21
|
+
Warning: if the filter alters the layer instance (for example by settings a subset
|
|
22
|
+
string) make sure to restore the original state or to work on a clone.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
qgis_layer = metadata_layer.qgis_layer
|
|
26
|
+
|
|
27
|
+
expression_text = getattr(view, 'father_features_expresion', None)
|
|
28
|
+
|
|
29
|
+
if not expression_text:
|
|
30
|
+
return
|
|
31
|
+
|
|
32
|
+
qgis_feature_request.combineFilterExpression(expression_text)
|