parent
06d39b615b
commit
a0b1a36fc1
5 changed files with 7 additions and 126 deletions
@ -1,62 +0,0 @@ |
|||||||
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() |
|
||||||
data = {'variants': [], 'variantAttributes': [], 'discount_policy': product.discount_policy} |
|
||||||
|
|
||||||
for attribute in sorted(variant_attributes, key=lambda x: x.main_attribute, reverse=True): |
|
||||||
data['variantAttributes'].append({ |
|
||||||
'name': attribute.name, |
|
||||||
'public_name': attribute.name.split('_')[1], |
|
||||||
'slug': attribute.slug, |
|
||||||
'values': [{'name': value.name, 'slug': value.slug} for value in attribute.values.all()] |
|
||||||
}) |
|
||||||
|
|
||||||
for variant in variants: |
|
||||||
price = variant.price |
|
||||||
|
|
||||||
variant_data = { |
|
||||||
'id': variant.id, |
|
||||||
'slug': variant.slug, |
|
||||||
'name': variant.name, |
|
||||||
'price': int(price), |
|
||||||
'attributes': variant.attributes, |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
data['variants'].append(variant_data) |
|
||||||
|
|
||||||
return data |
|
||||||
|
|
||||||
|
|
||||||
def expand_categories(categories): |
|
||||||
products = None |
|
||||||
for e in categories: |
|
||||||
if e.name.startswith('None'): |
|
||||||
products = Product.objects.filter(category=e) |
|
||||||
return [x for x in categories if not x.name.startswith('None')], products |
|
||||||
Loading…
Reference in new issue