def handler_dic(self):
     """View function to be called from template. Loads and queries coin handlers for health, with caching."""
     hdic = {
     }  # A dictionary of {handler_name: {headings:list, results:list[tuple/list]}
     reload_handlers()
     for coin in Coin.objects.all():
         try:
             if not has_manager(coin.symbol):
                 self.coin_fails.append(
                     'Cannot check {} (no manager registered in coin handlers)'
                     .format(coin))
                 continue
             # Try to load coin health data from cache.
             # If it's not found, query the manager and cache it for up to 30 seconds to avoid constant RPC hits.
             c_health = coin.symbol + '_health'
             mname, mhead, mres = cache.get_or_set(
                 c_health,
                 get_manager(coin.symbol).health(), 30)
             # Create the dict keys for the manager name if needed, then add the health results
             d = hdic[mname] = dict(
                 headings=list(mhead),
                 results=[]) if mname not in hdic else hdic[mname]
             d['results'].append(list(mres))
         except:
             log.exception(
                 'Something went wrong loading health data for coin %s',
                 coin)
             self.coin_fails.append(
                 'Failed checking {} (something went wrong loading health data, check server logs)'
                 .format(coin))
     return hdic
Esempio n. 2
0
 def get(self, request, *args, **kwargs):
     r = self.request
     u = r.user
     if not u.is_authenticated or not u.is_superuser:
         raise PermissionDenied
     reload_handlers()
     return super(AddCoinPairView, self).get(request, *args, **kwargs)
 def save(self, *args, **kwargs):
     """To avoid inconsistency, the symbol is automatically made uppercase"""
     self.symbol = self.symbol.upper()
     super(Coin, self).save(*args, **kwargs)
     # After a coin is updated in the DB, we should reload any coin_handlers to detect compatible loaders.
     # We need to use in-line loading to prevent recursive loading from the coin handlers causing issues.
     from payments.coin_handlers import reload_handlers
     reload_handlers()
 def get_fieldsets(self, request, obj=None):
     # To ensure that the Coin Type dropdown is properly populated, we call reload_handlers() just before
     # the create / update Coin page finishes loading it's data.
     reload_handlers()
     return super(CoinAdmin, self).get_fieldsets(request, obj)