crispy_forms_tags.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:mes 作者: osess 项目源码 文件源码
def get_response_dict(self, helper, context, is_formset):
        """
        Returns a dictionary with all the parameters necessary to render the form/formset in a template.

        :param attrs: Dictionary with the helper's attributes used for rendering the form/formset
        :param context: `django.template.Context` for the node
        :param is_formset: Boolean value. If set to True, indicates we are working with a formset.
        """
        if not isinstance(helper, FormHelper):
            raise TypeError('helper object provided to {% crispy %} tag must be a crispy.helper.FormHelper object.')

        attrs = helper.get_attributes(template_pack=self.template_pack)
        form_type = "form"
        if is_formset:
            form_type = "formset"

        # We take form/formset parameters from attrs if they are set, otherwise we use defaults
        response_dict = {
            'template_pack': settings.CRISPY_TEMPLATE_PACK,
            '%s_action' % form_type: attrs['attrs'].get("action", ''),
            '%s_method' % form_type: attrs.get("form_method", 'post'),
            '%s_tag' % form_type: attrs.get("form_tag", True),
            '%s_class' % form_type: attrs['attrs'].get("class", ''),
            '%s_id' % form_type: attrs['attrs'].get("id", ""),
            '%s_style' % form_type: attrs.get("form_style", None),
            'form_error_title': attrs.get("form_error_title", None),
            'formset_error_title': attrs.get("formset_error_title", None),
            'form_show_errors': attrs.get("form_show_errors", True),
            'help_text_inline': attrs.get("help_text_inline", False),
            'html5_required': attrs.get("html5_required", False),
            'form_show_labels': attrs.get("form_show_labels", True),
            'disable_csrf': attrs.get("disable_csrf", False),
            'inputs': attrs.get('inputs', []),
            'is_formset': is_formset,
            '%s_attrs' % form_type: attrs.get('attrs', ''),
            'flat_attrs': attrs.get('flat_attrs', ''),
            'error_text_inline': attrs.get('error_text_inline', True),
            'label_class': attrs.get('label_class', ''),
            'label_size': attrs.get('label_size', 0),
            'field_class': attrs.get('field_class', ''),
        }

        # Handles custom attributes added to helpers
        for attribute_name, value in attrs.items():
            if attribute_name not in response_dict:
                response_dict[attribute_name] = value

        if 'csrf_token' in context:
            response_dict['csrf_token'] = context['csrf_token']

        return response_dict
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号