from django import template
from django.conf import settings
from django.core import urlresolvers
from django.template import Context, Template
from django.utils.translation import get_language, ugettext_lazy as _
from satchmo.configuration import config_value
from satchmo.product.models import Category
from satchmo.shop.templatetags import get_filter_args

register = template.Library()

def is_producttype(product, ptype):
    """Returns True if product is ptype"""
    if ptype in product.get_subtypes():
        return "true"
    else:
        return ""

register.filter('is_producttype', is_producttype)

def product_images(product, args=""):
    args, kwargs = get_filter_args(args, 
        keywords=('include_main', 'maximum'), 
        boolargs=('include_main'),
        intargs=('maximum'),
        stripquotes=True)

    q = product.productimage_set
    if kwargs.get('include_main', True):
        q = q.all()
    else:
        main = product.main_image
        q = q.exclude(id = main.id)
    
    maximum = kwargs.get('maximum', -1)
    if maximum>-1:
        q = list(q)[:maximum]
    
    return q

register.filter('product_images', product_images)

def smart_attr(product, key):
    """Run the smart_attr function on the spec'd product
    """
    return product.smart_attr(key)
    
register.filter('smart_attr', smart_attr)

from django import template
from django.conf import settings
from django.core import urlresolvers
from django.template import Context, Template
from django.utils.translation import get_language, ugettext_lazy as _
from satchmo.configuration import config_value
from satchmo.product.models import Category
from satchmo.shop.templatetags import get_filter_args

register = template.Library()

def is_producttype(product, ptype):
    """Returns True if product is ptype"""
    if ptype in product.get_subtypes():
        return True
    else:
        return False

register.filter('is_producttype', is_producttype)

def product_images(product, args=""):
    args, kwargs = get_filter_args(args,
        keywords=('include_main', 'maximum'),
        boolargs=('include_main'),
        intargs=('maximum'),
        stripquotes=True)

    q = product.productimage_set
    if kwargs.get('include_main', True):
        q = q.all()
    else:
        main = product.main_image
        q = q.exclude(id = main.id)

    maximum = kwargs.get('maximum', -1)
    if maximum>-1:
        q = list(q)[:maximum]

    return q

register.filter('product_images', product_images)

def smart_attr(product, key):
    """Run the smart_attr function on the spec'd product
    """
    return product.smart_attr(key)

register.filter('smart_attr', smart_attr)

Change the is_producttype template tag to return a boolean rather than a string.
Change the is_producttype template tag to return a boolean rather than a string.

  from django import template
  from django.conf import settings
  from django.core import urlresolvers
  from django.template import Context, Template
  from django.utils.translation import get_language, ugettext_lazy as _
  from satchmo.configuration import config_value
  from satchmo.product.models import Category
  from satchmo.shop.templatetags import get_filter_args
  
  register = template.Library()
  
  def is_producttype(product, ptype):
      """Returns True if product is ptype"""
      if ptype in product.get_subtypes():
-         return "true"
+         return True
      else:
-         return ""
+         return False
  
  register.filter('is_producttype', is_producttype)
  
  def product_images(product, args=""):
-     args, kwargs = get_filter_args(args, 
+     args, kwargs = get_filter_args(args,
-         keywords=('include_main', 'maximum'), 
+         keywords=('include_main', 'maximum'),
          boolargs=('include_main'),
          intargs=('maximum'),
          stripquotes=True)
  
      q = product.productimage_set
      if kwargs.get('include_main', True):
          q = q.all()
      else:
          main = product.main_image
          q = q.exclude(id = main.id)
-     
+ 
      maximum = kwargs.get('maximum', -1)
      if maximum>-1:
          q = list(q)[:maximum]
-     
+ 
      return q
  
  register.filter('product_images', product_images)
  
  def smart_attr(product, key):
      """Run the smart_attr function on the spec'd product
      """
      return product.smart_attr(key)
-     
+ 
  register.filter('smart_attr', smart_attr)
  
Change the is_producttype template tag to return a boolean rather than a string.
## Code Before:
from django import template
from django.conf import settings
from django.core import urlresolvers
from django.template import Context, Template
from django.utils.translation import get_language, ugettext_lazy as _
from satchmo.configuration import config_value
from satchmo.product.models import Category
from satchmo.shop.templatetags import get_filter_args

register = template.Library()

def is_producttype(product, ptype):
    """Returns True if product is ptype"""
    if ptype in product.get_subtypes():
        return "true"
    else:
        return ""

register.filter('is_producttype', is_producttype)

def product_images(product, args=""):
    args, kwargs = get_filter_args(args, 
        keywords=('include_main', 'maximum'), 
        boolargs=('include_main'),
        intargs=('maximum'),
        stripquotes=True)

    q = product.productimage_set
    if kwargs.get('include_main', True):
        q = q.all()
    else:
        main = product.main_image
        q = q.exclude(id = main.id)
    
    maximum = kwargs.get('maximum', -1)
    if maximum>-1:
        q = list(q)[:maximum]
    
    return q

register.filter('product_images', product_images)

def smart_attr(product, key):
    """Run the smart_attr function on the spec'd product
    """
    return product.smart_attr(key)
    
register.filter('smart_attr', smart_attr)

## Instruction:
Change the is_producttype template tag to return a boolean rather than a string.
## Code After:
from django import template
from django.conf import settings
from django.core import urlresolvers
from django.template import Context, Template
from django.utils.translation import get_language, ugettext_lazy as _
from satchmo.configuration import config_value
from satchmo.product.models import Category
from satchmo.shop.templatetags import get_filter_args

register = template.Library()

def is_producttype(product, ptype):
    """Returns True if product is ptype"""
    if ptype in product.get_subtypes():
        return True
    else:
        return False

register.filter('is_producttype', is_producttype)

def product_images(product, args=""):
    args, kwargs = get_filter_args(args,
        keywords=('include_main', 'maximum'),
        boolargs=('include_main'),
        intargs=('maximum'),
        stripquotes=True)

    q = product.productimage_set
    if kwargs.get('include_main', True):
        q = q.all()
    else:
        main = product.main_image
        q = q.exclude(id = main.id)

    maximum = kwargs.get('maximum', -1)
    if maximum>-1:
        q = list(q)[:maximum]

    return q

register.filter('product_images', product_images)

def smart_attr(product, key):
    """Run the smart_attr function on the spec'd product
    """
    return product.smart_attr(key)

register.filter('smart_attr', smart_attr)
