mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-06 02:58:25 -04:00
broadcast-areas: only load geojson when needed
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import geojson
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
from notifications_utils.serialised_model import SerialisedModelCollection
|
from notifications_utils.serialised_model import SerialisedModelCollection
|
||||||
@@ -39,8 +40,8 @@ class BroadcastArea(IdentifiableMixin):
|
|||||||
|
|
||||||
self.id = id
|
self.id = id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.feature = feature
|
self._feature = feature
|
||||||
self.simple_feature = simple_feature
|
self._simple_feature = simple_feature
|
||||||
|
|
||||||
for coordinates in self.polygons:
|
for coordinates in self.polygons:
|
||||||
if coordinates[0] != coordinates[-1]:
|
if coordinates[0] != coordinates[-1]:
|
||||||
@@ -91,6 +92,14 @@ class BroadcastArea(IdentifiableMixin):
|
|||||||
def simple_unenclosed_polygons(self):
|
def simple_unenclosed_polygons(self):
|
||||||
return self._unenclosed_polygons(self.simple_feature)
|
return self._unenclosed_polygons(self.simple_feature)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def feature(self):
|
||||||
|
return geojson.loads(self._feature)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def simple_feature(self):
|
||||||
|
return geojson.loads(self._simple_feature)
|
||||||
|
|
||||||
|
|
||||||
class BroadcastAreaLibrary(SerialisedModelCollection, IdentifiableMixin, IdFromNameMixin, GetItemByIdMixin):
|
class BroadcastAreaLibrary(SerialisedModelCollection, IdentifiableMixin, IdFromNameMixin, GetItemByIdMixin):
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import geojson
|
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import sqlite3
|
import sqlite3
|
||||||
@@ -129,7 +128,7 @@ class BroadcastAreasRepository(object):
|
|||||||
results = cursor.fetchall()
|
results = cursor.fetchall()
|
||||||
|
|
||||||
areas = [
|
areas = [
|
||||||
(row[0], row[1], geojson.loads(row[2]), geojson.loads(row[3]))
|
(row[0], row[1], row[2], row[3])
|
||||||
for row in results
|
for row in results
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -145,7 +144,7 @@ class BroadcastAreasRepository(object):
|
|||||||
results = self.query(q, library_id)
|
results = self.query(q, library_id)
|
||||||
|
|
||||||
areas = [
|
areas = [
|
||||||
(row[0], row[1], geojson.loads(row[2]), geojson.loads(row[3]))
|
(row[0], row[1], row[2], row[3])
|
||||||
for row in results
|
for row in results
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user