# Show button def show(sender, **kwargs): instances = kwargs['instances'] request = kwargs['request'] if not request.user.is_authenticated(): return try: selected_instance_uuid = SelectedInstance.objects.get(account = request.account).instance.uuid except: # No such record, or instance is None selected_instance_uuid = None for instance in instances: if not hasattr(instance, 'component_data'): instance.component_data = SafeString('') if instance.uuid != selected_instance_uuid: instance.component_data += SafeString('''<td><input type="button" onclick="window.location.href = '/tracker/instance/select/%s/'" value="Select"></td>''' % instance.uuid) else: instance.component_data += SafeString('''<td><b><center>Selected</b></center></td>''') list_instances.connect(show) # Stored data class SelectedInstance(models.Model): account = models.OneToOneField(UserAccount) instance = models.ForeignKey(ServerInstance, blank=True, null=True)
request = kwargs['request'] if not request.user.is_authenticated(): return try: selected_instance_uuid = SelectedInstance.objects.get( account=request.account).instance.uuid except: # No such record, or instance is None selected_instance_uuid = None for instance in instances: if not hasattr(instance, 'component_data'): instance.component_data = SafeString('') if instance.uuid != selected_instance_uuid: instance.component_data += SafeString( '''<td><input type="button" onclick="window.location.href = '/tracker/instance/select/%s/'" value="Select"></td>''' % instance.uuid) else: instance.component_data += SafeString( '''<td><b><center>Selected</b></center></td>''') list_instances.connect(show) # Stored data class SelectedInstance(models.Model): account = models.OneToOneField(UserAccount) instance = models.ForeignKey(ServerInstance, blank=True, null=True)
# Copyright 2010 Alon Zakai ('kripken'). All rights reserved. # This file is part of Syntensity/the Intensity Engine, an open source project. See COPYING.txt for licensing. ''' Expires server instances after a while has passed since they updated the master. ''' __COMPONENT_PRECEDENCE__ = 100 from datetime import datetime from intensity.tracker.signals import list_instances STALE_SECONDS = 15*60 # 15 minutes def is_stale(last_update): return (datetime.now() - last_update).seconds > STALE_SECONDS def expire_stale(sender, **kwargs): instances = kwargs['instances'] for instance in instances: last_update = instance.last_update if is_stale(last_update): instance.delete() list_instances.connect(expire_stale)