Subversion Repositories SmartDukaan

Rev

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

Rev 17608 Rev 17610
Line 2162... Line 2162...
2162
        get_mongo_connection().Catalog.DealObject.update({'_id':_id},{"$set":data},upsert=False)
2162
        get_mongo_connection().Catalog.DealObject.update({'_id':_id},{"$set":data},upsert=False)
2163
        return {1:"Data updated successfully"}
2163
        return {1:"Data updated successfully"}
2164
    except:
2164
    except:
2165
        return {0:"Error in updating data"}
2165
        return {0:"Error in updating data"}
2166
 
2166
 
-
 
2167
def getAllFeaturedDealsForDealObject(offset, limit):
-
 
2168
    data = []
-
 
2169
    collection = get_mongo_connection().Catalog.FeaturedDealsDealObject
-
 
2170
    cursor = collection.find({}).skip(offset).limit(limit)
-
 
2171
    for val in cursor:
-
 
2172
        data.append(val)
-
 
2173
    return data
-
 
2174
 
-
 
2175
def addFeaturedDealForDealObject(data):
-
 
2176
    collection = get_mongo_connection().Catalog.FeaturedDealsDealObject
-
 
2177
    cursor = collection.find({'_id':data['_id']})
-
 
2178
    master = get_mongo_connection().Catalog.DealObject.find_one({'_id':data['_id']})
-
 
2179
    if master is None:
-
 
2180
        return {0:"Deal Object id wrong"}
-
 
2181
    otherInfoObj = data['otherInfo']
-
 
2182
    toPop = []
-
 
2183
    for x,y in otherInfoObj.iteritems():
-
 
2184
        if y==0:
-
 
2185
            toPop.append(x)
-
 
2186
    
-
 
2187
    for popItem in toPop:
-
 
2188
        otherInfoObj.pop(popItem)
-
 
2189
    if len(otherInfoObj.keys())==0:
-
 
2190
        return {0:"No rank info to add"}
-
 
2191
    
-
 
2192
    for x,y in otherInfoObj.iteritems():
-
 
2193
        exist = get_mongo_connection().Catalog.FeaturedDealsDealObject.find({'otherInfo.'+x:y})
-
 
2194
        if exist.count() >0:
-
 
2195
            return {0:"Rank already assigned Deal Object Id %s"%(exist[0]['_id'])}
-
 
2196
    if cursor.count() > 0:
-
 
2197
        return {0:"Deal Object Id information already present."}
-
 
2198
    else:
-
 
2199
        collection.insert(data)
-
 
2200
        return {1:"Data added successfully"}
-
 
2201
 
-
 
2202
 
2167
def main():
2203
def main():
2168
    data = {'hello':"ya"}
2204
    data = {'hello':"ya"}
2169
    addDealObject(data)
2205
    addDealObject(data)
2170
 
2206
 
2171
        
2207