Exemple #1
0
def make_form(tool, request=None):
    """
    Instantiate one form, based on the request and the tool
    :param tool:
    :param request: the current post request
    :return: an instanciated and initialized form
    """

    tool_inputs_details = tool.fetch_tool_json()
    tool_field_white_list, created = ToolFieldWhiteList.objects.get_or_create(
        tool=tool, context="w")
    formname = str(slugify(tool.name).title().replace('-', '')) + 'Form'
    prefix = formname.lower()

    # If not post, it means that we want to create a form with
    # default values
    formdata = None
    if request is not None and request.POST:
        formdata = request.POST

    return ToolForm(data=formdata,
                    prefix=prefix,
                    tool_params=tool_inputs_details.get('inputs'),
                    tool_id=tool.id_galaxy,
                    tool_name=tool.name,
                    whitelist=tool_field_white_list.saved_params,
                    fields_ids_mapping={},
                    n=0)