-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1347 from the-deep/feature/geo-parents
Support: GeoArea Filter + Parent information
- Loading branch information
Showing
39 changed files
with
397 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import logging | ||
from django.core.management.base import BaseCommand | ||
from django.db import transaction | ||
|
||
from geo.models import Region, AdminLevel | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Re-trigger cached data for all geo entities. For specific objects admin panel' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'--region', | ||
action='store_true', | ||
help='Calculate all regions cache', | ||
) | ||
parser.add_argument( | ||
'--admin-level', | ||
action='store_true', | ||
help='Calculate all regions admin level cache', | ||
) | ||
|
||
def calculate(self, Model): | ||
success_ids = [] | ||
qs = Model.objects.all() | ||
total = qs.count() | ||
for index, item in enumerate(qs.all(), start=1): | ||
try: | ||
self.stdout.write(f"({index}/{total}) [{item.pk}] {item.title}") | ||
with transaction.atomic(): | ||
item.calc_cache() | ||
success_ids.append(item.pk) | ||
except Exception: | ||
logger.error(f'{Model.__name__} Cache Calculation Failed!!', exc_info=True) | ||
self.stdout.write(self.style.SUCCESS(f'{success_ids=}')) | ||
|
||
def handle(self, *_, **options): | ||
calculate_regions = options['region'] | ||
calculate_admin_levels = options['admin_level'] | ||
|
||
if calculate_regions: | ||
self.calculate(Region) | ||
if calculate_admin_levels: | ||
self.calculate(AdminLevel) |
18 changes: 18 additions & 0 deletions
18
apps/geo/migrations/0042_rename_data_geoarea_cached_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.17 on 2023-08-02 09:32 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('geo', '0041_geoarea_centroid'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='geoarea', | ||
old_name='data', | ||
new_name='cached_data', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.