<s> from django . core . urlresolvers import reverse <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from horizon import exceptions <EOL> from horizon import forms <EOL> from horizon . utils import memoized <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . dashboards . admin . networks . agents import forms as project_forms <EOL> class AddView ( forms . ModalFormView ) : <EOL> form_class = project_forms . AddDHCPAgent <EOL> form_id = "<STR_LIT>" <EOL> template_name = '<STR_LIT>' <EOL> success_url = '<STR_LIT>' <EOL> failure_url = '<STR_LIT>' <EOL> submit_url = "<STR_LIT>" <EOL> title_and_label = _ ( "<STR_LIT>" ) <EOL> submit_label = modal_header = page_title = title_and_label <EOL> def get_success_url ( self ) : <EOL> return reverse ( self . success_url , <EOL> args = ( self . kwargs [ '<STR_LIT>' ] , ) ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( AddView , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = self . kwargs [ '<STR_LIT>' ] <EOL> args = ( self . kwargs [ '<STR_LIT>' ] , ) <EOL> context [ '<STR_LIT>' ] = reverse ( self . submit_url , args = args ) <EOL> context [ '<STR_LIT>' ] = reverse ( self . failure_url , args = args ) <EOL> return context <EOL> def get_initial ( self ) : <EOL> initial = super ( AddView , self ) . get_initial ( ) <EOL> agents = self . _get_agents ( ) <EOL> network_id = self . kwargs [ '<STR_LIT>' ] <EOL> try : <EOL> network = api . neutron . network_get ( self . request , network_id ) <EOL> initial . update ( { "<STR_LIT>" : network_id , <EOL> "<STR_LIT>" : network . name_or_id , <EOL> "<STR_LIT>" : agents } ) <EOL> return initial <EOL> except Exception : <EOL> redirect = reverse ( self . failure_url , <EOL> args = ( self . kwargs [ '<STR_LIT>' ] , ) ) <EOL> msg = _ ( "<STR_LIT>" ) <EOL> exceptions . handle ( self . request , msg , redirect = redirect ) <EOL> @ memoized . memoized_method <EOL> def _get_agents ( self ) : <EOL> try : <EOL> return api . neutron . agent_list ( self . request , <EOL> agent_type = '<STR_LIT>' ) <EOL> except Exception : <EOL> redirect = reverse ( self . failure_url , <EOL> args = ( self . kwargs [ '<STR_LIT>' ] , ) ) <EOL> msg = _ ( "<STR_LIT>" ) <EOL> exceptions . handle ( self . request , msg , redirect = redirect ) </s>
