udata 10.5.1.dev36034__py2.py3-none-any.whl → 10.5.1.dev36076__py2.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.

Potentially problematic release.


This version of udata might be problematic. Click here for more details.

@@ -0,0 +1,46 @@
1
+ import requests
2
+ from flask import current_app
3
+
4
+ from udata.commands import error, success
5
+ from udata.models import Dataset
6
+ from udata.tasks import job
7
+
8
+
9
+ def process_dataset(dataset):
10
+ target_dataset = Dataset.objects(id=dataset["datagouv_id"]).first()
11
+ if not target_dataset:
12
+ error(f"Dataset {dataset['id']} not found")
13
+ return
14
+ target_dataset.extras["transport:url"] = dataset["page_url"]
15
+ target_dataset.save()
16
+
17
+
18
+ def clear_datasets():
19
+ nb_datasets = Dataset.objects.filter(
20
+ **{
21
+ "extras__transport:url__exists": True,
22
+ }
23
+ ).update(
24
+ **{
25
+ "unset__extras__transport:url": True,
26
+ }
27
+ )
28
+ success(f"Removed transport:url from {nb_datasets} dataset(s)")
29
+
30
+
31
+ @job("map-transport-datasets")
32
+ def map_transport_datasets(self):
33
+ source = current_app.config.get("TRANSPORT_DATASETS_URL", None)
34
+ if not source:
35
+ error("TRANSPORT_DATASETS_URL variable must be set.")
36
+ return
37
+
38
+ response = requests.get(source)
39
+ if response.status_code != 200:
40
+ error("Remote platform unreachable.")
41
+ return
42
+ results_list = response.json()
43
+ clear_datasets()
44
+ for dataset in results_list:
45
+ process_dataset(dataset)
46
+ success(f"Done. {len(results_list)} datasets mapped to transport")
@@ -344,8 +344,6 @@ class CswIso19139DcatBackend(DcatBackend):
344
344
 
345
345
  ISO_SCHEMA = "http://www.isotc211.org/2005/gmd"
346
346
 
347
- XSL_URL = "https://raw.githubusercontent.com/datagouv/iso-19139-to-dcat-ap/patch-datagouv/iso-19139-to-dcat-ap.xsl"
348
-
349
347
  def walk_graph(self, url: str, fmt: str) -> Generator[tuple[int, Graph], None, None]:
350
348
  """
351
349
  Yield all RDF pages as `Graph` from the source
@@ -355,7 +353,8 @@ class CswIso19139DcatBackend(DcatBackend):
355
353
  See https://github.com/SEMICeu/iso-19139-to-dcat-ap for more information on the XSLT.
356
354
  """
357
355
  # Load XSLT
358
- xsl = ET.fromstring(self.get(self.XSL_URL).content, parser=SAFE_PARSER)
356
+ xsl_url = current_app.config["HARVEST_ISO19139_XSL_URL"]
357
+ xsl = ET.fromstring(self.get(xsl_url).content, parser=SAFE_PARSER)
359
358
  transform = ET.XSLT(xsl)
360
359
 
361
360
  # Start querying and parsing graph
@@ -18,7 +18,7 @@ from udata.rdf import DCAT, RDF, namespace_manager
18
18
  from udata.storage.s3 import get_from_json
19
19
 
20
20
  from .. import actions
21
- from ..backends.dcat import URIS_TO_REPLACE, CswIso19139DcatBackend
21
+ from ..backends.dcat import URIS_TO_REPLACE
22
22
  from .factories import HarvestSourceFactory
23
23
 
24
24
  log = logging.getLogger(__name__)
@@ -886,7 +886,7 @@ class CswIso19139DcatBackendTest:
886
886
  with open(os.path.join(CSW_DCAT_FILES_DIR, "XSLT.xml"), "r") as f:
887
887
  xslt = f.read()
888
888
  url = mock_csw_pagination(rmock, "geonetwork/srv/eng/csw.rdf", "geonetwork-iso-page-{}.xml")
889
- rmock.get(CswIso19139DcatBackend.XSL_URL, text=xslt)
889
+ rmock.get(current_app.config.get("HARVEST_ISO19139_XSL_URL"), text=xslt)
890
890
  org = OrganizationFactory()
891
891
  source = HarvestSourceFactory(
892
892
  backend="csw-iso-19139",
udata/settings.py CHANGED
@@ -281,6 +281,8 @@ class Defaults(object):
281
281
  HARVEST_GRAPHS_S3_BUCKET = None # If the catalog is bigger than `HARVEST_MAX_CATALOG_SIZE_IN_MONGO` store the graph inside S3 instead of MongoDB
282
282
  HARVEST_GRAPHS_S3_FILENAME_PREFIX = "" # Useful to store the graphs inside a subfolder of the bucket. For example by setting `HARVEST_GRAPHS_S3_FILENAME_PREFIX = 'graphs/'`
283
283
 
284
+ HARVEST_ISO19139_XSL_URL = "https://raw.githubusercontent.com/SEMICeu/iso-19139-to-dcat-ap/refs/heads/geodcat-ap-2.0.0/iso-19139-to-dcat-ap.xsl"
285
+
284
286
  # S3 connection details
285
287
  S3_URL = None
286
288
  S3_ACCESS_KEY_ID = None
@@ -508,6 +510,10 @@ class Defaults(object):
508
510
  ARCHIVE_COMMENT_USER_ID = None
509
511
  ARCHIVE_COMMENT_TITLE = _("This dataset has been archived")
510
512
 
513
+ # Transport extras
514
+ ##################
515
+ TRANSPORT_DATASETS_URL = None
516
+
511
517
  # Schemas parameters
512
518
  ####################
513
519
  SCHEMA_CATALOG_URL = None
udata/tasks.py CHANGED
@@ -163,6 +163,7 @@ def init_app(app):
163
163
  import udata.core.tags.tasks # noqa
164
164
  import udata.core.activity.tasks # noqa
165
165
  import udata.core.dataset.tasks # noqa
166
+ import udata.core.dataset.transport # noqa
166
167
  import udata.core.dataset.recommendations # noqa
167
168
  import udata.core.spatial.tasks # noqa
168
169
  import udata.core.reuse.tasks # noqa
@@ -0,0 +1,75 @@
1
+ import pytest
2
+ import requests_mock
3
+
4
+ from udata.core.dataset.factories import DatasetFactory
5
+ from udata.core.dataset.transport import clear_datasets, map_transport_datasets
6
+
7
+
8
+ @pytest.fixture
9
+ def mock_response():
10
+ return [
11
+ {
12
+ "datagouv_id": "61fd29da29ea95c7bc0e1211",
13
+ "id": "61fd29da29ea95c7bc0e1211",
14
+ "page_url": "https://transport.data.gouv.fr/datasets/horaires-theoriques-et-temps-reel-des-navettes-hivernales-de-lalpe-dhuez-gtfs-gtfs-rt",
15
+ "slug": "horaires-theoriques-et-temps-reel-des-navettes-hivernales-de-lalpe-dhuez-gtfs-gtfs-rt",
16
+ "title": "Navettes hivernales de l'Alpe d'Huez",
17
+ },
18
+ {
19
+ "datagouv_id": "5f23d4b3d39755210a04a99c",
20
+ "id": "5f23d4b3d39755210a04a99c",
21
+ "page_url": "https://transport.data.gouv.fr/datasets/horaires-theoriques-et-temps-reel-du-reseau-lr-11-lalouvesc-tournon-st-felicien-gtfs-gtfs-rt",
22
+ "slug": "horaires-theoriques-et-temps-reel-du-reseau-lr-11-lalouvesc-tournon-st-felicien-gtfs-gtfs-rt",
23
+ "title": "Réseau interurbain Lalouvesc / Tournon / St Felicien",
24
+ },
25
+ ]
26
+
27
+
28
+ @pytest.mark.usefixtures("clean_db")
29
+ class TransportTasksTest:
30
+ @pytest.mark.options(TRANSPORT_DATASETS_URL="http://local.test/api/datasets")
31
+ def test_map_transport_datasets(self, mock_response):
32
+ ds1 = DatasetFactory(id="61fd29da29ea95c7bc0e1211")
33
+ ds2 = DatasetFactory(id="5f23d4b3d39755210a04a99c")
34
+
35
+ with requests_mock.Mocker() as m:
36
+ m.get("http://local.test/api/datasets", json=mock_response)
37
+ map_transport_datasets()
38
+
39
+ ds1.reload()
40
+ ds2.reload()
41
+
42
+ assert (
43
+ ds1.extras["transport:url"]
44
+ == "https://transport.data.gouv.fr/datasets/horaires-theoriques-et-temps-reel-des-navettes-hivernales-de-lalpe-dhuez-gtfs-gtfs-rt"
45
+ )
46
+ assert (
47
+ ds2.extras["transport:url"]
48
+ == "https://transport.data.gouv.fr/datasets/horaires-theoriques-et-temps-reel-du-reseau-lr-11-lalouvesc-tournon-st-felicien-gtfs-gtfs-rt"
49
+ )
50
+
51
+ clear_datasets()
52
+
53
+ ds1.reload()
54
+ ds2.reload()
55
+
56
+ assert "transport:url" not in ds1.extras
57
+ assert "transport:url" not in ds2.extras
58
+
59
+ @pytest.mark.options(TRANSPORT_DATASETS_URL="http://local.test/api/datasets")
60
+ def test_map_transport_datasets_fail(self, mock_response):
61
+ """
62
+ We should not erase existing transport:url extras if the job fails
63
+ """
64
+ ds1 = DatasetFactory(id="61fd29da29ea95c7bc0e1211", extras={"transport:url": "dummy"})
65
+ ds2 = DatasetFactory(id="5f23d4b3d39755210a04a99c")
66
+
67
+ with requests_mock.Mocker() as m:
68
+ m.get("http://local.test/api/datasets", status_code=500)
69
+ map_transport_datasets()
70
+
71
+ ds1.reload()
72
+ ds2.reload()
73
+
74
+ assert ds1.extras["transport:url"] == "dummy"
75
+ assert "transport:url" not in ds2.extras
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: udata
3
- Version: 10.5.1.dev36034
3
+ Version: 10.5.1.dev36076
4
4
  Summary: Open data portal
5
5
  Home-page: https://github.com/opendatateam/udata
6
6
  Author: Opendata Team
@@ -142,12 +142,14 @@ It is collectively taken care of by members of the
142
142
 
143
143
  ## Current (in progress)
144
144
 
145
+ - Add config entry for ISO-DCAT XSLT URL [#3360](https://github.com/opendatateam/udata/pull/3360)
145
146
  - Fix failing to return dataservice in harvest preview because of no ID for URL [#3357](https://github.com/opendatateam/udata/pull/3357/)
146
147
  - Fix invalid resource format from harvested RDF records [#3354](https://github.com/opendatateam/udata/pull/3354)
147
148
  - Expose `dataset_id` for CommunityResource in /dataset/resource/id [#3258](https://github.com/opendatateam/udata/pull/3258)
148
149
  - Add a CI job to create a release on Sentry [#3266](https://github.com/opendatateam/udata/pull/3266)
149
150
  - Sort extensions in `/api/1/datasets/extensions/` response alphabetically [#3358](https://github.com/opendatateam/udata/pull/3358)
150
151
  - Migrate recommendations tasks, [udata-recommendations](https://github.com/opendatateam/udata-recommendations/) is no longer required [#3355](https://github.com/opendatateam/udata/pull/3355)
152
+ - Migrate udata-transport tasks, [udata-transport](https://github.com/opendatateam/udata-transport/) is no longer required [#3355](https://github.com/opendatateam/udata/pull/3355)
151
153
 
152
154
  ## 10.5.0 (2025-07-02)
153
155
 
@@ -13,10 +13,10 @@ udata/mail.py,sha256=FMGHcDAjHvk86iDUwBmVXpx3vbAb2c-j5C3BRnh9IYQ,2670
13
13
  udata/rdf.py,sha256=JmMxwq4fFBrBZQhJ6O9_nEeYUXspPzoZGTyGUD4Nyxs,18348
14
14
  udata/routing.py,sha256=E6sE1F74QyOoz5vcgEi-rNEhCegwLfOtBz5I9fWk-pM,7677
15
15
  udata/sentry.py,sha256=ekcxqUSqxfM98TtvCsPaOoX5i2l6PEcYt7kb4l3od-Q,3223
16
- udata/settings.py,sha256=jXflM02A-l1qeGcjegRtkw56cbQUDOPzqY85OBs_dV0,19345
16
+ udata/settings.py,sha256=DPG8V4Qkqc3jv1evxvEOlxyZH6h0wphKcP-b5D-d8D4,19576
17
17
  udata/sitemap.py,sha256=oRRWoPI7ZsFFnUAOqGT1YuXFFKHBe8EcRnUCNHD7xjM,979
18
18
  udata/tags.py,sha256=ydq4uokd6bzdeGVSpEXASVtGvDfO2LfQs9mptvvKJCM,631
19
- udata/tasks.py,sha256=Tt2Vy4fWyBkDz6cK4Mx3g2VdOLgfdDkWSNIc1QpoawQ,5032
19
+ udata/tasks.py,sha256=yTYBJG5bzEChX27p3MSqurSji84rg7w7OUvK4vuPRfY,5080
20
20
  udata/terms.md,sha256=nFx978tUQ3vTEv6POykXaZvcQ5e_gcvmO4ZgcfbSWXo,187
21
21
  udata/tracking.py,sha256=WOcqA1RlHN8EPFuEc2kNau54mec4-pvi-wUFrMXevzg,345
22
22
  udata/uris.py,sha256=sIhlzpwFO7ftOHYgTZmR7mCoty6a1n4KC4c0Qmx3lqo,3655
@@ -113,6 +113,7 @@ udata/core/dataset/recommendations.py,sha256=DlGSLU8D0nW6Ds1rjBav1WxC-0VW5yOCjkO
113
113
  udata/core/dataset/search.py,sha256=E7LqHBnq3sMefvmLwTpiw-Ovem2a3NJswHesRjctboE,5627
114
114
  udata/core/dataset/signals.py,sha256=WN4sV-lJlNsRkhcnhoy0SYJvCoYmK_5QFYZd1u-h4gs,161
115
115
  udata/core/dataset/tasks.py,sha256=6FzeLzJRQxzq7sBLUE8H8ZGLByix2EDOzGAsA8FteX8,10019
116
+ udata/core/dataset/transport.py,sha256=ihCXirY1dZjOfXKbf9HRCJTfIOc75rM1McwbeGjsW6A,1296
116
117
  udata/core/discussions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
117
118
  udata/core/discussions/actions.py,sha256=kjdBLDIeu0yWTSxQGgOpN1WoxUqbMygn4SiBk_S9T5I,1051
118
119
  udata/core/discussions/api.py,sha256=u9atdyPVGpyLin4IRF1ZhMp6gRmtJvV0Y8ksic_nbJo,12807
@@ -297,7 +298,7 @@ udata/harvest/signals.py,sha256=3AhFHMPIFH5vz01NX5ycR_RWH14MXFWnCT6__LSa-QI,1338
297
298
  udata/harvest/tasks.py,sha256=ddJtvE0s-kAYt27-rKH6n8U8vKD8qKczlJtdBJzMUns,1718
298
299
  udata/harvest/backends/__init__.py,sha256=QjoFfBJfpw_xgk5YYWI1SgKJOMEmTMlxSfW79GNkSTI,459
299
300
  udata/harvest/backends/base.py,sha256=2wyfw83e3xGQcHnQI-z26g1dg-uVtWcDgzsBk7iGX3Y,17480
300
- udata/harvest/backends/dcat.py,sha256=ofd3JiKL4x02GAPKtW1wryoZD0_P4xnwoZC2KWp_sNI,18698
301
+ udata/harvest/backends/dcat.py,sha256=IfUmqHy68Tt30E_kn4riExfgb-d7qPa--7KjCLCsia0,18637
301
302
  udata/harvest/backends/maaf.py,sha256=N7ty8ZWO9pfKPtZRk1wTaJ5pY6qi-0-GtF1p8jiYiY4,8102
302
303
  udata/harvest/backends/maaf.xsd,sha256=vEyG8Vqw7Yn_acjRdXjqUJgxOj4pv8bibep-FX-f3BQ,18322
303
304
  udata/harvest/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -306,7 +307,7 @@ udata/harvest/tests/person.jsonld,sha256=I7Ynh-PQlNeD51I1LrCgYOEjhL-WBeb65xzIE_s
306
307
  udata/harvest/tests/test_actions.py,sha256=Hm5MpOEFXBvFzcNMu7hvrWIiP6fiOXLuDOyrykL-4tc,25224
307
308
  udata/harvest/tests/test_api.py,sha256=dyCXhKgOO0XmCPgH_36sob8WVhtMB2WX1johbfzJtDI,21553
308
309
  udata/harvest/tests/test_base_backend.py,sha256=ow8ecGtD836mUqyPWYjkS5nx0STyT5RMLgBdDyOhts4,19233
309
- udata/harvest/tests/test_dcat_backend.py,sha256=O2SOSz34DwBxta9RrDJ2wGxxfwTKFyCHTEc1bH0oRI8,43717
310
+ udata/harvest/tests/test_dcat_backend.py,sha256=DCRtA0DDW7XrX7ux7GI6HaUcI-ZOWIoGe8Dl2pwGCo4,43713
310
311
  udata/harvest/tests/test_filters.py,sha256=PT2qopEIoXsqi8MsNDRuhNH7jGXiQo8r0uJrCOUd4aM,2465
311
312
  udata/harvest/tests/test_models.py,sha256=f9NRR2_S4oZFgF8qOumg0vv-lpnEBJbI5vNtcwFdSqM,831
312
313
  udata/harvest/tests/test_notifications.py,sha256=MMzTzkv-GXMNFeOwAi31rdTsAXyLCLOSna41zOtaJG0,816
@@ -669,6 +670,7 @@ udata/tests/dataset/test_dataset_rdf.py,sha256=7SorX0e0VD3hmj8C0qXA4Vb3Q3xl2qaE4
669
670
  udata/tests/dataset/test_dataset_recommendations.py,sha256=K52HXGXi9DuUSiSRQWpqTrsFCkYbv7K3upNp0fFp5v8,7068
670
671
  udata/tests/dataset/test_dataset_tasks.py,sha256=n1W2Pg0ez02d66zQG3N93kh7dpR2yLMRDqUI6PnPaI0,3088
671
672
  udata/tests/dataset/test_resource_preview.py,sha256=fp9mSL7unhyM66GR0gwhgX3OGQ4TJt7G9xU-CjsL3HI,3908
673
+ udata/tests/dataset/test_transport_tasks.py,sha256=BYr1WPV0Crirzb2jC_wAV4y_pzImRCAS4zYZ7qvCDeY,2964
672
674
  udata/tests/features/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
673
675
  udata/tests/features/territories/__init__.py,sha256=gMD73RL-ymcWvGPDPM0aPxz7WAfd1VEDL8YHRI7HT0Q,956
674
676
  udata/tests/features/territories/test_territories_api.py,sha256=UA5j5ZqLP3L3PdddMYJdizmftUFIjj3wWHOt5M2kQtU,7527
@@ -734,9 +736,9 @@ udata/translations/pt/LC_MESSAGES/udata.mo,sha256=9sCd1MUKvtVP_sOXvK-G5v4PfWkkdA
734
736
  udata/translations/pt/LC_MESSAGES/udata.po,sha256=-eJptz9s63rjkdm-3HJi_2t70pyv3-8EuXBn-B2qI_4,48419
735
737
  udata/translations/sr/LC_MESSAGES/udata.mo,sha256=qduXntHWe__KaUxJ4JwwyGG3eSgYb1auGdNax0lS49c,29169
736
738
  udata/translations/sr/LC_MESSAGES/udata.po,sha256=6QCuLMCRjgyAvu9U7i0P19ae8fm_uStfmxHLqUO9EoY,55394
737
- udata-10.5.1.dev36034.dist-info/LICENSE,sha256=V8j_M8nAz8PvAOZQocyRDX7keai8UJ9skgmnwqETmdY,34520
738
- udata-10.5.1.dev36034.dist-info/METADATA,sha256=j-kbOdj5x8dcfnIMgvlLhf-_h2pEL5-O9XNwNL0lANA,149656
739
- udata-10.5.1.dev36034.dist-info/WHEEL,sha256=Kh9pAotZVRFj97E15yTA4iADqXdQfIVTHcNaZTjxeGM,110
740
- udata-10.5.1.dev36034.dist-info/entry_points.txt,sha256=ETvkR4r6G1duBsh_V_fGWENQy17GTFuobi95MYBAl1A,498
741
- udata-10.5.1.dev36034.dist-info/top_level.txt,sha256=39OCg-VWFWOq4gCKnjKNu-s3OwFlZIu_dVH8Gl6ndHw,12
742
- udata-10.5.1.dev36034.dist-info/RECORD,,
739
+ udata-10.5.1.dev36076.dist-info/LICENSE,sha256=V8j_M8nAz8PvAOZQocyRDX7keai8UJ9skgmnwqETmdY,34520
740
+ udata-10.5.1.dev36076.dist-info/METADATA,sha256=7diG5zHyeuMPGlb1wYgvigaapy8Di8PQ_JYTRP4Eb5c,149934
741
+ udata-10.5.1.dev36076.dist-info/WHEEL,sha256=Kh9pAotZVRFj97E15yTA4iADqXdQfIVTHcNaZTjxeGM,110
742
+ udata-10.5.1.dev36076.dist-info/entry_points.txt,sha256=ETvkR4r6G1duBsh_V_fGWENQy17GTFuobi95MYBAl1A,498
743
+ udata-10.5.1.dev36076.dist-info/top_level.txt,sha256=39OCg-VWFWOq4gCKnjKNu-s3OwFlZIu_dVH8Gl6ndHw,12
744
+ udata-10.5.1.dev36076.dist-info/RECORD,,