Skip to content

Commit

Permalink
Merge pull request #106 from jantman/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
jantman committed Aug 7, 2017
2 parents cf3e4f9 + 8f61075 commit e3896fb
Show file tree
Hide file tree
Showing 32 changed files with 199 additions and 65 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Unreleased Changes
------------------

* Have ``ofxgetter`` enable ofxclient logging when running at DEBUG level (``-vv``).
* Bump ofxclient requirement to my `vanguard-fix <https://github.com/jantman/ofxclient/tree/vanguard-fix>`_ branch
for `PR #47 <https://github.com/captin411/ofxclient/pull/47>`_.
* `Issue #101 <https://github.com/jantman/biweeklybudget/issues/101>`_ - Fix static example amounts on ``/projects`` view.
* `Issue #103 <https://github.com/jantman/biweeklybudget/issues/103>`_ - Show most recent MPG in notification box after adding fuel fill.
* `Issue #97 <https://github.com/jantman/biweeklybudget/issues/97>`_ - Fix integration tests that are date-specific and break on certain dates (run all integration tests as if it were a fixed date).

0.3.0 (2017-07-09)
------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
return new Date(Date.UTC.apply(Date, arguments));
}
function UTCToday(){
var today = new Date();
return UTCDate(today.getFullYear(), today.getMonth(), today.getDate());
return UTCDate(BIWEEKLYBUDGET_DEFAULT_DATE.getFullYear(), BIWEEKLYBUDGET_DEFAULT_DATE.getMonth(), BIWEEKLYBUDGET_DEFAULT_DATE.getDate());
}
function isUTCEquals(date1, date2) {
return (
Expand Down
2 changes: 1 addition & 1 deletion biweeklybudget/flaskapp/static/js/budget_transfer_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function budgetTransferDivForm() {
function budgetTransferModal() {
$('#modalBody').empty();
$('#modalBody').append(budgetTransferDivForm());
$('#budg_txfr_frm_date').val(isoformat(new Date()));
$('#budg_txfr_frm_date').val(isoformat(BIWEEKLYBUDGET_DEFAULT_DATE));
$('#budg_txfr_frm_date_input_group').datepicker({
todayBtn: "linked",
autoclose: true,
Expand Down
11 changes: 9 additions & 2 deletions biweeklybudget/flaskapp/static/js/fuel.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,22 @@ function fuelModalDivForm() {
function fuelLogModal(dataTableObj) {
$('#modalBody').empty();
$('#modalBody').append(fuelModalDivForm());
$('#fuel_frm_date').val(isoformat(new Date()));
$('#fuel_frm_date').val(isoformat(BIWEEKLYBUDGET_DEFAULT_DATE));
$('#fuel_frm_date_input_group').datepicker({
todayBtn: "linked",
autoclose: true,
todayHighlight: true,
format: 'yyyy-mm-dd'
});
$('#modalSaveButton').click(function() {
handleForm('modalBody', 'fuelLogForm', '/forms/fuel', dataTableObj);
handleForm('modalBody', 'fuelLogForm', '/forms/fuel', function(data) {
// reload the table
dataTableObj.api().ajax.reload();
// reload the chart
updateCharts();
if(! $('#last_mpg_notice').length){ $('#notifications-row > div.col-lg-12').append('<div class="alert alert-info" id="last_mpg_notice"></div>'); }
$('#last_mpg_notice').html('Last fill MPG: ' + data['calculated_mpg']);
});
}).show();
$('#fuel_frm_account option[value=' + default_account_id + ']').prop('selected', 'selected').change();
$('#fuel_frm_budget option[value=' + fuel_budget_id + ']').prop('selected', 'selected').change();
Expand Down
23 changes: 20 additions & 3 deletions biweeklybudget/flaskapp/static/js/fuel_charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ Jason Antman <jason@jasonantman.com> <http://www.jasonantman.com>
################################################################################
*/

$(function() {
var ecoChart;
var priceChart;

function initCharts() {
$.ajax('/ajax/chart-data/fuel-economy').done(function(ajaxdata) {
Morris.Line({
ecoChart = Morris.Line({
element: 'mpg-chart',
data: ajaxdata['data'],
xkey: 'date',
Expand All @@ -51,7 +54,7 @@ $(function() {
});

$.ajax('/ajax/chart-data/fuel-prices').done(function(ajaxdata) {
Morris.Line({
priceChart = Morris.Line({
element: 'fuel-price-chart',
data: ajaxdata['data'],
xkey: 'date',
Expand All @@ -64,4 +67,18 @@ $(function() {
continuousLine: true
});
});
}

function updateCharts() {
$.ajax('/ajax/chart-data/fuel-economy').done(function(ajaxdata) {
ecoChart.setData(ajaxdata['data']);
});

$.ajax('/ajax/chart-data/fuel-prices').done(function(ajaxdata) {
priceChart.setData(ajaxdata['data']);
});
}

$(function() {
initCharts();
});
2 changes: 1 addition & 1 deletion biweeklybudget/flaskapp/static/js/payperiod_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function schedToTransModalDivFillAndShow(msg) {
function schedToTransModal(id, payperiod_start_date) {
$('#modalBody').empty();
$('#modalBody').append(schedToTransModalDivForm());
$('#schedtotrans_frm_date').val(isoformat(new Date()));
$('#schedtotrans_frm_date').val(isoformat(BIWEEKLYBUDGET_DEFAULT_DATE));
$('#schedtotrans_frm_date_input_group').datepicker({
todayBtn: "linked",
autoclose: true,
Expand Down
4 changes: 2 additions & 2 deletions biweeklybudget/flaskapp/static/js/payperiods.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
$('.calendar').map(function(index) {
$(this).datepicker({
defaultViewDate: {
year: (new Date()).getFullYear(),
month: (new Date()).getMonth() + (index - 1),
year: BIWEEKLYBUDGET_DEFAULT_DATE.getFullYear(),
month: BIWEEKLYBUDGET_DEFAULT_DATE.getMonth() + (index - 1),
date: 1
},
multidate: true,
Expand Down
2 changes: 1 addition & 1 deletion biweeklybudget/flaskapp/static/js/transactions_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function transModalDivFillAndShow(msg) {
function transModal(id, dataTableObj) {
$('#modalBody').empty();
$('#modalBody').append(transModalDivForm());
$('#trans_frm_date').val(isoformat(new Date()));
$('#trans_frm_date').val(isoformat(BIWEEKLYBUDGET_DEFAULT_DATE));
$('#trans_frm_date_input_group').datepicker({
todayBtn: "linked",
autoclose: true,
Expand Down
3 changes: 2 additions & 1 deletion biweeklybudget/flaskapp/templates/bomitem.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
<script src="/static/startbootstrap-sb-admin-2/vendor/datatables-responsive/dataTables.responsive.js"></script>

<!-- BootStrap DatePicker JS -->
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="/utils/datetest.js"></script>
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>

<script>
var project_id = {{ project_id }};
Expand Down
3 changes: 2 additions & 1 deletion biweeklybudget/flaskapp/templates/budgets.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
{% endblock %}
{% block extra_foot_script %}
<!-- BootStrap DatePicker JS -->
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="/utils/datetest.js"></script>
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script>
var default_account_id = {{ settings.DEFAULT_ACCOUNT_ID }};
</script>
Expand Down
3 changes: 2 additions & 1 deletion biweeklybudget/flaskapp/templates/fuel.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@
<script src="/static/startbootstrap-sb-admin-2/vendor/datatables-responsive/dataTables.responsive.js"></script>

<!-- BootStrap DatePicker JS -->
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="/utils/datetest.js"></script>
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>

<script>
var default_account_id = {{ settings.DEFAULT_ACCOUNT_ID }};
Expand Down
3 changes: 2 additions & 1 deletion biweeklybudget/flaskapp/templates/payperiod.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@
{% endblock %}
{% block extra_foot_script %}
<!-- BootStrap DatePicker JS -->
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="/utils/datetest.js"></script>
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script src="/static/startbootstrap-sb-admin-2/vendor/datatables-plugins/dataTables.bootstrap.min.js"></script>
<script src="/static/startbootstrap-sb-admin-2/vendor/datatables-responsive/dataTables.responsive.js"></script>

Expand Down
3 changes: 2 additions & 1 deletion biweeklybudget/flaskapp/templates/payperiods.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@
{% endblock %}
{% block extra_foot_script %}
<!-- BootStrap DatePicker JS -->
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="/utils/datetest.js"></script>
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script src="/static/js/custom.js"></script>
<script src="/static/js/payperiods.js"></script>
{% endblock %}
4 changes: 2 additions & 2 deletions biweeklybudget/flaskapp/templates/projects.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class="panel-heading">
<div class="row">
<div class="col-xs-12 text-right">
<div class="huge">{{ 45|dollars }}</div>
<div class="huge" id="active-remaining-cost">{{ remain_active|dollars }}</div>
<div>Remaining Cost - Active Projects</div>
</div>
</div>
Expand All @@ -29,7 +29,7 @@
<div class="panel-heading">
<div class="row">
<div class="col-xs-12 text-right">
<div class="huge">{{ 100|dollars }}</div>
<div class="huge" id="active-total-cost">{{ total_active|dollars }}</div>
<div>Total Cost - Active Projects</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion biweeklybudget/flaskapp/templates/reconcile.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
{% endblock %}
{% block extra_foot_script %}
<!-- BootStrap DatePicker JS -->
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="/utils/datetest.js"></script>
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>

<!-- DataTables JavaScript -->
<script src="/static/startbootstrap-sb-admin-2/vendor/datatables/js/jquery.dataTables.min.js"></script>
Expand Down
3 changes: 2 additions & 1 deletion biweeklybudget/flaskapp/templates/scheduled.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
<script src="/static/startbootstrap-sb-admin-2/vendor/datatables-responsive/dataTables.responsive.js"></script>

<!-- BootStrap DatePicker JS -->
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="/utils/datetest.js"></script>
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>

<script>
var default_account_id = {{ settings.DEFAULT_ACCOUNT_ID }};
Expand Down
3 changes: 2 additions & 1 deletion biweeklybudget/flaskapp/templates/transactions.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
<script src="/static/startbootstrap-sb-admin-2/vendor/datatables-responsive/dataTables.responsive.js"></script>

<!-- BootStrap DatePicker JS -->
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="/utils/datetest.js"></script>
<script src="/static/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>

<script>
var default_account_id = {{ settings.DEFAULT_ACCOUNT_ID }};
Expand Down
1 change: 1 addition & 0 deletions biweeklybudget/flaskapp/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@
from .help import *
from .fuel import *
from .projects import *
from .utils import *
6 changes: 4 additions & 2 deletions biweeklybudget/flaskapp/views/fuel.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ def submit(self, data):
'success_message': 'Successfully saved FuelFill %d '
'in database.' % fill.id,
'success': True,
'fill_id': fill.id
'fill_id': fill.id,
'calculated_mpg': fill.calculated_mpg
}
trans = Transaction()
budg = db_session.query(Budget).get(int(data['budget']))
Expand All @@ -361,7 +362,8 @@ def submit(self, data):
fill.id, trans.id),
'success': True,
'trans_id': trans.id,
'fill_id': fill.id
'fill_id': fill.id,
'calculated_mpg': fill.calculated_mpg
}


Expand Down
2 changes: 1 addition & 1 deletion biweeklybudget/flaskapp/views/payperiods.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def get(self):
d_str = request.args.get('date', None)
if d_str is None:
pp = BiweeklyPayPeriod.period_for_date(
datetime.now().date(), db_session
dtnow().date(), db_session
)
logger.debug('Redirect to current payperiod: %s', pp)
else:
Expand Down
13 changes: 12 additions & 1 deletion biweeklybudget/flaskapp/views/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ class ProjectsView(MethodView):
"""

def get(self):
return render_template('projects.html')
total_active = 0.0
remain_active = 0.0
for p in db_session.query(Project).filter(
Project.is_active.__eq__(True)
).all():
total_active += p.total_cost
remain_active += p.remaining_cost
return render_template(
'projects.html',
total_active=total_active,
remain_active=remain_active
)


class ProjectsAjax(SearchableAjaxView):
Expand Down
62 changes: 62 additions & 0 deletions biweeklybudget/flaskapp/views/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
The latest version of this package is available at:
<http://github.com/jantman/biweeklybudget>
################################################################################
Copyright 2016 Jason Antman <jason@jasonantman.com> <http://www.jasonantman.com>
This file is part of biweeklybudget, also known as biweeklybudget.
biweeklybudget is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
biweeklybudget is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with biweeklybudget. If not, see <http://www.gnu.org/licenses/>.
The Copyright and Authors attributions contained herein may not be removed or
otherwise altered, except to add the Author attribution of a contributor to
this work. (Additional Terms pursuant to Section 7b of the AGPL v3)
################################################################################
While not legally required, I sincerely request that anyone who finds
bugs please submit them at <https://github.com/jantman/biweeklybudget> or
to me via email, and that you send any contributions or improvements
either as a pull request on GitHub, or to me via email.
################################################################################
AUTHORS:
Jason Antman <jason@jasonantman.com> <http://www.jasonantman.com>
################################################################################
"""

from flask.views import MethodView
from biweeklybudget.settings import BIWEEKLYBUDGET_TEST_TIMESTAMP
from biweeklybudget.utils import dtnow
from biweeklybudget.flaskapp.app import app


class DateTestJS(MethodView):
"""
Handle GET /utils/datetest.js endpoint.
"""

def get(self):
print(BIWEEKLYBUDGET_TEST_TIMESTAMP)
if BIWEEKLYBUDGET_TEST_TIMESTAMP is None:
return 'var BIWEEKLYBUDGET_DEFAULT_DATE = new Date();'
dt = dtnow()
return 'var BIWEEKLYBUDGET_DEFAULT_DATE = new Date(%s, %s, %s);' % (
dt.year, (dt.month - 1), dt.day
)


app.add_url_rule(
'/utils/datetest.js',
view_func=DateTestJS.as_view('date_test_js')
)
8 changes: 7 additions & 1 deletion biweeklybudget/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
]
_INT_VARS = [
'DEFAULT_ACCOUNT_ID',
'FUEL_BUDGET_ID'
'FUEL_BUDGET_ID',
'BIWEEKLYBUDGET_TEST_TIMESTAMP'
]
_STRING_VARS = [
'DB_CONNSTRING',
Expand Down Expand Up @@ -110,6 +111,11 @@
#: string - *(optional)* Address to connect to Vault at, for OFX credentials.
VAULT_ADDR = None

#: int - FOR ACCEPTANCE TESTS ONLY - This is used to "fudge" the current time
#: to the specified integer timestamp. Used for acceptance tests only. Do NOT
#: set this outside of acceptance testing.
BIWEEKLYBUDGET_TEST_TIMESTAMP = None

if 'SETTINGS_MODULE' in os.environ:
logger.debug('Attempting to import settings module %s',
os.environ['SETTINGS_MODULE'])
Expand Down

0 comments on commit e3896fb

Please sign in to comment.