diff --git a/products/templatetags/products_filters.py b/products/templatetags/products_filters.py index 8903a0c..7469d19 100644 --- a/products/templatetags/products_filters.py +++ b/products/templatetags/products_filters.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], + "" + ) + '...' diff --git a/products/utils.py b/products/utils.py index 900a6af..e899f96 100644 --- a/products/utils.py +++ b/products/utils.py @@ -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()