Subversion Repositories SmartDukaan

Rev

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

Rev 13907 Rev 13910
Line 141... Line 141...
141
        return result
141
        return result
142
 
142
 
143
def getDeals(category_id, offset, limit, sort, direction):
143
def getDeals(category_id, offset, limit, sort, direction):
144
    rank = 1
144
    rank = 1
145
    deals = {}
145
    deals = {}
-
 
146
    outer_query = []
-
 
147
    outer_query.append({"showDeal":1})
-
 
148
    query = {}
-
 
149
    query['$gt'] = 0
-
 
150
    outer_query.append({'totalPoints':query})
-
 
151
    if category_id in (3,5):
-
 
152
        outer_query.append({'category_id':category_id})
146
    if sort is None or direction is None:
153
    if sort is None or direction is None:
147
        sortField = "totalPoints"
-
 
148
        direct = -1
154
        direct = -1
-
 
155
        print outer_query
-
 
156
        data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([('totalPoints',direct),('bestSellerPoints',direct),('nlcPoints',direct),('rank',direct)]).skip(offset).limit(limit))
-
 
157
        for temp in data:
-
 
158
            print temp['_id'],
-
 
159
            print '\t',
-
 
160
            print temp['totalPoints'],
-
 
161
            print '\t',
-
 
162
            print temp['bestSellerPoints'],
-
 
163
            print '\t',
-
 
164
            print temp['nlcPoints'],
-
 
165
            print '\t',
-
 
166
            print temp['rank']
149
    else:
167
    else:
150
        sortField = sort
168
        print outer_query
151
        direct = direction
169
        direct = direction
152
    if category_id == 0:
170
        if sort == "bestSellerPoints":
153
        print "All categories deals"
171
            print "yes,sorting by bestSellerPoints"
-
 
172
            data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([('bestSellerPoints',direct),('rank',direct),('nlcPoints',direct)]).skip(offset).limit(limit))
154
        print category_id
173
            for temp in data:
155
        print sortField
174
                print temp['_id'],
156
        print offset
175
                print '\t',
157
        print limit
176
                print temp['totalPoints'],
158
        print direct
177
                print '\t',
159
        data = list(get_mongo_connection().Catalog.Deals.find({'rank':{'$gt':0},'showDeal':1}).sort([(sortField,direct)]).skip(offset).limit(limit))
-
 
160
    else:
-
 
161
        print "selective category deals"
178
                print temp['bestSellerPoints'],
162
        print category_id
179
                print '\t',
163
        print sortField
180
                print temp['nlcPoints'],
164
        print offset
181
                print '\t',
165
        print limit
182
                print temp['rank']
166
        print direct
183
        else:
167
        data = list(get_mongo_connection().Catalog.Deals.find({'rank':{'$gt':0},'category_id':category_id,'showDeal':1}).sort([(sortField,direct)]).skip(offset).limit(limit))
184
            data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([(sort,direct)]).skip(offset).limit(limit))
-
 
185
            for temp in data:
168
    print data[0]['_id']
186
                print temp['_id'],
-
 
187
                print '\t',
-
 
188
                print temp['available_price']
169
    for d in data:
189
    for d in data:
170
        item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
190
        item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
171
        if not deals.has_key(item[0]['identifier']):
191
        if not deals.has_key(item[0]['identifier']):
172
            item[0]['dealRank'] = rank 
192
            item[0]['dealRank'] = rank 
173
            deals[item[0]['identifier']] = item[0]
193
            deals[item[0]['identifier']] = item[0]
Line 201... Line 221...
201
    
221
    
202
    
222
    
203
    
223
    
204
 
224
 
205
def main():
225
def main():
206
    populateCashBack()
226
    print getDeals(0, 0, 20, "available_price", 1)
207
    
227
    
208
if __name__=='__main__':
228
if __name__=='__main__':
209
    main()
229
    main()
210
230