-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
uber refactor of cities, states and countries. They now are direct re…
…latade to Lands, Villages and Acheological sites.
- Loading branch information
1 parent
1b97683
commit 5a19fbf
Showing
7 changed files
with
254 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from django.core.management.base import BaseCommand | ||
from boundaries.models import City, State, Country | ||
from core.models import IndigenousLand, ArchaeologicalPlace, IndigenousVillage | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Set Cities, States and Country for Villages, Lands and ArchaeologicalPlaces' | ||
|
||
def set_place_boundaries(self, queryset): | ||
|
||
for instance in queryset: | ||
instance.cities = City.objects.filter(geometry__covers=instance.geometry) | ||
instance.states = State.objects.filter(geometry__covers=instance.geometry) | ||
try: | ||
instance.country = Country.objects.get(geometry__covers=instance.geometry) | ||
except Country.DoesNotExist: | ||
self.stdout.write('Place {0} is not in any country!!!'.format(instance.name)) | ||
instance.save() | ||
|
||
def handle(self, *args, **options): | ||
|
||
self.stdout.write('Starting set villages...') | ||
self.set_place_boundaries(IndigenousVillage.objects.all()) | ||
self.stdout.write('Finished set villages!') | ||
self.stdout.write('Starting set Archaeological...') | ||
self.set_place_boundaries(ArchaeologicalPlace.objects.all()) | ||
self.stdout.write('Finished set Archaeological!') | ||
|
||
self.stdout.write('Starting set lands...') | ||
for land in IndigenousLand.objects.all(): | ||
land.cities = City.objects.filter(geometry__intersects=land.geometry) | ||
land.states = State.objects.filter(geometry__intersects=land.geometry) | ||
try: | ||
land.country = Country.objects.get(geometry__covers=land.geometry) | ||
except Country.DoesNotExist: | ||
self.stdout.write('Land {0} is not in any counry!!!'.format(land.name)) | ||
land.save() | ||
self.stdout.write('Finished set lands!') | ||
|
||
self.stdout.write('\n') | ||
self.stdout.write( | ||
'Cities, States and Country for Villages, Lands and ArchaeologicalPlaces succesfull set!!!') | ||
self.stdout.write('\n') |
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,51 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11 on 2018-05-01 22:17 | ||
from __future__ import unicode_literals | ||
|
||
import django.contrib.gis.db.models.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0039_auto_20180412_1241'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='indigenousland', | ||
name='documents', | ||
field=models.ManyToManyField(blank=True, help_text='Acrescente a documentação oficial sobre a terra indígena (decretos de homologação, portarias declaratórias,etc.).\n Caso o mesmo documento se refira a mais de uma terra indígena, ele pode já estar cadastrado e você pode apenas selecioná-lo.\n Confira na lista antes de adicionar. ', related_name='indigenousland_documentation', to='core.Document', verbose_name='documentation'), | ||
), | ||
migrations.AlterField( | ||
model_name='indigenousland', | ||
name='geometry', | ||
field=django.contrib.gis.db.models.fields.MultiPolygonField(help_text='Inclua aqui o polígono da terra indígena apenas em formato *.KML.\n Certifique-se de que apenas a terra indígena correspondente está no arquivo. ', srid=4326, verbose_name='Indigenous Land Spatial Data'), | ||
), | ||
migrations.AlterField( | ||
model_name='indigenousland', | ||
name='guarani_exclusive_possession_area_portion', | ||
field=models.FloatField(blank=True, help_text='Em caso de terras ainda em processo de regularização, caso tenha informação de qual porção da área já foi desintrusada incluir.\n Em áreas em que não se iniciou o processo de desintrusão colocar 0.', null=True, verbose_name='Guarani full and exclusive portion area possession'), | ||
), | ||
migrations.AlterField( | ||
model_name='indigenousland', | ||
name='others_exclusive_possession_area_portion', | ||
field=models.FloatField(blank=True, help_text='Em caso de terras ainda em processo de regularização, caso tenha informação de qual porção da área já foi desintrusada incluir.\n Em áreas em que não se iniciou o processo de desintrusão colocar 0. ', null=True, verbose_name="Other peoples' full and exclusive portion area possession"), | ||
), | ||
migrations.AlterField( | ||
model_name='indigenousland', | ||
name='prominent_subgroup', | ||
field=models.ManyToManyField(blank=True, related_name='indigenousland_prominent_subgroup_layers', to='core.ProminentEthnicSubGroup', verbose_name='Guarani ethnic sub-group'), | ||
), | ||
migrations.AlterField( | ||
model_name='indigenousvillage', | ||
name='geometry', | ||
field=django.contrib.gis.db.models.fields.PointField(help_text='Localize o ponto da aldeia.\n Você pode incluir as coordenadas geográficas (em graus decimais) ou\n localizar o ponto olhando o mapa ou a foto aérea do Google.', srid=4326, verbose_name='Geometry'), | ||
), | ||
migrations.AlterField( | ||
model_name='indigenousvillage', | ||
name='prominent_subgroup', | ||
field=models.ManyToManyField(blank=True, related_name='indigenousvillage_prominent_subgroup_layers', to='core.ProminentEthnicSubGroup', verbose_name='Guarani ethnic sub-group'), | ||
), | ||
] |
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,62 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11 on 2018-05-09 21:32 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('boundaries', '0005_auto_20180501_2240'), | ||
('core', '0040_auto_20180501_2217'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='archaeologicalplace', | ||
name='cities', | ||
field=models.ManyToManyField(blank=True, related_name='archaeologicalplace_ethnic_groups_layers', to='boundaries.City', verbose_name='Cities'), | ||
), | ||
migrations.AddField( | ||
model_name='archaeologicalplace', | ||
name='country', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='archaeologicalplace_ethnic_groups_layers', to='boundaries.Country', verbose_name='Country'), | ||
), | ||
migrations.AddField( | ||
model_name='archaeologicalplace', | ||
name='states', | ||
field=models.ManyToManyField(blank=True, related_name='archaeologicalplace_ethnic_groups_layers', to='boundaries.State', verbose_name='States'), | ||
), | ||
migrations.AddField( | ||
model_name='indigenousland', | ||
name='cities', | ||
field=models.ManyToManyField(blank=True, related_name='indigenousland_ethnic_groups_layers', to='boundaries.City', verbose_name='Cities'), | ||
), | ||
migrations.AddField( | ||
model_name='indigenousland', | ||
name='country', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='indigenousland_ethnic_groups_layers', to='boundaries.Country', verbose_name='Country'), | ||
), | ||
migrations.AddField( | ||
model_name='indigenousland', | ||
name='states', | ||
field=models.ManyToManyField(blank=True, related_name='indigenousland_ethnic_groups_layers', to='boundaries.State', verbose_name='States'), | ||
), | ||
migrations.AddField( | ||
model_name='indigenousvillage', | ||
name='cities', | ||
field=models.ManyToManyField(blank=True, related_name='indigenousvillage_ethnic_groups_layers', to='boundaries.City', verbose_name='Cities'), | ||
), | ||
migrations.AddField( | ||
model_name='indigenousvillage', | ||
name='country', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='indigenousvillage_ethnic_groups_layers', to='boundaries.Country', verbose_name='Country'), | ||
), | ||
migrations.AddField( | ||
model_name='indigenousvillage', | ||
name='states', | ||
field=models.ManyToManyField(blank=True, related_name='indigenousvillage_ethnic_groups_layers', to='boundaries.State', verbose_name='States'), | ||
), | ||
] |
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.