<commit_before># -*- coding: utf8 -*-
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import json
import logging

import django.forms
from django.utils.datastructures import SortedDict
from django.utils.translation import ugettext_lazy as _
import horizon.exceptions
import horizon.forms
import horizon.messages

from tuskar_ui import api
import tuskar_ui.forms
from tuskar_ui.utils import utils


LOG = logging.getLogger(__name__)


VIRT_TYPE_CHOICES = [
    ('kvm', _("Baremetal (kvm)")),
    ('qemu', _("Virtualized (qemu)")),
]

NEUTRON_PUBLIC_INTERFACE_CHOICES = [
    ('em2', _("Baremetal (em2)")),
    ('eth0', _("Virtualized (eth0)")),
]

CINDER_ISCSI_HELPER_CHOICES = [
    ('tgtadm', _('tgtadm')),
    ('lioadm', _('lioadm')),
]


def parameter_fields(request, prefix=None, read_only=False):
    fields = SortedDict()
    plan = api.tuskar.Plan.get_the_plan(request)
    parameters = plan.parameter_list(include_key_parameters=False)

    for p in parameters:
        if prefix and not p.name.startswith(prefix):
            continue
        if read_only:
            if p.hidden:
                widget = tuskar_ui.forms.StaticTextPasswordWidget
            else:
                widget = tuskar_ui.forms.StaticTextWidget
        else:
            if p.hidden:
                widget = django.forms.PasswordInput(render_value=True)
            elif 'Certificate' in p.name:
                widget = django.forms.Textarea
            else:
                widget = None
        fields[p.name] = django.forms.CharField(
            required=False,
            widget=widget,
            label=tuskar_ui.forms.label_with_tooltip(
                utils.de_camel_case(p.stripped_name),
                p.description,
            ),
            initial=p.value,
        )
    return fields


class ServiceConfig(horizon.forms.SelfHandlingForm):
    def __init__(self, *args, **kwargs):
        super(ServiceConfig, self).__init__(*args, **kwargs)
        self.fields.update(parameter_fields(self.request, read_only=True))

    def global_fieldset(self):
        return tuskar_ui.forms.fieldset(self, prefix='^(?!.*::)')<commit_msg>Use label for service config param if present<commit_after># -*- coding: utf8 -*-
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import json
import logging

import django.forms
from django.utils.datastructures import SortedDict
from django.utils.translation import ugettext_lazy as _
import horizon.exceptions
import horizon.forms
import horizon.messages

from tuskar_ui import api
import tuskar_ui.forms
from tuskar_ui.utils import utils


LOG = logging.getLogger(__name__)


VIRT_TYPE_CHOICES = [
    ('kvm', _("Baremetal (kvm)")),
    ('qemu', _("Virtualized (qemu)")),
]

NEUTRON_PUBLIC_INTERFACE_CHOICES = [
    ('em2', _("Baremetal (em2)")),
    ('eth0', _("Virtualized (eth0)")),
]

CINDER_ISCSI_HELPER_CHOICES = [
    ('tgtadm', _('tgtadm')),
    ('lioadm', _('lioadm')),
]


def parameter_fields(request, prefix=None, read_only=False):
    fields = SortedDict()
    plan = api.tuskar.Plan.get_the_plan(request)
    parameters = plan.parameter_list(include_key_parameters=False)

    for p in parameters:
        if prefix and not p.name.startswith(prefix):
            continue
        if read_only:
            if p.hidden:
                widget = tuskar_ui.forms.StaticTextPasswordWidget
            else:
                widget = tuskar_ui.forms.StaticTextWidget
        else:
            if p.hidden:
                widget = django.forms.PasswordInput(render_value=True)
            elif 'Certificate' in p.name:
                widget = django.forms.Textarea
            else:
                widget = None
        fields[p.name] = django.forms.CharField(
            required=False,
            widget=widget,
            label=tuskar_ui.forms.label_with_tooltip(
                p.label or utils.de_camel_case(p.stripped_name),
                p.description,
            ),
            initial=p.value,
        )
    return fields


class ServiceConfig(horizon.forms.SelfHandlingForm):
    def __init__(self, *args, **kwargs):
        super(ServiceConfig, self).__init__(*args, **kwargs)
        self.fields.update(parameter_fields(self.request, read_only=True))

    def global_fieldset(self):
        return tuskar_ui.forms.fieldset(self, prefix='^(?!.*::)')
{'fraction_non_alphanumeric': 0.10188116967777985, 'fraction_numerical': 0.0033525796237660645, 'mean_word_length': 2.773717498243148, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6806107', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1588, 'n_words': 412}