Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:hacklabr/mapaguarani into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagofassoni committed Apr 14, 2018
2 parents 226b003 + 9beb1b5 commit 3869a8b
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 156 deletions.
4 changes: 2 additions & 2 deletions compose/production/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ RUN chown django /entrypoint.sh
# Install js dependencies
COPY bower.json .
RUN bower --allow-root install
RUN mkdir /app && mv bower_components /app/
RUN mkdir -p /app && mv bower_components /app/

COPY . /app

RUN mkdir /app/staticfiles
RUN mkdir -p /app/staticfiles

# env.example must be used during build to provide a valid environment
RUN export $(cat /app/env.example | grep -v ^# | xargs) && \
Expand Down
4 changes: 4 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ DJANGO_ACCOUNT_ALLOW_REGISTRATION=True
# Sentry
DJANGO_SENTRY_DSN=

# Mailgun
DJANGO_MAILGUN_API_KEY=example
MAILGUN_SENDER_DOMAIN=example.com

REDIS_URL=

COURIER_ONESIGNAL_USER_ID=
Expand Down
23 changes: 14 additions & 9 deletions mapaguarani/config/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,20 @@

# EMAIL
# ------------------------------------------------------------------------------
# DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL',
# default='')
EMAIL_HOST = env("DJANGO_EMAIL_HOST", default='smtp.sendgrid.com')
# EMAIL_HOST_PASSWORD = env("SENDGRID_PASSWORD")
# EMAIL_HOST_USER = env('SENDGRID_USERNAME')
# EMAIL_PORT = env.int("EMAIL_PORT", default=587)
# EMAIL_SUBJECT_PREFIX = env("EMAIL_SUBJECT_PREFIX", default='[{{cookiecutter.project_name}}] ')
# EMAIL_USE_TLS = True
# SERVER_EMAIL = EMAIL_HOST_USER
## EMAIL
# ------------------------------------------------------------------------------
DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL',
default='<noreply@guarani.map.as>')
EMAIL_SUBJECT_PREFIX = env('DJANGO_EMAIL_SUBJECT_PREFIX', default='')
SERVER_EMAIL = env('DJANGO_SERVER_EMAIL', default=DEFAULT_FROM_EMAIL)

# Anymail with Mailgun
INSTALLED_APPS += ('anymail', )
ANYMAIL = {
'MAILGUN_API_KEY': env('DJANGO_MAILGUN_API_KEY'),
'MAILGUN_SENDER_DOMAIN': env('MAILGUN_SENDER_DOMAIN')
}
EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend'

# TEMPLATE CONFIGURATION
# ------------------------------------------------------------------------------
Expand Down
199 changes: 64 additions & 135 deletions mapaguarani/core/management/commands/import_lands_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,121 +15,86 @@ def handle(self, *args, **options):
ds = DataSource(shapefile_path)
source_layer = ds[0]

lands_layer, _ = MapLayer.objects.get_or_create(name='Terras Indígenas')
lands_layer.description = 'Camada de Terras Indígenas dos povos Guarani'
lands_layer, _ = MapLayer.objects.get_or_create(name='Terras Indígenas - Povos não Guaranis')
lands_layer.description = 'Camada de Terras Indígenas'
lands_layer.save()

def _get_ethnic_group(groups):

groups_names = []
if ',' in groups:
group_list = groups.split(',')
else:
group_list = groups.split()
if len(group_list) == 1:
groups_names.append(group_list[0])
elif 'e' in group_list and len(group_list) == 3:
groups_names.append(group_list[0])
groups_names.append(group_list[2])
elif len(group_list) == 4:
groups_names.append(group_list[0][:-1])
groups_names.append(group_list[1])
groups_names.append(group_list[3])
elif len(group_list) == 2 or len(group_list) == 3:
groups_names = group_list
else:
print('EthnicGroup:')
print(group_list)

for group_name in groups_names:
try:
yield EthnicGroup.objects.get(name=group_name)
except EthnicGroup.DoesNotExist:
print('Não achou EthnicGroup: ' + group_name)

def _get_ethnic_subgroup(groups):
def _get_ethnic_group(groups, create=False):
"""
The ethnic groups names must be separated by coma
"""
groups_names = []
if ',' in groups:
group_list = groups.split(',')
else:
group_list = groups.split()
if len(group_list) == 1:
if '/' not in group_list[0]:
groups_names.append(group_list[0])

for group_name in groups.split(','):
group_name = group_name.strip()
if not group_name:
return
if create:
ethnic_group, created = EthnicGroup.objects.get_or_create(name=group_name)
if created:
self.stdout.write('O povo {0} foi criado.'.format(group_name))
yield ethnic_group
else:
try:
yield EthnicGroup.objects.get(name=group_name)
except EthnicGroup.DoesNotExist:
self.stdout.write('O povo {0} não foi encontrato e não será criado, por favor verifique o arquivo de importação.'.format(group_name))


def _get_ethnic_subgroup(groups, create=False):
"""
The ethnic subgroups names must be separated by coma
"""
for group_name in groups.split(','):
group_name = group_name.strip()
if create:
ethnic_subgroup, _ = ProminentEthnicSubGroup.objects.get_or_create(name=group_name)
yield ethnic_subgroup
else:
group_list = groups.split('/')
if len(group_list) == 2:
groups_names = group_list
elif '/' in groups:
if group_list and len(group_list) == 3:
groups_names.append(group_list[0])
if '/' in group_list[2]:
group_list2 = group_list[2].split('/')
groups_names.append(group_list2[0])
groups_names.append(group_list2[1])
else:
groups_names.append(group_list[2])
elif len(group_list) == 2:
groups_names.append(group_list[0])
if '/'in group_list[1]:
groups_names.append(group_list[1][1:])
else:
groups_names.append(group_list[1])
elif len(group_list) == 4:
groups_names.append(group_list[0])
groups_names.append(group_list[2])
if '/'in group_list[3]:
groups_names.append(group_list[3][1:])
else:
groups_names.append(group_list[3])
elif len(group_list) == 2 or len(group_list) == 3:
groups_names = group_list
else:
print(group_list)

for group_name in groups_names:
try:
yield ProminentEthnicSubGroup.objects.get(name=group_name)
except ProminentEthnicSubGroup.DoesNotExist:
print('Não achou: ' + group_name)
print(groups)
print('\n')

def _get_land_tenure(name):
land_tenure, _ = LandTenure.objects.get_or_create(name=name)
return land_tenure

def _get_land_tenure_status(name):
land_tenure_status, _ = LandTenureStatus.objects.get_or_create(name=name)
return land_tenure_status
try:
yield EthnicGroup.objects.get(name=group_name)
except ProminentEthnicSubGroup.DoesNotExist:
self.stdout.write('O subgrupo Guarani {0} não foi encontrato e não será criado, por favor verifique o arquivo de importação.'.format(group_name))

for feat in source_layer:

official_area = feat.get('AREA').replace(".", "").replace(",", ".")
if official_area:
official_area = feat.get('AREA')
if isinstance(official_area, str):
official_area.replace(".", "").replace(",", ".")
official_area = float(official_area)
else:
if not official_area:
official_area = 0.0

kwargs = {
'layer': lands_layer,
'name': feat.get('TERRA_INDI'),
'other_names': feat.get('OUTRAS_DEN'),
# 'other_names': feat.get('OUTRAS_DEN'),
'official_area': official_area,
'claim': feat.get('REIVINDICA'),
'demand': feat.get('DEMANDA'),
# 'claim': feat.get('REIVINDICA'),
# 'demand': feat.get('DEMANDA'),
'source': feat.get('FONTE'),
'private_comments': feat.get('OBS_PRIVAD'),
'public_comments': feat.get('OBS_PUBLIC'),
'guarani_exclusive_possession_area_portion': float(feat.get('PORCAO_ARE')),
'others_exclusive_possession_area_portion': float(feat.get('PORCAO_AR2')),

# 'private_comments': feat.get('OBS_PRIVAD'),
# 'public_comments': feat.get('OBS_PUBLIC'),
# 'guarani_exclusive_possession_area_portion': float(feat.get('PORCAO_ARE')),
# 'others_exclusive_possession_area_portion': float(feat.get('PORCAO_AR2')),
# 'associated_land': feat.get('TERRAS_ASS'),
}

indigenous_land = IndigenousLand(**kwargs)
indigenous_land.geometry = feat.geom.wkt

land_tenure = feat.get('SITUACAO_F')
if land_tenure == 'Em Estudo':
land_tenure ='Em estudo'
if not LandTenure.objects.filter(name=land_tenure).exists():
raise(BaseException('Situação fundiária não encontrata! NOME: {0} STATUS: {1}'.format(feat.get('TERRA_INDI'), land_tenure)))
indigenous_land.land_tenure = LandTenure.objects.get(name=land_tenure)

land_tenure_status = feat.get('STATUS_REV')
if not LandTenureStatus.objects.filter(name=land_tenure_status).exists():
raise(BaseException('Status de revisão fundiária não encontrata: {}'.format(land_tenure_status)))
indigenous_land.land_tenure_status = LandTenureStatus.objects.get(name=land_tenure_status)

indigenous_land.geometry = feat.geom.wkt
try:
# try to save as MultPolygon
indigenous_land.save()
Expand All @@ -141,49 +106,13 @@ def _get_land_tenure_status(name):
indigenous_land.save()
# self.stdout.write('Terra indígena: ' + indigenous_land.name + 'Posição convertida de Polígono para Multipolígono.')

ethnic_groups = _get_ethnic_group(feat.get('GRUPO_ETNI'))
ethnic_groups = _get_ethnic_group(feat.get('GRUPO_ETNI'), create=True)
for group in ethnic_groups:
indigenous_land.ethnic_groups.add(group)

ethnic_subgroups = _get_ethnic_subgroup(feat.get('SUBGRUPO_P'))
for ethnic_subgroup in ethnic_subgroups:
indigenous_land.prominent_subgroup.add(ethnic_subgroup)

land_tenure = feat.get('SITUACAO_F')
if land_tenure == 'Sem Providências':
indigenous_land.land_tenure = _get_land_tenure('Sem Providências')
elif land_tenure in ['Regularizada', 'Regularizada (Em revisão de limites)']:
indigenous_land.land_tenure = _get_land_tenure('Regularizada')
elif land_tenure in ['Desapropriada', 'Desapropriada (Reivindicação de Identificação)']:
indigenous_land.land_tenure = _get_land_tenure('Desapropriada')
elif land_tenure in ['Em processo de desapropriação', 'Em processo de despropriação pelo Estado.',
'Área em processo de despropriação pelo Estado.', 'Em processo de Desapropriação.',
'Em processo de Desapropriação']:
indigenous_land.land_tenure = _get_land_tenure('Em processo de desapropriação')
elif land_tenure == 'Delimitada':
indigenous_land.land_tenure = _get_land_tenure('Delimitada')
elif land_tenure == 'Em estudo':
indigenous_land.land_tenure = _get_land_tenure('Em estudo')
elif land_tenure == 'Declarada':
indigenous_land.land_tenure = _get_land_tenure('Declarada')
elif land_tenure in ['Adquirida', 'Dominial Indígena']:
indigenous_land.land_tenure = _get_land_tenure('Adquirida')
elif land_tenure == 'Homologada':
indigenous_land.land_tenure = _get_land_tenure('Homologada')
else:
self.stdout.write('Situação fundiária não encontrata! NOME: ' + feat.get('TERRA_INDI') + 'STATUS: ' + land_tenure)

land_tenure_status = feat.get('STATUS_REV')
if land_tenure_status == 'Sem Revisão':
indigenous_land.land_tenure_status = _get_land_tenure_status('Sem Revisão')
elif land_tenure_status == 'Não Delimitada':
indigenous_land.land_tenure_status = _get_land_tenure_status('Não Delimitada')
elif land_tenure_status == 'Terra Revisada':
indigenous_land.land_tenure_status = _get_land_tenure_status('Terra Revisada')
elif land_tenure_status == 'Terra Original':
indigenous_land.land_tenure_status = _get_land_tenure_status('Terra Original')
else:
self.stdout.write('Status de revisão fundiária não encontrata: ' + land_tenure_status)
# ethnic_subgroups = _get_ethnic_subgroup(feat.get('SUBGRUPO_P'))
# for ethnic_subgroup in ethnic_subgroups:
# indigenous_land.prominent_subgroup.add(ethnic_subgroup)

indigenous_land.save()

Expand Down
6 changes: 3 additions & 3 deletions mapaguarani/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class SimpleIndigenousVillageViewSetWithPosition(FilterLayersBySiteAndUserAuthen

class FilterVillageMixin(object):
def get_queryset(self):
queryset = IndigenousVillage.objects.all()
queryset = super().get_queryset()
guarani_presence = self.request.query_params.get('guarani_presence', None)
if guarani_presence is not None:
if guarani_presence in ('False', 'false'):
Expand All @@ -149,7 +149,7 @@ def get_queryset(self):


class IndigenousVillageGeojsonView(FilterVillageMixin, FilterLayersBySiteAndUserAuthenticatedMixin, viewsets.ReadOnlyModelViewSet):
queryset = IndigenousVillage.objects.none()
queryset = IndigenousVillage.objects.all()
serializer_class = SimpleIndigenousGeojsonVillageSerializer


Expand All @@ -159,7 +159,7 @@ class IndigenousVillageKMLView(KMLViewMixin, IndigenousVillageGeojsonView):


class IndigenousVillageExportView(FilterVillageMixin, FilterLayersBySiteAndUserAuthenticatedMixin, PandasView):
queryset = IndigenousVillage.objects.none()
queryset = IndigenousVillage.objects.all()
serializer_class = IndigenousVillageExportSerializer


Expand Down
45 changes: 38 additions & 7 deletions mapaguarani/static/js/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,44 @@
var mapbox_hybrid = L.tileLayer(mapbox_url, {mapid: 'mapbox.streets-satellite', access_token: access_token, pane: 'base_tiles'});

// Official layers
var default_host = window.location.hostname;
var protected_areas_tile = L.tileLayer('http://' + default_host + ':4000/protected_areas_baseprotectedarea/{z}/{x}/{y}.png', {});
var boundaries_cities_tile = L.tileLayer('http://' + default_host + ':4000/boundaries_city/{z}/{x}/{y}.png', {
zIndex: 40
});
var boundaries_states_tile = L.tileLayer('http://' + default_host + ':4000/boundaries_state/{z}/{x}/{y}.png', {});
var boundaries_countries_tile = L.tileLayer('http://' + default_host + ':4000/boundaries_country/{z}/{x}/{y}.png', {});
var ProtectedAreaTileOptions = {
pane: 'base_tiles',
vectorTileLayerStyles: {
lands: function(properties, zoom) {
var styles = {
weight: 2,
fillColor: '#74c476',
color: '#74c476',
fillOpacity: 0.4,
opacity: 0.7,
fill: true,
};
return styles
},
},
};
var protected_areas_tile = L.vectorGrid.protobuf('tiles/protected_areas/{z}/{x}/{y}.pbf', ProtectedAreaTileOptions);

var boundariesTilesOptions = {
pane: 'base_tiles',
vectorTileLayerStyles: {
lands: function(properties, zoom) {
var styles = {
weight: 2,
fillColor: '#b2e2e2;',
color: '#b2e2e2;',
// fillOpacity: 0.4,
// opacity: 0.7,
// fill: true,
};
return styles
},
},
};

var boundaries_cities_tile = L.vectorGrid.protobuf('tiles/cities/{z}/{x}/{y}.pbf', boundariesTilesOptions);
var boundaries_states_tile = L.vectorGrid.protobuf('tiles/states/{z}/{x}/{y}.pbf', boundariesTilesOptions);
var boundaries_countries_tile = L.vectorGrid.protobuf('tiles/countries/{z}/{x}/{y}.pbf', boundariesTilesOptions);

/*
* Loading message
Expand Down

0 comments on commit 3869a8b

Please sign in to comment.