コード例 #1
0
def _crispy_helper(instance):
    """
    Create the crispy-forms FormHelper. The form will then be rendered
    using {% crispy form %} in the template.
    :param UserAS instance:
    """
    helper = FormHelper()
    helper.attrs['id'] = 'id_user_as_form'
    helper.layout = Layout(
        AppendedText('label', '<span class="fa fa-pencil"/>'),
        Field(
            'installation_type',
            template='scionlab/partials/installation_type_accordion.html',
        ),
    )

    # We need this to render the UserASForm along with the AttachmentConfForm
    helper.form_tag = False
    helper.disable_csrf = True

    # Inject some helpers into the context (crispy does the magic):
    helper.accordion_templates = ["scionlab/partials/installation_type_vm.html",
                                  "scionlab/partials/installation_type_pkg.html",
                                  "scionlab/partials/installation_type_src.html"]

    if instance and instance.pk:
        host = instance.hosts.get()
        helper.host_id = host.uid
        helper.host_secret = host.secret

    return helper
コード例 #2
0
    def _crispy_helper(self, instance):
        """
        Create the crispy-forms FormHelper. The form will then be rendered
        using {% crispy form %} in the template.
        """
        helper = FormHelper()
        helper.attrs['id'] = 'id_user_as_form'
        helper.layout = Layout(
            AppendedText('label',
                         text='<span class="fa fa-pencil"></span>',
                         title="Optional short label for your AS",
                         placeholder='"My Test AS X"'),
            'attachment_point',
            'use_vpn',
            AppendedText('public_ip',
                         '<span class="fa fa-external-link"></span>'),
            AppendedText('public_port',
                         '<span class="fa fa-share-square-o"></span>'),
            Row(Column(
                AppendedText(
                    'bind_ip',
                    '<span class="fa fa-external-link-square"></span>'),
                css_class='form-group col-md-6 mb-0',
            ),
                Column(
                    AppendedText('bind_port',
                                 '<span class="fa fa-share-square"></span>'),
                    css_class='form-group col-md-6 mb-0',
                ),
                css_id='row_id_bind_addr'),
            Field(
                'installation_type',
                template='scionlab/partials/installation_type_accordion.html',
            ),
        )

        # Inject some helpers into the context (crispy does the magic):
        helper.accordion_templates = [
            "scionlab/partials/installation_type_vm.html",
            "scionlab/partials/installation_type_pkg.html",
            "scionlab/partials/installation_type_src.html"
        ]

        if instance and instance.pk:
            host = instance.hosts.get()
            helper.host_id = host.uid
            helper.host_secret = host.secret

        return helper