Skip to content

Commit

Permalink
Merge pull request #3303 from GeotrekCE/fix-espritparcparser
Browse files Browse the repository at this point in the history
Fix EspritParcParser
  • Loading branch information
LePetitTim authored Nov 29, 2022
2 parents 4b6f675 + 39ccd56 commit 2d53d11
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions geotrek/tourism/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def filter_type1(self, src, val):
return self.apply_filter('type1', src, [val])


class EspritParcParser(AttachmentParserMixin, Parser):
class EspritParcParser(AttachmentParserMixin, TouristicContentMixin, Parser):
model = TouristicContent
eid = 'eid'
separator = None
Expand Down Expand Up @@ -614,7 +614,7 @@ def filter_attachments(self, src, val):

@property
def items(self):
return self.root['responseData']
return self.root['responseData'] or []

def next_row(self):
response = self.request_or_retry(self.url)
Expand Down Expand Up @@ -654,22 +654,29 @@ def filter_category(self, src, val):
def filter_type1(self, src, val):
dst = []
if val:
try:
dst.append(TouristicContentType1.objects.get(category=self.obj.category, label=val))
except TouristicContentType1.DoesNotExist:
self.add_warning(
_("Type 1 '{subval}' does not exist for category '{cat}'. Please add it").format(
subval=val, cat=self.obj.category.label))
if isinstance(val, str):
val = [val]
for subval in val:
try:
dst.append(TouristicContentType1.objects.get(category=self.obj.category, label=subval))
except TouristicContentType1.DoesNotExist:
self.add_warning(
_("Type 1 '{subval}' does not exist for category '{cat}'. Please add it").format(
subval=subval, cat=self.obj.category.label))
return dst

def filter_type2(self, src, val):
dst = []
if val:
try:
dst.append(TouristicContentType2.objects.get(category=self.obj.category, label=val))
except TouristicContentType2.DoesNotExist:
self.add_warning(_("Type 2 '{subval}' does not exist for category '{cat}'. Please add it").format(
subval=val, cat=self.obj.category.label))
if isinstance(val, str):
val = [val]
for subval in val:
try:
dst.append(TouristicContentType2.objects.get(category=self.obj.category, label=subval))
except TouristicContentType2.DoesNotExist:
self.add_warning(
_("Type 2 '{subval}' does not exist for category '{cat}'. Please add it").format(
subval=subval, cat=self.obj.category.label))
return dst


Expand Down

0 comments on commit 2d53d11

Please sign in to comment.