コード例 #1
0
ファイル: views.py プロジェクト: ranade1/hue
def serve_500_error(request, *args, **kwargs):
    """Registered handler for 500. We use the debug view to make debugging easier."""
    try:
        exc_info = sys.exc_info()
        if exc_info:
            if desktop.conf.HTTP_500_DEBUG_MODE.get(
            ) and exc_info[0] and exc_info[1]:
                # If (None, None, None), default server error describing why this failed.
                return django.views.debug.technical_500_response(
                    request, *exc_info)
            else:
                tb = traceback.extract_tb(exc_info[2])
                if is_ajax(request):
                    tb = '\n'.join(tb.format(
                    ) if sys.version_info[0] > 2 else [str(t) for t in tb])
                return render("500.mako", request, {'traceback': tb})
        else:
            # exc_info could be empty
            return render("500.mako", request, {})
    finally:
        # Fallback to default 500 response if ours fails
        # Will end up here:
        #   - Middleware or authentication backends problems
        #   - Certain missing imports
        #   - Packaging and install issues
        pass
コード例 #2
0
ファイル: views.py プロジェクト: ranade1/hue
def threads(request):
    """Dumps out server threads. Useful for debugging."""
    out = string_io()
    dump_traceback(file=out)

    if is_ajax(request):
        return HttpResponse(out.getvalue(), content_type="text/plain")
    else:
        return render(
            "threads.mako", request, {
                'text': out.getvalue(),
                'is_embeddable': request.GET.get('is_embeddable', False)
            })
コード例 #3
0
    def authorize(self, request):
        access_token = request.session.get('github_access_token')
        if access_token and GithubClient.is_authenticated(access_token):
            response = {
                'status': 0,
                'message': _('User is already authenticated to GitHub.')
            }
            return JsonResponse(response)
        else:
            auth_url = GithubClient.get_authorization_url()
            request.session['github_callback_redirect'] = request.GET.get(
                'currentURL')
            request.session['github_callback_fetch'] = request.GET.get(
                'fetchURL')
            response = {'status': -1, 'auth_url': auth_url}
            if is_ajax(request):
                return JsonResponse(response)

            return HttpResponseRedirect(auth_url)
コード例 #4
0
def index(request):
    if request.GET.get('pretty') == 'true':
        indent = 2
    else:
        indent = None

    rep = {
        'timestamp': datetime.datetime.utcnow().isoformat(),
        'metric': global_registry().dump_metrics(),
    }

    if is_ajax(request) or request.GET.get("format") == "json":
        return JsonResponse(rep, json_dumps_params={'indent': indent})
    else:
        return render(
            "metrics.mako", request, {
                'metrics': json.dumps(rep['metric']),
                'is_embeddable': request.GET.get('is_embeddable', False)
            })
コード例 #5
0
def list_designs(request):
  '''
  List all workflow designs. Result sorted by last modification time.
  Query params:
    owner       - Substring filter by owner field
    name        - Substring filter by design name field
  '''
  owner = request.GET.get('owner', '')
  name = request.GET.get('name', '')

  if is_ajax(request):
    return render_json({
      'designs': _list_designs(request, owner, name)
    }, js_safe=True)
  else:
    return render("designs.mako", request, {
      'currentuser': request.user,
      'owner': owner,
      'name': name,
      'apps': appmanager.get_apps_dict()
    })
コード例 #6
0
 def process_request(self, request):
     request.ajax = is_ajax(request) or request.GET.get("format",
                                                        "") == "json"
     return None
コード例 #7
0
 def _is_html(self, request, response):
     return not is_ajax(request) and \
         'html' in response['Content-Type'] and \
         200 <= response.status_code < 300