<s> from django . core . urlresolvers import reverse <EOL> from django . template import defaultfilters as d_filters <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . utils . translation import ungettext_lazy <EOL> from horizon import tables <EOL> from horizon . utils import filters <EOL> from openstack_dashboard import api <EOL> STATUS_CHOICES = ( <EOL> ( "<STR_LIT>" , None ) , <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT>" , False ) , <EOL> ( "<STR_LIT>" , False ) , <EOL> ( "<STR_LIT>" , None ) , <EOL> ( "<STR_LIT>" , None ) , <EOL> ) <EOL> class LaunchLink ( tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" <EOL> classes = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> icon = "<STR_LIT>" <EOL> class RestoreLink ( tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" <EOL> classes = ( "<STR_LIT>" , ) <EOL> icon = "<STR_LIT>" <EOL> def allowed ( self , request , backup = None ) : <EOL> return backup . status == '<STR_LIT>' <EOL> def get_link_url ( self , datum ) : <EOL> url = reverse ( self . url ) <EOL> return url + '<STR_LIT>' % datum . id <EOL> class DownloadBackup ( tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = '<STR_LIT>' <EOL> classes = ( "<STR_LIT>" , ) <EOL> def get_link_url ( self , datum ) : <EOL> ref = datum . locationRef . split ( '<STR_LIT:/>' ) <EOL> container_name = ref [ <NUM_LIT:5> ] <EOL> object_path = '<STR_LIT:/>' . join ( ref [ <NUM_LIT:6> : ] ) <EOL> return reverse ( self . url , <EOL> kwargs = { '<STR_LIT>' : container_name , <EOL> '<STR_LIT>' : object_path } ) <EOL> def allowed ( self , request , datum ) : <EOL> return datum . status == '<STR_LIT>' <EOL> class DeleteBackup ( tables . DeleteAction ) : <EOL> @ staticmethod <EOL> def action_present ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> @ staticmethod <EOL> def action_past ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> def delete ( self , request , obj_id ) : <EOL> api . trove . backup_delete ( request , obj_id ) <EOL> class UpdateRow ( tables . Row ) : <EOL> ajax = True <EOL> def get_data ( self , request , backup_id ) : <EOL> backup = api . trove . backup_get ( request , backup_id ) <EOL> try : <EOL> backup . instance = api . trove . instance_get ( request , <EOL> backup . instance_id ) <EOL> except Exception : <EOL> pass <EOL> return backup <EOL> def db_link ( obj ) : <EOL> if not hasattr ( obj , '<STR_LIT>' ) : <EOL> return <EOL> if hasattr ( obj . instance , '<STR_LIT:name>' ) : <EOL> return reverse ( <EOL> '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : obj . instance_id } ) <EOL> def db_name ( obj ) : <EOL> if not hasattr ( obj , '<STR_LIT>' ) or not hasattr ( obj . instance , '<STR_LIT:name>' ) : <EOL> return obj . instance_id <EOL> return obj . instance . name <EOL> def get_datastore ( obj ) : <EOL> if hasattr ( obj , "<STR_LIT>" ) : <EOL> return obj . datastore [ "<STR_LIT:type>" ] <EOL> return _ ( "<STR_LIT>" ) <EOL> def get_datastore_version ( obj ) : <EOL> if hasattr ( obj , "<STR_LIT>" ) : <EOL> return obj . datastore [ "<STR_LIT:version>" ] <EOL> return _ ( "<STR_LIT>" ) <EOL> def is_incremental ( obj ) : <EOL> return hasattr ( obj , '<STR_LIT>' ) and obj . parent_id is not None <EOL> class BackupsTable ( tables . DataTable ) : <EOL> name = tables . Column ( "<STR_LIT:name>" , <EOL> link = "<STR_LIT>" , <EOL> verbose_name = _ ( "<STR_LIT:Name>" ) ) <EOL> datastore = tables . Column ( get_datastore , <EOL> verbose_name = _ ( "<STR_LIT>" ) ) <EOL> datastore_version = tables . Column ( get_datastore_version , <EOL> verbose_name = _ ( "<STR_LIT>" ) ) <EOL> created = tables . Column ( "<STR_LIT>" , verbose_name = _ ( "<STR_LIT>" ) , <EOL> filters = [ filters . parse_isotime ] ) <EOL> instance = tables . Column ( db_name , link = db_link , <EOL> verbose_name = _ ( "<STR_LIT>" ) ) <EOL> incremental = tables . Column ( is_incremental , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> filters = ( d_filters . yesno , <EOL> d_filters . capfirst ) ) <EOL> status = tables . Column ( "<STR_LIT:status>" , <EOL> filters = ( d_filters . title , <EOL> filters . replace_underscores ) , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> status = True , <EOL> status_choices = STATUS_CHOICES ) <EOL> class Meta : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> status_columns = [ "<STR_LIT:status>" ] <EOL> row_class = UpdateRow <EOL> table_actions = ( LaunchLink , DeleteBackup ) <EOL> row_actions = ( RestoreLink , DownloadBackup , DeleteBackup ) </s>
