-
Notifications
You must be signed in to change notification settings - Fork 32
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
Resolve more backwards compatibility issues related to old taxcalc tables #814
Changes from 4 commits
5b4a687
28047b8
69116c7
7fcc713
2b4d02f
2da32f1
6fce841
fc6b876
21b283b
9a1ae6d
ae28a6e
caf6986
0d58dfb
78d700e
d243f19
1f6bed8
ad4fb24
1e90ae4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,25 @@ class DynamicBehaviorSaveInputs(models.Model): | |
micro_sim = models.ForeignKey(OutputUrl, blank=True, null=True, | ||
on_delete=models.SET_NULL) | ||
|
||
def get_tax_result(self): | ||
""" | ||
If taxcalc version is greater than or equal to 0.13.0, return table | ||
If taxcalc version is less than 0.13.0, then rename keys to new names | ||
and then return table | ||
""" | ||
outputurl = OutputUrl.objects.get(unique_inputs__pk=self.pk) | ||
taxcalc_vers = outputurl.taxcalc_vers | ||
taxcalc_vers = taxcalc_vers.split('.') | ||
# older PB versions stored commit reference too | ||
# e.g. taxcalc_vers = "0.9.0.d79abf" | ||
if len(taxcalc_vers) >=3: | ||
taxcalc_vers = taxcalc_vers[:3] | ||
taxcalc_vers = tuple(map(int, taxcalc_vers)) | ||
if taxcalc_vers >= (0, 13, 0): | ||
return self.tax_result | ||
else: | ||
return rename_keys(self.tax_result, PRE_TC_0130_RES_MAP) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @codekansas I would prefer to not copy this method from the taxbrain models code. Do you have any ideas for a cleaner solution? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll probably want to put this in a
in the top of the file, so that importing is consistent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @codekansas thanks for the advice. That makes sense. Another solution would be to create an abstract model class with this method. Then, the |
||
class Meta: | ||
permissions = ( | ||
("view_inputs", "Allowed to view Taxbrain."), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -757,7 +757,7 @@ class TaxSaveInputs(models.Model): | |
""" | ||
|
||
# Result | ||
_tax_result = JSONField(default=None, blank=True, null=True, db_column='tax_result') | ||
tax_result = JSONField(default=None, blank=True, null=True) | ||
|
||
# JSON input text | ||
json_text = models.ForeignKey(JSONReformTaxCalculator, null=True, default=None, blank=True) | ||
|
@@ -768,25 +768,24 @@ class TaxSaveInputs(models.Model): | |
# Creation DateTime | ||
creation_date = models.DateTimeField(default=datetime.datetime(2015, 1, 1)) | ||
|
||
|
||
@property | ||
def tax_result(self): | ||
def get_tax_result(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a good idea - I think the best "logic" for deciding if something should be a property is if:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, that makes sense. Thanks for the info. I also couldn't get the property approach to work without deleting the column in the database. |
||
""" | ||
If taxcalc version is greater than or equal to 0.13.0, return table | ||
If taxcalc version is less than 0.13.0, then rename keys to new names | ||
and then return table | ||
""" | ||
outputurl = OutputUrl.objects.get(unique_inputs__pk=self.pk) | ||
taxcalc_vers = outputurl.taxcalc_vers | ||
taxcalc_vers = tuple(map(int, taxcalc_vers.split('.'))) | ||
taxcalc_vers = taxcalc_vers.split('.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See earlier comment about using |
||
# older PB versions stored commit reference too | ||
# e.g. taxcalc_vers = "0.9.0.d79abf" | ||
if len(taxcalc_vers) >=3: | ||
taxcalc_vers = taxcalc_vers[:3] | ||
taxcalc_vers = tuple(map(int, taxcalc_vers)) | ||
if taxcalc_vers >= (0, 13, 0): | ||
return self._tax_result | ||
return self.tax_result | ||
else: | ||
return rename_keys(self._tax_result, PRE_TC_0130_RES_MAP) | ||
|
||
@tax_result.setter | ||
def tax_result(self, result): | ||
self._tax_result = result | ||
return rename_keys(self.tax_result, PRE_TC_0130_RES_MAP) | ||
|
||
class Meta: | ||
permissions = ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -826,7 +826,7 @@ def add_summary_column(table): | |
|
||
|
||
def get_result_context(model, request, url): | ||
output = model.tax_result | ||
output = model.get_tax_result() | ||
first_year = model.first_year | ||
quick_calc = model.quick_calc | ||
created_on = model.creation_date | ||
|
@@ -1014,7 +1014,7 @@ def csv_output(request, pk): | |
filename = "taxbrain_outputs_" + suffix + ".csv" | ||
response['Content-Disposition'] = 'attachment; filename="' + filename + '"' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is probably better to use the following:
Also: For debugging purposes, it is a good idea to log things (the response filename, for example). |
||
|
||
results = url.unique_inputs.tax_result | ||
results = url.unique_inputs.get_tax_result() | ||
first_year = url.unique_inputs.first_year | ||
csv_results = format_csv(results, pk, first_year) | ||
writer = csv.writer(response) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can simplify to
But probably the best solution would be to use some versioning comparison standard library, i.e.
distutils.version.StrictVersion
ordistutils.version.LooseVersion
so that you don't have to mess around with this version comparison stuff.