'Cleans Template & Environment data from form upload.
Does some of the crunchy bits for processing uploads vs raw
data depending on what the user specified. Identical process
for environment data & template data.
:type prefix: str
:param prefix: prefix (environment, template) of field
:type field_label: str
:param field_label: translated prefix str for messages
:type input_type: dict
:param prefix: existing cleaned fields from form
:rtype: dict
:return: cleaned dict including environment & template data'

def clean_uploaded_files(self, prefix, field_label, cleaned, files):

    upload_str = (prefix + '_upload')
    data_str = (prefix + '_data')
    url = cleaned.get((prefix + '_url'))
    data = cleaned.get((prefix + '_data'))
    has_upload = (upload_str in files)
    if (has_upload and (not url)):
        log_template_name = files[upload_str].name
        LOG.info('got    upload    %s', log_template_name)
        tpl = files[upload_str].read()
        if tpl.startswith('{'):
            try:
                json.loads(tpl)
            except Exception as e:
                msg = _('There    was    a    problem    parsing    the    %(prefix)s:    %(error)s')
                msg = (msg % {'prefix': prefix, 'error': six.text_type(e)})
                raise forms.ValidationError(msg)
        cleaned[data_str] = tpl
    elif (url and (has_upload or data)):
        msg = _('Please    specify    a    %s    using    only    one    source    method.')
        msg = (msg % field_label)
        raise forms.ValidationError(msg)
    elif (prefix == 'template'):
        if ((not url) and (not data)):
            msg = _('You    must    specify    a    template    via    one    of    the    available    sources.')
            raise forms.ValidationError(msg)
