cleaning product description from html
This commit is contained in:
@@ -19,4 +19,6 @@ woocommerce==2.1.1
|
||||
django-anymail[amazon_ses]==8.2
|
||||
boto3==1.17.11
|
||||
django-storages==1.11.1
|
||||
Faker==6.4.1
|
||||
Faker==6.4.1
|
||||
beautifulsoup4==4.9.3
|
||||
lxml==4.6.2
|
||||
@@ -15,6 +15,8 @@ import requests
|
||||
from PIL import Image
|
||||
from django.core.files import File
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from companies.models import Company
|
||||
from products.models import Product
|
||||
from products.serializers import ProductSerializer
|
||||
@@ -52,15 +54,13 @@ def create_imported_product(info, company, history, user):
|
||||
'company':company.id,
|
||||
'creator': user.id if user is not None else None,
|
||||
'history': history.id,
|
||||
'url': info['permalink'],
|
||||
'stock': info['stock_quantity'],
|
||||
'url': info.get('permalink'),
|
||||
'stock': info.get('stock_quantity'),
|
||||
'name': info.get('name'),
|
||||
'description': BeautifulSoup(info.get('description', ''), "lxml").text,
|
||||
'sku': info.get('sku'),
|
||||
'price': info.get('price'),
|
||||
}
|
||||
# parse the product info
|
||||
for key in info:
|
||||
if key in PRODUCT_FIELDS:
|
||||
instance_data[key] = info[key]
|
||||
# remove unwanted fields
|
||||
instance_data.pop('id')
|
||||
|
||||
# alternative method
|
||||
serializer = ProductSerializer(data=instance_data)
|
||||
|
||||
Reference in New Issue
Block a user