From 4146d6b5b678edc580f2c6c5ba0e1d5c012ef9e0 Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Fri, 30 Jan 2015 19:32:32 +0100 Subject: [PATCH] Added currency name shortening --- src/cutecoin/core/account.py | 2 +- src/cutecoin/core/community.py | 19 +++++++++++++++++++ src/cutecoin/models/txhistory.py | 14 +++++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py index 9c8708d6..04021a4e 100644 --- a/src/cutecoin/core/account.py +++ b/src/cutecoin/core/account.py @@ -39,7 +39,7 @@ class Account(object): be locally referenced by only one account. ''' referentials = {'Units': (units, '{0}'), - 'UD': (relative, 'UD {0}') + 'UD': (relative, 'ud {0}') } def __init__(self, salt, pubkey, name, communities, wallets, contacts, diff --git a/src/cutecoin/core/community.py b/src/cutecoin/core/community.py index d63eef72..0eb1330c 100644 --- a/src/cutecoin/core/community.py +++ b/src/cutecoin/core/community.py @@ -12,6 +12,7 @@ from ..tools.exceptions import NoPeerAvailable import logging import inspect import hashlib +import re from requests.exceptions import RequestException, Timeout @@ -121,6 +122,24 @@ class Community(object): def __eq__(self, other): return (other.currency == self.currency) + @property + def short_currency(self): + words = re.split('[_\W]+', self.currency) + shortened = "" + if len(words) > 1: + shortened = ''.join([w[0] for w in words]) + else: + vowels = ('a', 'e', 'i', 'o', 'u', 'y') + shortened = self.currency + shortened = ''.join([c for c in shortened if c not in vowels]) + return shortened + + @property + def currency_symbol(self): + letter = self.currency[0] + u = ord('\u24B6') + ord(letter) - ord('A') + return chr(u) + def dividend(self): ud = self.request(bma.blockchain.UD) if len(ud['result']['blocks']) > 0: diff --git a/src/cutecoin/models/txhistory.py b/src/cutecoin/models/txhistory.py index 41a38287..f296d714 100644 --- a/src/cutecoin/models/txhistory.py +++ b/src/cutecoin/models/txhistory.py @@ -76,7 +76,7 @@ class HistoryTableModel(QAbstractTableModel): amount = 0 for o in tx[1].outputs: pubkeys = [w.pubkey for w in self.account.wallets] - if o.pubkey not in pubkeys: + if o.pubkey in pubkeys: outputs.append(o) amount += o.amount comment = tx[1].comment @@ -86,12 +86,14 @@ class HistoryTableModel(QAbstractTableModel): except PersonNotFoundError: sender = pubkey - date_ts = self.community.get_block(tx[0]).mediantime + date_ts = self.community.get_block(tx[0]).time date = QDateTime.fromTime_t(date_ts) amount_ref = self.account.units_to_ref(amount, self.community) + ref_name = self.account.ref_name(self.community.short_currency) - return (date.date(), sender, "", "{0}".format(amount_ref), comment) + return (date.date(), sender, "", "{0} {1}".format(amount_ref, ref_name), + comment) def data_sent(self, tx): amount = 0 @@ -108,12 +110,14 @@ class HistoryTableModel(QAbstractTableModel): receiver = Person.lookup(pubkey, self.community).name except PersonNotFoundError: receiver = pubkey - date_ts = self.community.get_block(tx[0]).mediantime + date_ts = self.community.get_block(tx[0]).time date = QDateTime.fromTime_t(date_ts) amount_ref = self.account.units_to_ref(-amount, self.community) + ref_name = self.account.ref_name(self.community.short_currency) - return (date.date(), receiver, "{0}".format(amount_ref), "", comment) + return (date.date(), receiver, "{0} {1}".format(amount_ref, ref_name), + "", comment) def data(self, index, role): row = index.row() -- GitLab