Exemplo n.º 1
0
    def get_seller_commodities(self, seller_id, if_modified_since, check):
        resp = {}

        if not if_modified_since.isdigit():
            resp['status'] = REQUEST_PARAM_ERROR
            return json.dumps(resp, ensure_ascii=False)
        if_modified_since = int(if_modified_since)
        
        check = int(check)

        where = "WHERE %s='%s'" % (self.entry.COLUMN_NAME_SELLER_ID, seller_id) 
        other = "ORDER BY %s" % (self.entry.COLUMN_NAME_MODIFY_TIME)
        rows = get_instance().select(self.entry.TABLE_NAME, self.entry.COLUMNS, where, other)
        if rows == None:
            resp['status'] = SERVER_MYSQL_ERROR
            return json.dumps(resp, ensure_ascii=False)
            
        objects = []
        num = 0
        for r in rows:
            d = {self.entry.COLUMNS[i]:r[i] for i in range(len(self.entry.COLUMNS))}
            if d[self.entry.COLUMN_NAME_MODIFY_TIME] > if_modified_since:
                objects.append(d)
            else:
                num += d[self.entry.COLUMN_NAME_ID]
        
        resp['status'] = OK if not check or num == check else CHECK_ERROR 
        resp['commodities'] = objects
            
        return json.dumps(resp, ensure_ascii=False)
Exemplo n.º 2
0
    def get_area_sellers(self, area):
        resp = {}

        columns = [SellerServiceAreaEntry.COLUMN_NAME_SELLER_ID]
        where = "WHERE %s='%s'" % (SellerServiceAreaEntry.COLUMN_NAME_AREA, area) 
        rows = get_instance().select(SellerServiceAreaEntry.TABLE_NAME, columns, where)
        if rows == None:
            resp['status'] = SERVER_MYSQL_ERROR
            return json.dumps(resp, ensure_ascii=False)
        ids = set([r[0] for r in rows])
        print ids
        if ids:    
            rows = mysql.select(self.entry.TABLE_NAME, self.entry.COLUMNS, '')
            if rows == None:
                resp['status'] = SERVER_MYSQL_ERROR
                return json.dumps(resp, ensure_ascii=False)
            objects = []
            for r in rows:
                d = {self.entry.COLUMNS[i]:r[i] for i in range(len(self.entry.COLUMNS))}
                if d[self.entry.COLUMN_NAME_ID] in ids:
                    objects.append(d)
        
        resp['status'] = OK
        resp['sellers'] = objects
            
        return json.dumps(resp, ensure_ascii=False)
Exemplo n.º 3
0
    def get_area_sellers(self, area):
        resp = {}

        columns = [SellerServiceAreaEntry.COLUMN_NAME_SELLER_ID]
        where = "WHERE %s='%s'" % (SellerServiceAreaEntry.COLUMN_NAME_AREA,
                                   area)
        rows = get_instance().select(SellerServiceAreaEntry.TABLE_NAME,
                                     columns, where)
        if rows == None:
            resp['status'] = SERVER_MYSQL_ERROR
            return json.dumps(resp, ensure_ascii=False)
        ids = set([r[0] for r in rows])
        print ids
        if ids:
            rows = mysql.select(self.entry.TABLE_NAME, self.entry.COLUMNS, '')
            if rows == None:
                resp['status'] = SERVER_MYSQL_ERROR
                return json.dumps(resp, ensure_ascii=False)
            objects = []
            for r in rows:
                d = {
                    self.entry.COLUMNS[i]: r[i]
                    for i in range(len(self.entry.COLUMNS))
                }
                if d[self.entry.COLUMN_NAME_ID] in ids:
                    objects.append(d)

        resp['status'] = OK
        resp['sellers'] = objects

        return json.dumps(resp, ensure_ascii=False)
Exemplo n.º 4
0
 def get(self, id):
     resp = {}
     where = "WHERE %s='%s'" % (self.entry.COLUMN_NAME_ID, id) 
     rows = get_instance().select(self.entry.TABLE_NAME, self.entry.COLUMNS, where)
     if len(rows) != 1:
         resp['status'] = SERVER_MYSQL_ERROR
         return json.dumps(resp, ensure_ascii=False)
     
     resp['buyer'] = {self.entry.COLUMNS[i]:rows[0][i] for i in range(len(self.entry.COLUMNS))}
     resp['status'] = OK
         
     return json.dumps(resp, ensure_ascii=False)
Exemplo n.º 5
0
    def get(self, id):
        resp = {}
        where = "WHERE %s='%s'" % (self.entry.COLUMN_NAME_ID, id)
        rows = get_instance().select(self.entry.TABLE_NAME, self.entry.COLUMNS,
                                     where)
        if len(rows) != 1:
            resp['status'] = SERVER_MYSQL_ERROR
            return json.dumps(resp, ensure_ascii=False)

        resp['buyer'] = {
            self.entry.COLUMNS[i]: rows[0][i]
            for i in range(len(self.entry.COLUMNS))
        }
        resp['status'] = OK

        return json.dumps(resp, ensure_ascii=False)
Exemplo n.º 6
0
 def get_buyer_unfinished_orders(self, buyer_id):
     resp = {}
     where = "WHERE %s='%s'" % (self.entry.COLUMN_NAME_BUYER_ID, buyer_id) 
     other = "ORDER BY %s DESC" % (self.entry.COLUMN_NAME_MODIFY_TIME)
     rows = get_instance().select(self.entry.TABLE_NAME, self.entry.COLUMNS, where, other)
     if rows == None:
         resp['status'] = SERVER_MYSQL_ERROR
         return json.dumps(resp, ensure_ascii=False)
         
     objects = []
     for r in rows:
         d = {self.entry.COLUMNS[i]:r[i] for i in range(len(self.entry.COLUMNS))}
         objects.append(d)
     
     resp['status'] = OK
     resp['orders'] = objects
         
     return json.dumps(resp, ensure_ascii=False)
Exemplo n.º 7
0
    def get_buyer_unfinished_orders(self, buyer_id):
        resp = {}
        where = "WHERE %s='%s'" % (self.entry.COLUMN_NAME_BUYER_ID, buyer_id)
        other = "ORDER BY %s DESC" % (self.entry.COLUMN_NAME_MODIFY_TIME)
        rows = get_instance().select(self.entry.TABLE_NAME, self.entry.COLUMNS,
                                     where, other)
        if rows == None:
            resp['status'] = SERVER_MYSQL_ERROR
            return json.dumps(resp, ensure_ascii=False)

        objects = []
        for r in rows:
            d = {
                self.entry.COLUMNS[i]: r[i]
                for i in range(len(self.entry.COLUMNS))
            }
            objects.append(d)

        resp['status'] = OK
        resp['orders'] = objects

        return json.dumps(resp, ensure_ascii=False)