Skip to content

Commit

Permalink
Merge pull request #2 from lucernae/develop
Browse files Browse the repository at this point in the history
bugfix
  • Loading branch information
lucernae authored Aug 29, 2016
2 parents 1a170fe + 7a4af23 commit c9271ae
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
11 changes: 3 additions & 8 deletions forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

from django.forms import models
from django import forms

from geonode.layers.models import Layer

from geosafe.models import Analysis

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -54,14 +52,9 @@ class Meta:
attrs={'class': 'form-control'})
)

if_id_list = Analysis.impact_function_list

impact_function_id = forms.ChoiceField(
label='Impact Function ID',
required=True,
choices=[
(impact_function['id'], impact_function['name'])
for impact_function in if_id_list]
)

keep = forms.BooleanField(
Expand All @@ -80,7 +73,9 @@ def __init__(self, *args, **kwargs):
if hazard_layer:
self.fields['hazard_layer'].queryset = hazard_layer
if impact_function_ids:
self.fields['impact_function_id'].choices = impact_function_ids
self.fields['impact_function_id'].choices = [
(impact_function['id'], impact_function['name'])
for impact_function in impact_function_ids]

def save(self, commit=True):
instance = super(AnalysisCreationForm, self).save(commit=False)
Expand Down
11 changes: 9 additions & 2 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,17 @@ def get_default_impact_title(self):
)
return layer_name

impact_function_list = []
_impact_function_list = []

@classmethod
def impact_function_list(cls):
if not cls._impact_function_list:
from geosafe.tasks.headless.analysis import filter_impact_function
cls._impact_function_list = filter_impact_function.delay().get()
return cls._impact_function_list

def impact_function_name(self):
for i in self.impact_function_list:
for i in self.impact_function_list():
if i['id'] == self.impact_function_id:
return i['name']
return ''
Expand Down
5 changes: 3 additions & 2 deletions static/geosafe/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
label.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
margin-right: 0;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
Expand All @@ -30,7 +31,7 @@
text-align: right;
}
.onoffswitch-switch {
display: block; width: 18px; margin: 6px;
display: block; width: 21px; margin: 6px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 56px;
Expand Down
2 changes: 1 addition & 1 deletion templates/geosafe/analysis/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@
bounds.getNorthEast().lat
];
var url = '{% url "geosafe:layer-panel" bbox="9,9,9,9" %}';
url = url.replace("9%2C9%2C9%2C9", JSON.stringify(bound_param));
url = url.replace("9%2C9%2C9%2C9", JSON.stringify(bound_param)).replace("9,9,9,9", JSON.stringify(bound_param));
show_info_text('Extent Changed', 'Filtering available layer for extent');
$.get(url, function(data){
var exposure_id = $(".exposure.section a.selected").attr('data-id');
Expand Down
30 changes: 24 additions & 6 deletions views/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,29 @@ def get_context_data(self, **kwargs):
)
return context

def get_form(self, form_class):
kwargs = self.get_form_kwargs()
kwargs.update({
'impact_functions': Analysis.impact_function_list()
})
logger.error(kwargs)
return form_class(**kwargs)

def post(self, request, *args, **kwargs):
super(AnalysisCreateView, self).post(request, *args, **kwargs)
return HttpResponse(json.dumps({
'success': True,
'redirect': self.get_success_url()
}), content_type='application/json')
retval = super(AnalysisCreateView, self).post(request, *args, **kwargs)

form_class = self.get_form_class()
form = self.get_form(form_class)
if form.is_valid():
# return retval
return HttpResponse(json.dumps({
'success': True,
'redirect': self.get_success_url()
}), content_type='application/json')
else:
return HttpResponse(json.dumps({
'success': False
}), content_type='application/json')

def get_success_url(self):
kwargs = {
Expand Down Expand Up @@ -369,7 +386,8 @@ def layer_panel(request, bbox=None):
form = AnalysisCreationForm(
user=request.user,
exposure_layer=retrieve_layers('exposure', bbox=bbox),
hazard_layer=retrieve_layers('hazard', bbox=bbox))
hazard_layer=retrieve_layers('hazard', bbox=bbox),
impact_functions=Analysis.impact_function_list())
context = {
'sections': sections,
'form': form,
Expand Down

0 comments on commit c9271ae

Please sign in to comment.