Exemplo n.º 1
0
 def post(self, commodity):
     print 'CommoditiesApi post: [%s]' % commodity
     resp = {}
     try:
         d = json.loads(commodity)
         d[self.entry.COLUMN_NAME_MODIFY_TIME] = int(time.time())
         if not d[self.entry.COLUMN_NAME_THUMBNAIL]:
             d[self.entry.COLUMN_NAME_THUMBNAIL] = d[self.entry.COLUMN_NAME_IMAGE_1]
         cs = [x for x in d.keys() if x != self.entry.COLUMN_NAME_ID]
         id = d[self.entry.COLUMN_NAME_ID]
         if id == 0: # add commodity
             ps = ', '.join(cs)
             ss = ', '.join(['%s' for c in cs])
             sql = 'INSERT INTO %s (%s) VALUES (%s)' % (self.entry.TABLE_NAME, ps, ss)
         else: # replace
             kvs = ', '.join(['%s=%%s' % (c) for c in cs])
             sql = 'UPDATE %s SET %s WHERE %s=%d' % (self.entry.TABLE_NAME, kvs, self.entry.COLUMN_NAME_ID, id)
         print sql
         args = tuple([urllib.unquote(str(d[c])) for c in cs])
         print args
         r = mysql.execute(sql, args)
         if r != 1:
             print 'mysql execute return %d' % r
             resp['status'] = SERVER_MYSQL_ERROR
         else:
             resp['status'] = OK
     except Exception as e:
         print e
         resp['status'] = REQUEST_PARAM_ERROR
     return json.dumps(resp, ensure_ascii=False)
Exemplo n.º 2
0
 def post(data):
     resp = {}
     try:
         obj = json.loads(data)
         d = {col:obj[col] for col in self.entry.COLUMNS if col in obj}
         kvs = d.items()
         ks = ', '.join([x[0] for x in kvs])
         ss = ', '.join(['%s' for x in kvs])
         sql = "REPLACE INTO %s (%s) VALUES (%s)" % (self.entry.TABLE_NAME, ks, ss)
         args = tuple([x[1] for x in kvs])
         r = mysql.execute(sql, args)
         if r == -1:
             resp['status'] = SERVER_MYSQL_ERROR
         else:
             return self.get(s['id'])
     except Exception as e:
         resp['status'] = INPUT_DATA_ERROR
         resp['error'] = str(e)
         
     return json.dumps(resp, ensure_ascii=False)
Exemplo n.º 3
0
 def post(self, buyer):
     print 'BuyerApi post: [%s]' % buyer
     resp = {}
     try:
         d = json.loads(buyer)
         d[self.entry.COLUMN_NAME_MODIFY_TIME] = int(time.time())
         cs = [x for x in d.keys()]
         ps = ', '.join(cs)
         ss = ', '.join(['%s' for c in cs])
         sql = 'REPLACE INTO %s (%s) VALUES (%s)' % (self.entry.TABLE_NAME, ps, ss)
         args = tuple([urllib.unquote(str(d[c])) for c in cs])
         r = mysql.execute(sql, args)
         if r != 1:
             print 'mysql execute return %d' % r
             resp['status'] = SERVER_MYSQL_ERROR
         else:
             resp['status'] = OK
     except Exception as e:
         print e
         resp['status'] = REQUEST_PARAM_ERROR
     return json.dumps(resp, ensure_ascii=False)
Exemplo n.º 4
0
 def post(self, buyer):
     print 'BuyerApi post: [%s]' % buyer
     resp = {}
     try:
         d = json.loads(buyer)
         d[self.entry.COLUMN_NAME_MODIFY_TIME] = int(time.time())
         cs = [x for x in d.keys()]
         ps = ', '.join(cs)
         ss = ', '.join(['%s' for c in cs])
         sql = 'REPLACE INTO %s (%s) VALUES (%s)' % (self.entry.TABLE_NAME,
                                                     ps, ss)
         args = tuple([urllib.unquote(str(d[c])) for c in cs])
         r = mysql.execute(sql, args)
         if r != 1:
             print 'mysql execute return %d' % r
             resp['status'] = SERVER_MYSQL_ERROR
         else:
             resp['status'] = OK
     except Exception as e:
         print e
         resp['status'] = REQUEST_PARAM_ERROR
     return json.dumps(resp, ensure_ascii=False)