Skip to content

Commit e3d8e28

Browse files
committed
#99 refactor finance views
1 parent 4314f1c commit e3d8e28

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

core/views/ofm/finance_views.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,27 @@ def _get_chart_json(request, finance_method):
158158
current_season_number = Matchday.objects.all()[0].season.number
159159
season_number = request.GET.get('season_number', default=current_season_number)
160160
finances_this_season = Finance.objects.filter(user=request.user, matchday__season__number=season_number)
161+
162+
chart_json = {
163+
"series": finance_method(_get_finance_diffs(finances_this_season)),
164+
"categories": _get_matchdays_from_existing_finances(finances_this_season)
165+
}
166+
return chart_json
167+
168+
169+
def _get_finance_diffs(finances_this_season):
161170
diffs = []
162-
matchdays = []
163171
if len(finances_this_season) >= 1:
164172
first_finance_diff = finances_this_season[0].diff(Finance())
165-
166173
diffs.append(first_finance_diff)
167-
matchdays.append(finances_this_season[0].matchday.number)
168174
for idx, _ in enumerate(finances_this_season):
169175
if idx + 1 < finances_this_season.count():
170176
diffs.append(finances_this_season[idx].diff(finances_this_season[idx + 1]))
171-
matchdays.append(finances_this_season[idx + 1].matchday.number)
172-
series = finance_method(diffs)
173-
chart_json = {
174-
"series": series,
175-
"categories": matchdays
176-
}
177-
return chart_json
177+
return diffs
178+
179+
180+
def _get_matchdays_from_existing_finances(finances_this_season):
181+
return [finance.matchday.number for finance in finances_this_season]
178182

179183

180184
def _get_finance_attribute_json(name, finance_data):

0 commit comments

Comments
 (0)