On Sun, Jun 16, 2013 at 11:48 PM, Oliver Hafner <[email protected]>wrote:
> 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()
>
You need to call them as self.getUserBalance and self.sendFromUser etc.
Anand
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/groups/opt_out.