def settings(request): """Build context for settings page.""" context = { 'num_transactions': db.get_transaction_count(request.user), 'num_balances': db.get_balances(request.user).count(), } # User account form context['user_form'] = forms.UserEditForm( web.form_data(request), instance=request.user ) context['password_form'] = forms.PasswordChangeForm( web.form_data(request) ) # Person forms context['person_form'] = forms.PersonForm( web.form_data(request), instance=request.user.person ) # Exchange rates context['exchange_rates'] = db.get_exchange_rates(request.user) context['exchange_rate_form'] = forms.ExchangeRateForm( web.form_data(request) ) return web.render_context(request, 'settings.html', context=context)
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)
def run(self): """Run over all users and find chains of balances which will resolve down to lower balances. """ users = models.User.objects.filter(is_active=True).all() for user in users: self.log.debug("Resolving balances for %s" % user) balances = db.get_balances(user, credited=False) self.resolve_balances(balances)
def export_data(request): """Export all data for a user.""" data = { 'balances': [ balance.export_data() for balance in db.get_balances(request.user) ], 'transfers': [ transfer.export_data() for transfer in db.get_transfer_history(request.user, {}) ], 'exchange_rates': [ rate.export_data() for rate in db.get_exchange_rates(request.user) ] } return HttpResponse(json.dumps(data), mimetype="application/json")