def index(request): ''' Handler for the accounts view ''' # set the request in the connector object connector.request = request # get all wallets wallets = getWallets(connector) accounts = [] for wallet in wallets: accounts_by_wallet = wallet.listAccounts(gethidden=True) accounts = accounts + accounts_by_wallet sections = misc.getSiteSections(current_section) page_title = _("Accounts") context = { 'globals': MainConfig['globals'], 'breadcrumbs': misc.buildBreadcrumbs(current_section, 'all'), 'system_errors': connector.errors, 'system_alerts': connector.alerts, 'page_title': page_title, 'page_sections': sections, 'accounts': accounts, 'request': request, } return render(request, 'accounts/index.html', context)
def getAddAccountFormContext(account_name='', error=None, form=None): ''' Provide a common context between the account view and create account view ''' # get available currencies providers_available = [] providers = connector.config.keys() for provider_id in providers: providers_available.append({'id': provider_id, 'currency': connector.config[provider_id]['currency'], 'name': connector.config[provider_id]['name']}) page_title = _("Create account") sections = misc.getSiteSections(current_section) context = { 'globals': MainConfig['globals'], 'system_alerts': connector.alerts, 'system_errors': connector.errors, 'breadcrumbs': misc.buildBreadcrumbs(current_section, '', 'Create'), 'page_sections': sections, 'page_title': page_title, 'providers': providers_available, 'account_name': account_name, 'provider_id': provider_id, 'error_message': error, 'form': form, } return context
def index(request, selected_provider_id=sorted(connector.config.keys())[0]): ''' Handler for the accounts ''' sections = misc.getSiteSections(current_section) selected_provider_id = int(selected_provider_id) g = GeoIP() notsupported = 0; peers = connector.getPeerInfo(selected_provider_id) if 'error' in peers : peers = {} notsupported = 1 else : for peer in peers: info = g.city(peer['addr'].partition(':')[0]) if info is None: info = {} peer['ip'] = peer['addr'].partition(':')[0] peer['port'] = peer['addr'].partition(':')[2] peer['country'] = info.get('country_name', "") peer['country_code'] = info.get('country_code', "") peer['city'] = info.get('city', None) if info.get('city', None) != None else '' peer['lat'] = info.get('latitude', ""); peer['lon'] = info.get('longitude', ""); peer['subver'] = peer['subver'].replace("/", "") peer['in'] = misc.humanBytes(peer['bytesrecv']) if 'bytesrecv' in peer else 'N/A' peer['out'] = misc.humanBytes(peer['bytessent']) if 'bytessent' in peer else 'N/A' peer['lastsend'] = misc.twitterizeDate(peer['lastsend']) if 'lastsend' in peer else 'N/A' peer['lastrecv'] = misc.twitterizeDate(peer['lastrecv']) if 'lastrecv' in peer else 'N/A' peer['conntime'] = misc.timeSince(peer['conntime']) if 'conntime' in peer else 'N/A' peer['syncnode'] = peer['syncnode'] if 'syncnode' in peer else False currency_codes = {} currency_names = {} currency_symbols = {} for provider_id in connector.config: currency_names[provider_id] = connector.config[provider_id]['name'] currency_symbols[provider_id] = connector.config[provider_id]['symbol'] currency_codes[provider_id] = connector.config[provider_id]['currency'] currency_codes = sorted(currency_codes) page_title = _("Network") context = { 'globals': MainConfig['globals'], 'breadcrumbs': misc.buildBreadcrumbs(current_section, '', currency_names[selected_provider_id]), 'system_errors': connector.errors, 'system_alerts': connector.alerts, 'page_title': page_title, 'page_sections': sections, 'request': request, 'currency_codes': currency_codes, 'currency_names': currency_names, 'currency_symbols': currency_symbols, 'selected_provider_id': selected_provider_id, 'peers': peers, 'notsupported': notsupported } return render(request, 'network/index.html', context)
def getAddAccountFormContext(account_name='', error=None, form=None): ''' Provide a common context between the account view and create account view ''' # get available currencies providers_available = [] providers = connector.config.keys() for provider_id in providers: providers_available.append({ 'id': provider_id, 'currency': connector.config[provider_id]['currency'], 'name': connector.config[provider_id]['name'] }) page_title = _("Create account") sections = misc.getSiteSections(current_section) context = { 'globals': MainConfig['globals'], 'system_alerts': connector.alerts, 'system_errors': connector.errors, 'breadcrumbs': misc.buildBreadcrumbs(current_section, '', 'Create'), 'page_sections': sections, 'page_title': page_title, 'providers': providers_available, 'account_name': account_name, 'provider_id': provider_id, 'error_message': error, 'form': form, } return context
def transactionDetails(request, txid, provider_id): provider_id = int(provider_id) # set the request in the connector object connector.request = request # get wallet for provider_id wallet = getWalletByProviderId(connector, provider_id) transaction = wallet.getTransactionById(txid) if transaction.get('fee', False): transaction['fee'] = misc.longNumber(transaction['fee']) else: transaction['fee'] = "" if transaction['details'][0]['category'] == 'receive': if not len(transaction['details'][0]['account']): # get the default account for provider_id account = wallet.getDefaultAccount() else: account = wallet.getAccountByAddress( transaction['details'][0]['address']) elif transaction['details'][0]['category'] == 'send': account = transaction['account'] page_title = "Transaction details for %s" % txid context = { 'globals': MainConfig['globals'], 'system_errors': connector.errors, 'system_alerts': connector.alerts, 'request': request, 'breadcrumbs': misc.buildBreadcrumbs(current_section, '', 'Details of %s' % txid), 'page_title': page_title, 'page_sections': misc.getSiteSections(current_section), 'transaction': transaction, 'account': account, 'conf_limit': MainConfig['globals']['confirmation_limit'], } if request.method == 'GET': return render(request, 'transactions/details.html', context) else: # maybe convert to PDF ? return render(request, 'transactions/details.html', context)
def commonContext(request={}, selected_provider_id=1, form=None, errors=[], show_passphrase=False, show_warning_ssl=False): ''' This constructs a common context between the two views: index and send ''' page_title = "Transfer" selected_provider_id = int(selected_provider_id) # set the request in the connector object connector.request = request # get wallet for provider_id wallet = getWalletByProviderId(connector, selected_provider_id) # get all, codes, names and symbols for currencies currency_codes = {} currency_names = {} currency_symbols = {} for provider_id in connector.config: currency_names[provider_id] = connector.config[provider_id]['name'] currency_symbols[provider_id] = connector.config[provider_id]['symbol'] currency_codes[provider_id] = connector.config[provider_id]['currency'] # sort in reverse # currency_codes = sorted(currency_codes) # get a list of source accounts accounts = wallet.listAccounts(gethidden=True, getarchived=True) # addressbook values saved_addresses = savedAddress.objects.filter(currency=currency_codes.get(selected_provider_id, None), status__gt=1) addressbook_addresses = {} for saved_address in saved_addresses: addressbook_addresses[saved_address.address] = saved_address.name context = { 'globals': MainConfig['globals'], 'system_errors': connector.errors, 'system_alerts': connector.alerts, 'request': request, 'breadcrumbs': misc.buildBreadcrumbs(current_section, '', currency_names.get(selected_provider_id, "n/a")), 'page_sections': misc.getSiteSections('transfer'), 'page_title': page_title, 'currency_codes': currency_codes, 'currency_names': currency_names, 'currency_symbols': currency_symbols, 'accounts': accounts, 'selected_provider_id': selected_provider_id, 'form': form, 'errors': errors, 'show_passphrase': show_passphrase, 'ssl_warning': show_warning_ssl, 'addressbook_addresses': addressbook_addresses } return context
def getAddressBookCommonContext(request, form=None): ''' Get common context ''' page_title = "Addressbook" # add a list of pages in the view sections = misc.getSiteSections('addressbook') currency_symbols = misc.getCurrencySymbol(connector) book = savedAddress.objects.filter(status__gt=0) currencies_available = [] for provider_id in connector.services.keys(): currencies_available.append({ 'provider_id': provider_id, 'currency': connector.config[provider_id]['currency'], 'name': connector.config[provider_id]['name'] }) for address in book: timestamp = calendar.timegm(address.entered.timetuple()) address.time_pretty = misc.twitterizeDate(timestamp) if address.status == 1: address.button_text = _("enable") address.status_text = 'Hidden' address.icon = "glyphicon-minus-sign" address.icon_color = 'red-font' elif address.status == 2: address.button_text = _("disable") address.status_text = 'Active' address.icon = "glyphicon-ok-circle" address.icon_color = 'green-font' context = { 'globals': MainConfig['globals'], 'system_errors': connector.errors, 'system_alerts': connector.alerts, 'user': request.user, 'breadcrumbs': misc.buildBreadcrumbs(current_section), 'page_sections': sections, 'page_title': page_title, 'book': book, 'currencies': currencies_available, 'currency_symbols': currency_symbols, 'form': form, } return context
def details_with_transactions(request, provider_id, account_identifier="pipes", page=1): ''' Handler for the account details with transactions ''' # set the request in the connector object connector.request = request transactions_per_page = 10 provider_id = int(provider_id) page = int(page) # add a list of pages in the view sections = misc.getSiteSections(current_section) # get a wallet wallet = getWalletByProviderId(connector, provider_id) # get account details account = wallet.getAccountByIdentifier(account_identifier) transactions = [] if account: # get transaction details transactions = account.listTransactions(limit=transactions_per_page, start=(transactions_per_page * (page - 1))) page_title = _('Account details for "%s"') % (account['name']) sender_address_tooltip_text = "This address has been calculated using the Input Script Signature. You should verify before using it." context = { 'globals': MainConfig['globals'], 'request': request, 'system_alerts': connector.alerts, 'system_errors': connector.errors, 'breadcrumbs': misc.buildBreadcrumbs(current_section, '', account['name']), 'page_title': page_title, 'active_tab': 'transactions', 'current_page': page, 'next_page': (page + 1), 'prev_page': max(1, page - 1), 'levels': [(max(1, (page - 10)), max(1, (page - 100)), max(1, (page - 1000))), ((page + 10), (page + 100), (page + 1000))], 'page_sections': sections, 'wallet': wallet, 'account': account, 'transactions': transactions, 'sender_address_tooltip_text': sender_address_tooltip_text, 'transactions_per_page': transactions_per_page, } return render(request, 'accounts/details.html', context)
def index(request): ''' Handler for the dashboard main page ''' currect_section = 'dashboard' # set the request in the connector object connector.request = request # get all wallets wallets = getWallets(connector) # more efficient if we do only one call transactions = [] for wallet in wallets: transactions = transactions + wallet.listTransactions(5, 0) # sort result transactions = sorted(transactions, key=lambda k: k.get('time', 0), reverse=True) # get only 10 transactions transactions = transactions[0:5] # events list_of_events = Events.objects.all().order_by('-entered')[:5] for single_event in list_of_events: timestamp = calendar.timegm(single_event.entered.timetuple()) single_event.entered_pretty = misc.twitterizeDate(timestamp) page_title = "Dashboard" sections = misc.getSiteSections('dashboard') context = { 'globals': MainConfig['globals'], 'system_errors': connector.errors, 'system_alerts': connector.alerts, 'request': request, 'breadcrumbs': misc.buildBreadcrumbs(currect_section), 'page_title': page_title, 'page_sections': sections, 'wallets': wallets, 'transactions': transactions, 'events': list_of_events } return render(request, 'dashboard/index.html', context)
def transactionDetails(request, txid, provider_id): provider_id = int(provider_id) # set the request in the connector object connector.request = request # get wallet for provider_id wallet = getWalletByProviderId(connector, provider_id) transaction = wallet.getTransactionById(txid) if transaction.get('fee', False): transaction['fee'] = misc.longNumber(transaction['fee']) else: transaction['fee'] = "" if transaction['details'][0]['category'] == 'receive': if not len(transaction['details'][0]['account']): # get the default account for provider_id account = wallet.getDefaultAccount() else: account = wallet.getAccountByAddress(transaction['details'][0]['address']) elif transaction['details'][0]['category'] == 'send': account = transaction['account'] page_title = "Transaction details for %s" % txid context = { 'globals': MainConfig['globals'], 'system_errors': connector.errors, 'system_alerts': connector.alerts, 'request': request, 'breadcrumbs': misc.buildBreadcrumbs(current_section, '', 'Details of %s' % txid), 'page_title': page_title, 'page_sections': misc.getSiteSections(current_section), 'transaction': transaction, 'account': account, 'conf_limit': MainConfig['globals']['confirmation_limit'], } if request.method == 'GET': return render(request, 'transactions/details.html', context) else: # maybe convert to PDF ? return render(request, 'transactions/details.html', context)
def getAddressBookCommonContext(request, form=None): ''' Get common context ''' page_title = "Addressbook" # add a list of pages in the view sections = misc.getSiteSections('addressbook') currency_symbols = misc.getCurrencySymbol(connector) book = savedAddress.objects.filter(status__gt=0) currencies_available = [] for provider_id in connector.services.keys(): currencies_available.append({'provider_id': provider_id, 'currency': connector.config[provider_id]['currency'], 'name': connector.config[provider_id]['name']}) for address in book: timestamp = calendar.timegm(address.entered.timetuple()) address.time_pretty = misc.twitterizeDate(timestamp) if address.status == 1: address.button_text = _("enable") address.status_text = 'Hidden' address.icon = "glyphicon-minus-sign" address.icon_color = 'red-font' elif address.status == 2: address.button_text = _("disable") address.status_text = 'Active' address.icon = "glyphicon-ok-circle" address.icon_color = 'green-font' context = { 'globals': MainConfig['globals'], 'system_errors': connector.errors, 'system_alerts': connector.alerts, 'user': request.user, 'breadcrumbs': misc.buildBreadcrumbs(current_section), 'page_sections': sections, 'page_title': page_title, 'book': book, 'currencies': currencies_available, 'currency_symbols': currency_symbols, 'form': form, } return context
def details_with_addresses(request, provider_id, account_identifier="pipes", page=1): ''' Handler for the account details ''' # set the request in the connector object connector.request = request provider_id = int(provider_id) # add a list of pages in the view sections = misc.getSiteSections(current_section) # get a wallet wallet = getWalletByProviderId(connector, provider_id) # get account details account = wallet.getAccountByIdentifier(account_identifier) page_title = _('Account details for "%s"') % (account['name']) context = { 'globals': MainConfig['globals'], 'request': request, 'system_alerts': connector.alerts, 'system_errors': connector.errors, 'breadcrumbs': misc.buildBreadcrumbs(current_section, '', account['name']), 'page_title': page_title, 'active_tab': 'addresses', 'current_page': page, 'page_sections': sections, 'wallet': wallet, 'account': account, } return render(request, 'accounts/details.html', context)
def index(request, selected_provider_id=False, page=1): ''' handler for the transactions list ''' if selected_provider_id is False: selected_provider_id = connector.config.keys()[0] else: selected_provider_id = int(selected_provider_id) page = int(page) items_per_page = 10 page_title = "Transactions" hide_moves = request.user.setting.get('hide_moves') # get addressbook addressBookAddresses = savedAddress.objects.filter(status__gt=1) saved_addresses = {} for saved_address in addressBookAddresses: saved_addresses[saved_address.address] = saved_address.name # set the request in the connector object connector.request = request wallet = None wallets = getWallets(connector) for w in wallets: if w.provider_id == selected_provider_id: wallet = w # get transactions transactions_list = wallet.listTransactions(items_per_page, (items_per_page * (page - 1))) # sort transactions transactions_list = sorted(transactions_list, key=lambda k: k.get('time', 0), reverse=True) # remove moves if there is a user setting for it transactions = [] if bool(hide_moves): for transaction in transactions_list: if transaction['category'] != "move": transactions.append(transaction) else: transactions = transactions_list sender_address_tooltip_text = "This address has been calculated using the Input Script Signature. You should verify before using it." providers = {} for provider_id in connector.config: providers[provider_id] = connector.config[provider_id]['name'] context = { 'globals': MainConfig['globals'], 'system_errors': connector.errors, 'system_alerts': connector.alerts, 'request': request, 'breadcrumbs': misc.buildBreadcrumbs(current_section, '', connector.config[selected_provider_id]['name']), 'page_title': page_title, 'page_sections': misc.getSiteSections(current_section), 'transactions': transactions, 'transactions_per_page': items_per_page, 'show_pager': True, 'next_page': (page + 1), 'prev_page': max(1, page - 1), 'levels': [(max(1, (page - 10)), max(1, (page - 100)), max(1, (page - 1000))), ((page + 10), (page + 100), (page + 1000))], 'current_page': page, 'saved_addresses': saved_addresses, 'sender_address_tooltip_text': sender_address_tooltip_text, 'providers': providers, 'selected_provider_id': selected_provider_id, } return render(request, 'transactions/index.html', context)
def index(request, selected_provider_id=sorted(connector.config.keys())[0]): ''' Handler for the accounts ''' sections = misc.getSiteSections(current_section) selected_provider_id = int(selected_provider_id) g = GeoIP() notsupported = 0 peers = connector.getPeerInfo(selected_provider_id) if 'error' in peers: peers = {} notsupported = 1 else: for peer in peers: info = g.city(peer['addr'].partition(':')[0]) if info is None: info = {} peer['ip'] = peer['addr'].partition(':')[0] peer['port'] = peer['addr'].partition(':')[2] peer['country'] = info.get('country_name', "") peer['country_code'] = info.get('country_code', "") peer['city'] = info.get( 'city', None) if info.get('city', None) != None else '' peer['lat'] = info.get('latitude', "") peer['lon'] = info.get('longitude', "") peer['subver'] = peer['subver'].replace("/", "") peer['in'] = misc.humanBytes( peer['bytesrecv']) if 'bytesrecv' in peer else 'N/A' peer['out'] = misc.humanBytes( peer['bytessent']) if 'bytessent' in peer else 'N/A' peer['lastsend'] = misc.twitterizeDate( peer['lastsend']) if 'lastsend' in peer else 'N/A' peer['lastrecv'] = misc.twitterizeDate( peer['lastrecv']) if 'lastrecv' in peer else 'N/A' peer['conntime'] = misc.timeSince( peer['conntime']) if 'conntime' in peer else 'N/A' peer[ 'syncnode'] = peer['syncnode'] if 'syncnode' in peer else False currency_codes = {} currency_names = {} currency_symbols = {} for provider_id in connector.config: currency_names[provider_id] = connector.config[provider_id]['name'] currency_symbols[provider_id] = connector.config[provider_id]['symbol'] currency_codes[provider_id] = connector.config[provider_id]['currency'] currency_codes = sorted(currency_codes) page_title = _("Network") context = { 'globals': MainConfig['globals'], 'breadcrumbs': misc.buildBreadcrumbs(current_section, '', currency_names[selected_provider_id]), 'system_errors': connector.errors, 'system_alerts': connector.alerts, 'page_title': page_title, 'page_sections': sections, 'request': request, 'currency_codes': currency_codes, 'currency_names': currency_names, 'currency_symbols': currency_symbols, 'selected_provider_id': selected_provider_id, 'peers': peers, 'notsupported': notsupported } return render(request, 'network/index.html', context)