Subversion Repositories SmartDukaan

Rev

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

Rev 16834 Rev 16838
Line 165... Line 165...
165
                'JSON was incorrect.')
165
                'JSON was incorrect.')
166
            
166
            
167
            
167
            
168
    def on_post(self, request, resp):
168
    def on_post(self, request, resp):
169
        res = None
169
        res = None
170
        rejectCount = 0
-
 
171
        try:
170
        try:
172
            boundary = request.content_type.split(";")[1].strip().split("=")[1]
171
            boundary = request.content_type.split(";")[1].strip().split("=")[1]
173
            pdict= {'boundary':boundary}
172
            pdict= {'boundary':boundary}
174
            filepath = "/tmp/rejectfile"
173
            filepath = "/tmp/rejectfile"
175
            with open(filepath, 'wb') as image_file:
174
            with open(filepath, 'wb') as image_file:
Line 181... Line 180...
181
            with open(filepath, 'r') as image_file:
180
            with open(filepath, 'r') as image_file:
182
                res = cgi.parse_multipart(image_file, pdict)['rejects'][0]
181
                res = cgi.parse_multipart(image_file, pdict)['rejects'][0]
183
            if res:
182
            if res:
184
                with open(filepath, 'wb') as image_file:
183
                with open(filepath, 'wb') as image_file:
185
                    image_file.write(res)
184
                    image_file.write(res)
186
                rejectCount += process_rejects(filepath)
185
                rejectCount = process_rejects(filepath)
187
                resp.content_type = 'text/html'
186
                resp.content_type = 'text/html'
188
                resp.body = """
187
                resp.body = """
189
                    <html><head><title>Upload Rejects</title></head><body>
188
                    <html><head><title>Upload Rejects</title></head><body>
190
                <h1>Reject Successful</h1>
189
                <h1>Reject Successful</h1>
191
                <h2> %d orders rejected</h2>
190
                <h2> %d orders rejected</h2>
Line 198... Line 197...
198
                'Could not decode the request body. The '
197
                'Could not decode the request body. The '
199
                'JSON was incorrect.')
198
                'JSON was incorrect.')
200
 
199
 
201
 
200
 
202
def process_rejects(filepath):
201
def process_rejects(filepath):
-
 
202
    rejectCount = 0
203
    workbook = xlrd.open_workbook(filepath)
203
    workbook = xlrd.open_workbook(filepath)
204
    sheet = workbook.sheet_by_index(0)
204
    sheet = workbook.sheet_by_index(0)
205
    num_rows = sheet.nrows
205
    num_rows = sheet.nrows
206
    for rownum in range(1, num_rows):
206
    for rownum in range(1, num_rows):
207
        try:
207
        try:
208
            orderId, userId, merchantOrderId, subOrderId  = sheet.row_values(rownum)[0:4]
208
            orderId, userId, merchantOrderId, subOrderId  = sheet.row_values(rownum)[0:4]
209
            Mongo.rejectCashback(int(orderId), subOrderId)
209
            rejectCount += Mongo.rejectCashback(int(orderId), subOrderId)
210
        except:
210
        except:
211
            traceback.print_exc()
211
            traceback.print_exc()
212
              
212
    return rejectCount
213
 
213
 
214
class SnapShot():
214
class SnapShot():
215
    def on_get(self, req, resp):
215
    def on_get(self, req, resp):
216
        try:
216
        try:
217
            resp.content_type = 'text/html'
217
            resp.content_type = 'text/html'