Subversion Repositories SmartDukaan

Rev

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

Rev 15313 Rev 15314
Line 988... Line 988...
988
    else:
988
    else:
989
        return obj
989
        return obj
990
    
990
    
991
def getRetailerObj(retailer, otherContacts1=None):
991
def getRetailerObj(retailer, otherContacts1=None):
992
    print "before otherContacts1",otherContacts1
992
    print "before otherContacts1",otherContacts1
993
    otherContacts1 = [] if otherContacts1 is None else otherContacts1
993
    otherContacts = [] if otherContacts1 is None else otherContacts1
994
    print "afotherContacts1",otherContacts1
994
    print "afotherContacts1",otherContacts1
995
    obj = Mock()
995
    obj = Mock()
996
    obj.title = retailer.title
996
    obj.title = retailer.title
997
    obj.id = retailer.id
997
    obj.id = retailer.id
998
    if retailer.contact1 is not None and retailer.contact1 not in otherContacts1:
998
    if retailer.contact1 is not None and retailer.contact1 not in otherContacts:
999
        otherContacts1.append(retailer.contact1)
999
        otherContacts1.append(retailer.contact1)
1000
    if retailer.contact2 is not None and retailer.contact2 not in otherContacts1:
1000
    if retailer.contact2 is not None and retailer.contact2 not in otherContacts:
1001
        otherContacts1.append(retailer.contact2)
1001
        otherContacts1.append(retailer.contact2)
1002
    obj.address = retailer.address_new if retailer.address_new is not None else retailer.address
1002
    obj.address = retailer.address_new if retailer.address_new is not None else retailer.address
1003
    obj.contact1 = otherContacts1[0]
1003
    obj.contact1 = otherContacts1[0]
1004
    obj.contact2 = None if len(otherContacts1)==1 else otherContacts1[1]
1004
    obj.contact2 = None if len(otherContacts1)==1 else otherContacts1[1]
1005
    obj.scheduled = (retailer.call_priority is not None)
1005
    obj.scheduled = (retailer.call_priority is not None)
Line 1014... Line 1014...
1014
    return str(x.read())
1014
    return str(x.read())
1015
 
1015
 
1016
class SearchUser():
1016
class SearchUser():
1017
            
1017
            
1018
    def on_post(self, req, resp, agentId, searchType):
1018
    def on_post(self, req, resp, agentId, searchType):
-
 
1019
        retailersJsonArray = []
1019
        try:
1020
        try:
1020
            jsonReq = json.loads(req.stream.read(), encoding='utf-8')
1021
            jsonReq = json.loads(req.stream.read(), encoding='utf-8')
1021
            lgr.info( "Request in Search----\n"  + str(jsonReq))
1022
            lgr.info( "Request in Search----\n"  + str(jsonReq))
1022
            contact=jsonReq.get('searchTerm')
1023
            contact=jsonReq.get('searchTerm')
1023
            if(searchType=="number"):
1024
            if(searchType=="number"):
Line 1036... Line 1037...
1036
            retailers = session.query(Retailers).filter(anotherCondition).all()
1037
            retailers = session.query(Retailers).filter(anotherCondition).all()
1037
            if retailers is None:
1038
            if retailers is None:
1038
                resp.body = json.dumps("{}")
1039
                resp.body = json.dumps("{}")
1039
            else:
1040
            else:
1040
                for retailer in retailers:
1041
                for retailer in retailers:
1041
                    otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]    
1042
                    otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
1042
                    resp.body = json.dumps({"Retailers":[todict(getRetailerObj(retailer, otherContacts)) for retailer in retailers]}, encoding='utf-8')
1043
                    retailersJsonArray.append(todict(getRetailerObj(retailer, otherContacts)))    
-
 
1044
            resp.body = json.dumps({"Retailers":retailersJsonArray}, encoding='utf-8')
1043
            return
1045
            return
1044
        finally:
1046
        finally:
1045
            session.close()
1047
            session.close()
1046
 
1048
 
1047
 
1049