def build_pending_trans_records(request): """Supplement the pending trans records with a modify form and attempt to link them to any trans_records created by the user. """ recent_pending = db.get_recent_trans_for_user( request.user, limit=100, pending_only=True) pending_trans_records = db.get_pending_trans_for_user(request.user) for trans_record in pending_trans_records: cur_user_trans_record = None if trans_record.transaction: cur_user_trans_record = trans_record.other_trans_record trans_record.modify_form = forms.TransactionRecordForm( initial={ 'transaction_time': trans_record.transaction_time, 'currency': trans_record.currency.id, 'target_person': trans_record.creator_person.id, 'value': trans_record.value_str, 'from_receiver': trans_record.targets_transaction_type, }, instance=cur_user_trans_record ) trans_record.approve_with_record = trans_matcher.find_similar( recent_pending, trans_record ) yield trans_record
def home(request): """Setup homepage context.""" context = {} # New Transaction form new_trans_form_data = request.POST if request.method == 'POST' else None context['new_transaction_form'] = forms.TransactionRecordForm( web.form_data(request), initial={ 'currency': request.user.person.default_currency, 'transaction_time': datetime.datetime.now().strftime('%x %X') } ) context['pending_trans_records'] = list(build_pending_trans_records(request)) # Recent transactions, that may be confirmed context['recent_trans_records'] = db.get_recent_trans_for_user(request.user) # Currency balances context['balances'] = db.get_balances(request.user) # Notifications for recent news, transactions, balances context['notifications'] = get_notification_list(request.user) return web.render_context(request, 'home.html', context=context)