Source

django-pim / pcbank / templatetags / pcbank_extras.py

Full commit
# -*- coding: utf-8 -*-
from django import template
from django.template import Context
from pcbank.models import Bank, CreditCard, Bill, Transaction

register = template.Library()

@register.simple_tag
def bank_list():
    """
    Generates a dropdown list of all the currently active bank accounts.

    Usage::

        {% bank_list %}
    """
    bank_list = Bank.objects.filter(active=True)
    t = template.loader.get_template('pcbank/bank_dropdown.html')
    return t.render(Context({'bank_list':bank_list}))

@register.simple_tag
def cc_list():
    """
    Generates a dropdown list of all the currently active credit cards.

    Usage::

        {% cc_list %}
    """
    cc_list = CreditCard.objects.filter(active=True)
    t = template.loader.get_template('pcbank/cc_dropdown.html')
    return t.render(Context({'cc_list':cc_list}))

@register.simple_tag
def bill_list():
    """
    Generates a dropdown list of all the currently active bills.

    Usage::

        {% bill_list %}
    """
    bill_list = Bill.objects.filter(paid=False, payee__split_by__gt=1)
    t = template.loader.get_template('pcbank/bill_dropdown.html')
    return t.render(Context({'bill_list':bill_list}))

@register.inclusion_tag('pcbank/transaction_dropdown.html')
def transaction_list(amount):
    transaction_list = Transaction.objects.filter(amount=amount)
    return {'transaction_list':transaction_list}