diff --git a/deploy/taxbrain_server/celery_tasks.py b/deploy/taxbrain_server/celery_tasks.py index 45a303f4..ef1c2b18 100644 --- a/deploy/taxbrain_server/celery_tasks.py +++ b/deploy/taxbrain_server/celery_tasks.py @@ -99,8 +99,8 @@ def dropq_task(year, user_mods, first_budget_year, beh_params, tax_data): #Add taxcalc version to results vinfo = taxcalc._version.get_versions() - results['taxcalc_version'] = vinfo['version'] + '.' + vinfo['full'][:6] - results['dropq_version'] = vinfo['version'] + '.' + vinfo['full'][:6] + results['taxcalc_version'] = vinfo['version'] + results['dropq_version'] = vinfo['version'] json_res = json.dumps(results) return json_res @@ -141,8 +141,8 @@ def elasticity_gdp_task_async(year, user_mods, first_budget_year, elast_params): results = {'elasticity_gdp': gdp_elast_i} #Add taxcalc version to results vinfo = taxcalc._version.get_versions() - results['taxcalc_version'] = vinfo['version'] + '.' + vinfo['full'][:6] - results['dropq_version'] = vinfo['version'] + '.' + vinfo['full'][:6] + results['taxcalc_version'] = vinfo['version'] + results['dropq_version'] = vinfo['version'] json_res = json.dumps(results) return json_res @@ -163,12 +163,12 @@ def ogusa_async(user_mods, ogusa_params, guid): diff_table = taxcalc.dropq.format_macro_results(diff_data) results = {'df_ogusa': diff_table} vinfo = taxcalc._version.get_versions() - results['taxcalc_version'] = vinfo['version'] + '.' + vinfo['full'][:6] - results['dropq_version'] = vinfo['version'] + '.' + vinfo['full'][:6] + results['taxcalc_version'] = vinfo['version'] + results['dropq_version'] = vinfo['version'] #ogusa uses different version convention ogvinfo = ogusa._version.get_versions() - ogusa_version = ".".join([ogvinfo['version'], ogvinfo['full-revisionid'][:6]]) + ogusa_version = ogvinfo['version'] results['ogusa_version'] = ogusa_version json_res = json.dumps(results) return json_res @@ -189,10 +189,10 @@ def btax_async(user_mods): else: results.update(tables) vinfo = taxcalc._version.get_versions() - results['taxcalc_version'] = vinfo['version'] + '.' + vinfo['full'][:6] - results['dropq_version'] = vinfo['version'] + '.' + vinfo['full'][:6] + results['taxcalc_version'] = vinfo['version'] + results['dropq_version'] = vinfo['version'] binfo = btax._version.get_versions() - results['btax_version'] = binfo['version'] + '.' + binfo['full-revisionid'][:6] + results['btax_version'] = binfo['version'] return json.dumps(results) @@ -208,13 +208,13 @@ def example_async(): #Add version to results vinfo = taxcalc._version.get_versions() - results['taxcalc_version'] = vinfo['version'] + '.' + vinfo['full'][:6] + results['taxcalc_version'] = vinfo['version'] dqvinfo = taxcalc.dropq._version.get_versions() - results['dropq_version'] = vinfo['version'] + '.' + dqvinfo['full'][:6] + results['dropq_version'] = vinfo['version'] #ogusa uses different version convention ogvinfo = ogusa._version.get_versions() - ogusa_version = ".".join([ogvinfo['version'], ogvinfo['full-revisionid'][:6]]) + ogusa_version = ogvinfo['version'] results['ogusa_version'] = ogusa_version json_res = json.dumps(results) return json_res diff --git a/templates/btax/input_form.html b/templates/btax/input_form.html index 63f4c7cd..179268ab 100644 --- a/templates/btax/input_form.html +++ b/templates/btax/input_form.html @@ -37,8 +37,12 @@

About Cost of Capital Calculator

{% flatblock "ccc_what_is_ccc_dropdown" %}
-

Code Build

-

Version {{ btax_version }} - GitHub

+

PolicyBrain Code Build

+

Version {{ webapp_version }} - GitHub

+
+
+

B-Tax Code Build

+

Version {{ btax_version }} - GitHub

diff --git a/templates/btax/results.html b/templates/btax/results.html index d9921e17..60c9228b 100644 --- a/templates/btax/results.html +++ b/templates/btax/results.html @@ -89,7 +89,7 @@

{% flatblock "ccc_results_header" %}

-

These results were generated on {{ created_on|date:"D, M jS Y \a\t g:iA" }}
B-Tax version {{ unique_url.btax_vers }}
Taxcalc version {{ unique_url.taxcalc_vers }}

+

These results were generated by PolicyBrain version {{ webapp_version }} on {{ created_on|date:"D, M jS Y \a\t g:iA" }} UTC using B-Tax version {{ btax_version }}.

Edit Parameters diff --git a/templates/dynamic/behavior.html b/templates/dynamic/behavior.html index e349bbeb..ec44fc53 100644 --- a/templates/dynamic/behavior.html +++ b/templates/dynamic/behavior.html @@ -34,12 +34,15 @@

About TaxBrain

{% flatblock "taxbrain_what_is_taxbrain_dropdown" %}
-

Code Build

-

Version {{ taxcalc_version }} - GitHub

+

PolicyBrain Code Build

+

Version {{ webapp_version }} - GitHub

+
+
+

Tax-Calculator Code Build

+

Version {{ taxcalc_version }} - GitHub

-
{% csrf_token %} diff --git a/templates/dynamic/dynamic_input_form.html b/templates/dynamic/dynamic_input_form.html index cbad897a..3ebc8905 100644 --- a/templates/dynamic/dynamic_input_form.html +++ b/templates/dynamic/dynamic_input_form.html @@ -34,13 +34,19 @@

About TaxBrain

{% flatblock "taxbrain_what_is_taxbrain_dropdown" %}
-

Code Build

-

Version {{ taxcalc_version }} - GitHub

-

Version {{ ogusa_version }} - GitHub

+

PolicyBrain Code Build

+

Version {{ webapp_version }} - GitHub

+
+
+

OG-USA Code Build

+

Version {{ ogusa_version }} - GitHub

+
+
+

Tax-Calculator Code Build

+

Version {{ taxcalc_version }} - GitHub

- {% csrf_token %} diff --git a/templates/dynamic/elasticity.html b/templates/dynamic/elasticity.html index f004b153..45be2b6c 100644 --- a/templates/dynamic/elasticity.html +++ b/templates/dynamic/elasticity.html @@ -34,12 +34,15 @@

About TaxBrain

{% flatblock "taxbrain_what_is_taxbrain_dropdown" %}
-

Code Build

-

Version {{ taxcalc_version }} - GitHub

+

PolicyBrain Code Build

+

Version {{ webapp_version }} - GitHub

+
+
+

Tax-Calculator Code Build

+

Version {{ taxcalc_version }} - GitHub

- {% csrf_token %} diff --git a/templates/dynamic/elasticity_results.html b/templates/dynamic/elasticity_results.html index 566fed3a..da65bf4c 100644 --- a/templates/dynamic/elasticity_results.html +++ b/templates/dynamic/elasticity_results.html @@ -28,17 +28,20 @@

TaxBrain

-

Our History

+

About TaxBrain

{% flatblock "taxbrain_what_is_taxbrain_dropdown" %}
+
+

Tax-Calculator Code Build

+

Version {{ taxcalc_version }} - GitHub

- - +

{% flatblock "elasticity_results_header" %}

@@ -59,7 +62,7 @@

{% flatblock "elasticity_results_header" %}

-

These results were generated on {{ created_on|date:"D, M jS Y \a\t g:iA" }} using version {{ unique_url.taxcalc_vers }} TaxBrain. (ID: 10045)

+

These results were generated by PolicyBrain version {{ webapp_version }} on {{ created_on|date:"D, M jS Y \a\t g:iA" }} UTC using Tax-Calculator version {{ taxcalc_version }}.

The microsimulation upon which this dynamic simulation was based can be found here

Edit Parameters diff --git a/templates/dynamic/landing.html b/templates/dynamic/landing.html index 9f3731bb..168ce4de 100644 --- a/templates/dynamic/landing.html +++ b/templates/dynamic/landing.html @@ -34,12 +34,15 @@

About TaxBrain

{% flatblock "taxbrain_what_is_taxbrain_dropdown" %}
-

Code Build

-

Version {{ taxcalc_version }} - GitHub

+

PolicyBrain Code Build

+

Version {{ webapp_version }} - GitHub

+
+
+

Tax-Calculator Code Build

+

Version {{ taxcalc_version }} - GitHub

- {% csrf_token %} diff --git a/templates/dynamic/results.html b/templates/dynamic/results.html index 5062a7c5..62968e57 100644 --- a/templates/dynamic/results.html +++ b/templates/dynamic/results.html @@ -28,12 +28,16 @@

TaxBrain

-

Our History

+

About TaxBrain

{% flatblock "taxbrain_what_is_taxbrain_dropdown" %}
+
+

Tax-Calculator Code Build

+

Version {{ taxcalc_version }} - GitHub

@@ -43,7 +47,7 @@

Code Build

{% flatblock "dynamic_results_header" %} {{ tables.result_years.0 }} - {{ tables.result_years | last }}

-

These results were generated on {{ created_on|date:"D, M jS Y \a\t g:iA" }} using version {{ ogusa_version }} of the OGUSA package. (ID: 10045)

+

These results were generated by PolicyBrain version {{ webapp_version }} on {{ created_on|date:"D, M jS Y \a\t g:iA" }} UTC using Version {{ ogusa_version }}

The microsimulation upon which this dynamic simulation was based can be found here

diff --git a/templates/pages/apps.html b/templates/pages/apps.html index e1a974a4..7b790016 100644 --- a/templates/pages/apps.html +++ b/templates/pages/apps.html @@ -30,8 +30,8 @@

About B-Tax (Cost of Capital)

Code Build

-

Tax-Calculator Version {{ taxcalc_version }} - GitHub

-

B-Tax (Cost of Capital) Version {{ btax_version }} - GitHub

+

Tax-Calculator Version {{ taxcalc_version }} - GitHub

+

B-Tax (Cost of Capital) Version {{ btax_version }} - GitHub

More Information

diff --git a/templates/taxbrain/header.html b/templates/taxbrain/header.html index 71f848d6..51ee46ac 100644 --- a/templates/taxbrain/header.html +++ b/templates/taxbrain/header.html @@ -36,8 +36,12 @@

About Cost of Capital Calculator

{% flatblock "ccc_what_is_ccc_dropdown" %}
-

Code Build

-

Version {{ btax_version }} - GitHub

+

PolicyBrain Code Build

+

Version {{ webapp_version }} - GitHub

+
+
+

B-Tax Code Build

+

Version {{ btax_version }} - GitHub

@@ -50,8 +54,12 @@

Our History

{% flatblock "taxbrain_what_is_taxbrain_dropdown" %}
-

Code Build

-

Version {{ unique_url.taxcalc_vers }} - GitHub

+

PolicyBrain Code Build

+

Version {{ webapp_version }} - GitHub

+
+
+

Tax-Calculator Code Build

+

Version {{ taxcalc_version }} - GitHub

diff --git a/templates/taxbrain/input_file.html b/templates/taxbrain/input_file.html index 7b01a581..9d156d3a 100644 --- a/templates/taxbrain/input_file.html +++ b/templates/taxbrain/input_file.html @@ -37,8 +37,12 @@

About TaxBrain

{% flatblock "taxbrain_what_is_taxbrain_dropdown" %}
-

Code Build

-

Version {{ taxcalc_version }} - GitHub

+

PolicyBrain Code Build

+

Version {{ webapp_version }} - GitHub

+
+
+

Tax-Calculator Code Build

+

Version {{ taxcalc_version }} - GitHub

diff --git a/templates/taxbrain/input_form.html b/templates/taxbrain/input_form.html index 8f891f5e..fa3459a0 100644 --- a/templates/taxbrain/input_form.html +++ b/templates/taxbrain/input_form.html @@ -38,8 +38,12 @@

About TaxBrain

{% flatblock "taxbrain_what_is_taxbrain_dropdown" %}
-

Code Build

-

Version {{ taxcalc_version }} - GitHub

+

PolicyBrain Code Build

+

Version {{ webapp_version }} - GitHub

+
+
+

Tax-Calculator Code Build

+

Version {{ taxcalc_version }} - GitHub

diff --git a/templates/taxbrain/results.html b/templates/taxbrain/results.html index 063c7eab..a406dae9 100644 --- a/templates/taxbrain/results.html +++ b/templates/taxbrain/results.html @@ -47,7 +47,7 @@

{% flatblock "taxbrain_static_results_header" %}

{% flatblock "taxbrain_pe_results_header" %}

{% endif %} -

These results were generated on {{ created_on|date:"D, M jS Y \a\t g:iA" }} using version {{ unique_url.taxcalc_vers }} TaxBrain. (ID: 10045)

+

These results were generated by PolicyBrain version {{ webapp_version }} on {{ created_on|date:"D, M jS Y \a\t g:iA" }} UTC using Tax-Calculator version {{ taxcalc_version }}.

{% if quick_calc %}

This calculation used only 2% of the available data and only calculated revenues for one year instead of ten. For the full results, click here

diff --git a/webapp/apps/btax/helpers.py b/webapp/apps/btax/helpers.py index 4a2cac26..ac20c52e 100644 --- a/webapp/apps/btax/helpers.py +++ b/webapp/apps/btax/helpers.py @@ -39,7 +39,7 @@ BTAX_VERSION_INFO = btax._version.get_versions() -BTAX_VERSION = ".".join([BTAX_VERSION_INFO['version'], BTAX_VERSION_INFO['full-revisionid'][:6]]) +BTAX_VERSION = BTAX_VERSION_INFO['version'] # @@ -210,4 +210,3 @@ def group_args_to_btax_depr(btax_default_params, asset_yr_str): ) return depr_argument_groups - diff --git a/webapp/apps/btax/migrations/0002_btaxoutputurl_webapp_vers.py b/webapp/apps/btax/migrations/0002_btaxoutputurl_webapp_vers.py new file mode 100644 index 00000000..43386b65 --- /dev/null +++ b/webapp/apps/btax/migrations/0002_btaxoutputurl_webapp_vers.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('btax', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='btaxoutputurl', + name='webapp_vers', + field=models.CharField(default=None, max_length=50, null=True, blank=True), + ), + ] diff --git a/webapp/apps/btax/models.py b/webapp/apps/btax/models.py index 058eb175..b35d3ec5 100644 --- a/webapp/apps/btax/models.py +++ b/webapp/apps/btax/models.py @@ -141,6 +141,9 @@ class BTaxOutputUrl(models.Model): uuid = UUIDField(auto=True, default=None, null=True) btax_vers = models.CharField(blank=True, default=None, null=True, max_length=50) taxcalc_vers = models.CharField(blank=True, default=None, null=True, max_length=50) + webapp_vers = models.CharField(blank=True, default=None, null=True, + max_length=50) + def get_absolute_url(self): kwargs = { 'pk': self.pk diff --git a/webapp/apps/btax/tests/test_views.py b/webapp/apps/btax/tests/test_views.py index b25b8078..bb698c29 100644 --- a/webapp/apps/btax/tests/test_views.py +++ b/webapp/apps/btax/tests/test_views.py @@ -26,7 +26,7 @@ class BTaxViewsTests(TestCase): expected_results_tokens = ['cost of capital', 'change from reform', 'baseline', 'reform', 'industry', 'asset', 'accommodation', - 'typically financed', 'were generated on'] + 'typically financed', 'were generated by'] def setUp(self): # Every test needs a client. self.client = Client() diff --git a/webapp/apps/btax/views.py b/webapp/apps/btax/views.py index 359a4300..13d2604b 100644 --- a/webapp/apps/btax/views.py +++ b/webapp/apps/btax/views.py @@ -44,12 +44,14 @@ convert_val, make_bool) from ..taxbrain.views import (benefit_switch_fixup, - denormalize, normalize,taxcalc_version as TAXCALC_VERSION) + denormalize, normalize) from .compute import DropqComputeBtax, MockComputeBtax, JobFailError from ..constants import (METTR_TOOLTIP, METR_TOOLTIP, COC_TOOLTIP, DPRC_TOOLTIP, START_YEAR, START_YEARS) +from ..formatters import get_version +from django.conf import settings from .bubble_plot.bubble_plot_tabs import bubble_plot_tabs @@ -57,7 +59,16 @@ BTAX_VERSION_INFO = btax._version.get_versions() -BTAX_VERSION = ".".join([BTAX_VERSION_INFO['version'], BTAX_VERSION_INFO['full-revisionid'][:6]]) +BTAX_VERSION = BTAX_VERSION_INFO['version'] + +WEBAPP_VERSION = settings.WEBAPP_VERSION + + +tcversion_info = taxcalc._version.get_versions() + +TAXCALC_VERSION = tcversion_info['version'] + + JOB_PROC_TIME_IN_SECONDS = 30 @@ -182,6 +193,11 @@ def btax_results(request): pass else: unique_url.taxcalc_vers = TAXCALC_VERSION + if unique_url.webapp_vers is not None: + pass + else: + unique_url.webapp_vers = WEBAPP_VERSION + unique_url.unique_inputs = model unique_url.model_pk = model.pk cur_dt = datetime.datetime.utcnow() @@ -222,6 +238,7 @@ def btax_results(request): 'params': btax_default_params, 'btax_version': BTAX_VERSION, 'taxcalc_version': TAXCALC_VERSION, + 'webapp_version': WEBAPP_VERSION, 'start_years': START_YEARS, 'start_year': start_year, 'has_errors': has_errors, @@ -260,12 +277,18 @@ def edit_btax_results(request, pk): form_btax_input = make_bool_gds_ads(form_btax_input) hover_notes = hover_args_to_btax_depr() + btax_vers_disp = get_version(url, 'btax_vers', BTAX_VERSION) + webapp_vers_disp = get_version(url, 'webapp_vers', WEBAPP_VERSION) + + context_vers_disp = {'btax_version': btax_vers_disp, + 'webapp_version': webapp_vers_disp} + init_context = { 'form': form_btax_input, 'make_bool': make_bool, 'params': btax_default_params, - 'btax_version': BTAX_VERSION, - 'taxcalc_version': TAXCALC_VERSION, + 'btax_version': btax_vers_disp, + 'webapp_version': webapp_vers_disp, 'start_years': START_YEARS, 'start_year': str(start_year), 'has_errors': has_errors, @@ -302,6 +325,7 @@ def generate_mock_results(request): context.update({ 'btax_version':BTAX_VERSION, 'taxcalc_version': TAXCALC_VERSION, + 'webapp_vers': WEBAPP_VERSION, 'table_json': str(mock_json), 'is_btax': True, }) @@ -322,6 +346,12 @@ def output_detail(request, pk): except: raise Http404 + btax_vers_disp = get_version(url, 'btax_vers', BTAX_VERSION) + webapp_vers_disp = get_version(url, 'webapp_vers', WEBAPP_VERSION) + + context_vers_disp = {'btax_version': btax_vers_disp, + 'webapp_version': webapp_vers_disp} + model = url.unique_inputs if model.tax_result: exp_num_minutes = 0.25 @@ -344,8 +374,6 @@ def output_detail(request, pk): context.update({ 'locals': locals(), 'unique_url': url, - 'btax_version': BTAX_VERSION, - 'taxcalc_version': TAXCALC_VERSION, 'table_json': json.dumps(tables), 'created_on': created_on, 'first_year': first_year, @@ -355,6 +383,7 @@ def output_detail(request, pk): 'cdn_js': cdn_js, 'cdn_css': cdn_css, }) + context.update(context_vers_disp) return render(request, 'btax/results.html', context) else: @@ -417,6 +446,7 @@ def output_detail(request, pk): else: print "rendering not ready yet" - not_ready_data = {'eta': '100', 'is_btax': True, 'wait_interval': 7000} - return render_to_response('btax/not_ready.html', not_ready_data, + context = {'eta': '100', 'is_btax': True, 'wait_interval': 7000} + context.update(context_vers_disp) + return render_to_response('btax/not_ready.html', context, context_instance=RequestContext(request)) diff --git a/webapp/apps/dynamic/compute.py b/webapp/apps/dynamic/compute.py index eb0ff820..cb394685 100644 --- a/webapp/apps/dynamic/compute.py +++ b/webapp/apps/dynamic/compute.py @@ -11,7 +11,7 @@ from ..constants import START_YEAR dqversion_info = taxcalc._version.get_versions() -dropq_version = ".".join([dqversion_info['version'], dqversion_info['full'][:6]]) +dropq_version = dqversion_info['version'] NUM_BUDGET_YEARS = int(os.environ.get('NUM_BUDGET_YEARS', 10)) #Hard fail on lack of dropq workers dropq_workers = os.environ.get('DROPQ_WORKERS', '') diff --git a/webapp/apps/dynamic/migrations/0015_auto_20170918_1255.py b/webapp/apps/dynamic/migrations/0015_auto_20170918_1255.py new file mode 100644 index 00000000..68efb4fd --- /dev/null +++ b/webapp/apps/dynamic/migrations/0015_auto_20170918_1255.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('dynamic', '0014_auto_20170413_2300'), + ] + + operations = [ + migrations.AddField( + model_name='dynamicbehavioroutputurl', + name='webapp_vers', + field=models.CharField(default=None, max_length=50, null=True, blank=True), + ), + migrations.AddField( + model_name='dynamicelasticityoutputurl', + name='webapp_vers', + field=models.CharField(default=None, max_length=50, null=True, blank=True), + ), + migrations.AddField( + model_name='dynamicoutputurl', + name='webapp_vers', + field=models.CharField(default=None, max_length=50, null=True, blank=True), + ), + ] diff --git a/webapp/apps/dynamic/models.py b/webapp/apps/dynamic/models.py index c4c11f47..b782c6e6 100644 --- a/webapp/apps/dynamic/models.py +++ b/webapp/apps/dynamic/models.py @@ -143,6 +143,8 @@ class DynamicOutputUrl(models.Model): uuid = UUIDField(auto=True, default=None, null=True) ogusa_vers = models.CharField(blank=True, default=None, null=True, max_length=50) + webapp_vers = models.CharField(blank=True, default=None, null=True, + max_length=50) def get_absolute_url(self): kwargs = { @@ -163,6 +165,8 @@ class DynamicBehaviorOutputUrl(models.Model): uuid = UUIDField(auto=True, default=None, null=True) taxcalc_vers = models.CharField(blank=True, default=None, null=True, max_length=50) + webapp_vers = models.CharField(blank=True, default=None, null=True, + max_length=50) def get_absolute_url(self): kwargs = { @@ -183,6 +187,9 @@ class DynamicElasticityOutputUrl(models.Model): uuid = UUIDField(auto=True, default=None, null=True) taxcalc_vers = models.CharField(blank=True, default=None, null=True, max_length=50) + webapp_vers = models.CharField(blank=True, default=None, null=True, + max_length=50) + def get_absolute_url(self): kwargs = { diff --git a/webapp/apps/dynamic/views.py b/webapp/apps/dynamic/views.py index 5e611d4b..c365c733 100644 --- a/webapp/apps/dynamic/views.py +++ b/webapp/apps/dynamic/views.py @@ -56,18 +56,20 @@ ADJUSTED_TOOLTIP, INCOME_BINS_TOOLTIP, INCOME_DECILES_TOOLTIP, START_YEAR, START_YEARS) -from ..formatters import format_dynamic_params +from ..formatters import format_dynamic_params, get_version tcversion_info = taxcalc._version.get_versions() -taxcalc_version = ".".join([tcversion_info['version'], tcversion_info['full'][:6]]) +TAXCALC_VERSION = tcversion_info['version'] +# TODO: use import ogusa; ogusa.__version__ version_path = os.path.join(os.path.split(__file__)[0], "ogusa_version.json") with open(version_path, "r") as f: ogversion_info = json.load(f) -ogusa_version = ".".join([ogversion_info['version'], - ogversion_info['full-revisionid'][:6]]) +OGUSA_VERSION = ogversion_info['version'] +from django.conf import settings +WEBAPP_VERSION = settings.WEBAPP_VERSION def dynamic_input(request, pk): """ @@ -134,7 +136,7 @@ def dynamic_input(request, pk): int(start_year), microsim_data, pack_up_user_mods=False) - + # TODO: use OutputUrl class if submitted_ids: model.job_ids = denormalize(submitted_ids) model.guids = denormalize(guids) @@ -166,8 +168,9 @@ def dynamic_input(request, pk): init_context = { 'form': form_personal_exemp, 'params': ogusa_default_params, - 'taxcalc_version': taxcalc_version, - 'ogusa_version': ogusa_version, + 'taxcalc_version': TAXCALC_VERSION, + 'ogusa_version': OGUSA_VERSION, + 'webapp_version': WEBAPP_VERSION, 'start_year': start_year, 'pk': pk, 'is_disabled': disabled_flag, @@ -185,7 +188,6 @@ def dynamic_behavioral(request, pk): This view handles the dynamic behavioral input page and calls the function that handles the calculation on the inputs. """ - if request.method == 'POST': # Client is attempting to send inputs, validate as form data fields = dict(request.REQUEST) @@ -196,6 +198,20 @@ def dynamic_behavioral(request, pk): if dyn_mod_form.is_valid(): model = dyn_mod_form.save() + + curr_dict = dict(model.__dict__) + for key, value in curr_dict.items(): + print "got this ", key, value + + for key, value in curr_dict.items(): + if type(value) == type(unicode()): + curr_dict[key] = [convert_val(x) for x in value.split(',') if x] + else: + print "missing this: ", key + + # get macrosim data from form + worker_data = {k:v for k, v in curr_dict.items() if v not in (u'', None, [])} + #get microsim data outputsurl = OutputUrl.objects.get(pk=pk) model.micro_sim = outputsurl @@ -242,7 +258,12 @@ def dynamic_behavioral(request, pk): if unique_url.taxcalc_vers != None: pass else: - unique_url.taxcalc_vers = taxcalc_version + unique_url.taxcalc_vers = TAXCALC_VERSION + + if unique_url.webapp_vers != None: + pass + else: + unique_url.webapp_vers = WEBAPP_VERSION unique_url.unique_inputs = model unique_url.model_pk = model.pk @@ -269,7 +290,8 @@ def dynamic_behavioral(request, pk): init_context = { 'form': form_personal_exemp, 'params': behavior_default_params, - 'taxcalc_version': taxcalc_version, + 'taxcalc_version': TAXCALC_VERSION, + 'webapp_version': WEBAPP_VERSION, 'start_year': start_year, 'pk': pk } @@ -376,7 +398,12 @@ def dynamic_elasticities(request, pk): if unique_url.taxcalc_vers != None: pass else: - unique_url.taxcalc_vers = taxcalc_version + unique_url.taxcalc_vers = TAXCALC_VERSION + + if unique_url.webapp_vers != None: + pass + else: + unique_url.webapp_vers = WEBAPP_VERSION unique_url.unique_inputs = model unique_url.model_pk = model.pk @@ -401,7 +428,8 @@ def dynamic_elasticities(request, pk): init_context = { 'form': form_personal_exemp, 'params': elasticity_default_params, - 'taxcalc_version': taxcalc_version, + 'taxcalc_version': TAXCALC_VERSION, + 'webapp_version': WEBAPP_VERSION, 'start_year': start_year, 'pk': pk } @@ -431,10 +459,14 @@ def edit_dynamic_behavioral(request, pk): form_personal_exemp = DynamicBehavioralInputsModelForm(first_year=start_year, instance=model) behavior_default_params = default_behavior_parameters(int(start_year)) + taxcalc_vers_disp = get_version(url, 'taxcalc_vers', TAXCALC_VERSION) + webapp_vers_disp = get_version(url, 'webapp_vers', WEBAPP_VERSION) + init_context = { 'form': form_personal_exemp, 'params': behavior_default_params, - 'taxcalc_version': taxcalc_version, + 'taxcalc_version': taxcalc_vers_disp, + 'webapp_version': webapp_vers_disp, 'start_year': str(start_year), 'pk': model.micro_sim.pk } @@ -462,11 +494,14 @@ def edit_dynamic_elastic(request, pk): form_personal_exemp = DynamicElasticityInputsModelForm(first_year=start_year, instance=model) elasticity_default_params = default_elasticity_parameters(int(start_year)) + taxcalc_vers_disp = get_version(url, 'taxcalc_vers', TAXCALC_VERSION) + webapp_vers_disp = get_version(url, 'webapp_vers', WEBAPP_VERSION) init_context = { 'form': form_personal_exemp, 'params': elasticity_default_params, - 'taxcalc_version': taxcalc_version, + 'taxcalc_version': taxcalc_vers_disp, + 'webapp_version': webapp_vers_disp, 'start_year': str(start_year), 'pk': model.micro_sim.pk } @@ -486,8 +521,10 @@ def dynamic_landing(request, pk): 'pk': pk, 'is_authenticated': request.user.is_authenticated(), 'include_ogusa': include_ogusa, - 'start_year': request.GET['start_year'] - } + 'start_year': request.GET['start_year'], + 'taxcalc_version': TAXCALC_VERSION, + 'webapp_version': WEBAPP_VERSION + } return render_to_response('dynamic/landing.html', init_context) @@ -573,11 +610,11 @@ def elastic_results(request, pk): except: raise Http404 - if url.taxcalc_vers != None: - pass - else: - url.taxcalc_vers = taxcalc_version - url.save() + taxcalc_vers_disp = get_version(url, 'taxcalc_vers', TAXCALC_VERSION) + webapp_vers_disp = get_version(url, 'webapp_vers', WEBAPP_VERSION) + + context_vers_disp = {'taxcalc_version': taxcalc_vers_disp, + 'webapp_version': webapp_vers_disp} model = url.unique_inputs if model.tax_result: @@ -591,7 +628,8 @@ def elastic_results(request, pk): context = { 'locals':locals(), 'unique_url':url, - 'taxcalc_version':taxcalc_version, + 'taxcalc_version':taxcalc_vers_disp, + 'webapp_version':webapp_vers_disp, 'tables':tables, 'created_on':created_on, 'first_year':first_year, @@ -660,7 +698,9 @@ def elastic_results(request, pk): else: print "rendering not ready yet" - return render_to_response('dynamic/not_ready.html', {'eta':'100'}, context_instance=RequestContext(request)) + context = {'eta': '100'} + context.update(context_vers_disp) + return render_to_response('dynamic/not_ready.html', context, context_instance=RequestContext(request)) def ogusa_results(request, pk): @@ -672,12 +712,6 @@ def ogusa_results(request, pk): except: raise Http404 - if url.ogusa_vers != None: - pass - else: - url.ogusa_vers = ogusa_version - url.save() - output = url.unique_inputs.tax_result first_year = url.unique_inputs.first_year created_on = url.unique_inputs.creation_date @@ -685,10 +719,16 @@ def ogusa_results(request, pk): hostname = os.environ.get('BASE_IRI', 'http://www.ospc.org') microsim_url = hostname + "/taxbrain/" + str(url.unique_inputs.micro_sim.pk) + ogusa_vers_disp = get_version(url, 'ogusa_vers', OGUSA_VERSION) + taxcalc_vers_disp = get_version(url, 'taxcalc_vers', TAXCALC_VERSION) + webapp_vers_disp = get_version(url, 'webapp_vers', WEBAPP_VERSION) + context = { 'locals':locals(), 'unique_url':url, - 'ogusa_version':url.ogusa_vers, + 'ogusa_version':ougsa_vers_display, + 'webapp_version': webapp_vers_disp, + 'taxcalc_vers': taxcalc_vers_disp, 'tables':tables, 'created_on':created_on, 'first_year':first_year, @@ -708,14 +748,13 @@ def behavior_results(request, pk): except: raise Http404 - if url.taxcalc_vers != None: - pass - else: - url.taxcalc_vers = taxcalc_version - url.save() + taxcalc_vers_disp = get_version(url, 'taxcalc_vers', TAXCALC_VERSION) + webapp_vers_disp = get_version(url, 'webapp_vers', WEBAPP_VERSION) - model = url.unique_inputs + context_vers_disp = {'taxcalc_version': taxcalc_vers_disp, + 'webapp_version': webapp_vers_disp} + model = url.unique_inputs if model.tax_result: output = model.tax_result @@ -752,7 +791,6 @@ def behavior_results(request, pk): context = { 'locals':locals(), 'unique_url':url, - 'taxcalc_version':taxcalc_version, 'tables': json_table, 'created_on': created_on, 'first_year': first_year, @@ -761,6 +799,7 @@ def behavior_results(request, pk): 'microsim_url': microsim_url, 'results_type': "behavioral" } + context.update(context_vers_disp) return render(request, 'taxbrain/results.html', context) else: @@ -806,4 +845,6 @@ def behavior_results(request, pk): else: print "rendering not ready yet" - return render_to_response('dynamic/not_ready.html', {'eta': '100'}, context_instance=RequestContext(request)) + context = {'eta': '100'} + context.update(context_vers_disp) + return render_to_response('dynamic/not_ready.html', context, context_instance=RequestContext(request)) diff --git a/webapp/apps/formatters.py b/webapp/apps/formatters.py index 6fbf2219..c850dcf0 100644 --- a/webapp/apps/formatters.py +++ b/webapp/apps/formatters.py @@ -7,3 +7,19 @@ def format_dynamic_params(params): for key in ("growdiff_response", "consumption", "growdiff_baseline"): behavior_params[key] = {} return behavior_params + +def get_version(url_obj, attr_name, current_version): + """ + get formatted python version of library for diplay on web page + """ + # need to chop off the commit reference on older runs + vers_disp = (getattr(url_obj, attr_name) + if getattr(url_obj, attr_name) is not None + else current_version) + # only recently start storing webapp version. for older runs display + # the current version. an alternative is to display the first stable + # version if url.webapp_version is None + if len(vers_disp.split('.')) > 3: + vers_disp = '.'.join(vers_disp.split('.')[:-1]) + + return vers_disp diff --git a/webapp/apps/pages/views.py b/webapp/apps/pages/views.py index 24709836..96554c46 100644 --- a/webapp/apps/pages/views.py +++ b/webapp/apps/pages/views.py @@ -17,10 +17,8 @@ BTAX_VERSION_INFO = btax._version.get_versions() TAXCALC_VERSION_INFO = taxcalc._version.get_versions() -BTAX_VERSION = ".".join([BTAX_VERSION_INFO['version'], - BTAX_VERSION_INFO['full-revisionid'][:6]]) -TAXCALC_VERSION = ".".join([TAXCALC_VERSION_INFO['version'], - TAXCALC_VERSION_INFO['full'][:6]]) +BTAX_VERSION = BTAX_VERSION_INFO['version'] +TAXCALC_VERSION = TAXCALC_VERSION_INFO['version'] BLOG_URL = os.environ.get('BLOG_URL', 'www.ospc.org') EMAIL_DEFAULT = '1' diff --git a/webapp/apps/taxbrain/compute.py b/webapp/apps/taxbrain/compute.py index 54aa00de..c8d3b959 100644 --- a/webapp/apps/taxbrain/compute.py +++ b/webapp/apps/taxbrain/compute.py @@ -11,7 +11,7 @@ requests_mock.Mocker.TEST_PREFIX = 'dropq' dqversion_info = taxcalc._version.get_versions() -dropq_version = ".".join([dqversion_info['version'], dqversion_info['full'][:6]]) +dropq_version = dqversion_info['version'] NUM_BUDGET_YEARS = int(os.environ.get('NUM_BUDGET_YEARS', 10)) NUM_BUDGET_YEARS_QUICK = int(os.environ.get('NUM_BUDGET_YEARS_QUICK', 1)) #Hard fail on lack of dropq workers diff --git a/webapp/apps/taxbrain/helpers.py b/webapp/apps/taxbrain/helpers.py index 42bd1d29..8e72515b 100644 --- a/webapp/apps/taxbrain/helpers.py +++ b/webapp/apps/taxbrain/helpers.py @@ -149,7 +149,7 @@ def default_taxcalc_data(cls, start_year, metadata=False): # tcversion_info = taxcalc._version.get_versions() -taxcalc_version = ".".join([tcversion_info['version'], tcversion_info['full'][:6]]) +taxcalc_version = tcversion_info['version'] TAXCALC_COMING_SOON_FIELDS = [] diff --git a/webapp/apps/taxbrain/migrations/0054_outputurl_webapp_vers.py b/webapp/apps/taxbrain/migrations/0054_outputurl_webapp_vers.py new file mode 100644 index 00000000..1465eb75 --- /dev/null +++ b/webapp/apps/taxbrain/migrations/0054_outputurl_webapp_vers.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('taxbrain', '0053_auto_20170725_2141'), + ] + + operations = [ + migrations.AddField( + model_name='outputurl', + name='webapp_vers', + field=models.CharField(default=None, max_length=50, null=True, blank=True), + ), + ] diff --git a/webapp/apps/taxbrain/models.py b/webapp/apps/taxbrain/models.py index b6f4db29..ccdae9f9 100644 --- a/webapp/apps/taxbrain/models.py +++ b/webapp/apps/taxbrain/models.py @@ -742,6 +742,8 @@ class OutputUrl(models.Model): uuid = UUIDField(auto=True, default=None, null=True) taxcalc_vers = models.CharField(blank=True, default=None, null=True, max_length=50) + webapp_vers = models.CharField(blank=True, default=None, null=True, + max_length=50) def get_absolute_url(self): kwargs = { diff --git a/webapp/apps/taxbrain/views.py b/webapp/apps/taxbrain/views.py index 906ee6d4..ee930285 100644 --- a/webapp/apps/taxbrain/views.py +++ b/webapp/apps/taxbrain/views.py @@ -53,10 +53,15 @@ INCOME_BINS_TOOLTIP, INCOME_DECILES_TOOLTIP, START_YEAR, START_YEARS) +from ..formatters import get_version + +from django.conf import settings +WEBAPP_VERSION = settings.WEBAPP_VERSION tcversion_info = taxcalc._version.get_versions() -taxcalc_version = ".".join([tcversion_info['version'], tcversion_info['full'][:6]]) +TAXCALC_VERSION = tcversion_info['version'] + JOB_PROC_TIME_IN_SECONDS = 30 @@ -427,6 +432,13 @@ def submit_reform(request, user=None): json_reform.raw_assumption_text = assumptions_text # save GUI user params else: + job_ids = denormalize(submitted_ids) + model.job_ids = job_ids + model.first_year = int(start_year) + model.quick_calc = not do_full_calc + model.save() + unique_url = OutputUrl() + json_reform.reform_text = json.dumps(reform_dict) json_reform.assumption_text = json.dumps(assumptions_dict) json_reform.raw_reform_text = "" @@ -454,7 +466,11 @@ def submit_reform(request, user=None): if unique_url.taxcalc_vers is not None: pass else: - unique_url.taxcalc_vers = taxcalc_version + unique_url.taxcalc_vers = TAXCALC_VERSION + if unique_url.webapp_vers != None: + pass + else: + unique_url.webapp_vers = WEBAPP_VERSION unique_url.unique_inputs = model unique_url.model_pk = model.pk @@ -483,8 +499,6 @@ def file_input(request): else: unique_url, has_errors = submit_reform(request) # TODO: handle taxcalc_errors and taxcalc_warnings - # if no_inputs: - # raise IOError('handle no-inputs situation') return redirect(unique_url) # GET request, load a default form params = parse_qs(urlparse(request.build_absolute_uri()).query) @@ -494,8 +508,9 @@ def file_input(request): init_context = { 'form': None, 'errors': errors, + 'taxcalc_version': TAXCALC_VERSION, + 'webapp_version': WEBAPP_VERSION, 'params': None, # TODO: doesn't do anything-->: taxcalc_default_params, - 'taxcalc_version': taxcalc_version, 'start_years': START_YEARS, 'start_year': start_year, 'enable_quick_calc': ENABLE_QUICK_CALC @@ -553,7 +568,8 @@ def personal_results(request): init_context = { 'form': personal_inputs, 'params': nested_form_parameters(int(start_year)), - 'taxcalc_version': taxcalc_version, + 'taxcalc_version': TAXCALC_VERSION, + 'webapp_version': WEBAPP_VERSION, 'start_years': START_YEARS, 'start_year': start_year, 'has_errors': has_errors, @@ -605,10 +621,14 @@ def edit_personal_results(request, pk): form_personal_exemp = PersonalExemptionForm(first_year=start_year, instance=model) + taxcalc_vers_disp = get_version(url, 'taxcalc_vers', TAXCALC_VERSION) + webapp_vers_disp = get_version(url, 'webapp_vers', WEBAPP_VERSION) + init_context = { 'form': form_personal_exemp, 'params': nested_form_parameters(int(start_year)), - 'taxcalc_version': taxcalc_version, + 'taxcalc_version': taxcalc_vers_disp, + 'webapp_version': webapp_vers_disp, 'start_years': START_YEARS, 'start_year': str(start_year), 'is_edit_page': True @@ -695,7 +715,6 @@ def get_result_context(model, request, url): context = { 'locals':locals(), 'unique_url':url, - 'taxcalc_version':taxcalc_version, 'tables': json_table, 'created_on': created_on, 'first_year': first_year, @@ -724,8 +743,15 @@ def output_detail(request, pk): raise Http404 model = url.unique_inputs + + taxcalc_vers_disp = get_version(url, 'taxcalc_vers', TAXCALC_VERSION) + webapp_vers_disp = get_version(url, 'webapp_vers', WEBAPP_VERSION) + + context_vers_disp = {'taxcalc_version': taxcalc_vers_disp, + 'webapp_version': webapp_vers_disp} if model.tax_result: context = get_result_context(model, request, url) + context.update(context_vers_disp) context["raw_reform_text"] = model.json_text.raw_reform_text if model.json_text else "" context["raw_assumption_text"] = model.json_text.raw_assumption_text if model.json_text else "" return render(request, 'taxbrain/results.html', context) @@ -774,6 +800,7 @@ def output_detail(request, pk): model.creation_date = datetime.datetime.now() model.save() context = get_result_context(model, request, url) + context.update(context_vers_disp) return render(request, 'taxbrain/results.html', context) else: @@ -797,7 +824,9 @@ def output_detail(request, pk): return JsonResponse({'eta': exp_num_minutes}, status=200) else: - return render_to_response('taxbrain/not_ready.html', {'eta': '100'}, context_instance=RequestContext(request)) + context = {'eta': '100'} + context.update(context_vers_disp) + return render_to_response('taxbrain/not_ready.html', context, context_instance=RequestContext(request)) @permission_required('taxbrain.view_inputs') diff --git a/webapp/settings.py b/webapp/settings.py index 296ba2ac..0f2001c3 100644 --- a/webapp/settings.py +++ b/webapp/settings.py @@ -39,6 +39,8 @@ from django.conf import global_settings +WEBAPP_VERSION = "1.0.2" + TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + ( 'webapp.apps.pages.views.settings_context_processor', 'webapp.context_processors.google_analytics',