Skip to content

Commit

Permalink
Fix remaining indexing errors, turn off noisy system checks
Browse files Browse the repository at this point in the history
  • Loading branch information
hancush committed Sep 26, 2023
1 parent 92fefda commit e58c603
Show file tree
Hide file tree
Showing 3 changed files with 276 additions and 244 deletions.
101 changes: 62 additions & 39 deletions location/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@


class LocationManager(models.Manager):

def from_humane_id(self, humane_id):
if isinstance(humane_id, str):
return self.get(**{'sfm__location:humane_id:admin': humane_id})
return self.get(
**{
"sfm__location:humane_id:admin": humane_id,
"geometry__isnull": False,
}
)

return self.filter(**{'sfm__location:humane_id:admin__in': humane_id})
return self.filter(
**{
"sfm__location:humane_id:admin__in": humane_id,
"geometry__isnull": False,
}
)


class Location(models.Model):
Expand All @@ -21,16 +30,20 @@ class Location(models.Model):
feature_type = models.TextField(blank=True, null=True)
tags = models.JSONField(blank=True, null=True)
sfm = models.JSONField(blank=True, null=True)
adminlevel1 = models.ForeignKey('self',
related_name='area_locations',
on_delete=models.CASCADE,
null=True,
blank=True)
adminlevel2 = models.ForeignKey('self',
related_name='place_locations',
on_delete=models.CASCADE,
null=True,
blank=True)
adminlevel1 = models.ForeignKey(
"self",
related_name="area_locations",
on_delete=models.CASCADE,
null=True,
blank=True,
)
adminlevel2 = models.ForeignKey(
"self",
related_name="place_locations",
on_delete=models.CASCADE,
null=True,
blank=True,
)
adminlevel = models.CharField(max_length=50, null=True, blank=True)
geometry = GeometryField(blank=True, null=True)

Expand Down Expand Up @@ -60,42 +73,52 @@ def related_entities(self):
for associationarea in self.associationarea_set.all():
association = associationarea.object_ref
organization = association.organization.get_value().value
related_entities.append({
'name': organization.name.get_value().value,
'entity_type': _('Organization'),
'start_date': association.startdate.get_value(),
'end_date': association.enddate.get_value(),
'open_ended': association.open_ended.get_value(),
'url': reverse('view-organization', kwargs={'slug': organization.uuid}),
})
related_entities.append(
{
"name": organization.name.get_value().value,
"entity_type": _("Organization"),
"start_date": association.startdate.get_value(),
"end_date": association.enddate.get_value(),
"open_ended": association.open_ended.get_value(),
"url": reverse(
"view-organization", kwargs={"slug": organization.uuid}
),
}
)

for emplacementsite in self.emplacementsite_set.all():
emplacement = emplacementsite.object_ref
organization = emplacement.organization.get_value().value
related_entities.append({
'name': organization.name.get_value().value,
'entity_type': _('Organization'),
'start_date': emplacement.startdate.get_value(),
'end_date': emplacement.enddate.get_value(),
'open_ended': emplacement.open_ended.get_value(),
'url': reverse('view-organization', kwargs={'slug': organization.uuid}),
})
related_entities.append(
{
"name": organization.name.get_value().value,
"entity_type": _("Organization"),
"start_date": emplacement.startdate.get_value(),
"end_date": emplacement.enddate.get_value(),
"open_ended": emplacement.open_ended.get_value(),
"url": reverse(
"view-organization", kwargs={"slug": organization.uuid}
),
}
)

for violationlocation in self.violationlocation_set.all():
violation = violationlocation.object_ref
related_entities.append({
'name': truncatewords(violation.description.get_value(), 10),
'entity_type': _('Violation'),
'start_date': violation.startdate.get_value(),
'end_date': violation.enddate.get_value(),
'open_ended': '',
'url': reverse('view-violation', kwargs={'slug': violation.uuid}),
})
related_entities.append(
{
"name": truncatewords(violation.description.get_value(), 10),
"entity_type": _("Violation"),
"start_date": violation.startdate.get_value(),
"end_date": violation.enddate.get_value(),
"open_ended": "",
"url": reverse("view-violation", kwargs={"slug": violation.uuid}),
}
)

return related_entities

@property
def osm_feature_type(self):
if self.feature_type == 'boundary':
return 'relation'
if self.feature_type == "boundary":
return "relation"
return self.feature_type
Loading

0 comments on commit e58c603

Please sign in to comment.