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

Working on transactions history

parent f1207b80
No related branches found
No related tags found
No related merge requests found
......@@ -67,6 +67,33 @@
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="topMargin">
<number>5</number>
</property>
<item>
<widget class="QDateTimeEdit" name="date_from">
<property name="displayFormat">
<string>dd/MM/yyyy</string>
</property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDateTimeEdit" name="date_to">
<property name="displayFormat">
<string>dd/MM/yyyy</string>
</property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTableView" name="table_history">
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
......@@ -127,9 +154,42 @@
</hint>
</hints>
</connection>
<connection>
<sender>date_from</sender>
<signal>dateTimeChanged(QDateTime)</signal>
<receiver>CurrencyTabWidget</receiver>
<slot>dates_changed(QDateTime)</slot>
<hints>
<hint type="sourcelabel">
<x>114</x>
<y>73</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>149</y>
</hint>
</hints>
</connection>
<connection>
<sender>date_to</sender>
<signal>dateTimeChanged(QDateTime)</signal>
<receiver>CurrencyTabWidget</receiver>
<slot>dates_changed(QDateTime)</slot>
<hints>
<hint type="sourcelabel">
<x>285</x>
<y>73</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>149</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>refresh_wallet_content(QModelIndex)</slot>
<slot>wallet_context_menu(QPoint)</slot>
<slot>dates_changed(QDateTime)</slot>
</slots>
</ui>
......@@ -9,8 +9,8 @@ import time
import requests
from ucoinpy.api import bma
from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication, QMessageBox
from PyQt5.QtCore import QModelIndex, Qt, pyqtSlot, QObject, QThread, pyqtSignal
from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication
from PyQt5.QtCore import QModelIndex, Qt, pyqtSlot, QObject, QThread, pyqtSignal, QDateTime
from PyQt5.QtGui import QIcon
from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget
from .community_tab import CommunityTabWidget
......@@ -90,6 +90,19 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
else:
self.tabs_account.setEnabled(True)
self.refresh_wallets()
blockchain_init = QDateTime()
blockchain_init.setTime_t(self.community.get_block(1).mediantime)
blockchain_lastblock = QDateTime()
blockchain_lastblock.setTime_t(self.community.get_block().mediantime)
self.date_from.setMinimumDateTime(blockchain_init)
self.date_from.setDateTime(blockchain_init)
self.date_from.setMaximumDateTime(blockchain_lastblock)
self.date_to.setMinimumDateTime(blockchain_init)
self.date_to.setDateTime(blockchain_lastblock)
self.date_to.setMaximumDateTime(blockchain_lastblock)
self.table_history.setModel(
HistoryTableModel(self.app.current_account, self.community))
......@@ -192,3 +205,9 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
def closeEvent(self, event):
self.bc_watcher.deleteLater()
self.watcher_thread.deleteLater()
def dates_changed(self, datetime):
ts_from = self.date_from.dateTime().toTime_t()
ts_to = self.date_to.dateTime().toTime_t()
if self.table_history.model():
self.table_history.model().set_period(ts_from, ts_to)
......@@ -7,7 +7,7 @@ Created on 5 févr. 2014
import logging
from ..core.person import Person
from ..tools.exceptions import PersonNotFoundError
from PyQt5.QtCore import QAbstractTableModel, Qt, QVariant, QSortFilterProxyModel
from PyQt5.QtCore import QAbstractTableModel, Qt, QVariant, QAbstractProxyModel
from PyQt5.QtGui import QFont
from operator import itemgetter
import datetime
......@@ -27,8 +27,7 @@ class HistoryTableModel(QAbstractTableModel):
self.account = account
self.community = community
self.columns = ('Date', 'UID/Public key', 'Payment', 'Deposit', 'Comment')
self.section_sorting = 0
self.reversed = True
self.sorting = lambda
self.transactions = self.account.transactions_sent(self.community) + \
self.account.transactions_awaiting(self.community) + \
self.account.transactions_received(self.community)
......@@ -151,11 +150,34 @@ class HistoryTableModel(QAbstractTableModel):
3: amount_received,
4: comment}
self.transactions = self.account.transactions_sent(self.community) + \
self.account.transactions_awaiting(self.community) + \
self.account.transactions_received(self.community)
self.transactions = sorted(self.transactions,
reverse=(order == Qt.DescendingOrder),
key=key_getter[section])
self.layoutChanged.emit()
def set_period(self, ts_from, ts_to):
"""
Filter table by given timestamps
"""
self.layoutAboutToBeChanged.emit()
logging.debug("Filtering from {0} to {1}".format(ts_from, ts_to))
def in_period(tx):
block = self.community.get_block(tx[0])
return (block.mediantime in range(ts_from, ts_to))
self.transactions = self.account.transactions_sent(self.community) + \
self.account.transactions_awaiting(self.community) + \
self.account.transactions_received(self.community)
self.transactions = [tx for tx in filter(in_period, self.transactions)]
self.layoutChanged.emit()
def flags(self, index):
return Qt.ItemIsSelectable | Qt.ItemIsEnabled
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