Exemplo n.º 1
0
def session_detail(request, session_id):
    
    session = get_object_or_404(HttpSession, pk=session_id)
    html_formatter = HtmlFormatter()

    run_session(session)
    
    pretty_request = html_formatter.format(session.get_raw_request())
    
    if session.time_completed:
        if not session.http_error:
            pretty_response = html_formatter.format(session.http_response)
            session_time = session.time_completed - session.time_requested
            elapsed_milliseconds = session_time.microseconds / 1000.0
    else:
        pretty_response = render_to_string('spyglass/fragment_loading_placeholder.html', {'session_id': session.id})
        elapsed_milliseconds = None
    
    use_advanced_form = (len(session.http_body) != 0) or (len(session.http_headers) != 0)
    form, http_header_form = session_and_headers_form(session=session)
        
    context = {
        'session': session,
        'pretty_request': pretty_request,
        'pretty_response': pretty_response,
        'request_linenos': html_line_numbers(pretty_request),
        'response_linenos': html_line_numbers(pretty_response),
        'elapsed_milliseconds': elapsed_milliseconds,
        'form': form,
        'http_header_form': http_header_form,
        'use_advanced_form': use_advanced_form,
    }
    
    return render_to_response('spyglass/session_detail.html', context, context_instance=RequestContext(request))    
Exemplo n.º 2
0
def session_detail(request, session_id):
    
    session = get_object_or_404(HttpSession, pk=session_id)
    html_formatter = HtmlFormatter()

    run_session(session)
    
    pretty_request = html_formatter.format(session.get_raw_request())

    use_advanced_form = (len(session.http_body) != 0) or (len(session.http_headers) != 0)
    form, http_header_form = session_and_headers_form(session=session)

    response_template = open(os.path.join(settings.MEDIA_ROOT, 'mustache/session.mustache')).read()
    formatted_response = pystache.render(response_template, mustache_context_for_session(session))
    
    context = {
        'session': session,
        'pretty_request': pretty_request,
        'request_linenos': html_line_numbers(pretty_request),
        
        'show_placeholder': not session_is_ready(session),
        'formatted_response': formatted_response,
        
        'form': form,
        'http_header_form': http_header_form,
        'use_advanced_form': use_advanced_form,
    }
    
    return render_to_response('spyglass/session_detail.html', context, context_instance=RequestContext(request))    
Exemplo n.º 3
0
def session_completed_jsonp(request, session_id):

    session = get_object_or_404(HttpSession, pk=session_id)
    ready = session_is_ready(session)
    
    html_formatter = HtmlFormatter()
    response = {'session_id': session.id}
    
    response['complete'] = 'true' if ready else 'false'
    
    if ready:
        if session.http_error:
            response['error'] = session.get_http_error_display()
        else:
            pretty_response = html_formatter.format(session.http_response)
            response['pretty_response'] = pretty_response
            response['response_linenos'] = html_line_numbers(pretty_response)
            response['elapsed_milliseconds'] = (session.time_completed - session.time_requested).microseconds / 1000.0
    
    return HttpResponse(json.dumps(response), mimetype='application/json')
Exemplo n.º 4
0
def mustache_context_for_session(session):
    ready = session_is_ready(session)
    html_formatter = HtmlFormatter()
    ctx = {
        'MEDIA_URL': settings.MEDIA_URL,
        'session_id': session.id,
        'complete': 'true' if ready else 'false',
    }
    
    if ready:
        if session.http_error:
            ctx['http_error'] = session.get_http_error_display()
        else:
            pretty_response = html_formatter.format(session.http_response)
            ctx['pretty_response'] = pretty_response
            ctx['response_linenos'] = html_line_numbers(pretty_response)
            ctx['elapsed_milliseconds'] = (session.time_completed - session.time_requested).microseconds / 1000.0
            ctx['redirects'] = [{'url': s.url} for s in session.httpredirect_set.all()]
    else:
        ctx['response_linenos'] = '1\n2\n3'
        ctx['pretty_response'] = '<div class="loading-placeholder" session_id="%d">Refresh the page to see results...</div>' % session.id
    return ctx