Пример #1
0
def export(request, process_id):
    """View for exporting result process data in CSV or JSON format.  Thus,
    the return value is not an HTML response.

    :param request: the current HTTP Request object
    :param process_id: the database ID of the result to show

    :type request: HttpRequest
    :type process_id: unicode

    :return:
      the HTTP response object

    :rtype: HttpResponse
    """
    result = get_object_or_404(models.Result, pk=utils.convert_id_to_int(process_id))
    permissions.assert_can_view_result_process(request.user, result)
    data = result.get_data_for_table_export()
    # Translators: In a table
    result = utils.table_export(request, data, _("row"))
    if isinstance(result, tuple):
        column_groups_form, columns_form, table, switch_row_forms, old_data_form = result
    elif isinstance(result, HttpResponse):
        return result
    title = _("Table export for “{name}”").format(name=data.descriptive_name)
    return render(request, "samples/table_export.html", {"title": title, "column_groups": column_groups_form,
                                                         "columns": columns_form,
                                                         "rows": list(zip(table, switch_row_forms)) if table else None,
                                                         "old_data": old_data_form,
                                                         "backlink": request.GET.get("next", "")})
Пример #2
0
def show_thumbnail(request, process_id):
    """Shows the thumnail of a particular result image.  Although its response
    is an image rather than an HTML file, it is served by Django in order to
    enforce user permissions.

    :param request: the current HTTP Request object
    :param process_id: the database ID of the result to show

    :type request: HttpRequest
    :type process_id: unicode

    :return:
      the HTTP response object with the thumbnail image

    :rtype: HttpResponse
    """
    result = get_object_or_404(models.Result,
                               pk=utils.convert_id_to_int(process_id))
    permissions.assert_can_view_result_process(request.user, result)
    image_locations = result.get_image_locations()
    image_file = image_locations["image_file"]
    thumbnail_file = image_locations["thumbnail_file"]
    if is_update_necessary(thumbnail_file, [image_file]):
        mkdirs(thumbnail_file)
        subprocess.check_call([
            "convert",
            image_file + ("[0]" if result.image_type == "pdf" else ""),
            "-resize", "{0}x{0}".format(settings.THUMBNAIL_WIDTH),
            thumbnail_file
        ])
        storage_changed.send(models.Result)
    return static_file_response(thumbnail_file)
Пример #3
0
def export(request, process_id):
    """View for exporting result process data in CSV or JSON format.  Thus,
    the return value is not an HTML response.

    :param request: the current HTTP Request object
    :param process_id: the database ID of the result to show

    :type request: HttpRequest
    :type process_id: unicode

    :return:
      the HTTP response object

    :rtype: HttpResponse
    """
    result = get_object_or_404(models.Result, pk=utils.convert_id_to_int(process_id))
    permissions.assert_can_view_result_process(request.user, result)
    data = result.get_data_for_table_export()
    # Translators: In a table
    result = utils.table_export(request, data, _("row"))
    if isinstance(result, tuple):
        column_groups_form, columns_form, table, switch_row_forms, old_data_form = result
    elif isinstance(result, HttpResponse):
        return result
    title = _("Table export for “{name}”").format(name=data.descriptive_name)
    return render(request, "samples/table_export.html", {"title": title, "column_groups": column_groups_form,
                                                         "columns": columns_form,
                                                         "rows": list(zip(table, switch_row_forms)) if table else None,
                                                         "old_data": old_data_form,
                                                         "backlink": request.GET.get("next", "")})
Пример #4
0
def show(request, process_id):
    """Shows a particular result process.  The main purpose of this view is to
    be able to visit a result directly from a feed entry about a new/edited
    result.

    :param request: the current HTTP Request object
    :param process_id: the database ID of the result to show

    :type request: HttpRequest
    :type process_id: unicode

    :return:
      the HTTP response object

    :rtype: HttpResponse
    """
    result = get_object_or_404(models.Result,
                               pk=utils.convert_id_to_int(process_id))
    permissions.assert_can_view_result_process(request.user, result)
    if jb_common.utils.base.is_json_requested(request):
        return jb_common.utils.base.respond_in_json(result.get_data())
    template_context = {
        "title": _("Result “{title}”").format(title=result.title),
        "result": result,
        "samples": result.samples.all(),
        "sample_series": result.sample_series.all()
    }
    template_context.update(utils.digest_process(result, request.user))
    return render(request, "samples/show_single_result.html", template_context)
Пример #5
0
def show_thumbnail(request, process_id):
    """Shows the thumnail of a particular result image.  Although its response
    is an image rather than an HTML file, it is served by Django in order to
    enforce user permissions.

    :param request: the current HTTP Request object
    :param process_id: the database ID of the result to show

    :type request: HttpRequest
    :type process_id: unicode

    :return:
      the HTTP response object with the thumbnail image

    :rtype: HttpResponse
    """
    result = get_object_or_404(models.Result, pk=utils.convert_id_to_int(process_id))
    permissions.assert_can_view_result_process(request.user, result)
    image_locations = result.get_image_locations()
    image_file = image_locations["image_file"]
    thumbnail_file = image_locations["thumbnail_file"]
    if is_update_necessary(thumbnail_file, [image_file]):
        mkdirs(thumbnail_file)
        subprocess.check_call(["convert", image_file + ("[0]" if result.image_type == "pdf" else ""),
                               "-resize", "{0}x{0}".format(settings.THUMBNAIL_WIDTH), thumbnail_file])
        storage_changed.send(models.Result)
    return static_file_response(thumbnail_file)
Пример #6
0
def show_image(request, process_id):
    """Shows a particular result image.  Although its response is an image
    rather than an HTML file, it is served by Django in order to enforce user
    permissions.

    :param request: the current HTTP Request object
    :param process_id: the database ID of the result to show

    :type request: HttpRequest
    :type process_id: unicode

    :return:
      the HTTP response object with the image

    :rtype: HttpResponse
    """
    result = get_object_or_404(models.Result, pk=utils.convert_id_to_int(process_id))
    permissions.assert_can_view_result_process(request.user, result)
    image_locations = result.get_image_locations()
    return static_file_response(image_locations["image_file"], image_locations["sluggified_filename"])
Пример #7
0
def show_image(request, process_id):
    """Shows a particular result image.  Although its response is an image
    rather than an HTML file, it is served by Django in order to enforce user
    permissions.

    :param request: the current HTTP Request object
    :param process_id: the database ID of the result to show

    :type request: HttpRequest
    :type process_id: unicode

    :return:
      the HTTP response object with the image

    :rtype: HttpResponse
    """
    result = get_object_or_404(models.Result, pk=utils.convert_id_to_int(process_id))
    permissions.assert_can_view_result_process(request.user, result)
    image_locations = result.get_image_locations()
    return static_file_response(jb_common.utils.blobs.storage.export(image_locations["image_file"]),
                                image_locations["sluggified_filename"])
Пример #8
0
def show_thumbnail(request, process_id):
    """Shows the thumnail of a particular result image.  Although its response
    is an image rather than an HTML file, it is served by Django in order to
    enforce user permissions.

    :param request: the current HTTP Request object
    :param process_id: the database ID of the result to show

    :type request: HttpRequest
    :type process_id: unicode

    :return:
      the HTTP response object with the thumbnail image

    :rtype: HttpResponse
    """
    result = get_object_or_404(models.Result, pk=utils.convert_id_to_int(process_id))
    permissions.assert_can_view_result_process(request.user, result)
    image_locations = result.get_image_locations()
    image_filename = image_locations["image_file"]
    thumbnail_file = image_locations["thumbnail_file"]
    content = get_cached_file_content(thumbnail_file, partial(generate_thumbnail, result, image_filename),
                                      [image_filename])
    return static_response(content, content_type="image/png")
Пример #9
0
def show(request, process_id):
    """Shows a particular result process.  The main purpose of this view is to
    be able to visit a result directly from a feed entry about a new/edited
    result.

    :param request: the current HTTP Request object
    :param process_id: the database ID of the result to show

    :type request: HttpRequest
    :type process_id: unicode

    :return:
      the HTTP response object

    :rtype: HttpResponse
    """
    result = get_object_or_404(models.Result, pk=utils.convert_id_to_int(process_id))
    permissions.assert_can_view_result_process(request.user, result)
    if jb_common.utils.base.is_json_requested(request):
        return jb_common.utils.base.respond_in_json(result.get_data())
    template_context = {"title": _("Result “{title}”").format(title=result.title), "result": result,
                        "samples": result.samples.all(), "sample_series": result.sample_series.all()}
    template_context.update(utils.digest_process(result, request.user))
    return render(request, "samples/show_single_result.html", template_context)
Пример #10
0
def show_thumbnail(request, process_id):
    """Shows the thumnail of a particular result image.  Although its response
    is an image rather than an HTML file, it is served by Django in order to
    enforce user permissions.

    :param request: the current HTTP Request object
    :param process_id: the database ID of the result to show

    :type request: HttpRequest
    :type process_id: unicode

    :return:
      the HTTP response object with the thumbnail image

    :rtype: HttpResponse
    """
    result = get_object_or_404(models.Result, pk=utils.convert_id_to_int(process_id))
    permissions.assert_can_view_result_process(request.user, result)
    image_locations = result.get_image_locations()
    image_filename = image_locations["image_file"]
    thumbnail_file = image_locations["thumbnail_file"]
    content = get_cached_file_content(thumbnail_file, partial(generate_thumbnail, result, image_filename),
                                      [image_filename])
    return static_response(content, content_type="image/png")