<s> import json <EOL> from django . core . urlresolvers import reverse_lazy <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 import tabs <EOL> from horizon . utils import memoized <EOL> from openstack_dashboard . api import glance <EOL> from openstack_dashboard . dashboards . admin . metadata_defs import constants <EOL> from openstack_dashboard . dashboards . admin . metadata_defs import forms as admin_forms <EOL> from openstack_dashboard . dashboards . admin . metadata_defs import tables as admin_tables <EOL> from openstack_dashboard . dashboards . admin . metadata_defs import tabs as admin_tabs <EOL> class AdminIndexView ( tables . DataTableView ) : <EOL> table_class = admin_tables . AdminNamespacesTable <EOL> template_name = constants . METADATA_INDEX_TEMPLATE <EOL> page_title = _ ( "<STR_LIT>" ) <EOL> def has_prev_data ( self , table ) : <EOL> return self . _prev <EOL> def has_more_data ( self , table ) : <EOL> return self . _more <EOL> def get_data ( self ) : <EOL> namespaces = [ ] <EOL> prev_marker = self . request . GET . get ( <EOL> admin_tables . AdminNamespacesTable . _meta . prev_pagination_param , <EOL> None ) <EOL> if prev_marker is not None : <EOL> sort_dir = '<STR_LIT>' <EOL> marker = prev_marker <EOL> else : <EOL> sort_dir = '<STR_LIT>' <EOL> marker = self . request . GET . get ( <EOL> admin_tables . AdminNamespacesTable . _meta . pagination_param , None ) <EOL> try : <EOL> namespaces , self . _more , self . _prev = glance . metadefs_namespace_list ( self . request , <EOL> marker = marker , <EOL> paginate = True , <EOL> sort_dir = sort_dir ) <EOL> if prev_marker is not None : <EOL> namespaces = sorted ( namespaces , <EOL> key = lambda ns : getattr ( ns , '<STR_LIT>' ) , <EOL> reverse = True ) <EOL> except Exception : <EOL> self . _prev = False <EOL> self . _more = False <EOL> msg = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( self . request , msg ) <EOL> return namespaces <EOL> class CreateView ( forms . ModalFormView ) : <EOL> form_class = admin_forms . CreateNamespaceForm <EOL> template_name = constants . METADATA_CREATE_TEMPLATE <EOL> context_object_name = '<STR_LIT>' <EOL> success_url = reverse_lazy ( constants . METADATA_INDEX_URL ) <EOL> page_title = _ ( "<STR_LIT>" ) <EOL> submit_label = _ ( "<STR_LIT>" ) <EOL> class DetailView ( tabs . TabView ) : <EOL> redirect_url = constants . METADATA_INDEX_URL <EOL> tab_group_class = admin_tabs . NamespaceDetailTabs <EOL> template_name = constants . METADATA_DETAIL_TEMPLATE <EOL> page_title = "<STR_LIT>" <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( DetailView , self ) . get_context_data ( ** kwargs ) <EOL> context [ "<STR_LIT>" ] = self . get_data ( ) <EOL> return context <EOL> @ memoized . memoized_method <EOL> def get_data ( self ) : <EOL> try : <EOL> namespace = glance . metadefs_namespace_get ( <EOL> self . request , self . kwargs [ '<STR_LIT>' ] , wrap = True ) <EOL> except Exception : <EOL> url = reverse_lazy ( constants . METADATA_INDEX_URL ) <EOL> exceptions . handle ( self . request , <EOL> _ ( '<STR_LIT>' ) , <EOL> redirect = url ) <EOL> else : <EOL> return namespace <EOL> def get_tabs ( self , request , * args , ** kwargs ) : <EOL> namespace = self . get_data ( ) <EOL> return self . tab_group_class ( request , namespace = namespace , ** kwargs ) <EOL> class ManageResourceTypes ( forms . ModalFormView ) : <EOL> template_name = constants . METADATA_MANAGE_RESOURCES_TEMPLATE <EOL> form_class = admin_forms . ManageResourceTypesForm <EOL> success_url = reverse_lazy ( constants . METADATA_INDEX_URL ) <EOL> def get_initial ( self ) : <EOL> try : <EOL> resource_types = glance . metadefs_namespace_resource_types ( <EOL> self . request , self . kwargs [ "<STR_LIT:id>" ] ) <EOL> except Exception : <EOL> resource_types = [ ] <EOL> msg = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( self . request , msg ) <EOL> return { '<STR_LIT:id>' : self . kwargs [ "<STR_LIT:id>" ] , <EOL> '<STR_LIT>' : resource_types } <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ManageResourceTypes , self ) . get_context_data ( ** kwargs ) <EOL> selected_type_names = [ selected_type [ '<STR_LIT:name>' ] for selected_type in <EOL> context [ '<STR_LIT>' ] . initial [ '<STR_LIT>' ] ] <EOL> try : <EOL> result = [ unselected_type for unselected_type in <EOL> glance . metadefs_resource_types_list ( self . request ) <EOL> if unselected_type [ '<STR_LIT:name>' ] not in selected_type_names ] <EOL> except Exception : <EOL> result = [ ] <EOL> msg = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( self . request , msg ) <EOL> for initial_type in context [ '<STR_LIT>' ] . initial [ '<STR_LIT>' ] : <EOL> selected_type = initial_type . copy ( ) <EOL> selected_type [ '<STR_LIT>' ] = True <EOL> result . insert ( <NUM_LIT:0> , selected_type ) <EOL> context [ '<STR_LIT:id>' ] = self . kwargs [ '<STR_LIT:id>' ] <EOL> try : <EOL> context [ "<STR_LIT>" ] = json . dumps ( result ) <EOL> except Exception : <EOL> context [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> msg = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( self . request , msg ) <EOL> return context </s>
