Subversion Repositories SmartDukaan

Rev

Rev 1416 | Rev 1970 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1416 Rev 1926
Line 455... Line 455...
455
    
455
    
456
    warehouses = item.currentInventory.warehouse
456
    warehouses = item.currentInventory.warehouse
457
    return warehouses
457
    return warehouses
458
 
458
 
459
def get_best_sellers(start_index, stop_index, category=-1):
459
def get_best_sellers(start_index, stop_index, category=-1):
460
    query = get_best_sellers_query(category)
460
    query = get_best_sellers_query(category, None)
461
    best_sellers = query.all()[start_index:stop_index]
461
    best_sellers = query.all()[start_index:stop_index]
462
    return get_thrift_item_list(best_sellers)
462
    return get_thrift_item_list(best_sellers)
463
 
463
 
464
def get_best_sellers_count(category):
464
def get_best_sellers_count(category):
465
    count = get_best_sellers_query(category).count()
465
    count = get_best_sellers_query(category, None).count()
466
    if count is None:
466
    if count is None:
467
        count = 0
467
        count = 0
468
    return count
468
    return count
469
 
469
 
470
def get_best_sellers_catalog_ids(start_index, stop_index, category=-1):
470
def get_best_sellers_catalog_ids(start_index, stop_index, brand, category=-1):
471
    query = get_best_sellers_query(category)
471
    query = get_best_sellers_query(category, brand)
472
    best_sellers = query.all()[start_index:stop_index]
472
    best_sellers = query.all()[start_index:stop_index]
473
    return [item.catalog_item_id for item in best_sellers]
473
    return [item.catalog_item_id for item in best_sellers]
474
    
474
 
475
def get_best_sellers_query(category):
475
def get_best_sellers_query(category, brand):
476
    query = Item.query.filter_by(status=status.ACTIVE).filter(Item.bestSellingRank != None)
476
    query = Item.query.filter_by(status=status.ACTIVE).filter(Item.bestSellingRank != None)
477
    if category != -1:
477
    if category != -1:
478
        query = query.filter_by(category=category)
478
        query = query.filter_by(category=category)
-
 
479
    if brand is not None:
-
 
480
        query = query.filter_by(brand=brand)
479
    query = query.order_by(asc(Item.bestSellingRank))
481
    query = query.order_by(asc(Item.bestSellingRank))
480
    return query
482
    return query
481
 
483
 
482
def get_best_deals(category=-1):
484
def get_best_deals(category=-1):
483
    query = get_best_deals_query(category)
485
    query = get_best_deals_query(category, None)
484
    items = query.all()
486
    items = query.all()
485
    return get_thrift_item_list(items)
487
    return get_thrift_item_list(items)
486
 
488
 
487
def get_best_deals_count(category=-1):
489
def get_best_deals_count(category=-1):
488
    count = get_best_deals_query(category).count()
490
    count = get_best_deals_query(category, None).count()
489
    if count is None:
491
    if count is None:
490
        count = 0
492
        count = 0
491
    return count
493
    return count
492
    
494
    
493
def get_best_deals_catalog_ids(start_index, stop_index, category=-1):
495
def get_best_deals_catalog_ids(start_index, stop_index, brand, category=-1):
494
    query = get_best_deals_query(category)
496
    query = get_best_deals_query(category, brand)
495
    best_deal_items = query.all()[start_index:stop_index]
497
    best_deal_items = query.all()[start_index:stop_index]
496
    return [item.catalog_item_id for item in best_deal_items]
498
    return [item.catalog_item_id for item in best_deal_items]
497
 
499
 
498
def get_best_deals_query(category):
500
def get_best_deals_query(category, brand):
499
    query = Item.query.filter_by(status=status.ACTIVE).filter(Item.bestDealValue != None)
501
    query = Item.query.filter_by(status=status.ACTIVE).filter(Item.bestDealValue != None)
500
    if category != -1:
502
    if category != -1:
501
        query = query.filter_by(category=category)
503
        query = query.filter_by(category=category)
-
 
504
    if brand is not None:
-
 
505
        query = query.filter_by(brand=brand)
502
    query = query.group_by(Item.catalog_item_id).order_by(desc(Item.bestDealValue))
506
    query = query.group_by(Item.catalog_item_id).order_by(desc(Item.bestDealValue))
503
    return query
507
    return query
504
 
508
 
505
def get_latest_arrivals(limit, category=-1):
509
def get_latest_arrivals(limit, category=-1):
506
    query = get_latest_arrivals_query(category)
510
    query = get_latest_arrivals_query(category, None)
507
    items = query.all()[0:limit]
511
    items = query.all()[0:limit]
508
    return get_thrift_item_list(items)
512
    return get_thrift_item_list(items)
509
    
513
    
510
def get_latest_arrivals_count(limit, category=-1):
514
def get_latest_arrivals_count(limit, category=-1):
511
    count = get_latest_arrivals_query(category).count()
515
    count = get_latest_arrivals_query(category, None).count()
512
    if count is None:
516
    if count is None:
513
        count = 0
517
        count = 0
514
    count = min(count, limit)
518
    count = min(count, limit)
515
    return count
519
    return count
516
    
520
    
517
def get_latest_arrivals_catalog_ids(start_index, stop_index, category=-1):
521
def get_latest_arrivals_catalog_ids(start_index, stop_index, brand, category=-1):
518
    query = get_latest_arrivals_query(category)
522
    query = get_latest_arrivals_query(category, brand)
519
    latest_arrivals = query.all()[start_index:stop_index]
523
    latest_arrivals = query.all()[start_index:stop_index]
520
    return [item.catalog_item_id for item in latest_arrivals]
524
    return [item.catalog_item_id for item in latest_arrivals]
521
 
525
 
522
def get_latest_arrivals_query(category):
526
def get_latest_arrivals_query(category, brand):
523
    query = Item.query.filter_by(status=status.ACTIVE)
527
    query = Item.query.filter_by(status=status.ACTIVE)
524
    if category != -1:
528
    if category != -1:
525
        query = query.filter_by(category=category)
529
        query = query.filter_by(category=category)
-
 
530
    if brand is not None:
-
 
531
        query = query.filter_by(brand=brand)
526
    query = query.group_by(Item.catalog_item_id).order_by(desc(Item.startDate))
532
    query = query.group_by(Item.catalog_item_id).order_by(desc(Item.startDate))
527
    return query
533
    return query
528
 
534
 
529
def get_thrift_item_list(items):
535
def get_thrift_item_list(items):
530
    return [to_t_item(item) for item in items if item != None]
536
    return [to_t_item(item) for item in items if item != None]