Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger Geopoint ES Index on Geospatial Feature Flag Enable #35126

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions corehq/apps/geospatial/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from corehq.util.quickcache import quickcache

from .dispatchers import CaseManagementMapDispatcher
from corehq.apps.geospatial.const import INDEX_ES_TASK_HELPER_BASE_KEY
from .es import (
BUCKET_CASES_AGG,
CASE_PROPERTIES_AGG,
Expand All @@ -38,6 +39,7 @@
geojson_to_es_geoshape,
get_geo_case_property,
validate_geometry,
get_celery_task_tracker,
)


Expand All @@ -59,12 +61,14 @@ class BaseCaseMapReport(ProjectReport, CaseListMixin, XpathCaseSearchFilterMixin
def template_context(self):
# Whatever is specified here can be accessed through initial_page_data
context = super(BaseCaseMapReport, self).template_context
celery_task_tracker = get_celery_task_tracker(self.domain, base_key=INDEX_ES_TASK_HELPER_BASE_KEY)
context.update({
'mapbox_access_token': settings.MAPBOX_ACCESS_TOKEN,
'saved_polygons': [
{'id': p.id, 'name': p.name, 'geo_json': p.geo_json}
for p in GeoPolygon.objects.filter(domain=self.domain).all()
],
'es_indexing_message': celery_task_tracker.get_message()
AmitPhulera marked this conversation as resolved.
Show resolved Hide resolved
})
return context

Expand Down
21 changes: 18 additions & 3 deletions corehq/apps/geospatial/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@
from corehq.form_processor.models import CommCareCase
from corehq.util.timezones.utils import get_timezone

from .const import GPS_POINT_CASE_PROPERTY, POLYGON_COLLECTION_GEOJSON_SCHEMA
from .const import (
GPS_POINT_CASE_PROPERTY,
POLYGON_COLLECTION_GEOJSON_SCHEMA,
INDEX_ES_TASK_HELPER_BASE_KEY,
)
from .models import GeoConfig, GeoPolygon
from .utils import (
CaseOwnerUpdate,
Expand All @@ -59,13 +63,24 @@
set_case_gps_property,
set_user_gps_property,
update_cases_owner,
get_celery_task_tracker,
)


def geospatial_default(request, *args, **kwargs):
return HttpResponseRedirect(CaseManagementMap.get_url(*args, **kwargs))


class BaseGeospatialView(BaseDomainView):

@property
def main_context(self):
context = super().main_context
celery_task_tracker = get_celery_task_tracker(self.domain, base_key=INDEX_ES_TASK_HELPER_BASE_KEY)
context['es_indexing_message'] = celery_task_tracker.get_message()
return context


class CaseDisbursementAlgorithm(BaseDomainView):
urlname = "case_disbursement"

Expand Down Expand Up @@ -151,7 +166,7 @@ def delete(self, request, *args, **kwargs):
})


class BaseConfigView(BaseDomainView):
class BaseConfigView(BaseGeospatialView):
section_name = _("Data")

@method_decorator(toggles.GEOSPATIAL.required_decorator())
Expand Down Expand Up @@ -229,7 +244,7 @@ def page_context(self):
return context


class GPSCaptureView(BaseDomainView):
class GPSCaptureView(BaseGeospatialView):
urlname = 'gps_capture'
template_name = 'gps_capture_view.html'

Expand Down