(project, job=None, source_data={}, fill_with={})
return json_data
Produces a filled in JSON data based on user input.
Produces a filled in JSON data based on user input.
Produces a filled in JSON data based on user input .
def fill_json_data(project, job=None, source_data={}, fill_with={}):
    """
    Produces a filled in JSON data based on user input.
    """

    # Creates a data.id to data mapping.
    store = dict((data.id, data) for data in project.data_set.all())

    # Make a copy of the original json data used to render the form.
    json_data = copy.deepcopy(source_data)

    # Get default dictionary to fill with from json data 'value'
    default = {field: item.get('value', '') for field, item in json_data.items()}
    fill_with = fill_with or default

    # Alter the json data and fill in the extra information.
    for field, item in json_data.items():

        # If the field is a data field then fill in more information.
        if item.get("source") == "PROJECT" and fill_with.get(field, '').isalnum():
            try:
                data_id = int(fill_with.get(field))
                data = store.get(data_id)
                # This mutates the `item` dictionary!
                data.fill_dict(item)
            except Exception as exc:
                logger.error(exc)
                # This mutates the `item` dictionary!
                value = fill_with.get(field, "MISSING")
                fill_in(item=item, value=value)

            continue

        # The JSON value will be overwritten with the selected field value.
        if field in fill_with:
            item["value"] = fill_with[field]
            # Clean the textbox value
            if item.get('display') == TEXTBOX:
                item["value"] = util.clean_text(fill_with[field])

            if item.get('display') == UPLOAD:
                # Add uploaded file to job directory.
                upload_value = fill_with.get(field)
                if not upload_value:
                    item['value'] = ''
                    continue
                # Link or write the stream located in the fill_with
                path = add_file(target_dir=job.get_data_dir(), source=upload_value)
                item['value'] = path

    return json_data
def fill_json_data ( project , job = None , source_data = { } , fill_with = { } ) : # Creates a data.id to data mapping. store = dict ( ( data . id , data ) for data in project . data_set . all ( ) ) # Make a copy of the original json data used to render the form. json_data = copy . deepcopy ( source_data ) # Get default dictionary to fill with from json data 'value' default = { field : item . get ( 'value' , '' ) for field , item in json_data . items ( ) } fill_with = fill_with or default # Alter the json data and fill in the extra information. for field , item in json_data . items ( ) : # If the field is a data field then fill in more information. if item . get ( "source" ) == "PROJECT" and fill_with . get ( field , '' ) . isalnum ( ) : try : data_id = int ( fill_with . get ( field ) ) data = store . get ( data_id ) # This mutates the `item` dictionary! data . fill_dict ( item ) except Exception as exc : logger . error ( exc ) # This mutates the `item` dictionary! value = fill_with . get ( field , "MISSING" ) fill_in ( item = item , value = value ) continue # The JSON value will be overwritten with the selected field value. if field in fill_with : item [ "value" ] = fill_with [ field ] # Clean the textbox value if item . get ( 'display' ) == TEXTBOX : item [ "value" ] = util . clean_text ( fill_with [ field ] ) if item . get ( 'display' ) == UPLOAD : # Add uploaded file to job directory. upload_value = fill_with . get ( field ) if not upload_value : item [ 'value' ] = '' continue # Link or write the stream located in the fill_with path = add_file ( target_dir = job . get_data_dir ( ) , source = upload_value ) item [ 'value' ] = path return json_data