Skip to content

Commit

Permalink
Turned the cart template tag into a classytag, because being classy i…
Browse files Browse the repository at this point in the history
…s good ;-)
  • Loading branch information
Jonas Obrist committed Apr 5, 2011
1 parent 42082bb commit a943452
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
classifiers=CLASSIFIERS,
install_requires=[
'Django>=1.2',
'django-classy-tags>=0.3.3',
],
packages=find_packages(exclude=["example", "example.*"]),
zip_safe = False
Expand Down
17 changes: 11 additions & 6 deletions shop/templatetags/shop_tags.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# -*- coding: utf-8 -*-
from django import template
from classytags.helpers import InclusionTag

from shop.util.cart import get_or_create_cart


register = template.Library()


@register.inclusion_tag('shop/templatetags/_cart.html', takes_context=True)
def cart(context):
class Cart(InclusionTag):
'''
Inclusion tag for displaying cart summary.
'''
cart = get_or_create_cart(context['request'])
return {
'cart': cart,
}
template = 'shop/templatetags/_cart.html'

def get_context(self, context):
cart = get_or_create_cart(context['request'])
return {
'cart': cart
}
register.tag(Cart)

0 comments on commit a943452

Please sign in to comment.