Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
def transaction_list(request):
	"""List transactions."""
	context = {}
	context['filter_form'] = filter_form = forms.TransferListForm(request.GET)
	filters = filter_form.cleaned_data if filter_form.is_valid() else {}

	context['records'] = db.get_transfer_history(request.user, filters)
	return web.render_context(request, 'transaction_list.html', context=context)
Exemple #4
0
def news(request):
	"""Get latest news posts."""
	news = models.NewsPost.objects.filter(
		site=config.SITE_ID,
	).order_by('-time_created')[:20]
	content = models.Content.objects.get(name='news_header', site=config.SITE_ID)

	context = {
		'news_posts': news,
		'header': content
	}
	return web.render_context(request, 'news.html', context=context)
Exemple #5
0
def index(request):
	if request.user.is_authenticated():
		return redirect('home')

	intro = models.Content.objects.get(name='intro', site=config.SITE_ID)
	context = {
		'login_form': forms.LoginForm(),
		'user_form': forms.UserCreateForm(web.form_data(request)),
		'intro': intro,
		'site': Site.objects.get(id=config.SITE_ID) 
	}
	return web.render_context(request, 'index.html', context=context)
Exemple #6
0
def content_view(request, name):
	"""Get a piece of content by name."""
	content = models.Content.objects.get(name=name, site=config.SITE_ID)
	return web.render_context(request, 'content.html',
		context={'content': content}
	)