コード例 #1
0
ファイル: feed.py プロジェクト: daasara/riba
 def create_update_product_tags(self, product, tags):
     for tag_info in tags:
         tag_field = slugify(tag_info['value'])
         display_name = tag_info['value']
         tag_type = tag_info['type']
         try:
             tag = Tag.objects.using('default').get(tag = tag_field)
         except Tag.DoesNotExist:
             tag = Tag(display_name = display_name)
             tag.tag = tag_field
             tag.save(using='default')
         try:
             product_tag = ProductTags.objects.using('default').get(product = product, tag = tag, type = tag_type)
         except ProductTags.DoesNotExist:
             product_tag = ProductTags(product = product, tag = tag, type = tag_type)
             product_tag.save(using='default')
コード例 #2
0
def compute(sync):
    _client_id = 5
    last_month = datetime.now() + timedelta(days=-30)
    # Get srcs of products created before 1 month
    new_rate_charts = SellerRateChart.objects.select_related('product', 'product__status').filter(product__is_online=True, seller__client=_client_id,\
                      product__created_on__gte=last_month).order_by("-product__created_on")[:200]
    new_products = []
    for src in new_rate_charts:
        new_products.append(src.product)
    # New arrivals products should be atleast 45 items
    if len(new_products) < 45:
        new_rate_charts = SellerRateChart.objects.select_related('product', 'product__status').filter(product__is_online=True,\
                          seller__client=_client_id).order_by("-product__created_on")[:200]
        new_products = []
        for src in new_rate_charts:
            new_products.append(src.product)

    # Create popular_deal tag, for indexing products into solr
    tag_type = 'new_arrivals'
    tag = Tag.objects.filter(tag=tag_type)
    if not tag:
        tag = Tag(tag=tag_type)
        tag.display_name = tag_type.capitalize()
        tag.save()
    else:
        tag = tag[0]
    products = []
    # variant_products contains product obj of {normal, variant} type
    # so replace variant products by variable 
    # to reindex in solr
    variant_products = new_products
    productvariants = ProductVariant.objects.select_related('blueprint', 'variant').filter(variant__in=variant_products)
    variant_product_map = {}
    for pv in productvariants:
        # get {variable : variant} mapping
        variant_product_map[pv.variant] = pv.blueprint
    for product in variant_products:
        prod = product
        if product.type == 'variant':
            try:
                # get corresponding variable of variant from variable:variant mapping
                prod = variant_product_map[product]
            except KeyError:
                continue
        if prod not in products:
            products.append(prod)
    # products list contains all products with type {variable, normal}
    product_ids_to_reindexed = []
    for product in products:
        try:
            pt = ProductTags.objects.select_related('product').get(type=tag_type, product=product, tag=tag)
        except ProductTags.DoesNotExist:
            pt = ProductTags()
            pt.type = tag_type
            pt.product = product  
            pt.tag = tag
            pt.save()
            # if product is not included in previous list then
            # then create ProductTag for it and reindex it 
        product_ids_to_reindexed.append(int(product.id))
    # Get previously indexed new arrivals from solr
    from utils.solrutils import solr_search
    q = 'tag_id:%s AND client_id:%s' % (tag.id, _client_id)
    params = {'rows':1000}
    solr_result = solr_search(q, fields='id', highlight=None, score=True, sort=None, sort_order="asc", operation='/select',\
                  active_product_query='', boost_query='', request=None, **params)

    indexed_new_arrivals = [int(res['id']) for res in solr_result.results]

    # ProductTags of (previously_indexed_new_arrivals - current_new_arrivals)
    # should to be removed
    new_arrivals_to_remove = set(indexed_new_arrivals) - set(product_ids_to_reindexed)
    product_ids_to_reindexed = set(product_ids_to_reindexed) - set(indexed_new_arrivals)
    log.info("New Arrivals ID:: %s" % product_ids_to_reindexed)
    sync.found = len(indexed_new_arrivals)
    sync.deletes = len(new_arrivals_to_remove)
    sync.add = len(product_ids_to_reindexed)
    sync.save()
    if not product_ids_to_reindexed:
        log.info("Found no new_arrivals")    
        return
    products_to_reindexed = Product.objects.filter(id__in=product_ids_to_reindexed)
    
    removed_new_arrivals = []
    for product_tag in ProductTags.objects.select_related('product').filter(product__in=new_arrivals_to_remove, tag=tag):
        removed_new_arrivals.append(product_tag.product)
        product_tag.delete()

    for product in products_to_reindexed:
        # Reindex:
        # 1) new product set (to add tag entry into solr)
        # 2) old tagged product set (to delete tag entry from solr)
        product.update_solr_index()
    for product in removed_new_arrivals:
        product.update_solr_index()
コード例 #3
0
os.environ['DJANGO_SETTINGS_MODULE'] = 'tinla.fbsettings'

ROOT_FOLDER = os.path.realpath(os.path.dirname(__file__))
ROOT_FOLDER = ROOT_FOLDER[:ROOT_FOLDER.rindex('/')]

if ROOT_FOLDER not in sys.path:
    sys.path.insert(1, ROOT_FOLDER + '/')

# also add the parent folder
PARENT_FOLDER = ROOT_FOLDER[:ROOT_FOLDER.rindex('/')+1]
if PARENT_FOLDER not in sys.path:
    sys.path.insert(1, PARENT_FOLDER)

from catalog.models import Tag, ProductTags

pt = ProductTags.objects.select_related('tag').filter(type='clearance_sale')
for d in pt:
    tag_field = '%s-clearance'%d.tag.tag
    try:
        t = Tag.objects.using("default").get(tag=tag_field, type="clearance")
    except Tag.DoesNotExist:
        t = Tag(tag=tag_field, type="clearance")
        t.display_name = d.tag.display_name
        t.save(using='default')
    try:
        p = ProductTags.objects.using("default").get(tag=t, type="new_clearance_sale", product=d.product)
    except ProductTags.DoesNotExist:
        p = ProductTags(tag=t, type="new_clearance_sale", product=d.product)
        p.save(using='default')
    p.product.update_solr_index()
コード例 #4
0

tag_name = 'eureka'
promotion_name = 'eureka'
client_id = 5
list_id = 3280

list = List.objects.get(id= list_id, type=promotion_name)
listitems = list.listitem_set.select_related('sku', 'sku__product').filter(status='active')
srcs = [l.sku for l in listitems]

tag = Tag.objects.filter(tag=tag_name)
if not tag:
    tag = Tag(tag=tag_name)
    tag.display_name = tag_name.capitalize()
    tag.save()
else:
    tag = tag[0]


previously_added_products = []
product_tags = ProductTags.objects.select_related('product').filter(type=promotion_name)
for pt in product_tags:
    previously_added_products.append(pt.product)

products_to_reindexed = []
products = []
variant_products = [s.product for s in srcs]
productvariants = ProductVariant.objects.select_related('blueprint', 'variant').filter(variant__in=variant_products)
variant_product_map = {}
コード例 #5
0
tag_name = 'eureka'
promotion_name = 'eureka'
client_id = 5
list_id = 3280

list = List.objects.get(id=list_id, type=promotion_name)
listitems = list.listitem_set.select_related(
    'sku', 'sku__product').filter(status='active')
srcs = [l.sku for l in listitems]

tag = Tag.objects.filter(tag=tag_name)
if not tag:
    tag = Tag(tag=tag_name)
    tag.display_name = tag_name.capitalize()
    tag.save()
else:
    tag = tag[0]

previously_added_products = []
product_tags = ProductTags.objects.select_related('product').filter(
    type=promotion_name)
for pt in product_tags:
    previously_added_products.append(pt.product)

products_to_reindexed = []
products = []
variant_products = [s.product for s in srcs]
productvariants = ProductVariant.objects.select_related(
    'blueprint', 'variant').filter(variant__in=variant_products)
variant_product_map = {}
コード例 #6
0
def index_popular_deals(popular_pending_deals,
                        popular_confirmed_deals,
                        client_id=5):
    popular_products = popular_pending_deals + popular_confirmed_deals
    popular_products = Product.objects.filter(id__in=popular_products,
                                              is_online=True)
    if not popular_products:
        popular_orders = OrderCountByState.objects.select_related('product').filter(client=client_id,\
                         product__is_online=True).order_by('-order_count')[:200]
        popular_products = [order.product for order in popular_orders]
    # Create popular_deal tag, for indexing products into solr
    popular_type = 'popular_deals'
    tag = Tag.objects.filter(tag=popular_type)
    if not tag:
        tag = Tag(tag=popular_type)
        tag.display_name = popular_type.capitalize()
        tag.save()
    else:
        tag = tag[0]
    product_ids_to_reindexed = []
    products = []
    variant_products = popular_products
    productvariants = ProductVariant.objects.select_related(
        'blueprint', 'variant').filter(variant__in=variant_products)
    variant_product_map = {}
    for pv in productvariants:
        variant_product_map[pv.variant] = pv.blueprint
    for product in variant_products:
        prod = product
        if product.type == 'variant':
            try:
                prod = variant_product_map[product]
            except KeyError:
                continue
        if prod not in products:
            products.append(prod)
    for product in products:
        try:
            pt = ProductTags.objects.select_related('product').get(
                type=popular_type, product=product, tag=tag)
        except ProductTags.DoesNotExist:
            pt = ProductTags()
            pt.type = popular_type
            pt.product = product
            pt.tag = tag
            pt.save()
            product_ids_to_reindexed.append(int(product.id))

    from utils.solrutils import solr_search
    q = 'tag_id:%s AND client_id:%s' % (tag.id, client_id)
    params = {'rows': 1000}
    solr_result = solr_search(q, fields='id', highlight=None, score=True, sort=None, sort_order="asc", operation='/select',\
                  active_product_query='', boost_query='', request=None, **params)

    indexed_popular_deals = [int(res['id']) for res in solr_result.results]

    popular_deals_to_remove = set(indexed_popular_deals) - set(
        product_ids_to_reindexed)
    product_ids_to_reindexed = set(product_ids_to_reindexed) - set(
        indexed_popular_deals)
    log.info("Popular Deals ID:: %s" % product_ids_to_reindexed)
    sync.found = len(indexed_popular_deals)
    sync.deletes = len(popular_deals_to_remove)
    sync.add = len(product_ids_to_reindexed)
    sync.save()
    if not product_ids_to_reindexed:
        log.info("Found no popular_deals")
        return

    products_to_reindexed = Product.objects.filter(
        id__in=product_ids_to_reindexed)

    removed_popular_deals = []
    for product_tag in ProductTags.objects.select_related('product').filter(
            product__in=popular_deals_to_remove, tag=tag):
        removed_popular_deals.append(product_tag.product)
        product_tag.delete()

    for product in products_to_reindexed:
        # Reindex:
        # 1) new product set (to add tag entry into solr)
        # 2) old tagged product set (to delete tag entry from solr)
        product.update_solr_index()
    for product in removed_popular_deals:
        product.update_solr_index()
コード例 #7
0
ファイル: itz_setup_file.py プロジェクト: daasara/riba
        list.title=list_title
        list.description=list_desc
        list.type=list_type
        list.save()
        print "Okay list created -",list
        list_id = list.id
    '''
    tag = Tag.objects.filter(tag=tag_name)
    if tag:
        print "Okay Tag-", tag
        tag = tag[0]
    else:
        print tag, " not found"
        tag = Tag(tag=tag_name)
        tag.display_name = tag_name.capitalize()
        tag.save()
        print "Okay tag created -", tag

    tag_hero = Tag.objects.filter(tag=tag_hero_name)
    if tag_hero:
        print "Okay Tag-", tag_hero
        tag_hero = tag_hero[0]
    else:
        print tag_hero_name, " not found"
        tag_hero = Tag(tag=tag_hero_name)
        tag_hero.display_name = tag_hero_name.capitalize()
        tag_hero.save()
        print "Okay tag hero created -", tag_hero
    tag_hero_id = tag_hero.id
    print "tag_hero_id -->", tag_hero_id
    '''
コード例 #8
0
     list.title=list_title
     list.description=list_desc
     list.type=list_type
     list.save()
     print "Okay list created -",list
     list_id = list.id
 '''
 tag = Tag.objects.filter(tag=tag_name)
 if tag:
     print "Okay Tag-", tag
     tag = tag[0]
 else:
     print tag, " not found"
     tag = Tag(tag=tag_name)
     tag.display_name = tag_name.capitalize()
     tag.save()
     print "Okay tag created -",tag
 
 tag_hero = Tag.objects.filter(tag=tag_hero_name)
 if tag_hero:
     print "Okay Tag-", tag_hero
     tag_hero = tag_hero[0]
 else:
     print tag_hero_name, " not found"
     tag_hero = Tag(tag=tag_hero_name)
     tag_hero.display_name = tag_hero_name.capitalize()
     tag_hero.save()
     print "Okay tag hero created -",tag_hero
 tag_hero_id = tag_hero.id
 print "tag_hero_id -->",tag_hero_id
 
コード例 #9
0
s = wb.sheet_by_index(0)
for col in range(s.ncols):
    heading_map[s.cell(0,col).value.lower().encode('ascii','ignore')] = col
    
for row_num in range(1,s.nrows):
    row = s.row(row_num)
    
    if row[heading_map['article id']].ctype in (2,3):
        article_id = str(int(row[heading_map['article id']].value))
    else:
        article_id = str(row[heading_map['article id']].value)

    tag_label = str(row[heading_map['tag']].value.strip())
    tag_value = slugify(tag_label)

    src = SellerRateChart.objects.filter(article_id=article_id)
    if src:
        src = src[0]
        try:
            tag = Tag.objects.using("default").get(tag=tag_value, type = "clearance")
        except Tag.DoesNotExist:
            tag = Tag(tag=tag_value, display_name=tag_label, type = "clearance")
            tag.save(using="default")

        try:
            p = ProductTags.objects.using("default").get(tag=tag, type="new_clearance_sale", product=src.product)
        except ProductTags.DoesNotExist:
            p = ProductTags(tag=tag, type="new_clearance_sale", product=src.product)
            p.save(using='default')
        src.product.update_solr_index()
コード例 #10
0
def index_popular_deals(popular_pending_deals, popular_confirmed_deals, client_id=5):
    popular_products = popular_pending_deals + popular_confirmed_deals
    popular_products = Product.objects.filter(id__in=popular_products, is_online=True)
    if not popular_products:
        popular_orders = OrderCountByState.objects.select_related('product').filter(client=client_id,\
                         product__is_online=True).order_by('-order_count')[:200]
        popular_products = [order.product for order in popular_orders]
    # Create popular_deal tag, for indexing products into solr
    popular_type = 'popular_deals'
    tag = Tag.objects.filter(tag=popular_type)
    if not tag:
        tag = Tag(tag=popular_type)
        tag.display_name = popular_type.capitalize()
        tag.save()
    else:
        tag = tag[0]
    product_ids_to_reindexed = []
    products = []
    variant_products = popular_products
    productvariants = ProductVariant.objects.select_related('blueprint', 'variant').filter(variant__in=variant_products)
    variant_product_map = {}
    for pv in productvariants:
        variant_product_map[pv.variant] = pv.blueprint
    for product in variant_products:
        prod = product
        if product.type == 'variant':
            try:
                prod = variant_product_map[product]
            except KeyError:
                continue
        if prod not in products:
            products.append(prod)
    for product in products:
        try:
            pt = ProductTags.objects.select_related('product').get(type=popular_type, product=product, tag=tag)
        except ProductTags.DoesNotExist:
            pt = ProductTags()
            pt.type = popular_type
            pt.product = product  
            pt.tag = tag
            pt.save()
            product_ids_to_reindexed.append(int(product.id))

    from utils.solrutils import solr_search
    q = 'tag_id:%s AND client_id:%s' % (tag.id, client_id)
    params = {'rows':1000}
    solr_result = solr_search(q, fields='id', highlight=None, score=True, sort=None, sort_order="asc", operation='/select',\
                  active_product_query='', boost_query='', request=None, **params)

    indexed_popular_deals = [int(res['id']) for res in solr_result.results]

    popular_deals_to_remove = set(indexed_popular_deals) - set(product_ids_to_reindexed)
    product_ids_to_reindexed = set(product_ids_to_reindexed) - set(indexed_popular_deals)
    log.info("Popular Deals ID:: %s" % product_ids_to_reindexed)
    sync.found = len(indexed_popular_deals)
    sync.deletes = len(popular_deals_to_remove)
    sync.add = len(product_ids_to_reindexed)
    sync.save()
    if not product_ids_to_reindexed:
        log.info("Found no popular_deals")
        return

    products_to_reindexed = Product.objects.filter(id__in=product_ids_to_reindexed)

    removed_popular_deals= []
    for product_tag in ProductTags.objects.select_related('product').filter(product__in=popular_deals_to_remove, tag=tag):
        removed_popular_deals.append(product_tag.product)
        product_tag.delete()

    for product in products_to_reindexed:
        # Reindex:
        # 1) new product set (to add tag entry into solr)
        # 2) old tagged product set (to delete tag entry from solr)
        product.update_solr_index()
    for product in removed_popular_deals:
        product.update_solr_index()
コード例 #11
0
def compute(sync):
    _client_id = 5
    last_month = datetime.now() + timedelta(days=-30)
    # Get srcs of products created before 1 month
    new_rate_charts = SellerRateChart.objects.select_related('product', 'product__status').filter(product__is_online=True, seller__client=_client_id,\
                      product__created_on__gte=last_month).order_by("-product__created_on")[:200]
    new_products = []
    for src in new_rate_charts:
        new_products.append(src.product)
    # New arrivals products should be atleast 45 items
    if len(new_products) < 45:
        new_rate_charts = SellerRateChart.objects.select_related('product', 'product__status').filter(product__is_online=True,\
                          seller__client=_client_id).order_by("-product__created_on")[:200]
        new_products = []
        for src in new_rate_charts:
            new_products.append(src.product)

    # Create popular_deal tag, for indexing products into solr
    tag_type = 'new_arrivals'
    tag = Tag.objects.filter(tag=tag_type)
    if not tag:
        tag = Tag(tag=tag_type)
        tag.display_name = tag_type.capitalize()
        tag.save()
    else:
        tag = tag[0]
    products = []
    # variant_products contains product obj of {normal, variant} type
    # so replace variant products by variable
    # to reindex in solr
    variant_products = new_products
    productvariants = ProductVariant.objects.select_related(
        'blueprint', 'variant').filter(variant__in=variant_products)
    variant_product_map = {}
    for pv in productvariants:
        # get {variable : variant} mapping
        variant_product_map[pv.variant] = pv.blueprint
    for product in variant_products:
        prod = product
        if product.type == 'variant':
            try:
                # get corresponding variable of variant from variable:variant mapping
                prod = variant_product_map[product]
            except KeyError:
                continue
        if prod not in products:
            products.append(prod)
    # products list contains all products with type {variable, normal}
    product_ids_to_reindexed = []
    for product in products:
        try:
            pt = ProductTags.objects.select_related('product').get(
                type=tag_type, product=product, tag=tag)
        except ProductTags.DoesNotExist:
            pt = ProductTags()
            pt.type = tag_type
            pt.product = product
            pt.tag = tag
            pt.save()
            # if product is not included in previous list then
            # then create ProductTag for it and reindex it
        product_ids_to_reindexed.append(int(product.id))
    # Get previously indexed new arrivals from solr
    from utils.solrutils import solr_search
    q = 'tag_id:%s AND client_id:%s' % (tag.id, _client_id)
    params = {'rows': 1000}
    solr_result = solr_search(q, fields='id', highlight=None, score=True, sort=None, sort_order="asc", operation='/select',\
                  active_product_query='', boost_query='', request=None, **params)

    indexed_new_arrivals = [int(res['id']) for res in solr_result.results]

    # ProductTags of (previously_indexed_new_arrivals - current_new_arrivals)
    # should to be removed
    new_arrivals_to_remove = set(indexed_new_arrivals) - set(
        product_ids_to_reindexed)
    product_ids_to_reindexed = set(product_ids_to_reindexed) - set(
        indexed_new_arrivals)
    log.info("New Arrivals ID:: %s" % product_ids_to_reindexed)
    sync.found = len(indexed_new_arrivals)
    sync.deletes = len(new_arrivals_to_remove)
    sync.add = len(product_ids_to_reindexed)
    sync.save()
    if not product_ids_to_reindexed:
        log.info("Found no new_arrivals")
        return
    products_to_reindexed = Product.objects.filter(
        id__in=product_ids_to_reindexed)

    removed_new_arrivals = []
    for product_tag in ProductTags.objects.select_related('product').filter(
            product__in=new_arrivals_to_remove, tag=tag):
        removed_new_arrivals.append(product_tag.product)
        product_tag.delete()

    for product in products_to_reindexed:
        # Reindex:
        # 1) new product set (to add tag entry into solr)
        # 2) old tagged product set (to delete tag entry from solr)
        product.update_solr_index()
    for product in removed_new_arrivals:
        product.update_solr_index()