Subversion Repositories SmartDukaan

Rev

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

Rev 16905 Rev 16927
Line 652... Line 652...
652
        except:
652
        except:
653
            print traceback.print_exc()
653
            print traceback.print_exc()
654
        return retailer
654
        return retailer
655
    
655
    
656
    def on_get(self, req, resp, agentId, callType=None, retailerId=None):
656
    def on_get(self, req, resp, agentId, callType=None, retailerId=None):
657
        global RETAILER_DETAIL_CALL_COUNTER
-
 
658
        RETAILER_DETAIL_CALL_COUNTER += 1
-
 
659
        lgr.info( "RETAILER_DETAIL_CALL_COUNTER " +  str(RETAILER_DETAIL_CALL_COUNTER))
-
 
660
        self.agentId = int(agentId)
-
 
661
        self.callType = callType
-
 
662
        if retailerId is not None:
-
 
663
            self.retailerId = int(retailerId)
-
 
664
            retailerLink = session.query(RetailerLinks).filter_by(retailer_id=self.retailerId).first()
-
 
665
            if retailerLink is not None:
-
 
666
                code = retailerLink.code
-
 
667
            else: 
-
 
668
                code = self.getCode()
-
 
669
                retailerLink = RetailerLinks()
-
 
670
                retailerLink.code = code
-
 
671
                retailerLink.agent_id = self.agentId
-
 
672
                retailerLink.retailer_id = self.retailerId
-
 
673
                
-
 
674
                activationCode=Activation_Codes()
-
 
675
                activationCode.code = code
-
 
676
                session.commit()
-
 
677
            session.close()
-
 
678
            resp.body =  json.dumps({"result":{"code":code,"link":make_tiny(code)}}, encoding='utf-8')
-
 
679
            return 
-
 
680
        retryFlag = False 
-
 
681
        if RETAILER_DETAIL_CALL_COUNTER % TOTAL >= DEALER_FRESH_FACTOR:
-
 
682
            retryFlag=True
-
 
683
        try:
657
        try:
-
 
658
            global RETAILER_DETAIL_CALL_COUNTER
-
 
659
            RETAILER_DETAIL_CALL_COUNTER += 1
-
 
660
            lgr.info( "RETAILER_DETAIL_CALL_COUNTER " +  str(RETAILER_DETAIL_CALL_COUNTER))
-
 
661
            self.agentId = int(agentId)
-
 
662
            self.callType = callType
-
 
663
            if retailerId is not None:
-
 
664
                self.retailerId = int(retailerId)
-
 
665
                retailerLink = session.query(RetailerLinks).filter_by(retailer_id=self.retailerId).first()
-
 
666
                if retailerLink is not None:
-
 
667
                    code = retailerLink.code
-
 
668
                else: 
-
 
669
                    code = self.getCode()
-
 
670
                    retailerLink = RetailerLinks()
-
 
671
                    retailerLink.code = code
-
 
672
                    retailerLink.agent_id = self.agentId
-
 
673
                    retailerLink.retailer_id = self.retailerId
-
 
674
                    
-
 
675
                    activationCode=Activation_Codes()
-
 
676
                    activationCode.code = code
-
 
677
                    session.commit()
-
 
678
                session.close()
-
 
679
                resp.body =  json.dumps({"result":{"code":code,"link":make_tiny(code)}}, encoding='utf-8')
-
 
680
                return 
-
 
681
            retryFlag = False 
-
 
682
            if RETAILER_DETAIL_CALL_COUNTER % TOTAL >= DEALER_FRESH_FACTOR:
-
 
683
                retryFlag=True
-
 
684
            try:
684
            if retryFlag:
685
                if retryFlag:
685
                retailer = self.getRetryRetailer()
686
                    retailer = self.getRetryRetailer()
686
            else:
687
                else:
687
                retailer = self.getNewRetailer()
688
                    retailer = self.getNewRetailer()
-
 
689
                if retailer is None:
-
 
690
                    resp.body = "{}"
-
 
691
                    return
-
 
692
                fetchInfo = FetchDataHistory()
-
 
693
                fetchInfo.agent_id = self.agentId
-
 
694
                fetchInfo.call_type = self.callType
-
 
695
                agent = session.query(Agents).filter_by(id=self.agentId).first()
-
 
696
                last_disposition = session.query(CallHistory).filter_by(agent_id=self.agentId).order_by(CallHistory.id.desc()).first()
-
 
697
                if last_disposition is None or last_disposition.created < agent.last_login:
-
 
698
                    fetchInfo.last_action = 'login'
-
 
699
                    fetchInfo.last_action_time = agent.last_login 
-
 
700
                else:
-
 
701
                    fetchInfo.last_action = 'disposition'
-
 
702
                    fetchInfo.last_action_time = last_disposition.created
-
 
703
                fetchInfo.retailer_id = retailer.id
-
 
704
                session.commit()
-
 
705
                
-
 
706
                otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
-
 
707
                resp.body = json.dumps(todict(getRetailerObj(retailer, otherContacts, self.callType)), encoding='utf-8')
-
 
708
                
-
 
709
                return
-
 
710
                
-
 
711
            finally:
-
 
712
                session.close()
-
 
713
    
688
            if retailer is None:
714
            if retailer is None:
689
                resp.body = "{}"
715
                resp.body = "{}"
690
                return
-
 
691
            fetchInfo = FetchDataHistory()
-
 
692
            fetchInfo.agent_id = self.agentId
-
 
693
            fetchInfo.call_type = self.callType
-
 
694
            agent = session.query(Agents).filter_by(id=self.agentId).first()
-
 
695
            last_disposition = session.query(CallHistory).filter_by(agent_id=self.agentId).order_by(CallHistory.id.desc()).first()
-
 
696
            if last_disposition is None or last_disposition.created < agent.last_login:
-
 
697
                fetchInfo.last_action = 'login'
-
 
698
                fetchInfo.last_action_time = agent.last_login 
-
 
699
            else:
716
            else:
700
                fetchInfo.last_action = 'disposition'
717
                print "It should never come here"
701
                fetchInfo.last_action_time = last_disposition.created
-
 
702
            fetchInfo.retailer_id = retailer.id
-
 
703
            session.commit()
-
 
704
            
-
 
705
            otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
-
 
706
            resp.body = json.dumps(todict(getRetailerObj(retailer, otherContacts, self.callType)), encoding='utf-8')
718
                resp.body = json.dumps(todict(getRetailerObj(retailer)), encoding='utf-8')
707
            
-
 
708
            return
-
 
709
            
-
 
710
        finally:
719
        finally:
711
            session.close()
720
            session.close()
712
 
-
 
713
        if retailer is None:
-
 
714
            resp.body = "{}"
-
 
715
        else:
-
 
716
            print "It should never come here"
-
 
717
            resp.body = json.dumps(todict(getRetailerObj(retailer)), encoding='utf-8')
-
 
718
        
-
 
719
        
721
        
720
    def on_post(self, req, resp, agentId, callType):
722
    def on_post(self, req, resp, agentId, callType):
721
        returned = False
723
        returned = False
722
        self.agentId = int(agentId)
724
        self.agentId = int(agentId)
723
        self.callType = callType
725
        self.callType = callType