Classes and POST

27 views
Skip to first unread message

Oliver Hafner

unread,
Jun 16, 2013, 2:18:56 PM6/16/13
to we...@googlegroups.com
Is there a way to have a general class e.g.  Customers, which would have def's for add, delete, update?  and then have some kind of inherited post options?

It seems to me that creating a new class for each function with its own POST code is pretty long winded way to do things?  Is there a way to do this so I could have:

urls = (
  '/', 'index',
  '/bitcoin/(.+)','bitcoin',
  '/bitcoin/UserBalance/(.+)', 'bitcoinWallet.getbalance',
  '/bitcoin/SendFromUser/(.+)','bitcoinWallet.sendfromuser',
  '/bitcoin/ListAccounts/','bitcoinWallet.listaccounts'
)

class bitcoinWallet:
    import web
    import bitcoinrpc
    import bitcoinrpc.data

    def POST(self):
        i = web.input() 
        if i.action == "GetUserBalance":
            getUserBalance(i.bitcoinAccount)
        elif i.action == "SendFromUser":
            sendFromUser(i.Account, i.to,i.amount)
        elif i.action == "ListAccounts":

     def __init__(self):
            conn = bitcoinrpc.connect_to_remote('username', 'password', host='server', port=8332)
        
    def getUserBalance(self, bitcoinAccount):
        balance = conn.getaccountaddress(bitcoinAccount)
        return balance
    
    def sendFromUser(self, bitcoinAccount, to, amount):
        txid = conn.sendfrom(bitcoinAccount, to, amount)
        return txid
    
    def listAccounts(self):
        accounts = conn.listaccounts()
        return accounts
    
    if __name__ == "__main__":
        app = web.application(urls, globals())
        app.run()

Anand Chitipothu

unread,
Jun 16, 2013, 11:43:26 PM6/16/13
to webpy
You need to call them as self.getUserBalance and self.sendFromUser etc.

Anand
Reply all
Reply to author
Forward
0 new messages