Skip to content

Commit

Permalink
improve openair list perfs
Browse files Browse the repository at this point in the history
  • Loading branch information
lpofredc committed Sep 20, 2023
1 parent 104ee6d commit 62529f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
14 changes: 0 additions & 14 deletions geotrek/sensitivity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,6 @@ def openair(self):
}
return wkt2openair(**data)

@property
def wgs84_geom(self):
geom = self.geom
if geom.geom_type == 'Point':
geom = geom.buffer(self.species.radius or settings.SENSITIVITY_DEFAULT_RADIUS, 4)
if self.species.radius:
geometry = ()
for coords in geom.coords[0]:
coords += (self.species.radius, )
geometry += (coords, )
geom = GEOSGeometry(Polygon(geometry), srid=settings.SRID)
geom = geom.transform(4326, clone=True) # KML uses WGS84
return geom

def is_public(self):
return self.published

Expand Down
12 changes: 10 additions & 2 deletions geotrek/sensitivity/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ class SensitiveAreaOpenAirList(PublicOrReadPermMixin, ListView):

def get_queryset(self):
aerial_practice = SportPractice.objects.filter(name__in=settings.SENSITIVITY_OPENAIR_SPORT_PRACTICES)
return SensitiveArea.objects.filter(species__practices__in=aerial_practice)
return SensitiveArea.objects.filter(
species__practices__in=aerial_practice, published=True
).select_related('species')

def render_to_response(self, context):
areas = self.get_queryset()
Expand All @@ -220,7 +222,13 @@ def render_to_response(self, context):
* This file was created on: {timestamp}\n\n""".format(scheme=self.request.scheme, domain=self.request.META['HTTP_HOST'], timestamp=datetime.now())
airspace_list = []
for a in areas:
airspace_list.append(a.openair())
if not a.openair():
logger.error(
"The openair format cannot be generated for area %s-%s",
a.id, a
)
else:
airspace_list.append(a.openair())
airspace_core = '\n\n'.join(airspace_list)
airspace_file = file_header + airspace_core
response = HttpResponse(airspace_file, content_type='application/octet-stream; charset=UTF-8')
Expand Down

0 comments on commit 62529f0

Please sign in to comment.