Skip to content

Commit

Permalink
Merge pull request #1984 from unicef/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
robertavram authored Apr 17, 2024
2 parents 19ab6b6 + 1c4332e commit c7321f1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
7 changes: 5 additions & 2 deletions django_api/etools_prp/apps/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from leaflet.admin import LeafletGeoAdmin
from unicef_locations.models import CartoDBTable

from .cartodb import import_locations
from .cartodb import import_locations, rebuild_tree
from .forms import CartoDBTableForm
from .models import Location, PRPRoleOld, Realm, ResponsePlan, Workspace

Expand Down Expand Up @@ -48,7 +48,7 @@ class CartoDBTableAdmin(admin.ModelAdmin):
'parent_table_name',
)

actions = ('import_sites',)
actions = ('import_sites', 'rebuild_tree')
raw_id_fields = ('parent', )

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

def rebuild_tree(self, request, queryset):
rebuild_tree.delay()


class WorkspaceAdmin(admin.ModelAdmin):
list_display = ('title', 'workspace_code', 'business_area_code',
Expand Down
8 changes: 8 additions & 0 deletions django_api/etools_prp/apps/core/cartodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from celery.utils.log import get_task_logger
from pyrestcli.auth import BaseAuthClient
from unicef_locations.models import CartoDBTable
from unicef_locations.utils import get_location_model

from etools_prp.apps.core.locations_sync import PRPLocationSynchronizer
from etools_prp.apps.core.models import Location
Expand Down Expand Up @@ -156,9 +157,16 @@ def create_location(pcode,

@shared_task
def import_locations(carto_table_pk):
logger.info("import locations started")
PRPLocationSynchronizer(carto_table_pk).sync()


@shared_task
def rebuild_tree():
logger.info("rebuild tree started")
get_location_model().objects.rebuild()


@shared_task
def update_sites_from_cartodb(carto_table_pk):
"""
Expand Down
6 changes: 3 additions & 3 deletions django_api/etools_prp/apps/core/locations_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ def create_or_update_locations(self, batch_size=500):
for loc in newly_created:
loc.workspaces.add(self.workspace)

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

def clean_upper_level(self):
Expand Down

0 comments on commit c7321f1

Please sign in to comment.