Skip to content

Commit

Permalink
Fix issue with location context (#4334)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimasciput authored Oct 30, 2024
1 parent 627a98e commit dbe1a3e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
28 changes: 20 additions & 8 deletions bims/models/location_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,26 @@ def add_context_group(self, group_key):

for result in feature_data['result']:
if context_key in result['feature']:
LocationContext.objects.update_or_create(
site=self,
group=context_group,
defaults={
'fetch_time': timezone.now(),
'value': str(result['feature'][context_key])
}
)
try:
LocationContext.objects.update_or_create(
site=self,
group=context_group,
defaults={
'fetch_time': timezone.now(),
'value': str(result['feature'][context_key])
}
)
except LocationContext.MultipleObjectsReturned:
LocationContext.objects.filter(
site=self,
group=context_group,
).delete()
LocationContext.objects.create(
site=self,
group=context_group,
fetch_time=timezone.now(),
value=str(result['feature'][context_key])
)
return True, 'Added'

try:
Expand Down
7 changes: 5 additions & 2 deletions bims/views/context_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ class LocationContextGroupSerializer(serializers.ModelSerializer):

def get_native_layer_name(self, obj: LocationContextGroup):
if obj.key and is_uuid(obj.key):
layer = Layer.objects.get(unique_id=obj.key)
return layer.name
try:
layer = Layer.objects.get(unique_id=obj.key)
return layer.name
except Layer.DoesNotExist:
return ''
return ''

def get_is_native_layer(self, obj: LocationContextGroup):
Expand Down

0 comments on commit dbe1a3e

Please sign in to comment.