Skip to content

Commit

Permalink
Merge pull request #827 from hdoupe/cleanup_822
Browse files Browse the repository at this point in the history
Merged #827
  • Loading branch information
hdoupe authored Mar 1, 2018
2 parents c69168d + cd12b66 commit b280f58
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 11 deletions.
12 changes: 12 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ Go
[here](https://github.com/OpenSourcePolicyCenter/PolicyBrain/pulls?q=is%3Apr+is%3Aclosed)
for a complete commit history.

Release 1.4.2 on 2018-02-28
----------------------------
**Major Changes**
- None

**Minor Changes**
- None

**Bug Fixes**
- [#827](https://github.com/OpenSourcePolicyCenter/PolicyBrain/pull/827) - Remove errors for un-displayed parameters and save input data for warning/error message page - Hank Doupe


Release 1.4.1 on 2018-02-27
----------------------------
**Major Changes**
Expand Down
8 changes: 4 additions & 4 deletions conda-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
gevent
pillow
pyparsing
bokeh=0.12.7
nomkl
taxcalc==0.15.2
btax==0.2.2
ogusa==0.5.8
numba>=0.33.0
pandas>=0.22.0
gevent
pillow
pyparsing
bokeh=0.12.7
11 changes: 11 additions & 0 deletions webapp/apps/taxbrain/behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ def set_fields(self, upstream_obj, nonparam_fields=None):

self.input_fields = input_fields

def pop_extra_errors(self, errors_warnings):
"""
Removes errors on extra parameters
"""
for action in ['warnings', 'errors']:
params = list(errors_warnings[action].keys())
for param in params:
if param not in self.raw_input_fields:
errors_warnings[action].pop(param)


def get_model_specs(self):
"""
Stub to remind that this part of the API is needed
Expand Down
4 changes: 4 additions & 0 deletions webapp/apps/taxbrain/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ def __init__(self, first_year, *args, **kwargs):
# https://www.pydanny.com/overloading-form-fields.html
self.fields.update(self.Meta.update_fields)

print('SS_Earnings_c_cpi field', self.fields['SS_Earnings_c_cpi'].__dict__)
print('SS_Earnings_c_cpi widget', self.fields['SS_Earnings_c_cpi'].widget.__dict__)
print('SS_Earnings_c_cpi meta widget', self._meta.widgets['SS_Earnings_c_cpi'].__dict__)

def clean(self):
"""
" This method should be used to provide custom model validation, and to
Expand Down
7 changes: 6 additions & 1 deletion webapp/apps/taxbrain/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ def set_fields(self):
2. Map TB names to TC names
3. Do more specific type checking--in particular, check if
field is the type that Tax-Calculator expects from this param
4. Remove errors on undisplayed parameters
"""
Fieldable.set_fields(self, taxcalc.Policy,
nonparam_fields=self.NONPARAM_FIELDS)
Expand All @@ -780,10 +781,14 @@ def get_model_specs(self):
returns: reform_dict, assumptions_dict, errors_warnings
"""
return param_formatters.get_reform_from_gui(
(reform_dict, assumptions_dict, reform_text, assumptions_text,
errors_warnings) = param_formatters.get_reform_from_gui(
self.start_year,
taxbrain_fields=self.input_fields,
)
Fieldable.pop_extra_errors(self, errors_warnings)
return (reform_dict, assumptions_dict, reform_text, assumptions_text,
errors_warnings)

@property
def start_year(self):
Expand Down
2 changes: 1 addition & 1 deletion webapp/apps/taxbrain/param_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def parse_value(value, meta_param):
# upstream package will handle the error
return parsed
else: # parsed is type float
return parsed
return float(parsed)

def parse_fields(param_dict, default_params):
"""
Expand Down
8 changes: 8 additions & 0 deletions webapp/apps/taxbrain/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,15 @@ def test_taxbrain_spec_operators_in_validation_params_OK(self):

check_posted_params(result['tb_dropq_compute'], truth_mods, START_YEAR)

def test_taxbrain_warning_on_widow_param(self):
"""
Test case where error is added on undisplayed parameter
"""
data = get_post_data(START_YEAR, _ID_BenefitSurtax_Switches=False)
data[u'STD_3'] = ['10000']
response = self.client.post('/taxbrain/', data)

assert response.status_code == 200

def test_taxbrain_wildcard_in_validation_params_gives_error(self):
"""
Expand Down
13 changes: 10 additions & 3 deletions webapp/apps/taxbrain/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ def submit_reform(request, user=None, json_reform_id=None):
taxcalc_errors = True if errors_warnings['errors'] else False
taxcalc_warnings = True if errors_warnings['warnings'] else False
if personal_inputs is not None:
# ensure that parameters causing the warnings are shown on page
# with warnings/errors
personal_inputs = TaxBrainForm(
start_year,
initial=json.loads(personal_inputs.data['raw_input_fields'])
)
# TODO: parse warnings for file_input
# only handle GUI errors for now
if ((taxcalc_errors or taxcalc_warnings)
Expand Down Expand Up @@ -433,6 +439,8 @@ def personal_results(request):
has_errors = False
use_puf_not_cps = True
if request.method=='POST':
print('method=POST get', request.GET)
print('method=POST post', request.POST)
obj, _, has_errors, _ = process_reform(request)

# case where validation failed in forms.TaxBrainForm
Expand All @@ -448,11 +456,10 @@ def personal_results(request):
personal_inputs = obj
start_year = personal_inputs._first_year


else:
# Probably a GET request, load a default form
print('get get', request.GET)
print('get post', request.POST)
print('method=GET get', request.GET)
print('method=GET post', request.POST)
params = parse_qs(urlparse(request.build_absolute_uri()).query)
if 'start_year' in params and params['start_year'][0] in START_YEARS:
start_year = params['start_year'][0]
Expand Down
3 changes: 2 additions & 1 deletion webapp/apps/test_assets/test_param_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def test_meta_param():
)
def test_parse_values(name, value, exp, default_params_Policy):
meta_param = get_default_policy_param(name, default_params_Policy)
assert parse_value(value, meta_param) == exp
act = parse_value(value, meta_param)
assert act == exp and type(act) == type(exp)

# Test meta_param construction and attribute access
def test_parse_fields(default_params_Policy):
Expand Down
2 changes: 1 addition & 1 deletion webapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
]


WEBAPP_VERSION = "1.4.1"
WEBAPP_VERSION = "1.4.2"

# Application definition

Expand Down

0 comments on commit b280f58

Please sign in to comment.