python类Field()的实例源码

admin.py 文件源码 项目:authserver 作者: jdelic 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_form(self, req: HttpRequest, obj: Domain=None, **kwargs: Any) -> type:
        if req.GET.get("_prefill_key", "0") == "1":
            def formfield_callback(field: _ModelField, request: HttpRequest=None, **kwargs: Any) -> Type[_FormField]:
                f = self.formfield_for_dbfield(field, request=request, **kwargs)  # type: _FormField
                # f can be None if the dbfield does not get a FormField (like hidden fields
                # or auto increment IDs). Only the dbfield has a .name attribute.
                if f and field.name == "dkimkey":
                    if obj:
                        obj.dkimkey = RSA.generate(2048).exportKey("PEM").decode("utf-8")
                    else:
                        f.initial = RSA.generate(2048).exportKey("PEM").decode("utf-8")
                return f

            kwargs["formfield_callback"] = functools.partial(formfield_callback, request=req)

        form_t = super().get_form(req, obj, **kwargs)
        return form_t
widgets.py 文件源码 项目:callisto-core 作者: project-callisto 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def textinfo(cls, choice):
        attrs = {
            'placeholder': choice.get('extra_info_text'),
            'class': "extra-widget extra-widget-text",
            'style': "display: none;",
        }
        return Field(
            required=False,
            widget=TextInput(attrs=attrs),
        )
widgets.py 文件源码 项目:django-wizard-builder 作者: project-callisto 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def textinfo(cls, choice):
        attrs = {
            'placeholder': choice.get('extra_info_text'),
            'class': "extra-widget extra-widget-text",
            'style': "display: none;",
        }
        return Field(
            required=False,
            widget=TextInput(attrs=attrs),
        )


问题


面经


文章

微信
公众号

扫码关注公众号