Subversion Repositories SmartDukaan

Rev

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

Rev 15202 Rev 15207
Line 18... Line 18...
18
import traceback
18
import traceback
19
import urllib
19
import urllib
20
import urllib2
20
import urllib2
21
import uuid
21
import uuid
22
from operator import and_
22
from operator import and_
-
 
23
import string
-
 
24
 
-
 
25
alphalist = list(string.uppercase)
-
 
26
alphalist.remove('O')
-
 
27
numList = ['1','2','3','4','5','6','7','8','9']
-
 
28
codesys = [alphalist, alphalist, numList, numList, numList]
-
 
29
 
-
 
30
 
-
 
31
def getNextCode(codesys, code=None):
-
 
32
    if code is None:
-
 
33
        code = []
-
 
34
        for charcode in codesys:
-
 
35
            code.append(charcode[0])
-
 
36
        return string.join(code, '')
-
 
37
    carry = True
-
 
38
    code = list(code)
-
 
39
    lastindex = len(codesys) - 1
-
 
40
    while carry:
-
 
41
        listChar = codesys[lastindex]
-
 
42
        newIndex = (listChar.index(code[lastindex])+1)%len(listChar)
-
 
43
        print newIndex
-
 
44
        code[lastindex] = listChar[newIndex]
-
 
45
        if newIndex != 0:
-
 
46
            carry = False
-
 
47
        lastindex -= 1
-
 
48
        if lastindex ==-1:
-
 
49
            raise BaseException("All codes are exhausted")
-
 
50
        
-
 
51
    return string.join(code, '')
-
 
52
        
-
 
53
        
-
 
54
 
-
 
55
 
23
global RETAILER_DETAIL_CALL_COUNTER
56
global RETAILER_DETAIL_CALL_COUNTER
24
RETAILER_DETAIL_CALL_COUNTER = 0
57
RETAILER_DETAIL_CALL_COUNTER = 0
25
 
58
 
26
lgr = getLogger('/var/log/retailer-acquisition-api.log')
59
lgr = getLogger('/var/log/retailer-acquisition-api.log')
27
DEALER_RETRY_FACTOR = int(PythonPropertyReader.getConfig('DEALER_RETRY_FACTOR'))
60
DEALER_RETRY_FACTOR = int(PythonPropertyReader.getConfig('DEALER_RETRY_FACTOR'))
Line 690... Line 723...
690
            self.callHistory.disposition_description = 'Not a retailer'    
723
            self.callHistory.disposition_description = 'Not a retailer'    
691
        session.commit()
724
        session.commit()
692
        return True   
725
        return True   
693
        
726
        
694
    def getCode(self,):
727
    def getCode(self,):
695
        prefix = None
728
        newCode = None
696
        notFound = True
729
        lastLink = session.query(RetailerLinks).order_by(RetailerLinks.id.desc()).with_lockmode("update").first()
697
        while notFound:
730
        if lastLink is not None:
698
            code = uuid.uuid4().hex[:10] if prefix is None else prefix + uuid.uuid4().hex[:6]
731
            if len(lastLink.code)==len(codesys):
699
            notFound = '0' in code and session.query(RetailerLinks).filter_by(code=code).first() is not None
732
                newCode=lastLink.code
700
        return code
733
        return getNextCode(codesys, newCode)
701
    
734
    
702
    def callLater(self,):
735
    def callLater(self,):
703
        self.retailer.status = 'retry' if self.callType == 'fresh' else 'fretry'
736
        self.retailer.status = 'retry' if self.callType == 'fresh' else 'fretry'
704
        self.retailer.call_priority = None
737
        self.retailer.call_priority = None
705
        if self.callDisposition == 'call_later':
738
        if self.callDisposition == 'call_later':
Line 865... Line 898...
865
    
898
    
866
class Mock(object):
899
class Mock(object):
867
    pass
900
    pass
868
 
901
 
869
def main():
902
def main():
870
    l=Login()
-
 
871
    l.test("manaskapoor31@gmail.com", "qwerty", "fresh")
903
    print getNextCode(codesys, 'ZZ999')
872
    
904
    
873
if __name__ == '__main__':
905
if __name__ == '__main__':
874
        main()
906
    main()
875
        
907
        
876
908