Skip to content
Snippets Groups Projects
Commit 143f77d3 authored by inso's avatar inso
Browse files

Lien wallets <-> community dans les models

parent 42dc1d8a
No related branches found
No related tags found
No related merge requests found
......@@ -35,7 +35,7 @@ class AddCommunityDialog(QDialog, Ui_AddCommunityDialog):
port = self.portBox.value()
try:
community = self.account.communities.addCommunity(MainNode(server, port), self.account.keyFingerprint())
self.account.wallets.addWallet(community.currency)
self.account.wallets.addWallet(community)
self.communityView.setModel( CommunityTreeModel(community) )
except NotMemberOfCommunityError as e:
QErrorMessage(self).showMessage(e.message)
......
......@@ -69,8 +69,7 @@ class Account(object):
def jsonify(self):
data = {'name' : self.name,
'pgpKeyId' : self.pgpKeyId,
'communities' : self.communities.jsonify(),
'wallets' : self.wallets.jsonify()}
'communities' : self.communities.jsonify(self.wallets)}
return data
......
......@@ -37,13 +37,13 @@ class Communities(object):
raise NotMemberOfCommunityError(keyFingerprint, community.currency + "-" + community.amendmentId())
def jsonify(self):
def jsonify(self, wallets):
'''
Return the list of communities in a key:value form.
'''
data = []
for community in self.communitiesList:
data.append(community.jsonify())
data.append(community.jsonify(wallets))
return data
......
......@@ -28,9 +28,8 @@ def loadAccount(jsonData):
account.pgpKeyId = jsonData['pgpKeyId']
account.name = jsonData['name']
account.communities = Communities()
for communityData in jsonData['communities']:
account.communities.communitiesList.append(communityFactory.loadCommunity(communityData))
account.wallets = Wallets()
for walletData in jsonData['wallets']:
account.wallets.walletsList.append(walletFactory.loadWallet(walletData))
for communityData in jsonData['communities']:
account.communities.communitiesList.append(communityFactory.loadCommunity(communityData, account))
return account
\ No newline at end of file
......@@ -37,12 +37,13 @@ class Wallets(object):
return w
return None
def jsonify(self):
def jsonify(self, community):
'''
Return the list of wallets in a key:value form.
'''
communityWallets = [w for w in self.walletsList if w.community == community]
data = []
for wallet in self.walletsList:
for wallet in communityWallets:
data.append(wallet.jsonify())
return data
......@@ -67,8 +67,9 @@ class Community(object):
data.append(node.jsonify())
return data
def jsonify(self):
def jsonify(self, wallets):
data = {'nodes' : self.jsonifyNodesList(),
'currency' : self.currency}
'currency' : self.currency,
'wallets' : wallets.jsonify(self)}
return data
......@@ -5,6 +5,7 @@ Created on 11 févr. 2014
'''
from cutecoin.models.community import Community
from cutecoin.models.node import MainNode
from cutecoin.models.wallet import factory
import ucoinpy as ucoin
def createCommunity(mainNode):
......@@ -15,10 +16,12 @@ def createCommunity(mainNode):
return community
def loadCommunity(jsonData):
def loadCommunity(jsonData, account):
community = Community()
for nodeData in jsonData['nodes']:
community.knownNodes.append(MainNode(nodeData['server'], nodeData['port']))
community.currency = jsonData['currency']
for walletsData in jsonData['wallets']:
account.wallets.walletsList.append(factory.loadWallet(walletsData, community))
return community
......@@ -20,11 +20,12 @@ class Wallet(object):
Constructor
'''
self.coins = []
self.currency = ""
self.community = None
self.name = "Main Wallet"
def __eq__(self, other):
return ( self.currency == other.currency )
return ( self.community == other.community )
def value(self):
value = 0
......@@ -32,8 +33,8 @@ class Wallet(object):
value += coin.value()
return value
def refreshCoins(self, community, pgpFingerprint):
dataList = community.ucoinRequest(lambda : ucoin.hdc.coins.List, ctor_args={'pgp_fingerprint':pgpFingerprint})
def refreshCoins(self, pgpFingerprint):
dataList = self.community.ucoinRequest(lambda : ucoin.hdc.coins.List, ctor_args={'pgp_fingerprint':pgpFingerprint})
for issaunces in dataList['coins']:
issuer = issaunces['issuer']
for coinsIds in issaunces['ids']:
......@@ -42,7 +43,7 @@ class Wallet(object):
self.coins.append(coin)
def getText(self):
return str(self.value()) + " " + self.currency
return self.name + " : " + str(self.value()) + " " + self.community.currency
def jsonifyCoinsList(self):
data = []
......@@ -52,6 +53,6 @@ class Wallet(object):
def jsonify(self):
return {'coins': self.jsonifyCoinsList(),
'currency': self.currency}
'name': self.name}
......@@ -6,16 +6,16 @@ Created on 11 févr. 2014
from cutecoin.models.wallet import Wallet
from cutecoin.models.coin import Coin
def createWallet(currency):
def createWallet(community):
wallet = Wallet()
wallet.currency = currency
wallet.community = community
return wallet
def loadWallet(jsonData):
def loadWallet(jsonData, community):
wallet = Wallet()
for coinData in jsonData['coins']:
wallet.coins.append(Coin(coinData['coin']))
wallet.currency = jsonData['currency']
wallet.community = community
return wallet
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment