Skip to content
Browse files

Allow viewing details of any account

The logic used to prepare the dropdown list of accounts is VERY SLOW and
needs to be refactored.
  • Loading branch information...
1 parent ed3bb7a commit a9d48e5458170c756b92a0e4c3b8a6dcab45cd17 @nylen committed Apr 2, 2012
Showing with 26 additions and 0 deletions.
  1. +12 −0 money_templates/templates/index.html
  2. +13 −0 money_views/views.py
  3. +1 −0 urls.py
View
12 money_templates/templates/index.html
@@ -9,5 +9,17 @@
{% for account in accounts %}
{% include "account_block.html" %}
{% endfor %}
+ <div class="block">
+ <form action="{% url money_views.views.any_account %}" method="get">
+ <label for="select-account">Other account:</label>
+ <select name="select_account" id="select-account">
+ <option value="" selected="selected">(Choose an account)</option>
+ {% for account in all_accounts %}
+ <option value="{{ account.guid }}">{{ account.path }}</option>
+ {% endfor %}
+ </select>
+ <input type="submit" value="Go" />
+ </form>
+ </div>
</body>
</html>
View
13 money_views/views.py
@@ -2,7 +2,9 @@
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
+from django.core.urlresolvers import reverse
from django.http import HttpResponse
+from django.shortcuts import redirect
from django.template import RequestContext, loader
import filters
@@ -24,14 +26,25 @@ def index(request):
template = loader.get_template('index.html')
accounts = [Account.from_path(path) for path in settings.ACCOUNTS_LIST]
+ all_accounts = list(Account.objects.all())
+ all_accounts.sort(key=lambda a: a.path())
+
c = RequestContext(request, {
'accounts': accounts,
+ 'all_accounts': all_accounts,
'show_account_links': True,
})
return HttpResponse(template.render(c))
@login_required
+def any_account(request):
+ return redirect(reverse(
+ 'money_views.views.account',
+ kwargs={'key': request.GET.get('select_account', '')}))
+
+
+@login_required
def account(request, key):
template = loader.get_template('account_details.html')
View
1 urls.py
@@ -6,6 +6,7 @@
urlpatterns = patterns('',
(r'^$', 'money_views.views.index'),
+ (r'^any_account$', 'money_views.views.any_account'),
(r'^accounts/(?P<key>[0-9a-f]+)$', 'money_views.views.account'),
(r'^accounts/(?P<key>[0-9a-f]+)/modify$', 'money_views.views.modify'),
(r'^accounts/(?P<key>[0-9a-f]+)/categorize$', 'money_views.views.batch_categorize'),

0 comments on commit a9d48e5

Please sign in to comment.
Something went wrong with that request. Please try again.