Subversion Repositories SmartDukaan

Rev

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

Rev 14398 Rev 14481
Line 260... Line 260...
260
    def on_get(self,req,resp,userId):
260
    def on_get(self,req,resp,userId):
261
        UserSpecificDeals.generateSheet(userId)
261
        UserSpecificDeals.generateSheet(userId)
262
        json_docs = json.dumps({'True':'Sheet generated, mail sent.'}, default=json_util.default)
262
        json_docs = json.dumps({'True':'Sheet generated, mail sent.'}, default=json_util.default)
263
        resp.body = json.dumps(json_docs, encoding='utf-8')
263
        resp.body = json.dumps(json_docs, encoding='utf-8')
264
 
264
 
265
 
-
 
266
 
-
 
267
class CommonUpdate():
265
class CommonUpdate():
268
    
266
    
269
    def on_post(self,req,resp):
267
    def on_post(self,req,resp):
270
        try:
268
        try:
271
            result_json = json.loads(req.stream.read(), encoding='utf-8')
269
            result_json = json.loads(req.stream.read(), encoding='utf-8')
Line 276... Line 274...
276
                'JSON was incorrect.')
274
                'JSON was incorrect.')
277
            
275
            
278
        result = Mongo.updateCollection(result_json)
276
        result = Mongo.updateCollection(result_json)
279
        resp.body = json.dumps(result, encoding='utf-8')
277
        resp.body = json.dumps(result, encoding='utf-8')
280
        resp.content_type = "application/json; charset=utf-8"
278
        resp.content_type = "application/json; charset=utf-8"
-
 
279
 
-
 
280
class NegativeDeals():
-
 
281
    
-
 
282
    def on_get(self, req, resp):
-
 
283
        
-
 
284
        offset = req.get_param_as_int("offset")
-
 
285
        limit = req.get_param_as_int("limit")
-
 
286
        
-
 
287
        result = Mongo.getAllNegativeDeals(offset, limit)
-
 
288
        json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
-
 
289
        resp.body = json_docs
-
 
290
 
-
 
291
    
-
 
292
    def on_post(self, req, resp):
-
 
293
        
-
 
294
        try:
-
 
295
            result_json = json.loads(req.stream.read(), encoding='utf-8')
-
 
296
        except ValueError:
-
 
297
            raise falcon.HTTPError(falcon.HTTP_400,
-
 
298
                'Malformed JSON',
-
 
299
                'Could not decode the request body. The '
-
 
300
                'JSON was incorrect.')
-
 
301
            
-
 
302
        result = Mongo.addNegativeDeals(result_json)
-
 
303
        resp.body = json.dumps(result, encoding='utf-8')
-
 
304
 
-
 
305
class ManualDeals():
-
 
306
    
-
 
307
    def on_get(self, req, resp):
-
 
308
        
-
 
309
        offset = req.get_param_as_int("offset")
-
 
310
        limit = req.get_param_as_int("limit")
-
 
311
        
-
 
312
        result = Mongo.getAllManualDeals(offset, limit)
-
 
313
        json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
-
 
314
        resp.body = json_docs
-
 
315
 
-
 
316
    
-
 
317
    def on_post(self, req, resp):
-
 
318
        
-
 
319
        try:
-
 
320
            result_json = json.loads(req.stream.read(), encoding='utf-8')
-
 
321
        except ValueError:
-
 
322
            raise falcon.HTTPError(falcon.HTTP_400,
-
 
323
                'Malformed JSON',
-
 
324
                'Could not decode the request body. The '
-
 
325
                'JSON was incorrect.')
-
 
326
            
-
 
327
        result = Mongo.addManualDeals(result_json)
-
 
328
        resp.body = json.dumps(result, encoding='utf-8')
-
 
329
        
-
 
330
class CommonDelete():
-
 
331
    def on_post(self,req,resp):
-
 
332
        try:
-
 
333
            result_json = json.loads(req.stream.read(), encoding='utf-8')
-
 
334
        except ValueError:
-
 
335
            raise falcon.HTTPError(falcon.HTTP_400,
-
 
336
                'Malformed JSON',
-
 
337
                'Could not decode the request body. The '
-
 
338
                'JSON was incorrect.')
-
 
339
            
-
 
340
        result = Mongo.deleteDocument(result_json)
-
 
341
        resp.body = json.dumps(result, encoding='utf-8')
-
 
342
        resp.content_type = "application/json; charset=utf-8"