<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 import tables <EOL> from horizon . utils . memoized import memoized <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . dashboards . admin . volumes . volume_types . qos_specs import forms as project_forms <EOL> from openstack_dashboard . dashboards . admin . volumes . volume_types . qos_specs import tables as project_tables <EOL> class QosSpecMixin ( object ) : <EOL> @ memoized <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( QosSpecMixin , self ) . get_context_data ( ** kwargs ) <EOL> if '<STR_LIT:key>' in self . kwargs : <EOL> context [ '<STR_LIT:key>' ] = self . kwargs [ '<STR_LIT:key>' ] <EOL> if '<STR_LIT>' in self . kwargs : <EOL> context [ '<STR_LIT>' ] = self . kwargs [ '<STR_LIT>' ] <EOL> qos_spec_id = context [ '<STR_LIT>' ] <EOL> try : <EOL> qos_list = api . cinder . qos_spec_get ( self . request , qos_spec_id ) <EOL> context [ '<STR_LIT>' ] = qos_list . name <EOL> except Exception : <EOL> context [ '<STR_LIT>' ] = _ ( '<STR_LIT>' ) <EOL> return context <EOL> class IndexView ( QosSpecMixin , forms . ModalFormMixin , tables . DataTableView ) : <EOL> table_class = project_tables . SpecsTable <EOL> template_name = '<STR_LIT>' <EOL> def get_data ( self ) : <EOL> try : <EOL> qos_spec_id = self . kwargs [ '<STR_LIT>' ] <EOL> qos_list = api . cinder . qos_spec_get_keys ( self . request , qos_spec_id ) <EOL> except Exception : <EOL> qos_list = [ ] <EOL> exceptions . handle ( self . request , <EOL> _ ( '<STR_LIT>' ) ) <EOL> return qos_list <EOL> class CreateKeyValuePairView ( QosSpecMixin , forms . ModalFormView ) : <EOL> form_class = project_forms . CreateKeyValuePair <EOL> template_name = '<STR_LIT>' <EOL> success_url = '<STR_LIT>' <EOL> def get_initial ( self ) : <EOL> qos_spec_id = self . kwargs [ '<STR_LIT>' ] <EOL> return { '<STR_LIT>' : qos_spec_id } <EOL> def get_success_url ( self ) : <EOL> return reverse ( self . success_url , <EOL> args = ( self . kwargs [ '<STR_LIT>' ] , ) ) <EOL> class EditKeyValuePairView ( QosSpecMixin , forms . ModalFormView ) : <EOL> form_class = project_forms . EditKeyValuePair <EOL> template_name = '<STR_LIT>' <EOL> success_url = '<STR_LIT>' <EOL> def get_success_url ( self ) : <EOL> return reverse ( self . success_url , <EOL> args = ( self . kwargs [ '<STR_LIT>' ] , ) ) <EOL> def get_initial ( self ) : <EOL> qos_spec_id = self . kwargs [ '<STR_LIT>' ] <EOL> key = self . kwargs [ '<STR_LIT:key>' ] <EOL> try : <EOL> qos_specs = api . cinder . qos_spec_get ( self . request , qos_spec_id ) <EOL> except Exception : <EOL> qos_specs = { } <EOL> exceptions . handle ( self . request , <EOL> _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> return { '<STR_LIT>' : qos_spec_id , <EOL> '<STR_LIT:key>' : key , <EOL> '<STR_LIT:value>' : qos_specs . specs . get ( key , '<STR_LIT>' ) } </s>
