Subversion Repositories SmartDukaan

Rev

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

Rev 2828 Rev 2975
Line 659... Line 659...
659
 
659
 
660
def get_latest_arrivals(limit, category=-1):
660
def get_latest_arrivals(limit, category=-1):
661
    '''
661
    '''
662
    Returns up to limit number of Latest Arrivals in the given category.
662
    Returns up to limit number of Latest Arrivals in the given category.
663
    '''
663
    '''
-
 
664
    categories = []
-
 
665
    if category != -1:
-
 
666
        categories = [category]
664
    query = get_latest_arrivals_query(Item, category, None)
667
    query = get_latest_arrivals_query(Item, categories, None)
665
    items = query.all()[0:limit]
668
    items = query.all()[0:limit]
666
    return get_thrift_item_list(items)
669
    return get_thrift_item_list(items)
667
    
670
    
668
def get_latest_arrivals_count(limit, category=-1):
671
def get_latest_arrivals_count(limit, category=-1):
669
    '''
672
    '''
670
    Returns the number of latest arrivals which will be displayed on the website.
673
    Returns the number of latest arrivals which will be displayed on the website.
671
    Ignores the category if it's passed as -1.
674
    Ignores the category if it's passed as -1.
672
    '''
675
    '''
-
 
676
    categories = []
-
 
677
    if category != -1:
-
 
678
        categories = [category]
673
    count = get_latest_arrivals_counting_query(func.count(distinct(Item.catalog_item_id)), category, None).scalar()
679
    count = get_latest_arrivals_counting_query(func.count(distinct(Item.catalog_item_id)), categories, None).scalar()
674
    if count is None:
680
    if count is None:
675
        count = 0
681
        count = 0
676
    count = min(count, limit)
682
    count = min(count, limit)
677
    return count
683
    return count
678
    
684
    
679
def get_latest_arrivals_catalog_ids(start_index, stop_index, brand, category=-1):
685
def get_latest_arrivals_catalog_ids(start_index, stop_index, brand, categories=[]):
680
    '''
686
    '''
681
    Returns the catalog_item_ids of the latest arrivals between the start and the stop index
687
    Returns the catalog_item_ids of the latest arrivals between the start and the stop index
682
    Ignores the category if it's passed as -1 and the brand if it's passed as None.
688
    Ignores the category if it's passed as -1 and the brand if it's passed as None.
683
    '''
689
    '''
684
    query = get_latest_arrivals_query(Item, category, brand)
690
    query = get_latest_arrivals_query(Item, categories, brand)
685
    latest_arrivals = query.all()[start_index:stop_index]
691
    latest_arrivals = query.all()[start_index:stop_index]
686
    return [item.catalog_item_id for item in latest_arrivals]
692
    return [item.catalog_item_id for item in latest_arrivals]
687
 
693
 
688
def get_latest_arrivals_counting_query(obj, category, brand):
694
def get_latest_arrivals_counting_query(obj, categories, brand):
689
    '''
695
    '''
690
    Returns the query to be used to count Latest arrivals.
696
    Returns the query to be used to count Latest arrivals.
691
    Ignores the category if it's passed as -1 and the brand if it's passed as None.
697
    Ignores the category if it's passed as -1 and the brand if it's passed as None.
692
    '''
698
    '''
693
    query = session.query(obj).filter_by(status=status.ACTIVE)
699
    query = session.query(obj).filter_by(status=status.ACTIVE)
-
 
700
    
694
    if category != -1:
701
    all_categories = []
-
 
702
    for category in categories:
695
        all_categories = [category]
703
        all_categories.append(category)
696
        child_categories = get_child_categories(category)
704
        child_categories = get_child_categories(category)
697
        if child_categories is not None:
705
        if child_categories:
698
            all_categories = all_categories + child_categories 
706
            all_categories = all_categories + child_categories
-
 
707
    if all_categories: 
699
        query = query.filter(Item.category.in_(all_categories))
708
        query = query.filter(Item.category.in_(all_categories))
-
 
709
    
700
    if brand is not None:
710
    if brand is not None:
701
        query = query.filter_by(brand=brand)
711
        query = query.filter_by(brand=brand)
702
    return query
712
    return query
703
 
713
 
704
def get_latest_arrivals_query(obj, category, brand):
714
def get_latest_arrivals_query(obj, categories, brand):
705
    '''
715
    '''
706
    Returns the query to be used to retrieve Latest Arrivals.
716
    Returns the query to be used to retrieve Latest Arrivals.
707
    Ignores the category if it's passed as -1 and the brand if it's passed as None.
717
    Ignores the category if it's passed as -1 and the brand if it's passed as None.
708
    '''
718
    '''
709
    query = get_latest_arrivals_counting_query(obj, category, brand)
719
    query = get_latest_arrivals_counting_query(obj, categories, brand)
710
    query = query.group_by(Item.catalog_item_id).order_by(desc(Item.startDate))
720
    query = query.group_by(Item.catalog_item_id).order_by(desc(Item.startDate))
711
    return query
721
    return query
712
 
722
 
713
def get_thrift_item_list(items):
723
def get_thrift_item_list(items):
714
    return [to_t_item(item) for item in items if item != None]
724
    return [to_t_item(item) for item in items if item != None]