Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push geonode #311

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ sftp_pg_credential.env
sftp_media_credential-dev.env
sftp_pg_credential-dev.env
inaware_credential.env
geonode_credential.env

# apt-cacher-ng
71-apt-cacher-ng
Expand Down
7 changes: 7 additions & 0 deletions deployment/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,10 @@ load-flood-test-data:
@echo "Load flood test data"
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) exec uwsgi python manage.py loadfloodtestdata

superuser:
@echo
@echo "------------------------------------------------------------------"
@echo "Creating a superuser in production mode"
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) exec uwsgi python manage.py createsuperuser
9 changes: 9 additions & 0 deletions deployment/ansible/development/group_vars/all.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ inaware:
user: inawareuser
password: thepassword

# This is used to push hazard layer to GeoNode.
# Set this fact to your appropriate credentials.
geonode:
enable: False
user: test_geonode_user
password: test_geonode_password
url: http://url_to_geonode_instance


# This declaration is used to describe port forwarding that is being used
# by docker-compose. Leave it as default.
docker_port_forward:
Expand Down
9 changes: 9 additions & 0 deletions deployment/ansible/development/group_vars/all.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ inaware:
user:
password:

# This is used to push hazard layer to GeoNode.
# Set this fact to your appropriate credentials.
geonode:
enable: False
user: test_geonode_user
password: test_geonode_password
url: http://url_to_geonode_instance


# This declaration is used to describe port forwarding that is being used
# by docker-compose. Leave it as default.
docker_port_forward:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@
owner: '{{ remote_user }}'
group: '{{ remote_group }}'
mode: "u=rw,g=rw,o=r"

- name: customize geonode credentials
template:
src: geonode_credential.env.j2
dest: '{{ project_path }}/deployment/geonode_credential.env'
owner: '{{ remote_user }}'
group: '{{ remote_group }}'
mode: "u=rw,g=rw,o=r"
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ services:
- TASK_ALWAYS_EAGER={{ inasafe_django.task_always_eager }}
- INASAFE_OUTPUT_DIR={{ inasafe_headless.working_dir }}/outputs
- ON_TRAVIS={{ on_travis }}
- REALTIME_GEONODE_ENABLE={{ geonode.enable }}
links:
- smtp:smtp
- db:db
Expand Down Expand Up @@ -331,6 +332,8 @@ services:
- INASAFE_WORK_DIR={{ inasafe_headless.working_dir }}
- INASAFE_OUTPUT_DIR={{ inasafe_headless.working_dir }}/outputs
- QGIS_DEBUG=0
env_file:
- geonode_credential.env
network_mode: "bridge"

{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# copy this template as sftp_credential.env for production mode credential
# and as sftp_credential-dev.env for development mode credential
REALTIME_GEONODE_ENABLE={{ geonode.enable }}
REALTIME_GEONODE_URL={{ geonode.url }}
REALTIME_GEONODE_USER={{ geonode.user }}
REALTIME_GEONODE_PASSWORD={{ geonode.password }}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<env name="INASAFE_REALTIME_BROKER_URL" value="amqp://guest:guest@{{ inasafe_realtime.broker }}:{{ inasafe_realtime.broker_port }}/" />
<env name="INASAFE_HEADLESS_BROKER_URL" value="amqp://guest:guest@{{ inasafe_headless.broker }}:{{ inasafe_headless.broker_port }}/" />
<env name="INASAFE_OUTPUT_DIR" value="{{ inasafe_headless.working_dir }}/outputs" />
<env name="REALTIME_GEONODE_ENABLE" value="{{ geonode.enable }}"/>
<env name="MAPQUEST_MAP_KEY" value="{{ inasafe_django.mapquest_map_key }}" />
<env name="SITE_DOMAIN_NAME" value="{{ inasafe_django.site_domain_name }}" />
<env name="PYTHONUNBUFFERED" value="1" />
Expand Down
17 changes: 10 additions & 7 deletions django_project/realtime/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ class EarthquakeReportInline(StackedInline):

class EarthquakeAdmin(LeafletGeoAdmin):
"""Admin Class for Earthquake Model."""
list_display = ('shake_id', 'source_type', 'time', 'location_description',
'magnitude', 'depth')
list_display = (
'shake_id', 'source_type', 'time', 'location_description',
'magnitude', 'depth', 'push_task_status', 'push_task_result')
list_filter = ('location_description', )
search_fields = ['shake_id', 'location_description']
inlines = [
Expand Down Expand Up @@ -125,8 +126,9 @@ class FloodReportInline(StackedInline):

class FloodAdmin(ModelAdmin):
"""Admin Class for Flood Event."""
list_display = ('event_id', 'data_source', 'time',
'total_affected', 'boundary_flooded')
list_display = (
'event_id', 'data_source', 'time', 'total_affected',
'boundary_flooded', 'push_task_status', 'push_task_result')

inlines = [
ImpactInline,
Expand All @@ -151,9 +153,10 @@ class AshReportInline(StackedInline):

class AshAdmin(ModelAdmin):
"""Admin class for Ash model"""
list_display = ('volcano', 'alert_level', 'event_time',
'event_time_zone_string', 'eruption_height',
'forecast_duration')
list_display = (
'volcano', 'alert_level', 'event_time',
'event_time_zone_string', 'eruption_height',
'forecast_duration', 'push_task_status', 'push_task_result')
inlines = [
ImpactInline,
AshReportInline
Expand Down
2 changes: 2 additions & 0 deletions django_project/realtime/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
LOGGER_NAME = 'InaSAFE Realtime REST Server'

ON_TRAVIS = ast.literal_eval(os.environ.get('ON_TRAVIS', 'False'))
REALTIME_GEONODE_ENABLE = ast.literal_eval(
os.environ.get('REALTIME_GEONODE_ENABLE', 'False'))

# PROJECT_NAME: The project name for this apps e.g InaSAFE
default_project_name = 'InaSAFE Realtime'
Expand Down
24 changes: 24 additions & 0 deletions django_project/realtime/migrations/0063_auto_20180604_0809.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('realtime', '0062_auto_20180511_1932'),
]

operations = [
migrations.AddField(
model_name='ash',
name='push_task_result',
field=models.TextField(default=b'', help_text='Task result of GeoNode Push Task', null=True, verbose_name='Report push task result', blank=True),
),
migrations.AddField(
model_name='ash',
name='push_task_status',
field=models.CharField(default=None, max_length=255, blank=True, help_text='The Status for the GeoNode Push Task', null=True, verbose_name='GeoNode Push Task Status'),
),
]
24 changes: 24 additions & 0 deletions django_project/realtime/migrations/0064_auto_20180607_0724.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('realtime', '0063_auto_20180604_0809'),
]

operations = [
migrations.AddField(
model_name='flood',
name='push_task_result',
field=models.TextField(default=b'', help_text='Task result of GeoNode Push Task', null=True, verbose_name='Report push task result', blank=True),
),
migrations.AddField(
model_name='flood',
name='push_task_status',
field=models.CharField(default=None, max_length=255, blank=True, help_text='The Status for the GeoNode Push Task', null=True, verbose_name='GeoNode Push Task Status'),
),
]
24 changes: 24 additions & 0 deletions django_project/realtime/migrations/0065_auto_20180607_0742.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('realtime', '0064_auto_20180607_0724'),
]

operations = [
migrations.AddField(
model_name='earthquake',
name='push_task_result',
field=models.TextField(default=b'', help_text='Task result of GeoNode Push Task', null=True, verbose_name='Report push task result', blank=True),
),
migrations.AddField(
model_name='earthquake',
name='push_task_status',
field=models.CharField(default=None, max_length=255, blank=True, help_text='The Status for the GeoNode Push Task', null=True, verbose_name='GeoNode Push Task Status'),
),
]
15 changes: 15 additions & 0 deletions django_project/realtime/models/ash.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ class Meta:
default='None',
blank=True)

push_task_status = models.CharField(
verbose_name=_('GeoNode Push Task Status'),
help_text=_('The Status for the GeoNode Push Task'),
max_length=255,
default=None,
null=True,
blank=True)

push_task_result = models.TextField(
verbose_name=_('Report push task result'),
help_text=_('Task result of GeoNode Push Task'),
default='',
blank=True,
null=True)

objects = models.GeoManager()

def __unicode__(self):
Expand Down
15 changes: 15 additions & 0 deletions django_project/realtime/models/earthquake.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ class Meta:
),
default=False)

push_task_status = models.CharField(
verbose_name=_('GeoNode Push Task Status'),
help_text=_('The Status for the GeoNode Push Task'),
max_length=255,
default=None,
null=True,
blank=True)

push_task_result = models.TextField(
verbose_name=_('Report push task result'),
help_text=_('Task result of GeoNode Push Task'),
default='',
blank=True,
null=True)

objects = EarthquakeManager()

def __unicode__(self):
Expand Down
15 changes: 15 additions & 0 deletions django_project/realtime/models/flood.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@ class Meta:
help_text=_('Total boundary affected by flood'),
default=0)

push_task_status = models.CharField(
verbose_name=_('GeoNode Push Task Status'),
help_text=_('The Status for the GeoNode Push Task'),
max_length=255,
default=None,
null=True,
blank=True)

push_task_result = models.TextField(
verbose_name=_('Report push task result'),
help_text=_('Task result of GeoNode Push Task'),
default='',
blank=True,
null=True)

objects = FloodManager()

def delete(self, using=None):
Expand Down
3 changes: 3 additions & 0 deletions django_project/realtime/signals/ash.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from realtime.app_settings import LOGGER_NAME, ANALYSIS_LANGUAGES
from realtime.models.ash import Ash
from realtime.tasks.ash import generate_event_report, generate_hazard_layer
from realtime.tasks.geonode import push_hazard_to_geonode

__author__ = 'Rizky Maulana Nugraha <[email protected]>'
__date__ = '7/18/16'
Expand Down Expand Up @@ -37,5 +38,7 @@ def ash_post_save(sender, instance, **kwargs):
if instance.analysis_flag:
for lang in ANALYSIS_LANGUAGES:
generate_event_report.delay(instance, locale=lang)
push_hazard_to_geonode.delay(sender, instance)

except BaseException as e:
LOGGER.exception(e)
2 changes: 2 additions & 0 deletions django_project/realtime/signals/earthquake.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from realtime.app_settings import LOGGER_NAME, ANALYSIS_LANGUAGES
from realtime.models.earthquake import Earthquake
from realtime.tasks.earthquake import generate_event_report
from realtime.tasks.geonode import push_hazard_to_geonode

__author__ = 'Rizky Maulana Nugraha <[email protected]>'
__date__ = '7/18/16'
Expand All @@ -31,5 +32,6 @@ def earthquake_post_save(sender, instance, **kwargs):
for lang in ANALYSIS_LANGUAGES:
generate_event_report.delay(
instance, locale=lang)
push_hazard_to_geonode.delay(sender, instance)
except BaseException:
pass
3 changes: 3 additions & 0 deletions django_project/realtime/signals/flood.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from realtime.app_settings import LOGGER_NAME, ANALYSIS_LANGUAGES
from realtime.models.flood import Flood
from realtime.tasks.flood import generate_event_report
from realtime.tasks.geonode import push_hazard_to_geonode

__author__ = 'Rizky Maulana Nugraha <[email protected]>'
__date__ = '12/4/15'
Expand All @@ -30,5 +31,7 @@ def flood_post_save(
if instance.analysis_flag:
for lang in ANALYSIS_LANGUAGES:
generate_event_report.delay(instance, locale=lang)
if instance.analysis_flag:
push_hazard_to_geonode.delay(instance)
except Exception as e:
LOGGER.exception(e)
1 change: 1 addition & 0 deletions django_project/realtime/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from realtime.tasks.flood import * # noqa
from realtime.tasks.ash import * # noqa
from realtime.tasks.indicator import * # noqa
from realtime.tasks.geonode import * # noqa

__author__ = 'Rizky Maulana Nugraha <[email protected]>'
__date__ = '12/3/15'
3 changes: 2 additions & 1 deletion django_project/realtime/tasks/ash.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def generate_hazard_layer(ash_event):
# Handle hazard process
handle_hazard_process.s(
event_id=ash_event.id
).set(queue=handle_hazard_process.queue)
).set(queue=handle_hazard_process.queue),

)

@app.task
Expand Down
Loading