OpenStack Dashboard (Horizon)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

views.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Copyright 2013 Hewlett-Packard Development Company, L.P.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14. from django.core.urlresolvers import reverse
  15. from django.utils.translation import ugettext_lazy as _
  16. from horizon import exceptions
  17. from horizon import messages
  18. from horizon import tables
  19. from horizon import workflows
  20. from openstack_dashboard import api
  21. from openstack_dashboard import policy
  22. from openstack_dashboard.dashboards.identity.domains import constants
  23. from openstack_dashboard.dashboards.identity.domains \
  24. import tables as project_tables
  25. from openstack_dashboard.dashboards.identity.domains \
  26. import workflows as project_workflows
  27. from openstack_dashboard.utils import identity
  28. class IndexView(tables.DataTableView):
  29. table_class = project_tables.DomainsTable
  30. template_name = constants.DOMAINS_INDEX_VIEW_TEMPLATE
  31. page_title = _("Domains")
  32. def get_data(self):
  33. domains = []
  34. domain_context = self.request.session.get('domain_context')
  35. if policy.check((
  36. ("identity", "identity:list_domains"),
  37. ), self.request) and not domain_context:
  38. try:
  39. domains = api.keystone.domain_list(self.request)
  40. except Exception:
  41. exceptions.handle(self.request,
  42. _('Unable to retrieve domain list.'))
  43. elif policy.check((
  44. ("identity", "identity:get_domain"),
  45. ), self.request):
  46. try:
  47. domain_id = identity.get_domain_id_for_operation(self.request)
  48. domain = api.keystone.domain_get(self.request, domain_id)
  49. domains.append(domain)
  50. except Exception:
  51. exceptions.handle(self.request,
  52. _('Unable to retrieve domain information.'))
  53. else:
  54. msg = _("Insufficient privilege level to view domain information.")
  55. messages.info(self.request, msg)
  56. return domains
  57. class CreateDomainView(workflows.WorkflowView):
  58. workflow_class = project_workflows.CreateDomain
  59. class UpdateDomainView(workflows.WorkflowView):
  60. workflow_class = project_workflows.UpdateDomain
  61. def get_initial(self):
  62. initial = super(UpdateDomainView, self).get_initial()
  63. domain_id = self.kwargs['domain_id']
  64. initial['domain_id'] = domain_id
  65. try:
  66. # get initial domain info
  67. domain_info = api.keystone.domain_get(self.request,
  68. domain_id)
  69. for field in constants.DOMAIN_INFO_FIELDS:
  70. initial[field] = getattr(domain_info, field, None)
  71. except Exception:
  72. exceptions.handle(self.request,
  73. _('Unable to retrieve domain details.'),
  74. redirect=reverse(constants.DOMAINS_INDEX_URL))
  75. return initial