<s> import math <EOL> from django . forms . forms import BoundField <EOL> import locale <EOL> from django import template <EOL> from django . conf import settings <EOL> from django . core . cache import cache <EOL> from django . core . exceptions import ObjectDoesNotExist <EOL> from django . core . urlresolvers import reverse <EOL> from django . template import Node , TemplateSyntaxError <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> import lfs . catalog . utils <EOL> import lfs . core . utils <EOL> import lfs . core . views <EOL> import lfs . utils . misc <EOL> import logging <EOL> from lfs . caching . utils import get_cache_group_id <EOL> from lfs . catalog . models import Category <EOL> from lfs . catalog . settings import VARIANT <EOL> from lfs . catalog . settings import CATEGORY_VARIANT_CHEAPEST_PRICES <EOL> from lfs . catalog . settings import SORTING_MAP <EOL> from lfs . catalog . models import Product <EOL> from lfs . catalog . models import PropertyOption <EOL> from lfs . catalog . settings import PRODUCT_TYPE_LOOKUP <EOL> from lfs . core . models import Action <EOL> from lfs . page . models import Page <EOL> from lfs . shipping import utils as shipping_utils <EOL> from lfs . manufacturer . models import Manufacturer <EOL> logger = logging . getLogger ( __name__ ) <EOL> register = template . Library ( ) <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def category_children ( context , categories ) : <EOL> """<STR_LIT:U+0020>""" <EOL> return { "<STR_LIT>" : categories } <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def google_analytics_tracking ( context ) : <EOL> """<STR_LIT>""" <EOL> shop = lfs . core . utils . get_default_shop ( context . get ( "<STR_LIT>" ) ) <EOL> return { <EOL> "<STR_LIT>" : shop . ga_site_tracking , <EOL> "<STR_LIT>" : shop . google_analytics_id , <EOL> } <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def google_analytics_ecommerce ( context , clear_session = True ) : <EOL> """<STR_LIT>""" <EOL> request = context . get ( "<STR_LIT>" ) <EOL> order = request . session . get ( "<STR_LIT>" ) <EOL> shop = lfs . core . utils . get_default_shop ( request ) <EOL> if clear_session and "<STR_LIT>" in request . session : <EOL> del request . session [ "<STR_LIT>" ] <EOL> if "<STR_LIT>" in request . session : <EOL> del request . session [ "<STR_LIT>" ] <EOL> return { <EOL> "<STR_LIT>" : request , <EOL> "<STR_LIT>" : order , <EOL> "<STR_LIT>" : shop , <EOL> "<STR_LIT>" : shop . ga_ecommerce_tracking , <EOL> "<STR_LIT>" : shop . google_analytics_id , <EOL> } <EOL> def _get_shipping ( context , product ) : <EOL> request = context . get ( "<STR_LIT>" ) <EOL> if product . is_deliverable ( ) == False : <EOL> return { <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : shipping_utils . get_product_delivery_time ( request , product ) <EOL> } <EOL> else : <EOL> return { <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : shipping_utils . get_product_delivery_time ( request , product ) <EOL> } <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def shipping ( context , variant ) : <EOL> return _get_shipping ( context , variant ) <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def sorting ( context ) : <EOL> """<STR_LIT:U+0020>""" <EOL> request = context . get ( "<STR_LIT>" ) <EOL> sorting = request . session . get ( "<STR_LIT>" ) <EOL> sort_options = [ ] <EOL> for item in SORTING_MAP : <EOL> sort_options . append ( item ) <EOL> return { "<STR_LIT>" : sorting , "<STR_LIT>" : sort_options } <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def breadcrumbs ( context , obj , current_page = '<STR_LIT>' ) : <EOL> """<STR_LIT:U+0020>""" <EOL> if isinstance ( obj , Category ) : <EOL> cache_key = "<STR_LIT>" % ( settings . CACHE_MIDDLEWARE_KEY_PREFIX , obj . slug ) <EOL> objects = cache . get ( cache_key ) <EOL> if objects is not None : <EOL> return objects <EOL> objects = [ current_page ] if current_page else [ ] <EOL> while obj is not None : <EOL> objects . insert ( <NUM_LIT:0> , { <EOL> "<STR_LIT:name>" : obj . name , <EOL> "<STR_LIT:url>" : obj . get_absolute_url ( ) , <EOL> } ) <EOL> obj = obj . parent <EOL> result = { <EOL> "<STR_LIT>" : objects , <EOL> "<STR_LIT>" : context . get ( "<STR_LIT>" ) , <EOL> } <EOL> cache . set ( cache_key , result ) <EOL> elif isinstance ( obj , Product ) : <EOL> request = context . get ( "<STR_LIT>" ) <EOL> objects = [ { <EOL> "<STR_LIT:name>" : obj . get_name ( ) , <EOL> "<STR_LIT:url>" : obj . get_absolute_url ( ) , <EOL> } ] <EOL> lm = request . session . get ( '<STR_LIT>' ) <EOL> if lm and obj . manufacturer == lm : <EOL> objects . insert ( <NUM_LIT:0> , { <EOL> "<STR_LIT:name>" : lm . name , <EOL> "<STR_LIT:url>" : lm . get_absolute_url ( ) , <EOL> } ) <EOL> objects . insert ( <NUM_LIT:0> , { <EOL> "<STR_LIT:name>" : _ ( u"<STR_LIT>" ) , <EOL> "<STR_LIT:url>" : reverse ( "<STR_LIT>" ) } ) <EOL> else : <EOL> category = obj . get_current_category ( request ) <EOL> if category : <EOL> while category is not None : <EOL> objects . insert ( <NUM_LIT:0> , { <EOL> "<STR_LIT:name>" : category . name , <EOL> "<STR_LIT:url>" : category . get_absolute_url ( ) , <EOL> } ) <EOL> category = category . parent <EOL> result = { <EOL> "<STR_LIT>" : objects , <EOL> "<STR_LIT>" : context . get ( "<STR_LIT>" ) , <EOL> } <EOL> elif isinstance ( obj , Page ) : <EOL> objects = [ ] <EOL> objects . append ( { <EOL> "<STR_LIT:name>" : _ ( u"<STR_LIT>" ) , <EOL> "<STR_LIT:url>" : reverse ( "<STR_LIT>" ) } ) <EOL> objects . append ( { "<STR_LIT:name>" : obj . title } ) <EOL> result = { <EOL> "<STR_LIT>" : objects , <EOL> "<STR_LIT>" : context . get ( "<STR_LIT>" ) , <EOL> } <EOL> elif isinstance ( obj , Manufacturer ) : <EOL> objects = [ ] <EOL> objects . append ( { <EOL> "<STR_LIT:name>" : _ ( u"<STR_LIT>" ) , <EOL> "<STR_LIT:url>" : reverse ( "<STR_LIT>" ) } ) <EOL> objects . append ( { "<STR_LIT:name>" : obj . name } ) <EOL> result = { <EOL> "<STR_LIT>" : objects , <EOL> "<STR_LIT>" : context . get ( "<STR_LIT>" ) , <EOL> } <EOL> else : <EOL> result = { <EOL> "<STR_LIT>" : ( { "<STR_LIT:name>" : obj } , ) , <EOL> "<STR_LIT>" : context . get ( "<STR_LIT>" ) , <EOL> } <EOL> return result <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def product_navigation ( context , product ) : <EOL> """<STR_LIT>""" <EOL> request = context . get ( "<STR_LIT>" ) <EOL> try : <EOL> default_sorting = settings . LFS_PRODUCTS_SORTING <EOL> except AttributeError : <EOL> default_sorting = "<STR_LIT>" <EOL> sorting = request . session . get ( "<STR_LIT>" , default_sorting ) <EOL> if sorting . strip ( ) == '<STR_LIT>' : <EOL> sorting = '<STR_LIT>' <EOL> request . session [ "<STR_LIT>" ] = sorting <EOL> slug = product . slug <EOL> if product . is_variant ( ) : <EOL> product = product . parent <EOL> slug = product . slug <EOL> pn_cache_key = get_cache_group_id ( '<STR_LIT>' ) <EOL> lm = request . session . get ( '<STR_LIT>' ) <EOL> if lm and product . manufacturer == lm : <EOL> cache_key = "<STR_LIT>" % ( settings . CACHE_MIDDLEWARE_KEY_PREFIX , <EOL> pn_cache_key , <EOL> slug ) <EOL> res = cache . get ( cache_key ) <EOL> if res and sorting in res : <EOL> return res [ sorting ] <EOL> products = Product . objects . filter ( manufacturer = lm ) <EOL> else : <EOL> category = product . get_current_category ( request ) <EOL> if category is None : <EOL> return { "<STR_LIT>" : False } <EOL> else : <EOL> cache_key = "<STR_LIT>" % ( settings . CACHE_MIDDLEWARE_KEY_PREFIX , <EOL> pn_cache_key , <EOL> slug ) <EOL> res = cache . get ( cache_key ) <EOL> if res and sorting in res : <EOL> return res [ sorting ] <EOL> categories = [ category ] <EOL> if category . show_all_products : <EOL> categories . extend ( category . get_all_children ( ) ) <EOL> products = Product . objects . filter ( categories__in = categories ) <EOL> if not request . user . is_superuser : <EOL> products = products . filter ( active = True ) <EOL> products = products . exclude ( sub_type = VARIANT ) . distinct ( ) . order_by ( sorting ) <EOL> product_slugs = list ( products . values_list ( '<STR_LIT>' , flat = True ) ) <EOL> product_index = product_slugs . index ( slug ) <EOL> if product_index > <NUM_LIT:0> : <EOL> previous = product_slugs [ product_index - <NUM_LIT:1> ] <EOL> else : <EOL> previous = None <EOL> total = len ( product_slugs ) <EOL> if product_index < total - <NUM_LIT:1> : <EOL> next_product = product_slugs [ product_index + <NUM_LIT:1> ] <EOL> else : <EOL> next_product = None <EOL> result = { <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : previous , <EOL> "<STR_LIT>" : next_product , <EOL> "<STR_LIT>" : product_index + <NUM_LIT:1> , <EOL> "<STR_LIT>" : total , <EOL> "<STR_LIT>" : context . get ( "<STR_LIT>" ) , <EOL> } <EOL> cache . set ( cache_key , { '<STR_LIT>' : result } ) <EOL> return result <EOL> class ActionsNode ( Node ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , group_name ) : <EOL> self . group_name = group_name <EOL> def render ( self , context ) : <EOL> request = context . get ( "<STR_LIT>" ) <EOL> context [ "<STR_LIT>" ] = Action . objects . filter ( active = True , group__name = self . group_name ) <EOL> return '<STR_LIT>' <EOL> def do_actions ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> len_bits = len ( bits ) <EOL> if len_bits != <NUM_LIT:2> : <EOL> raise TemplateSyntaxError ( _ ( '<STR_LIT>' ) % bits [ <NUM_LIT:0> ] ) <EOL> return ActionsNode ( bits [ <NUM_LIT:1> ] ) <EOL> register . tag ( '<STR_LIT>' , do_actions ) <EOL> class CheapestVariantNode ( Node ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , product_id ) : <EOL> self . product_id = template . Variable ( product_id ) <EOL> def render ( self , context ) : <EOL> product_id = self . product_id . resolve ( context ) <EOL> request = context . get ( "<STR_LIT>" ) <EOL> cheapest_variant = None <EOL> min_price = None <EOL> for variant in Product . objects . filter ( parent__id = product_id ) : <EOL> price = variant . get_price_gross ( request ) <EOL> if price == <NUM_LIT:0> : <EOL> continue <EOL> if ( min_price is None ) or ( price < min_price ) : <EOL> cheapest_variant = variant <EOL> min_price = price <EOL> context [ "<STR_LIT>" ] = cheapest_variant <EOL> return "<STR_LIT>" <EOL> def do_cheapest_variant ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> len_bits = len ( bits ) <EOL> if len_bits != <NUM_LIT:2> : <EOL> raise TemplateSyntaxError ( '<STR_LIT>' % bits [ <NUM_LIT:0> ] ) <EOL> return CheapestVariantNode ( bits [ <NUM_LIT:1> ] ) <EOL> register . tag ( '<STR_LIT>' , do_cheapest_variant ) <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def tabs ( context , obj = None ) : <EOL> """<STR_LIT:U+0020>""" <EOL> if obj is None : <EOL> obj = context . get ( "<STR_LIT>" ) or context . get ( "<STR_LIT>" ) <EOL> request = context . get ( "<STR_LIT>" ) <EOL> tabs = Action . objects . filter ( active = True , group = <NUM_LIT:1> ) <EOL> if isinstance ( obj , ( Product , Category ) ) : <EOL> top_category = lfs . catalog . utils . get_current_top_category ( request , obj ) <EOL> if top_category : <EOL> for tab in tabs : <EOL> if top_category . get_absolute_url ( ) . find ( tab . link ) != - <NUM_LIT:1> : <EOL> tab . selected = True <EOL> break <EOL> else : <EOL> for tab in tabs : <EOL> if request . path . find ( tab . link ) != - <NUM_LIT:1> : <EOL> tab . selected = True <EOL> break <EOL> return { <EOL> "<STR_LIT>" : tabs , <EOL> "<STR_LIT>" : context . get ( "<STR_LIT>" ) , <EOL> } <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def top_level_categories ( context ) : <EOL> """<STR_LIT>""" <EOL> request = context . get ( "<STR_LIT>" ) <EOL> obj = context . get ( "<STR_LIT>" ) or context . get ( "<STR_LIT>" ) <EOL> categories = [ ] <EOL> top_category = lfs . catalog . utils . get_current_top_category ( request , obj ) <EOL> for category in Category . objects . filter ( parent = None ) [ : <NUM_LIT:4> ] : <EOL> if top_category : <EOL> current = top_category . id == category . id <EOL> else : <EOL> current = False <EOL> categories . append ( { <EOL> "<STR_LIT:url>" : category . get_absolute_url ( ) , <EOL> "<STR_LIT:name>" : category . name , <EOL> "<STR_LIT>" : current , <EOL> } ) <EOL> return { <EOL> "<STR_LIT>" : categories , <EOL> } <EOL> class TopLevelCategory ( Node ) : <EOL> """<STR_LIT>""" <EOL> def render ( self , context ) : <EOL> request = context . get ( "<STR_LIT>" ) <EOL> obj = context . get ( "<STR_LIT>" ) or context . get ( "<STR_LIT>" ) <EOL> top_level_category = lfs . catalog . utils . get_current_top_category ( request , obj ) <EOL> context [ "<STR_LIT>" ] = top_level_category . name <EOL> return '<STR_LIT>' <EOL> def do_top_level_category ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> len_bits = len ( bits ) <EOL> if len_bits != <NUM_LIT:1> : <EOL> raise TemplateSyntaxError ( _ ( '<STR_LIT>' ) % bits [ <NUM_LIT:0> ] ) <EOL> return TopLevelCategory ( ) <EOL> register . tag ( '<STR_LIT>' , do_top_level_category ) <EOL> class CartInformationNode ( Node ) : <EOL> """<STR_LIT:U+0020>""" <EOL> def render ( self , context ) : <EOL> request = context . get ( "<STR_LIT>" ) <EOL> cart = lfs . cart . utils . get_cart ( request ) <EOL> if cart is None : <EOL> amount_of_items = <NUM_LIT:0> <EOL> price = <NUM_LIT:0.0> <EOL> else : <EOL> amount_of_items = cart . get_amount_of_items ( ) <EOL> price = cart . get_price_gross ( request , total = True ) <EOL> context [ "<STR_LIT>" ] = amount_of_items <EOL> context [ "<STR_LIT>" ] = price <EOL> return '<STR_LIT>' <EOL> def do_cart_information ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> len_bits = len ( bits ) <EOL> if len_bits != <NUM_LIT:1> : <EOL> raise TemplateSyntaxError ( _ ( '<STR_LIT>' ) % bits [ <NUM_LIT:0> ] ) <EOL> return CartInformationNode ( ) <EOL> register . tag ( '<STR_LIT>' , do_cart_information ) <EOL> class CurrentCategoryNode ( Node ) : <EOL> """<STR_LIT:U+0020>""" <EOL> def render ( self , context ) : <EOL> request = context . get ( "<STR_LIT>" ) <EOL> product = context . get ( "<STR_LIT>" ) <EOL> context [ "<STR_LIT>" ] = product . get_current_category ( request ) <EOL> return '<STR_LIT>' <EOL> def do_current_category ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> len_bits = len ( bits ) <EOL> if len_bits != <NUM_LIT:2> : <EOL> raise TemplateSyntaxError ( _ ( '<STR_LIT>' ) % bits [ <NUM_LIT:0> ] ) <EOL> return CurrentCategoryNode ( ) <EOL> register . tag ( '<STR_LIT>' , do_current_category ) <EOL> class ComeFromPageNode ( Node ) : <EOL> """<STR_LIT:U+0020>""" <EOL> def render ( self , context ) : <EOL> request = context . get ( "<STR_LIT>" ) <EOL> product = context . get ( "<STR_LIT>" ) <EOL> context [ "<STR_LIT>" ] = product . get_come_from_page ( request ) <EOL> return '<STR_LIT>' <EOL> def do_come_from_page ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> len_bits = len ( bits ) <EOL> if len_bits != <NUM_LIT:2> : <EOL> raise TemplateSyntaxError ( _ ( '<STR_LIT>' ) % bits [ <NUM_LIT:0> ] ) <EOL> return ComeFromPageNode ( ) <EOL> register . tag ( '<STR_LIT>' , do_come_from_page ) <EOL> def get_slug_from_request ( request ) : <EOL> """<STR_LIT>""" <EOL> slug = request . path . split ( "<STR_LIT:/>" ) [ - <NUM_LIT:1> ] <EOL> try : <EOL> int ( slug ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> slug = request . path . split ( "<STR_LIT:/>" ) [ - <NUM_LIT:2> ] <EOL> return slug <EOL> @ register . filter <EOL> def currency_text ( value , request = None , grouping = True ) : <EOL> """<STR_LIT>""" <EOL> if locale . getlocale ( locale . LC_ALL ) [ <NUM_LIT:0> ] is None : <EOL> lfs . core . views . one_time_setup ( ) <EOL> if not value : <EOL> value = <NUM_LIT:0.0> <EOL> shop = lfs . core . utils . get_default_shop ( request ) <EOL> try : <EOL> result = locale . currency ( value , grouping = grouping , international = shop . use_international_currency_code ) <EOL> except ValueError , e : <EOL> result = value <EOL> logger . error ( "<STR_LIT>" % e ) <EOL> if value < <NUM_LIT:0> : <EOL> if result [ - <NUM_LIT:1> ] == '<STR_LIT:->' : <EOL> length = len ( locale . nl_langinfo ( locale . CRNCYSTR ) ) <EOL> result = '<STR_LIT>' % ( result [ <NUM_LIT:0> : length ] , result [ length : - <NUM_LIT:1> ] ) <EOL> return result <EOL> @ register . filter <EOL> def currency ( value , request = None , grouping = True ) : <EOL> """<STR_LIT>""" <EOL> if locale . getlocale ( locale . LC_ALL ) [ <NUM_LIT:0> ] is None : <EOL> lfs . core . views . one_time_setup ( ) <EOL> if not value : <EOL> value = <NUM_LIT:0.0> <EOL> shop = lfs . core . utils . get_default_shop ( request ) <EOL> try : <EOL> result = locale . currency ( value , grouping = grouping , international = shop . use_international_currency_code ) <EOL> except ValueError , e : <EOL> result = str ( value ) <EOL> logger . error ( "<STR_LIT>" % e ) <EOL> negative = False <EOL> if value < <NUM_LIT:0> : <EOL> negative = True <EOL> if result [ - <NUM_LIT:1> ] == '<STR_LIT:->' : <EOL> length = len ( locale . nl_langinfo ( locale . CRNCYSTR ) ) <EOL> result = '<STR_LIT>' % ( result [ <NUM_LIT:0> : length ] , result [ length : - <NUM_LIT:1> ] ) <EOL> return mark_safe ( '<STR_LIT>' % { <EOL> '<STR_LIT:result>' : result . strip ( ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if negative else '<STR_LIT>' , <EOL> } ) <EOL> @ register . filter <EOL> def decimal_l10n ( value , digits = <NUM_LIT:2> ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> value = float ( value ) <EOL> except ValueError : <EOL> return value <EOL> format_str = "<STR_LIT>" % digits <EOL> return locale . format_string ( format_str , value ) <EOL> @ register . filter <EOL> def quantity ( quantity ) : <EOL> """<STR_LIT>""" <EOL> if str ( quantity ) . find ( "<STR_LIT>" ) == - <NUM_LIT:1> : <EOL> return quantity <EOL> else : <EOL> return int ( float ( quantity ) ) <EOL> @ register . filter <EOL> def sub_type_name ( sub_type , arg = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return PRODUCT_TYPE_LOOKUP [ sub_type ] <EOL> except KeyError : <EOL> return "<STR_LIT>" <EOL> @ register . filter <EOL> def multiply ( score , pixel ) : <EOL> """<STR_LIT>""" <EOL> return score * pixel <EOL> @ register . filter <EOL> def option_name ( option_id ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> option_id = int ( float ( option_id ) ) <EOL> except ValueError : <EOL> pass <EOL> try : <EOL> option = PropertyOption . objects . get ( pk = option_id ) <EOL> except ( PropertyOption . DoesNotExist , ValueError ) : <EOL> return option_id <EOL> else : <EOL> return option . name <EOL> @ register . filter <EOL> def option_name_for_property_value ( property_value ) : <EOL> """<STR_LIT>""" <EOL> if property_value . property . is_select_field : <EOL> try : <EOL> option_id = int ( float ( property_value . value ) ) <EOL> except ValueError : <EOL> return property_value . value <EOL> try : <EOL> option = PropertyOption . objects . get ( pk = option_id ) <EOL> except ( PropertyOption . DoesNotExist , ValueError ) : <EOL> return option_id <EOL> else : <EOL> return option . name <EOL> return property_value . value <EOL> @ register . filter <EOL> def packages ( cart_item ) : <EOL> """<STR_LIT>""" <EOL> packing_unit , packing_unit_unit = cart_item . product . get_packing_info ( ) <EOL> if packing_unit : <EOL> try : <EOL> amount = float ( cart_item . amount ) <EOL> except ValueError : <EOL> amount = locale . atof ( cart_item . amount ) <EOL> return int ( math . ceil ( amount / packing_unit ) ) <EOL> return <NUM_LIT:0> <EOL> class CategoryProductPricesGrossNode ( Node ) : <EOL> def __init__ ( self , product_id ) : <EOL> self . product_id = template . Variable ( product_id ) <EOL> def render ( self , context ) : <EOL> request = context . get ( "<STR_LIT>" ) <EOL> product_id = self . product_id . resolve ( context ) <EOL> product = Product . objects . get ( pk = product_id ) <EOL> if product . is_variant ( ) : <EOL> parent = product . parent <EOL> else : <EOL> parent = product <EOL> if parent . category_variant == CATEGORY_VARIANT_CHEAPEST_PRICES : <EOL> if product . get_for_sale ( ) : <EOL> info = parent . get_cheapest_standard_price_gross ( request ) <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> info = parent . get_cheapest_price_gross ( request ) <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> info = parent . get_cheapest_base_price_gross ( request ) <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> else : <EOL> if product . get_for_sale ( ) : <EOL> context [ "<STR_LIT>" ] = product . get_standard_price_gross ( request ) <EOL> context [ "<STR_LIT>" ] = product . get_price_gross ( request ) <EOL> context [ "<STR_LIT>" ] = False <EOL> context [ "<STR_LIT>" ] = product . get_base_price_gross ( request ) <EOL> context [ "<STR_LIT>" ] = False <EOL> if product . get_active_packing_unit ( ) : <EOL> context [ "<STR_LIT>" ] = product . get_base_packing_price_gross ( request ) <EOL> return "<STR_LIT>" <EOL> def do_category_product_prices_gross ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> if len ( bits ) != <NUM_LIT:2> : <EOL> raise TemplateSyntaxError ( '<STR_LIT>' % bits [ <NUM_LIT:0> ] ) <EOL> return CategoryProductPricesGrossNode ( bits [ <NUM_LIT:1> ] ) <EOL> register . tag ( '<STR_LIT>' , do_category_product_prices_gross ) <EOL> class CategoryProductPricesNetNode ( Node ) : <EOL> def __init__ ( self , product_id ) : <EOL> self . product_id = template . Variable ( product_id ) <EOL> def render ( self , context ) : <EOL> request = context . get ( "<STR_LIT>" ) <EOL> product_id = self . product_id . resolve ( context ) <EOL> product = Product . objects . get ( pk = product_id ) <EOL> if product . is_variant ( ) : <EOL> parent = product . parent <EOL> else : <EOL> parent = product <EOL> if parent . category_variant == CATEGORY_VARIANT_CHEAPEST_PRICES : <EOL> if product . get_for_sale ( ) : <EOL> info = parent . get_cheapest_standard_price_net ( request ) <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> info = parent . get_cheapest_price_net ( request ) <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> info = parent . get_cheapest_base_price_net ( request ) <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> else : <EOL> if product . get_for_sale ( ) : <EOL> context [ "<STR_LIT>" ] = product . get_standard_price_net ( request ) <EOL> context [ "<STR_LIT>" ] = product . get_price_net ( request ) <EOL> context [ "<STR_LIT>" ] = False <EOL> context [ "<STR_LIT>" ] = product . get_base_price_net ( request ) <EOL> context [ "<STR_LIT>" ] = False <EOL> if product . get_active_packing_unit ( ) : <EOL> context [ "<STR_LIT>" ] = product . get_base_packing_price_net ( request ) <EOL> return "<STR_LIT>" <EOL> def do_category_product_prices_net ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> if len ( bits ) != <NUM_LIT:2> : <EOL> raise TemplateSyntaxError ( '<STR_LIT>' % bits [ <NUM_LIT:0> ] ) <EOL> return CategoryProductPricesNetNode ( bits [ <NUM_LIT:1> ] ) <EOL> register . tag ( '<STR_LIT>' , do_category_product_prices_net ) <EOL> class CategoryProductPricesNode ( Node ) : <EOL> def __init__ ( self , product_id ) : <EOL> self . product_id = template . Variable ( product_id ) <EOL> def render ( self , context ) : <EOL> request = context . get ( "<STR_LIT>" ) <EOL> product_id = self . product_id . resolve ( context ) <EOL> product = Product . objects . get ( pk = product_id ) <EOL> if product . is_variant ( ) : <EOL> parent = product . parent <EOL> else : <EOL> parent = product <EOL> if parent . category_variant == CATEGORY_VARIANT_CHEAPEST_PRICES : <EOL> if product . get_for_sale ( ) : <EOL> info = parent . get_cheapest_standard_price ( request ) <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> info = parent . get_cheapest_price ( request ) <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> info = parent . get_cheapest_base_price ( request ) <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> context [ "<STR_LIT>" ] = info [ "<STR_LIT>" ] <EOL> else : <EOL> if product . get_for_sale ( ) : <EOL> context [ "<STR_LIT>" ] = product . get_standard_price ( request ) <EOL> context [ "<STR_LIT>" ] = product . get_price ( request ) <EOL> context [ "<STR_LIT>" ] = False <EOL> context [ "<STR_LIT>" ] = product . get_base_price ( request ) <EOL> context [ "<STR_LIT>" ] = False <EOL> if product . get_active_packing_unit ( ) : <EOL> context [ "<STR_LIT>" ] = product . get_base_packing_price ( request ) <EOL> return "<STR_LIT>" <EOL> def do_category_product_prices ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> if len ( bits ) != <NUM_LIT:2> : <EOL> raise TemplateSyntaxError ( '<STR_LIT>' % bits [ <NUM_LIT:0> ] ) <EOL> return CategoryProductPricesNode ( bits [ <NUM_LIT:1> ] ) <EOL> register . tag ( '<STR_LIT>' , do_category_product_prices ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_price ( product , request ) : <EOL> return product . get_price ( request ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_price_net ( product , request ) : <EOL> return product . get_price_net ( request ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_price_gross ( product , request ) : <EOL> return product . get_price_gross ( request ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_standard_price ( product , request ) : <EOL> return product . get_standard_price ( request ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_standard_price_net ( product , request ) : <EOL> return product . get_standard_price_net ( request ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_standard_price_gross ( product , request ) : <EOL> return product . get_standard_price_gross ( request ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_for_sale_price ( product , request ) : <EOL> return product . get_for_sale_price ( request ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_for_sale_price_net ( product , request ) : <EOL> return product . get_for_sale_price_net ( request ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_for_sale_price_gross ( product , request ) : <EOL> return product . get_for_sale_price_gross ( request ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_base_price ( product , request ) : <EOL> return product . get_base_price ( request ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_base_price_net ( product , request ) : <EOL> return product . get_base_price_net ( request ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_base_price_gross ( product , request ) : <EOL> return product . get_base_price_gross ( request ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_base_packing_price ( product , request ) : <EOL> return product . get_base_packing_price ( request ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_base_packing_price_net ( product , request ) : <EOL> return product . get_base_packing_price_net ( request ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def get_base_packing_price_gross ( product , request ) : <EOL> return product . get_base_packing_price_gross ( request ) <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def lfs_form ( context , form ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( form , BoundField ) : <EOL> form = [ form ] <EOL> context [ '<STR_LIT>' ] = form <EOL> context [ '<STR_LIT>' ] = hasattr ( form , '<STR_LIT>' ) <EOL> return context <EOL> @ register . filter ( name = '<STR_LIT>' , is_safe = True ) <EOL> def get_pay_link ( order , request = None , force_paid = False ) : <EOL> """<STR_LIT>""" <EOL> if force_paid or order . can_be_paid ( ) : <EOL> return order . get_pay_link ( request ) <EOL> return '<STR_LIT>' <EOL> @ register . simple_tag ( takes_context = True ) <EOL> def render_address ( context , address , address_type ) : <EOL> request = context . get ( '<STR_LIT>' ) <EOL> return mark_safe ( address . as_html ( request , type = address_type ) ) <EOL> @ register . filter <EOL> def clean_amount ( amount , product ) : <EOL> return product . get_clean_quantity ( amount ) </s>
