Subversion Repositories SmartDukaan

Rev

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

Rev 16828 Rev 16829
Line 164... Line 164...
164
                'Could not decode the request body. The '
164
                'Could not decode the request body. The '
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
        
169
        res = None
170
        try:
170
        try:
171
            boundary = request.content_type.split(";")[1].strip().split("=")[1]
171
            boundary = request.content_type.split(";")[1].strip().split("=")[1]
172
            pdict= {'boundary':boundary}
172
            pdict= {'boundary':boundary}
173
            chunks = []
173
            chunks = []
174
            filepath = "/tmp/rejectfile"
174
            filepath = "/tmp/rejectfile"
Line 177... Line 177...
177
                    chunk = request.stream.read(4096)
177
                    chunk = request.stream.read(4096)
178
                    if not chunk:
178
                    if not chunk:
179
                        break
179
                        break
180
                    image_file.write(chunk)
180
                    image_file.write(chunk)
181
            with open(filepath, 'r') as image_file:
181
            with open(filepath, 'r') as image_file:
182
                print cgi.parse_multipart(image_file, pdict)
182
                res = cgi.parse_multipart(image_file, pdict)['rejects'][0]
-
 
183
            if res:
183
            #rejectCount = process_rejects(filepath) #this function is not yet implemented
184
                with open(filepath, 'wb') as image_file:
184
            rejectCount = 1
185
                    image_file.write(res)
-
 
186
                rejectCount = process_rejects(filepath) #this function is not yet implemented
185
            resp.content_type = 'text/html'
187
                resp.content_type = 'text/html'
186
            resp.body = """
188
                resp.body = """
187
                <html><head><title>Upload Rejects</title></head><body>
189
                    <html><head><title>Upload Rejects</title></head><body>
188
            <h1>Reject Successful</h1>
190
                <h1>Reject Successful</h1>
189
            <h2> %d orders rejected</h2>
191
                <h2> %d orders rejected</h2>
190
   
192
       
191
            </body></html>
193
                </body></html>
192
                """%(rejectCount) 
194
                    """%(rejectCount) 
193
        except ValueError:
195
        except ValueError:
194
            raise falcon.HTTPError(falcon.HTTP_400,
196
            raise falcon.HTTPError(falcon.HTTP_400,
195
                'Malformed JSON',
197
                'Malformed JSON',
196
                'Could not decode the request body. The '
198
                'Could not decode the request body. The '
197
                'JSON was incorrect.')
199
                'JSON was incorrect.')