def get_total_balance(request, year=None, month=None): if not request.user.is_authenticated(): raise PermissionDenied current = get_past_time(use_view=True) try: year = int(year) except (TypeError, ValueError): year = current.year if month is None: months = [x for x in range(1, 13)] else: try: months = [int(month)] except (TypeError, ValueError): months = [current.month] output = [] for month in months: start = datetime(year, month, 1).replace(tzinfo=utc) end = datetime(year, month, calendar.mdays[month]).replace(tzinfo=utc) output.append(functions.get_total_balance_by_date(month, year)) return create_json_response(output, request)
def get_latest_total_balance(request): if not request.user.is_authenticated(): raise PermissionDenied current = get_past_time(use_view=True) year = current.year month = current.month output = dict([('month', month), ('year', year)] + functions.get_total_balance_by_date(month, year).items()) return create_json_response(output, request)