# Path: djangui/forms/scripts.py
# class DjanguiForm(forms.Form):
# 
#     def add_djangui_fields(self):
#         # This adds fields such as job name, description that we like to validate on but don't want to include in
#         # form rendering
#         self.fields['job_name'] = forms.CharField()
#         self.fields['job_description'] = forms.CharField(required=False)
# 
# Path: djangui/backend/utils.py
# def sanitize_name(name):
# def sanitize_string(value):
# def get_storage(local=True):
# def get_job_commands(job=None):
# def create_djangui_job(user=None, script_pk=None, data=None):
# def get_master_form(model=None, pk=None):
# def get_form_groups(model=None, pk=None, initial=None):
# def validate_form(form=None, data=None, files=None):
# def load_scripts():
# def get_storage_object(path, local=False):
# def add_djangui_script(script=None, group=None):
# def valid_user(obj, user):
# def mkdirs(path):
# def get_file_info(filepath):
# def test_delimited(filepath):
# def test_fastx(filepath):
# def create_job_fileinfo(job):
# def get_file_previews(job):
#     CHOICE_MAPPING = {
# 
#     }


import copy
import json
import six
from collections import OrderedDict
from django import forms
from .scripts import DjanguiForm
from ..backend import utils
from ..models import ScriptParameter
from __future__ import absolute_import
__author__ = 'chris'




class DjanguiFormFactory(object):
    djangui_forms = {}

    @staticmethod
    def get_field(param, initial=None):
        field = param.form_field
        choices = json.loads(param.choices)
        field_kwargs = {'label': param.script_param.title(),
                        'required': param.required,
                        'help_text': param.param_help,
                        }
        if choices:
            field = 'ChoiceField'
            base_choices = [(None, '----')] if not param.required else []
            field_kwargs['choices'] = base_choices+[(str(i), str(i).title()) for i in choices]
        if field == 'FileField':
            if param.is_output:
                field = 'CharField'
                initial = None
            else:
                if initial is not None:

# Path: djangui/forms/scripts.py
# class DjanguiForm(forms.Form):
# 
#     def add_djangui_fields(self):
#         # This adds fields such as job name, description that we like to validate on but don't want to include in
#         # form rendering
#         self.fields['job_name'] = forms.CharField()
#         self.fields['job_description'] = forms.CharField(required=False)
# 
# Path: djangui/backend/utils.py
# def sanitize_name(name):
# def sanitize_string(value):
# def get_storage(local=True):
# def get_job_commands(job=None):
# def create_djangui_job(user=None, script_pk=None, data=None):
# def get_master_form(model=None, pk=None):
# def get_form_groups(model=None, pk=None, initial=None):
# def validate_form(form=None, data=None, files=None):
# def load_scripts():
# def get_storage_object(path, local=False):
# def add_djangui_script(script=None, group=None):
# def valid_user(obj, user):
# def mkdirs(path):
# def get_file_info(filepath):
# def test_delimited(filepath):
# def test_fastx(filepath):
# def create_job_fileinfo(job):
# def get_file_previews(job):
#     CHOICE_MAPPING = {
# 
#     }


# Path: djangui/forms/factory.py
import copy
import json
import six
from collections import OrderedDict
from django import forms
from .scripts import DjanguiForm
from ..backend import utils
from ..models import ScriptParameter

from __future__ import absolute_import
__author__ = 'chris'




class DjanguiFormFactory(object):
    djangui_forms = {}

    @staticmethod
    def get_field(param, initial=None):
        field = param.form_field
        choices = json.loads(param.choices)
        field_kwargs = {'label': param.script_param.title(),
                        'required': param.required,
                        'help_text': param.param_help,
                        }
        if choices:
            field = 'ChoiceField'
            base_choices = [(None, '----')] if not param.required else []
            field_kwargs['choices'] = base_choices+[(str(i), str(i).title()) for i in choices]
        if field == 'FileField':
            if param.is_output:
                field = 'CharField'
                initial = None
            else:
                if initial is not None:

                    initial = utils.get_storage_object(initial) if not hasattr(initial, 'path') else initial