Ejemplo n.º 1
0
def preview_snippet(request):
    """
    Build a snippet using info from the POST parameters, and preview that
    snippet on a mock about:home page.
    """
    try:
        template_id = int(request.POST.get('template_id', None))
    except (TypeError, ValueError):
        return HttpResponseBadRequest()

    template = get_object_or_none(SnippetTemplate, id=template_id)
    data = request.POST.get('data', None)

    # Validate that data is JSON.
    try:
        json.loads(data)
    except (TypeError, ValueError):
        data = None

    # If your parameters are wrong, I have no sympathy for you.
    if data is None or template is None:
        return HttpResponseBadRequest()

    # Build a snippet that isn't saved so we can render it.
    snippet = Snippet(template=template, data=data)

    if strtobool(request.POST.get('activity_stream', 'false')):
        template_name = 'base/preview_as.jinja'
        preview_client = Client('5', 'Firefox', '57.0', 'default', 'default',
                                'en-US', 'release', 'default', 'default',
                                'default')
    else:
        template_name = 'base/preview.jinja'
        preview_client = Client('4', 'Firefox', '24.0', 'default', 'default',
                                'en-US', 'release', 'default', 'default',
                                'default')

    skip_boilerplate = request.POST.get('skip_boilerplate', 'false')
    skip_boilerplate = strtobool(skip_boilerplate)
    if skip_boilerplate:
        template_name = 'base/preview_without_shell.jinja'

    return render(
        request, template_name, {
            'snippets_json': json.dumps([snippet.to_dict()]),
            'client': preview_client,
            'preview': True,
            'current_firefox_major_version':
            util.current_firefox_major_version(),
        })
Ejemplo n.º 2
0
def preview_snippet(request):
    """
    Build a snippet using info from the POST parameters, and preview that
    snippet on a mock about:home page.
    """
    try:
        template_id = int(request.POST.get('template_id', None))
    except (TypeError, ValueError):
        return HttpResponseBadRequest()

    template = get_object_or_none(SnippetTemplate, id=template_id)
    data = request.POST.get('data', None)

    # Validate that data is JSON.
    try:
        json.loads(data)
    except (TypeError, ValueError):
        data = None

    # If your parameters are wrong, I have no sympathy for you.
    if data is None or template is None:
        return HttpResponseBadRequest()

    # Build a snippet that isn't saved so we can render it.
    snippet = Snippet(template=template, data=data)

    if strtobool(request.POST.get('activity_stream', 'false')):
        template_name = 'base/preview_as.jinja'
        preview_client = Client(5, 'Firefox', '57.0', 'default', 'default', 'en-US',
                                'release', 'default', 'default', 'default')
    else:
        template_name = 'base/preview.jinja'
        preview_client = Client(4, 'Firefox', '24.0', 'default', 'default', 'en-US',
                                'release', 'default', 'default', 'default')

    skip_boilerplate = request.POST.get('skip_boilerplate', 'false')
    skip_boilerplate = strtobool(skip_boilerplate)
    if skip_boilerplate:
        template_name = 'base/preview_without_shell.jinja'

    return render(request, template_name, {
        'snippets_json': json.dumps([snippet.to_dict()]),
        'client': preview_client,
        'preview': True,
        'current_firefox_major_version': util.current_firefox_major_version(),
    })
Ejemplo n.º 3
0
def preview_snippet(request):
    """
    Build a snippet using info from the POST parameters, and preview that
    snippet on a mock about:home page.
    """
    try:
        template_id = int(request.POST.get('template_id', None))
    except (TypeError, ValueError):
        return HttpResponseBadRequest()

    template = get_object_or_none(SnippetTemplate, id=template_id)
    data = request.POST.get('data', None)

    # Validate that data is JSON.
    try:
        json.loads(data)
    except (TypeError, ValueError):
        data = None

    # If your parameters are wrong, I have no sympathy for you.
    if data is None or template is None:
        return HttpResponseBadRequest()

    # Build a snippet that isn't saved so we can render it.
    snippet = Snippet(template=template, data=data)

    skip_boilerplate = request.POST.get('skip_boilerplate', 'false')
    skip_boilerplate = strtobool(skip_boilerplate)

    template_name = 'base/preview_without_shell.jinja' if skip_boilerplate else 'base/preview.jinja'
    current_firefox_version = (
        version_list(product_details.firefox_history_major_releases)[0].split('.', 1)[0])

    return render(request, template_name, {
        'snippets_json': json.dumps([snippet.to_dict()]),
        'client': PREVIEW_CLIENT,
        'preview': True,
        'current_firefox_version': current_firefox_version,
    })
Ejemplo n.º 4
0
def preview_snippet(request):
    """
    Build a snippet using info from the POST parameters, and preview that
    snippet on a mock about:home page.
    """
    try:
        template_id = int(request.POST.get('template_id', None))
    except (TypeError, ValueError):
        return HttpResponseBadRequest()

    template = get_object_or_none(SnippetTemplate, id=template_id)
    data = request.POST.get('data', None)

    # Validate that data is JSON.
    try:
        json.loads(data)
    except (TypeError, ValueError):
        data = None

    # If your parameters are wrong, I have no sympathy for you.
    if data is None or template is None:
        return HttpResponseBadRequest()

    # Build a snippet that isn't saved so we can render it.
    snippet = Snippet(template=template, data=data)

    skip_boilerplate = request.POST.get('skip_boilerplate', 'false')
    skip_boilerplate = strtobool(skip_boilerplate)

    template_name = 'base/preview_without_shell.html' if skip_boilerplate else 'base/preview.html'

    return render(
        request, template_name, {
            'snippets_json': json.dumps([snippet.to_dict()]),
            'client': PREVIEW_CLIENT,
            'preview': True,
        })