Skip to content

Commit

Permalink
Merge branch 'dev' into update_weasyprint
Browse files Browse the repository at this point in the history
  • Loading branch information
wlorenzetti authored Nov 26, 2024
2 parents f080b32 + 5ccc075 commit fbf0d59
Show file tree
Hide file tree
Showing 25 changed files with 1,074 additions and 27,418 deletions.
1 change: 1 addition & 0 deletions g3w-admin/client/static/client/app.min.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions g3w-admin/client/static/client/app.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions g3w-admin/client/static/client/app.min.js.map

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion g3w-admin/client/static/client/css/app.min.css

This file was deleted.

98 changes: 0 additions & 98 deletions g3w-admin/client/static/client/css/vendor.min.css

This file was deleted.

2 changes: 0 additions & 2 deletions g3w-admin/client/static/client/js/app.min.js

This file was deleted.

1 change: 0 additions & 1 deletion g3w-admin/client/static/client/js/app.min.js.map

This file was deleted.

27,284 changes: 0 additions & 27,284 deletions g3w-admin/client/static/client/js/vendor.min.js

This file was deleted.

966 changes: 966 additions & 0 deletions g3w-admin/client/static/client/vendor.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions g3w-admin/client/static/client/vendor.min.js.map

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions g3w-admin/client/templates/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no" name="viewport">
<title>{{ page_title }}</title>
<link rel="icon" href="{% if SETTINGS.G3WSUITE_CUSTOM_STATIC_URL and SETTINGS.G3WSUITE_FAVICON %}{{ SETTINGS.G3WSUITE_FAVICON }}{% else %}{% static '/img/favicon.ico' %}{% endif %}">
<link rel="stylesheet" href="{% with client_default|add:"/css/vendor.min.css" as vendor_css %}{% static vendor_css %}{% endwith %}">
<link rel="stylesheet" href="{% with client_default|add:"/css/app.min.css" as app_css %}{% static app_css %}{% endwith %}">
<link rel="stylesheet" href="{% with client_default|add:"/app.min.css" as app_css %}{% static app_css %}{% endwith %}">
{% if SETTINGS.G3WSUITE_CUSTOM_STATIC_URL %}{% for css in SETTINGS.G3WSUITE_CUSTOM_CSS %}
<link rel="stylesheet" type="text/css" href="{{ css }}" />
{% endfor %}{% endif %}
Expand All @@ -20,9 +19,9 @@
{{ SETTINGS.SENTRY_JS | safe }}
{% endif %}
<app id="app"></app>
<script src="{% with client_default|add:"/js/vendor.min.js" as vendor_js %}{% static vendor_js %}{% endwith %}"></script>
<script src="{% with client_default|add:"/vendor.min.js" as vendor_js %}{% static vendor_js %}{% endwith %}"></script>
<script>{{ group_config | safe }}</script>
<script src="{% with client_default|add:"/js/app.min.js" as app_js %}{% static app_js %}{% endwith %}"></script>
<script src="{% with client_default|add:"/app.min.js" as app_js %}{% static app_js %}{% endwith %}"></script>
{% if SETTINGS.G3WSUITE_CUSTOM_STATIC_URL %}{% for js in SETTINGS.G3WSUITE_CUSTOM_JS %}
<script src="{{ js }}"></script>
{% endfor %}{% endif %}
Expand Down
27 changes: 24 additions & 3 deletions g3w-admin/core/api/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ def response_data_mode(self, request, export_features=False):
attrs.append(attr_idx)
qgis_feature_request.setSubsetOfAttributes(attrs)

# Get feature: apply pagination if 'page' parameters is set
self.features = get_qgis_features(
self.metadata_layer.qgis_layer, qgis_feature_request, **kwargs)

Expand Down Expand Up @@ -697,11 +698,31 @@ def response_data_mode(self, request, export_features=False):
f = feature_collection['features'][i]
f['id'] = fids_map[f['id']]

self.results.update(APIVectorLayerStructure(**{
api_vector_data = {
'data': feature_collection,
'count': count_qgis_features(self.metadata_layer.qgis_layer, qgis_feature_request, **kwargs),
'geometryType': self.metadata_layer.geometry_type,
}).as_dict())
'geometryType': self.metadata_layer.geometry_type
}

# Cafe with 'autofilter' parameter: get every id from qgis_feature_request
# ------------------------------------------------------------------------
if 'autofilter' in self.request_data and str(self.request_data['autofilter']) == '1':

# Remove pagination
for k in ('page', 'page_size'):
if k in kwargs:
del(kwargs[k])

# Reset limit
if qgis_feature_request.limit() != -1:
qgis_feature_request = QgsFeatureRequest(qgis_feature_request)
qgis_feature_request.setLimit(-1)

self.total_feature_ids = [str(f.id()) for f in get_qgis_features(
self.metadata_layer.qgis_layer, qgis_feature_request, **kwargs)]


self.results.update(APIVectorLayerStructure(**api_vector_data).as_dict())

# FIXME: add extra fields data by signals and receivers
# FIXME: featurecollection = post_serialize_maplayer.send(layer_serializer, layer=self.layer_name)
Expand Down
4 changes: 4 additions & 0 deletions g3w-admin/core/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.contrib.auth import REDIRECT_FIELD_NAME
from guardian.exceptions import GuardianError
from guardian.utils import get_40x_or_None, get_anonymous_user
from qdjango.utils.session import reset_filtertoken

import logging

Expand Down Expand Up @@ -169,6 +170,9 @@ def _wrapped_view(request, *args, **kwargs):
else:
user_pk = request.user.pk

# Reset sessiontokenfilter
reset_filtertoken(request)

key = f"{key_prefix}{'_'.join([str(kwargs[k]) for k in key_args] + [str(user_pk)])}"
logger.debug(f"[CACHING /api/config]: Key {key}")
response = cache.get(key)
Expand Down
2 changes: 1 addition & 1 deletion g3w-admin/editing/static/editing/js/plugin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion g3w-admin/editing/static/editing/js/plugin.js.map

Large diffs are not rendered by default.

17 changes: 3 additions & 14 deletions g3w-admin/qdjango/api/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from qdjango.signals import load_qdjango_widget_layer
from qdjango.apps import get_qgs_project
from qdjango.utils.structure import QdjangoMetaLayer, datasourcearcgis2dict
from qdjango.utils.session import reset_filtertoken
from qdjango.api.layers.serializers import FilterLayerSavedSerializer
from core.utils.structure import mapLayerAttributes
from core.configs import *
Expand Down Expand Up @@ -224,19 +225,6 @@ def get_metadata(self, instance, qgs_project):

return metadata

def reset_filtertoken(self):
"""Check session token filter ad delete it"""

try:
if settings.SESSION_COOKIE_NAME in self.request.COOKIES:
stf = SessionTokenFilter.objects.get(
sessionid=self.request.COOKIES[settings.SESSION_COOKIE_NAME])
stf.delete()
except AttributeError:
return None
except SessionTokenFilter.DoesNotExist:
return None

def layer_is_empty(self, layer):
"""
Check if a vector layer is empty (not data)
Expand Down Expand Up @@ -614,7 +602,7 @@ def readLeaf(layer, container):
ret['messages'] = self.get_messages(instance)

# reset tokenfilter by session
self.reset_filtertoken()
reset_filtertoken(self.request)

# add edit url if user has grant
if hasattr(self.request, 'user') and self.request.user.has_perm('qdjango.change_project', instance):
Expand Down Expand Up @@ -980,6 +968,7 @@ def etype(field, key, default=None):
ret['options'] = {
'queryurl': None,
'title': body['title'],
'paginate': body['paginate'] if 'paginate' in body else False,
'results': body['results'],
'dozoomtoextent': body['dozoomtoextent'],
'layerid': self.layerid,
Expand Down
6 changes: 3 additions & 3 deletions g3w-admin/qdjango/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def add_filter_token(**kwargs):
:return: A dict with autofilter token
:rtype: dict, None
"""
# check if is instance of layerVectorView
# Check if is instance of layerVectorView
if (
isinstance(kwargs["sender"], LayerVectorView)
and kwargs["sender"].mode_call == MODE_DATA
Expand All @@ -357,8 +357,8 @@ def add_filter_token(**kwargs):
try:
# Get fids
results = kwargs["sender"].results.results
if results['result']:
fids = [f["id"] for f in results['vector']['data']['features']]
if results['result'] and hasattr(kwargs["sender"], 'total_feature_ids'):
fids = kwargs["sender"].total_feature_ids

if fids:
rkwargs = {'project_type': 'qdjango',
Expand Down
29 changes: 25 additions & 4 deletions g3w-admin/qdjango/static/qdjango/js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ ga.Qdjango.widgetEditor = {
})
break
case "search":

paginate = $(".rightCol").find("#paginate").prop('checked');

obj = {
title: $(".rightCol").find("#title").val(), // Search title
paginate: paginate,
query: "simpleWmsSearch", // It can be removed?
usewmsrequest: true, // Always set to true
fields: [],
Expand Down Expand Up @@ -252,7 +256,12 @@ ga.Qdjango.widgetEditor = {
var textInput = $('<input class="form-control" type="text" name="resultfield_text" value="' + alInVa + '">')

var tiVa = that.isset(values) && that.isset(values.title) ? values.title : ""
var paVa = that.isset(values) && that.isset(values.paginate) ? values.paginate : false
var title = $('<input class="form-control" type="text" name="title" id="title" value="' + tiVa + '">')
var paginate = $('<input type="checkbox" name="paginate" id="paginate" value="1">')
if (paVa) {
paginate.prop('checked', true);
}

var div = $(
'<div class="bloccoGenerale box box-danger">\
Expand All @@ -265,14 +274,21 @@ ga.Qdjango.widgetEditor = {
<div class="row">\
<div class="form-group col-md-12">\
<div class="controls title">\
<label class="control-label requiredField">' +
gettext("Search title") +
"</label>\
<label class="control-label requiredField">\
' + gettext("Search title") + '\
</label>\
</div>\
</div>\
<div class="form-group col-md-12">\
<div class="controls paginate">\
<label class="control-label requiredField">\
' + gettext("Paginate resutls") + '\
</label>\
</div>\
</div>\
</div>\
<div>\
</div>"
</div>'
)

var onAddAction = function (btn, values) {
Expand Down Expand Up @@ -312,6 +328,11 @@ ga.Qdjango.widgetEditor = {
.append(title)
.append('<div class="help-block">' + gettext("Client search title identification") + "</div>")

div
.find(".paginate")
.append(paginate)
.append('<div class="help-block">' + gettext("Check it if you want paginate the search results") + "</div>")

div.find(".fieldSelect").first().append(fieldSelect)
div.find(".textInput").first().append(textInput)
$(".rightCol").append(div)
Expand Down
31 changes: 31 additions & 0 deletions g3w-admin/qdjango/utils/session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# coding=utf-8
"""" Utility function for session
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the Mozilla Public License 2.0.
"""

__author__ = '[email protected]'
__date__ = '2024-11-15'
__copyright__ = 'Copyright 2015 - 2024, Gis3w'
__license__ = 'MPL 2.0'

from django.conf import settings
from qdjango.models import SessionTokenFilter

def reset_filtertoken(request):
"""
Check session token filter ad delete it
:param request: Django request object
"""

try:
if settings.SESSION_COOKIE_NAME in request.COOKIES:
stf = SessionTokenFilter.objects.get(
sessionid=request.COOKIES[settings.SESSION_COOKIE_NAME])
stf.delete()
except AttributeError:
return None
except SessionTokenFilter.DoesNotExist:
return None
4 changes: 2 additions & 2 deletions g3w-admin/qdjango/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def _get_sessiontokenfilter():
"""
Get or create an instance of SessionTokeFilter model
:return: A tuple with the instance of SessioneTokeFilter model and a boolean state for created or retreive
:return: A tuple with the instance of SessionTokeFilter model and a boolean state for created or retreive
:rtype: tuple
"""
s, created = SessionTokenFilter.objects.get_or_create(
Expand Down Expand Up @@ -545,7 +545,7 @@ def _check_url_params_name_fid(mode):

s, created = _get_sessiontokenfilter()

# Check if a recordo for surrent layer is present for update or create it
# Check if a record for current layer is present for update or create it
s.stf_layers.update_or_create(
layer=fls.layer,
defaults={
Expand Down

0 comments on commit fbf0d59

Please sign in to comment.