Пример #1
0
def __getModulesDjangoForms__():
    forms = {}
    for mod in ht.getModulesNames():
        form = __createHtmlModalForm__(mod)
        if form:
            for url in form:
                if form[url]:
                    forms[mod] = form
    return forms
def __getModulesDjangoFormsModal__(session_id=None):
    forms = {}
    for mod in ht.getModulesNames():
        mod_data = {}
        functions = __getModuleFunctionNamesFromConfig__(mod)
        if functions:
            for functs in functions:
                form = __createHtmlModalForm__(
                    mod, 'django_form_module_function', functs, session_id)
                if form:
                    mod_data[functs] = form
        if mod_data:
            forms[mod] = mod_data
    return forms
def __getModulesModalTests__():
    """Return's an Array with all modules as keys and their values, the Modal GUI function forms

    Parameters
    ----------
        None

    Return
    ----------
        Array
    """
    tools_functions = {}
    for tool in ht.getModulesNames():
        tool_functions = Config.getConfig(
            parentKey='modules', key=tool, subkey='django_form_module_function')
        if tool_functions:
            tools_functions[tool] = tool_functions
    return tools_functions
def __getModulesGuiNames__():
    """Return's an Array with the Label for GUI for that module

    Parameters
    ----------
        None

    Return
    ----------
        Array
    """
    names = {}
    for tool in ht.getModulesNames():
        label = ht.Config.getConfig(
            parentKey='modules', key=tool, subkey='__gui_label__')
        if label:
            names[tool] = label
    return names
Пример #5
0
                        .format(mod_url=func_call),
                        is_warn=True)
                    if functions_not_loaded and func_call in functions_not_loaded:
                        functions_not_loaded.remove(func_call)
                    functions_not_loaded.append(func_call)
                    UtilsDjangoViewsAuto.createTemplateFunctionForModule(
                        moduleName, ht.getModuleCategory(moduleName),
                        func_call)
    else:
        pass
        #Logger.printMessage(message='loadModuleUrls', description='{mod} has no functions on views config definition'.format(mod=mod), is_warn=True)


# Automatically creates the URL's get by the modules and the configurations
try:
    for mod in ht.getModulesNames():
        #Logger.printMessage(message='Initialize', description='Loading mod \'{mod}\''.format(mod=mod))
        loadModuleUrls(mod)

    if functions_not_loaded or main_functions_not_loaded:
        if functions_not_loaded:
            ht.Logger.printMessage(
                message='CORE VIEWS',
                description='Loaded new function{s} views: {d}'.format(
                    s='s' if len(functions_not_loaded) > 1 else '',
                    d=', '.join(functions_not_loaded)),
                is_info=True)
        if main_functions_not_loaded:
            ht.Logger.printMessage(
                message='CORE VIEWS',
                description='Loaded new main function views: {d}'.format(
Пример #6
0
def __createHtmlModalForm__(mod,
                            config_subkey='django_form_main_function',
                            config_extrasubkey=None,
                            session_id=None):
    module_form = Config.getConfig(parentKey='modules',
                                   key=mod,
                                   subkey=config_subkey,
                                   extrasubkey=config_extrasubkey)
    functionModal = Config.getConfig(parentKey='modules',
                                     key=mod,
                                     subkey=config_subkey,
                                     extrasubkey='__function__')
    default_classnames_per_type = Config.getConfig(parentKey='django',
                                                   key='html',
                                                   subkey='modal_forms',
                                                   extrasubkey='default_types')

    if not module_form:
        return

    html = "<div class=\"modal-body\">"
    footer = '<div class="modal-footer">'
    m_form = module_form

    # For ajax
    submit_id = ''

    if '__function__' in m_form:
        submit_id = 'submit_{mod}_{name}'.format(mod=mod,
                                                 name=m_form['__function__'])

    for m in m_form:
        temp_m_form = m_form
        if not m == '__async__' and not m == '__function__' and not '__separator' in m and (
                isinstance(temp_m_form, dict) and
            (('systems' in temp_m_form[m]
              and __os.name in temp_m_form[m]['systems'])
             or not 'systems' in temp_m_form[m])):
            if '__type__' in temp_m_form[m]:
                input_type = temp_m_form[m]['__type__']

                input_className = ''
                if not input_type in default_classnames_per_type:
                    ht.Logger.printMessage(
                        message='__createHtmlModalForm__',
                        description=
                        'There is no __className__ defined for this type of input \'{input_type}\''
                        .format(input_type=input_type),
                        color=ht.Logger.__Fore.YELLOW)
                else:
                    input_className = default_classnames_per_type[input_type][
                        '__className__']

                input_placeholder = ''
                if 'placeholder' in temp_m_form[m]:
                    input_placeholder = temp_m_form[m]['placeholder']

                input_label_desc = ''
                if 'label_desc' in temp_m_form[m]:
                    input_label_desc = temp_m_form[m]['label_desc']

                input_value = ''
                if 'value' in temp_m_form[m]:
                    input_value = temp_m_form[m]['value']

                if 'api' in m:
                    input_value = Config.getAPIKey(
                        '{m}_api'.format(m=mod.split('_')[-1]),
                        session_id=session_id)
                    input_className = ' '.join([input_className, 'apiKey'])

                if input_value != 0 and (not input_value
                                         or 'None' == input_value
                                         or 'null' == input_value):
                    input_value = ''

                checkbox_selected = False
                if 'selected' in temp_m_form[m]:
                    checkbox_selected = temp_m_form[m]['selected']

                loading_text = ''
                if 'loading_text' in temp_m_form[m]:
                    loading_text = temp_m_form[m]['loading_text']

                required = ''
                if 'required' in temp_m_form[m] and temp_m_form[m][
                        'required'] == True:
                    required = 'required'

                # Creates a select if any options are filled by another func
                try:
                    options_from_function = []
                    if 'options_from_function' in temp_m_form[m]:
                        options_from_function = temp_m_form[m][
                            'options_from_function']
                        for optModuleName in options_from_function:
                            if optModuleName in ht.getModulesNames(
                            ) or optModuleName in [
                                    moduleNm.replace('ht_', '')
                                    for moduleNm in ht.getModulesNames()
                            ]:
                                functionCall = 'ht.getModule(\'{mod}\').{func}()'.format(
                                    mod=optModuleName,
                                    func=temp_m_form[m]
                                    ['options_from_function'][optModuleName])
                                options_from_function = eval(functionCall)
                            elif 'core' == optModuleName:
                                functionCall = 'ht.{func}()'.format(
                                    func=temp_m_form[m]
                                    ['options_from_function'][optModuleName])
                                options_from_function = eval(functionCall)
                            else:
                                functionCall = '{m}.{func}()'.format(
                                    m=optModuleName,
                                    func=temp_m_form[m]
                                    ['options_from_function'][optModuleName])
                                options_from_function = eval(functionCall)
                except Exception as e:
                    Logger.printMessage(str(e), is_error=True)
                    options_from_function = []

                if options_from_function:
                    input_type = 'select'

                if input_type == 'file':
                    html += "<div class='input-group'>"
                    html += "<input type='file' class='custom-file-input' name='{id}' {required}>".format(
                        id=m, required=required)
                    html += "<label class='custom-file-label' for='{id}'>Choose file</label>".format(
                        id=m)
                    html += "</div>"

                elif input_type == 'checkbox':
                    checkbox_disabled = ''
                    color_on = 'primary'
                    color_off = 'warning'

                    if '__pool_it_' in m and not ht.__WANT_TO_BE_IN_POOL__:
                        checkbox_disabled = 'disabled'
                        color_on = 'default'
                        color_off = 'default'

                    if checkbox_selected:
                        html += "<div class=\"checkbox\"><input type=\"checkbox\" class=\"checkbox\" data-toggle=\"toggle\" data-on=\"On\" data-off=\"Off\" data-onstyle=\"{color_on}\" data-offstyle=\"{color_off}\" id=\"{id}\" name=\"{id}\" {required} checked {disabled}><label style=\"padding: 0 10px;\" for=\"{id}\">{input_label_desc}</label></div><br />".format(
                            color_on=color_on,
                            color_off=color_off,
                            id=m,
                            input_label_desc=input_label_desc,
                            required=required,
                            disabled=checkbox_disabled)
                    else:
                        html += "<div class=\"checkbox\"><input type=\"checkbox\" class=\"checkbox\" data-toggle=\"toggle\" data-on=\"On\" data-off=\"Off\" data-onstyle=\"{color_on}\" data-offstyle=\"{color_off}\" id=\"{id}\" name=\"{id}\" {required} {disabled}><label style=\"padding: 0 10px;\" for=\"{id}\">{input_label_desc}</label></div><br />".format(
                            color_on=color_on,
                            color_off=color_off,
                            id=m,
                            input_label_desc=input_label_desc,
                            required=required,
                            disabled=checkbox_disabled)

                elif input_type == 'select':

                    html += "<span class=\"name-select\" value=\"{placeholder}\">{placeholder}</span><select id=\"editable-select-{id}\" name=\"{id}\" placeholder=\"{placeholder}\" class=\"{className}\" {required}>".format(
                        placeholder=input_placeholder,
                        className=input_className,
                        id=m,
                        required=required)
                    html += "<option value='{input_value}' selected>{input_value}</option>".format(
                        input_value=input_value)

                    if input_value in options_from_function:
                        options_from_function.remove(input_value)

                    for func in options_from_function:
                        html += "<option value='{cat}'>{cat}</option>".format(
                            cat=func)

                    html += "</select><script>$('#editable-select-{id}').editableSelect();".format(
                        id=m)

                    if required != '':
                        html += "$('#editable-select-{id}').prop('required',true);".format(
                            id=m)

                    html += "</script>"

                elif input_type == 'button':

                    footer += "<button type=\"button\" class=\"{className}\" data-dismiss=\"modal\">{input_value}</button>".format(
                        className=input_className, input_value=input_value)

                elif input_type == 'submit':

                    submit_id = '{m}_{f}'.format(m=m, f=config_extrasubkey)
                    footer += "<input type=\"submit\" class=\"{className}\" value=\"{input_value}\" id=\"{id}\" />".format(
                        className=input_className,
                        input_value=input_value,
                        id=submit_id)

                    if loading_text:
                        footer += "<script>$('#"
                        footer += m
                        footer += "').on('click', function(e){$('#"
                        footer += m
                        footer += "').attr('value', '{loading_text}'); e.preventDevault();".format(
                            loading_text=loading_text)
                        footer += "});</script>"

                elif input_type == 'textarea':

                    if input_label_desc:
                        html += "<div class=\"form-group row\"><label for=\"{id}\" class=\"col-4 col-form-label label-description\">{input_label_desc}</label><div class=\"col-4\"><textarea class=\"{className}\" name=\"{id}\" id=\"{id}\" rows=\"{rows}\" placeholder=\"{placeholder}\"></textarea></div></div>".format(
                            className=input_className,
                            id=m,
                            placeholder=input_placeholder,
                            input_label_desc=input_label_desc,
                            rows=str(
                                int(len(input_placeholder) / 100) +
                                input_placeholder.count('\n')))
                    else:
                        html += "<textarea class=\"{className}\" name=\"{id}\" id=\"{id}\" rows=\"{rows}\" placeholder=\"{placeholder}\"></textarea>".format(
                            className=input_className,
                            id=m,
                            placeholder=input_placeholder,
                            rows=str(
                                int(len(input_placeholder) / 100) +
                                input_placeholder.count('\n')))

                else:
                    html += "<div class='md-form'><label for=\"{id}\">{input_label_desc}</label><input class=\"{className}\" type=\"{input_type}\" value=\"{input_value}\" placeholder=\"{placeholder}\" name=\"{id}\" {required}/></div>".format(
                        id=m,
                        placeholder=input_placeholder,
                        input_label_desc=input_label_desc,
                        className=input_className,
                        input_type=input_type,
                        input_value=input_value,
                        required=required)

        if '__separator' in m and '__' == m[-2:] and m_form[m] == True:
            html += "<hr class='sidebar-divider my-0 my-separator'>"

    for m in m_form:
        if '__async__' == m and m_form[m]:
            html += "<input type='text' value='true' id='is_async' hidden />"

    footer += '</div>'
    html += footer
    html += '</div>'

    for m in m_form:
        if '__async__' == m and m_form[m] == True:
            async_script = "<script> $(function() { "
            async_script += "$('#{submit_id}').click(function(e)".format(
                submit_id=submit_id)
            async_script += "{ e.preventDefault();"
            async_script += "$.ajax({"
            async_script += "headers: { 'X-CSRFToken': '{"
            async_script += "{csrf_token"
            async_script += "}"
            async_script += "}' }, "
            async_script += "cache: false, contentType: false, processData: false, "
            if config_extrasubkey:
                async_script += "url : '/modules/{mod}/{functionName}/', type : 'POST', async: true, data: $('#form_{mod}_{functionName}').serializeArray(), ".format(
                    mod=mod, functionName=config_extrasubkey)
            else:
                async_script += "url : '/modules/{mod}/{mod}/', type : 'POST', async: true, data: $('#form_{mod}').serializeArray(), ".format(
                    mod=mod)
            async_script += "success : function(res) {"
            async_script += "if('data' in res){"
            async_script += "alert(res.data)"
            async_script += "} else { "
            async_script += "alert('Error')"
            async_script += "}"
            async_script += "}, error : function(xhr,errmsg,err) { console.log(xhr.status + ': ' + xhr.responseText); } }); }); }); </script>"
            html += async_script
    if config_subkey == 'django_form_main_function':
        return {functionModal: html}
    return html