1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

# -*- coding: utf-8 -*- 

from django import template 

 

from classytags.helpers import InclusionTag 

from classytags.core import Options 

from classytags.arguments import Argument 

 

from shop.util.cart import get_or_create_cart 

 

 

register = template.Library() 

 

 

class Cart(InclusionTag): 

    """ 

    Inclusion tag for displaying cart summary. 

    """ 

    template = 'shop/templatetags/_cart.html' 

 

    def get_context(self, context): 

        cart = get_or_create_cart(context['request']) 

        return { 

            'cart': cart 

        } 

register.tag(Cart) 

 

 

class Order(InclusionTag): 

    """ 

    Inclusio tag for displaying order. 

    """ 

    template = 'shop/templatetags/_order.html' 

    options = Options( 

        Argument('order', resolve=True), 

        ) 

 

    def get_context(self, context, order): 

        return { 

            'order': order 

        } 

register.tag(Order)