<s> import logging <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . core . urlresolvers import reverse <EOL> from horizon import exceptions <EOL> from horizon import forms <EOL> from horizon import workflows <EOL> import disaster_recovery . api . api as freezer_api <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class SessionConfigurationAction ( workflows . Action ) : <EOL> session_id = forms . ChoiceField ( <EOL> help_text = _ ( "<STR_LIT>" ) , <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = True ) <EOL> job_id = forms . CharField ( <EOL> widget = forms . HiddenInput ( ) , <EOL> required = True ) <EOL> def populate_session_id_choices ( self , request , context ) : <EOL> sessions = [ ] <EOL> try : <EOL> sessions = freezer_api . Session ( request ) . list ( ) <EOL> except Exception : <EOL> exceptions . handle ( request , _ ( '<STR_LIT>' ) ) <EOL> sessions = [ ( s . session_id , s . description ) for s in sessions ] <EOL> sessions . insert ( <NUM_LIT:0> , ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) ) <EOL> return sessions <EOL> class Meta : <EOL> name = _ ( "<STR_LIT>" ) <EOL> slug = "<STR_LIT>" <EOL> class SessionConfiguration ( workflows . Step ) : <EOL> action_class = SessionConfigurationAction <EOL> contributes = ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> class AttachJobToSession ( workflows . Workflow ) : <EOL> slug = "<STR_LIT>" <EOL> name = _ ( "<STR_LIT>" ) <EOL> finalize_button_name = _ ( "<STR_LIT>" ) <EOL> success_message = _ ( '<STR_LIT>' ) <EOL> failure_message = _ ( '<STR_LIT>' ) <EOL> success_url = "<STR_LIT>" <EOL> default_steps = ( SessionConfiguration , ) <EOL> def handle ( self , request , context ) : <EOL> try : <EOL> freezer_api . Session ( request ) . add_job ( context [ '<STR_LIT>' ] , <EOL> context [ '<STR_LIT>' ] ) <EOL> return reverse ( "<STR_LIT>" ) <EOL> except Exception : <EOL> exceptions . handle ( request ) <EOL> return False </s>
