Example #1
0
    def test_stripquotes_get_args(self):
        args, kwargs = get_filter_args('"test",one="test",two=2', stripquotes=True)
        self.assertEqual(args[0], 'test')

        self.assertEqual(kwargs['one'], 'test')

        self.assertEqual(kwargs['two'], '2')

        args, kwargs = get_filter_args('"test",one="test",two=2', stripquotes=False)
        self.assertEqual(args[0], '"test"')

        self.assertEqual(kwargs['one'], '"test"')
Example #2
0
    def test_stripquotes_get_args(self):
        args, kwargs = get_filter_args('"test",one="test",two=2', stripquotes=True)
        self.assertEqual(args[0], "test")

        self.assertEqual(kwargs["one"], "test")

        self.assertEqual(kwargs["two"], "2")

        args, kwargs = get_filter_args('"test",one="test",two=2', stripquotes=False)
        self.assertEqual(args[0], '"test"')

        self.assertEqual(kwargs["one"], '"test"')
Example #3
0
    def test_stripquotes_get_args(self):
        args, kwargs = get_filter_args('"test",one="test",two=2',
                                       stripquotes=True)
        self.assertEqual(args[0], "test")

        self.assertEqual(kwargs["one"], "test")

        self.assertEqual(kwargs["two"], "2")

        args, kwargs = get_filter_args('"test",one="test",two=2',
                                       stripquotes=False)
        self.assertEqual(args[0], '"test"')

        self.assertEqual(kwargs["one"], '"test"')
Example #4
0
    def test_stripquotes_get_args(self):
        args, kwargs = get_filter_args('"test",one="test",two=2',
                                       stripquotes=True)
        self.assertEqual(args[0], 'test')

        self.assertEqual(kwargs['one'], 'test')

        self.assertEqual(kwargs['two'], '2')

        args, kwargs = get_filter_args('"test",one="test",two=2',
                                       stripquotes=False)
        self.assertEqual(args[0], '"test"')

        self.assertEqual(kwargs['one'], '"test"')
Example #5
0
    def test_keystrip_get_args(self):
        args, kwargs = get_filter_args("test,one=1,two=2", ("one"), ("one"))
        self.assertEqual(args[0], "test")

        self.assertEqual(kwargs["one"], 1)

        self.assertFalse("two" in kwargs)
Example #6
0
    def test_numerical_get_args(self):
        args, kwargs = get_filter_args("test,one=1,two=2", (), ("one", "two"))
        self.assertEqual(args[0], "test")

        self.assertEqual(kwargs["one"], 1)

        self.assertEqual(kwargs["two"], 2)
Example #7
0
    def test_numerical_get_args(self):
        args, kwargs = get_filter_args("test,one=1,two=2", (), ("one", "two"))
        self.assertEqual(args[0], "test")

        self.assertEqual(kwargs["one"], 1)

        self.assertEqual(kwargs["two"], 2)
Example #8
0
    def test_simple_get_args(self):
        args, kwargs = get_filter_args("one=1,two=2")
        self.assertEqual(len(args), 0)

        self.assertEqual(kwargs["one"], "1")

        self.assertEqual(kwargs["two"], "2")
Example #9
0
    def test_numerical_get_args(self):
        args, kwargs = get_filter_args('test,one=1,two=2', (), ('one', 'two'))
        self.assertEqual(args[0], 'test')

        self.assertEqual(kwargs['one'], 1)

        self.assertEqual(kwargs['two'], 2)
Example #10
0
    def test_simple_get_args(self):
        args, kwargs = get_filter_args('one=1,two=2')
        self.assertEqual(len(args), 0)

        self.assertEqual(kwargs['one'], '1')

        self.assertEqual(kwargs['two'], '2')
Example #11
0
    def test_extended_get_args(self):
        args, kwargs = get_filter_args('test,one=1,two=2')
        self.assertEqual(args[0], 'test')

        self.assertEqual(kwargs['one'], '1')

        self.assertEqual(kwargs['two'], '2')
Example #12
0
    def test_numerical_get_args(self):
        args, kwargs = get_filter_args('test,one=1,two=2', (), ('one','two'))
        self.assertEqual(args[0], 'test')

        self.assertEqual(kwargs['one'], 1)

        self.assertEqual(kwargs['two'], 2)
Example #13
0
def currency(value, args=""):
    """Convert a value to a money formatted string.

    places:  required number of places after the decimal point
    curr:    optional currency symbol before the sign (may be blank)
    wrapcents:tag to wrap the part after the decimal point

    Usage:
        val|currency
        val|currency:'places=2'
        val|currency:'places=2:wrapcents=sup'
    """
    
    if value == '' or value is None:
        return value

    args, kwargs = get_filter_args(args, 
        keywords=('places','curr', 'wrapcents'),
        intargs=('places',), stripquotes=True)

    try:
        value = Decimal(str(value))
    except InvalidOperation:
        log.error("Could not convert value '%s' to decimal", value)
        raise
        
    if not 'places' in kwargs:
        kwargs['places'] = 2
        
    return mark_safe(moneyfmt(value, **kwargs))
Example #14
0
    def test_keystrip_get_args(self):
        args, kwargs = get_filter_args('test,one=1,two=2', ('one'), ('one'))
        self.assertEqual(args[0], 'test')

        self.assertEqual(kwargs['one'], 1)

        self.assertFalse('two' in kwargs)
Example #15
0
    def test_simple_get_args(self):
        args, kwargs = get_filter_args('one=1,two=2')
        self.assertEqual(len(args), 0)

        self.assertEqual(kwargs['one'], '1')

        self.assertEqual(kwargs['two'], '2')
Example #16
0
def currency(value, args=""):
    """Convert a value to a money formatted string.

    places:  required number of places after the decimal point
    curr:    optional currency symbol before the sign (may be blank)
    sep:     optional grouping separator (comma, period, space, or blank)
    dp:      decimal point indicator (comma or period)
             only specify as blank when places is zero
    pos:     optional sign for positive numbers: '+', space or blank
    neg:     optional sign for negative numbers: '-', '(', space or blank
    trailneg:optional trailing minus indicator:  '-', ')', space or blank
    wrapcents:tag to wrap the part after the decimal point

    Usage:
        val|currency
        val|currency:'places=2'
        val|currency:'places=2:wrapcents=sup'
    """
    
    if value == '':
        return value

    args, kwargs = get_filter_args(args, 
        keywords=('places','curr','sep','dp','pos','neg','trailneg','wrapcents'),
        intargs=('places',), stripquotes=True)

    value = Decimal(str(value))
        
    return moneyfmt(value, **kwargs)
Example #17
0
def currency(value, args=""):
    """Convert a value to a money formatted string.

    places:  required number of places after the decimal point
    curr:    optional currency symbol before the sign (may be blank)
    sep:     optional grouping separator (comma, period, space, or blank)
    dp:      decimal point indicator (comma or period)
             only specify as blank when places is zero
    pos:     optional sign for positive numbers: '+', space or blank
    neg:     optional sign for negative numbers: '-', '(', space or blank
    trailneg:optional trailing minus indicator:  '-', ')', space or blank
    wrapcents:tag to wrap the part after the decimal point

    Usage:
        val|currency
        val|currency:'places=2'
        val|currency:'places=2:wrapcents=sup'
    """

    if value == '':
        return value

    args, kwargs = get_filter_args(args,
                                   keywords=('places', 'curr', 'sep', 'dp',
                                             'pos', 'neg', 'trailneg',
                                             'wrapcents'),
                                   intargs=('places', ),
                                   stripquotes=True)

    value = Decimal(str(value))

    return moneyfmt(value, **kwargs)
Example #18
0
    def test_keystrip_get_args(self):
        args, kwargs = get_filter_args('test,one=1,two=2', ('one'), ('one'))
        self.assertEqual(args[0], 'test')

        self.assertEqual(kwargs['one'], 1)

        self.assertFalse('two' in kwargs)
Example #19
0
    def test_simple_get_args(self):
        args, kwargs = get_filter_args("one=1,two=2")
        self.assertEqual(len(args), 0)

        self.assertEqual(kwargs["one"], "1")

        self.assertEqual(kwargs["two"], "2")
Example #20
0
    def test_keystrip_get_args(self):
        args, kwargs = get_filter_args("test,one=1,two=2", ("one"), ("one"))
        self.assertEqual(args[0], "test")

        self.assertEqual(kwargs["one"], 1)

        self.assertFalse("two" in kwargs)
Example #21
0
    def test_extended_get_args(self):
        args, kwargs = get_filter_args("test,one=1,two=2")
        self.assertEqual(args[0], "test")

        self.assertEqual(kwargs["one"], "1")

        self.assertEqual(kwargs["two"], "2")
Example #22
0
    def test_extended_get_args(self):
        args, kwargs = get_filter_args("test,one=1,two=2")
        self.assertEqual(args[0], "test")

        self.assertEqual(kwargs["one"], "1")

        self.assertEqual(kwargs["two"], "2")
Example #23
0
    def test_extended_get_args(self):
        args, kwargs = get_filter_args('test,one=1,two=2')
        self.assertEqual(args[0], 'test')

        self.assertEqual(kwargs['one'], '1')

        self.assertEqual(kwargs['two'], '2')
Example #24
0
def product_category_siblings(product, args=""):
    args, kwargs = get_filter_args(
        args, keywords=("variations", "include_self"), boolargs=("variations", "include_self"), stripquotes=True
    )

    sibs = product.get_category.product_set.all().order_by("ordering", "name")
    if not kwargs.get("variations", True):
        sibs = [sib for sib in sibs if not sib.has_variants]

    if not kwargs.get("include_self", True):
        sibs = [sib for sib in sibs if not sib == product]

    return sibs
Example #25
0
def product_category_siblings(product, args=""):
    args, kwargs = get_filter_args(args,
        keywords=('variations', 'include_self'),
        boolargs=('variations', 'include_self'),
        stripquotes=True)

    sibs = product.get_category.product_set.all().order_by('ordering', 'name')
    if not kwargs.get('variations', True):
        sibs = [sib for sib in sibs if not sib.has_variants]

    if not kwargs.get('include_self', True):
        sibs = [sib for sib in sibs if not sib == product]

    return sibs
Example #26
0
def product_category_siblings(product, args=""):
    args, kwargs = get_filter_args(args,
                                   keywords=('variations', 'include_self'),
                                   boolargs=('variations', 'include_self'),
                                   stripquotes=True)

    sibs = product.get_category.product_set.all().order_by('ordering', 'name')
    if not kwargs.get('variations', True):
        sibs = [sib for sib in sibs if not sib.has_variants]

    if not kwargs.get('include_self', True):
        sibs = [sib for sib in sibs if not sib == product]

    return sibs
Example #27
0
def order_variable(order, args):
    """
    Get a variable from an order

    Sample usage::

      {{ order|order_variable:'variable' }}

    """
    args, kwargs = get_filter_args(args)
    args = token.split_contents()
    if not len(args == 1):
        raise template.TemplateSyntaxError("%r filter expected variable, got: %s" % (args[0], args))

    return order.get_variable(args[0])
Example #28
0
def product_category_siblings(product, args=""):
    args, kwargs = get_filter_args(
        args,
        keywords=("variations", "include_self"),
        boolargs=("variations", "include_self"),
        stripquotes=True,
    )

    sibs = product.get_category.product_set.all().order_by("ordering", "name")
    if not kwargs.get("variations", True):
        sibs = [sib for sib in sibs if not sib.has_variants]

    if not kwargs.get("include_self", True):
        sibs = [sib for sib in sibs if not sib == product]

    return sibs
Example #29
0
def order_variable(order, args):
    """
    Get a variable from an order

    Sample usage::

      {{ order|order_variable:'variable' }}

    """
    args, kwargs = get_filter_args(args)
    args = token.split_contents()
    if not len(args == 1):
        raise template.TemplateSyntaxError(
            "%r filter expected variable, got: %s" % (args[0], args))

    return order.get_variable(args[0])
Example #30
0
def product_count(category, args=''):
    """Get a count of products for the base object.

    If `category` is None, then count everything.
    If it is a `Category` object then count everything in the category and subcategories.
    """
    args, kwargs = get_filter_args(args, boolargs=('variations'))
    variations = kwargs.get('variations', False)
    try:
        ct = caching.cache_get('product_count', category, variations)
    except caching.NotCachedError:
        if not category:
            ct = Product.objects.active_by_site(variations=variations).count()
        else:
            ct = category.active_products(include_children=True, variations=variations).count()

        caching.cache_set('product_count', category, args, value=ct)
    return ct
Example #31
0
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
Example #32
0
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
Example #33
0
def product_count(category, args=''):
    """Get a count of products for the base object.

    If `category` is None, then count everything.
    If it is a `Category` object then count everything in the category and subcategories.
    """
    args, kwargs = get_filter_args(args, boolargs=('variations'))
    variations = kwargs.get('variations', False)
    try:
        ct = caching.cache_get('product_count', category, variations)
    except caching.NotCachedError:
        if not category:
            ct = Product.objects.active_by_site(variations=variations).count()
        else:
            ct = category.active_products(include_children=True,
                                          variations=variations).count()

        caching.cache_set('product_count', category, args, value=ct)
    return ct