Skip to content

Commit c7321f1

Browse files
authored
Merge pull request #1984 from unicef/staging
Staging
2 parents 19ab6b6 + 1c4332e commit c7321f1

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

django_api/etools_prp/apps/core/admin.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from leaflet.admin import LeafletGeoAdmin
44
from unicef_locations.models import CartoDBTable
55

6-
from .cartodb import import_locations
6+
from .cartodb import import_locations, rebuild_tree
77
from .forms import CartoDBTableForm
88
from .models import Location, PRPRoleOld, Realm, ResponsePlan, Workspace
99

@@ -48,7 +48,7 @@ class CartoDBTableAdmin(admin.ModelAdmin):
4848
'parent_table_name',
4949
)
5050

51-
actions = ('import_sites',)
51+
actions = ('import_sites', 'rebuild_tree')
5252
raw_id_fields = ('parent', )
5353

5454
def parent_table_name(self, obj):
@@ -58,6 +58,9 @@ def import_sites(self, request, queryset):
5858
for table in queryset:
5959
import_locations.delay(table.pk)
6060

61+
def rebuild_tree(self, request, queryset):
62+
rebuild_tree.delay()
63+
6164

6265
class WorkspaceAdmin(admin.ModelAdmin):
6366
list_display = ('title', 'workspace_code', 'business_area_code',

django_api/etools_prp/apps/core/cartodb.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from celery.utils.log import get_task_logger
1111
from pyrestcli.auth import BaseAuthClient
1212
from unicef_locations.models import CartoDBTable
13+
from unicef_locations.utils import get_location_model
1314

1415
from etools_prp.apps.core.locations_sync import PRPLocationSynchronizer
1516
from etools_prp.apps.core.models import Location
@@ -156,9 +157,16 @@ def create_location(pcode,
156157

157158
@shared_task
158159
def import_locations(carto_table_pk):
160+
logger.info("import locations started")
159161
PRPLocationSynchronizer(carto_table_pk).sync()
160162

161163

164+
@shared_task
165+
def rebuild_tree():
166+
logger.info("rebuild tree started")
167+
get_location_model().objects.rebuild()
168+
169+
162170
@shared_task
163171
def update_sites_from_cartodb(carto_table_pk):
164172
"""

django_api/etools_prp/apps/core/locations_sync.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ def create_or_update_locations(self, batch_size=500):
146146
for loc in newly_created:
147147
loc.workspaces.add(self.workspace)
148148

149-
logger.info("Rebuilding the tree, have patience")
150-
get_location_model().objects.rebuild()
151-
logger.info("Rebuilt")
149+
logger.info("Rebuilding the tree, have patience -deferred for now. done separately")
150+
# get_location_model().objects.rebuild()
151+
# logger.info("Rebuilt")
152152
return new, updated, skipped, error
153153

154154
def clean_upper_level(self):

0 commit comments

Comments
 (0)