views.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python
  2. # Licensed to Cloudera, Inc. under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. Cloudera, Inc. licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. import json
  18. import logging
  19. from django.utils.translation import ugettext as _
  20. from desktop import appmanager
  21. from desktop.lib.django_util import JsonResponse, render, login_notrequired
  22. from desktop.log.access import access_log_level
  23. from desktop.models import Settings, hue_version
  24. from desktop.views import collect_usage
  25. def admin_wizard(request):
  26. if request.user.is_superuser:
  27. apps = appmanager.get_apps(request.user)
  28. else:
  29. apps = []
  30. app_names = [app.name for app in sorted(apps, key=lambda app: app.menu_index)]
  31. return render('admin_wizard.mako', request, {
  32. 'version': hue_version(),
  33. 'apps': dict([(app.name, app) for app in apps]),
  34. 'app_names': app_names,
  35. 'is_embeddable': request.GET.get('is_embeddable', False),
  36. 'collect_usage': collect_usage(),
  37. })
  38. def update_preferences(request):
  39. response = {'status': -1, 'data': ''}
  40. if request.method == 'POST':
  41. try:
  42. settings = Settings.get_settings()
  43. settings.collect_usage = request.POST.get('collect_usage', False)
  44. settings.save()
  45. response['status'] = 0
  46. response['collect_usage'] = settings.collect_usage
  47. except Exception, e:
  48. response['data'] = str(e)
  49. else:
  50. response['data'] = _('POST request required.')
  51. return JsonResponse(response)