Skip to content

Commit

Permalink
✨ [FEAT] Add GeotrekSiteParser and tests (refs #3569)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chatewgne committed Feb 2, 2024
1 parent 47a85b1 commit 7d787a3
Show file tree
Hide file tree
Showing 21 changed files with 2,074 additions and 0 deletions.
53 changes: 53 additions & 0 deletions geotrek/outdoor/parsers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from geotrek.common.parsers import (ApidaeBaseParser, AttachmentParserMixin, GeotrekParser, GlobalImportError, Parser)
from geotrek.outdoor.models import Site


class GeotrekSiteParser(GeotrekParser):
"""Geotrek parser for Outoor Site"""
fill_empty_translated_fields = True
url = None
model = Site
replace_fields = {
"eid": "uuid",
"geom": "geometry"
}
url_categories = {
"practice": "outdoor_practice",
"ratings": "outdoor_rating",
"themes": "theme",
"type": "outdoor_sitetype",
'labels': 'label',
'source': 'source',
'managers': 'organism',
'structure': 'structure',
}
categories_keys_api_v2 = {
"practice": "name",
"ratings": "name",
"themes": "label",
"type": "name",
'labels': 'name',
'source': 'name',
'managers': 'name',
'structure': 'name',
}
natural_keys = {
"practice": "name",
"ratings": "name",
"themes": "label",
"type": "name",
'labels': 'name',
'source': 'name',
'managers': 'organism',
'structure': 'name',
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.next_url = f"{self.url}/api/v2/outdoor_site"
print("AFTER INIT 9999999999999999999999999999999999999999999999999999999")

def end(self):
"""Add children after all treks imported are created in database."""
#super().end()
print("MAKE LINK BETWEEN SITES")
42 changes: 42 additions & 0 deletions geotrek/outdoor/tests/data/geotrek_parser_v2/informationdesk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"accessibility": {
"en": "",
"fr": ""
},
"description": {
"en": "",
"fr": ""
},
"email": null,
"label_accessibility": null,
"latitude": null,
"longitude": null,
"municipality": null,
"name": {
"en": "Test en",
"fr": "Test fr"
},
"phone": null,
"photo_url": "",
"uuid": "f2ace594-2444-48ba-a316-5ead2fc29011",
"postal_code": null,
"provider": "",
"street": null,
"type": {
"id": 1,
"label": {
"en": "Test type",
"fr": "Test type fr"
},
"pictogram": "http://geotrek.local:8000/media/upload/vtt_d66RAwr.svg"
},
"website": null
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"label": {
"en": "Test type",
"fr": "Test type fr"
},
"pictogram": "http://geotrek.local:8000/media/upload/vtt_d66RAwr.svg"
}
]
}
20 changes: 20 additions & 0 deletions geotrek/outdoor/tests/data/geotrek_parser_v2/label.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 4,
"advice": {
"en": "Reco en",
"fr": "Reco fr"
},
"filter": true,
"name": {
"en": "Label en",
"fr": "Label fr"
},
"pictogram": null
}
]
}
11 changes: 11 additions & 0 deletions geotrek/outdoor/tests/data/geotrek_parser_v2/organism.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"name": "Organisme"
}
]
}
Loading

0 comments on commit 7d787a3

Please sign in to comment.