update products

remotes/origin/HEAD
Max Yakovenko 8 years ago
parent 0210ea6005
commit c422c1b14e
  1. 20
      products/templatetags/products_filters.py
  2. 21
      products/utils.py

@ -1,9 +1,12 @@
from functools import reduce
from django.utils.html import strip_tags
from django.utils.translation import ugettext_lazy as _
from django.template import Library
from cart.forms import CartAddInlineForm
from products.utils import ProductDesctipionHtmlParser
register = Library()
@ -13,15 +16,6 @@ def apply_nds_status(doesNdsInclude):
return _('Включено') if doesNdsInclude else _('Не включено')
@register.filter
def apply_product_offer_form(product):
initial = {
'offer': product.id,
'amount': 1
}
return CartAddInlineForm(initial=initial)
@register.filter
def apply_query_params(params, doAppend=False):
"""
@ -56,6 +50,12 @@ def get_item(dictionary, key):
return dictionary.get(key)
# @TODO: WRONG SOLUTION. REWRITE
@register.filter
def apply_desc_preview(description):
return description
text = strip_tags(description)
return reduce(
lambda text, line: text + line,
text.split('.')[:3],
""
) + '...'

@ -1,6 +1,27 @@
from django.utils.html_parser import HTMLParser
from .models import Product
#@TODO: MAKE DESCTIPTION PREVIEW
class ProductDesctipionHtmlParser(HTMLParser):
def __init__(self, convert_charrefs=False, **kwargs):
super().__init__(convert_charrefs, **kwargs)
def error(self, message):
pass
def handle_startendtag(self, tag, attrs):
super().handle_startendtag(tag, attrs)
def handle_data(self, data):
super().handle_data(data)
def handle_endtag(self, tag):
super().handle_endtag(tag)
#@TODO: NOT USED. FIGURE OUT THE PUPRPOSE OF THIS CODE
def get_variant_picker_data(product):
variants = product.variants.all()
variant_attributes = product.attributes.all()

Loading…
Cancel
Save