当前位置: 首页>>代码示例>>Python>>正文


Python forms.Form方法代码示例

本文整理汇总了Python中django.forms.Form方法的典型用法代码示例。如果您正苦于以下问题:Python forms.Form方法的具体用法?Python forms.Form怎么用?Python forms.Form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms的用法示例。


在下文中一共展示了forms.Form方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_config_form

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def make_config_form(self, data: Dict[str, Any] = None, files: Dict = None) -> BaseConfigForm:
        """
        Returns a Django Form instance that can be used to edit this question's details.

        The Form's 'cleaned_data' should match this QuestionVersion.config object (unless overriding this method and
        ConfigForm.to_jsonable to deal with differences)
        """
        if self.version is None:
            initial = {}
        else:
            initial = self.version.config

        if self.version.question:
            initial['points'] = self.question.points

        form = self.ConfigForm(data=data, files=files, initial=initial)
        if self.question.id:
            form.fields['points'].help_text = 'Changing this will update all versions of this question.'
        return form 
开发者ID:sfu-fas,项目名称:coursys,代码行数:21,代码来源:base.py

示例2: get_entry_form

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def get_entry_form(cls, editor, units, handler=None, person=None, **kwargs):
        """
        Return a Django Form that can be used to create/edit a CareerEvent
        """
        initial = {
            'start_date': datetime.date.today(),
        }
        form = cls.EntryForm(editor=editor,
                             units=units,
                             initial=initial,
                             handler=handler,
                             person=person,
                             **kwargs)
        form.legend = cls.NAME
        form.use_required_attribute = False
        return form

    # event configuration 
开发者ID:sfu-fas,项目名称:coursys,代码行数:20,代码来源:base.py

示例3: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request', None)
        super(GeneralFSForm, self).__init__(*args, **kwargs)
        if hasattr(self.request, "project") and self.request.project is not None:
            xform = XForm.objects.filter(
                Q(user=self.request.user) | Q(fieldsightformlibrary__is_global=True) |
                Q(fieldsightformlibrary__project=self.request.project) |
                Q(fieldsightformlibrary__organization=self.request.organization))

        elif hasattr(self.request, "organization") and self.request.organization is not None:
            xform = XForm.objects.filter(
                Q(user=self.request.user) |
                Q(fieldsightformlibrary__is_global=True) |
                Q(fieldsightformlibrary__organization=self.request.organization))
        else:
            xform = XForm.objects.filter(
                Q(user=self.request.user) | Q(fieldsightformlibrary__is_global=True))
        self.fields['xf'].choices = [(obj.id, obj.title) for obj in xform]
        self.fields['xf'].empty_label = None
        self.fields['xf'].label = "Form" 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:22,代码来源:forms.py

示例4: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def __init__(self, course, *args, **kwargs):
        forms.Form.__init__(self, *args, **kwargs)

        self.groups = {}
        self.teachers = get_teacher_choises(course)
        groups_teacher = {}
        for default_teacher in DefaultTeacher.objects.filter(group__in=course.groups.all()):
            groups_teacher[default_teacher.group.id] = default_teacher.teacher.id

        for group in course.groups.all():
            group_key = "group_{0}".format(group.id)
            self.groups[group_key] = group
            self.fields[group_key] = forms.ChoiceField(
                initial=groups_teacher.get(group.id, 0),
                choices=self.teachers,
                label=group.name
            ) 
开发者ID:znick,项目名称:anytask,代码行数:19,代码来源:forms.py

示例5: set_choices

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def set_choices(self, family):
        # There's probably a better way of doing this
        board_choices = [(brd.id, brd.name) for brd in Board.objects.filter(family=family)]

        self.fields['board_type'].choices = board_choices


# class GuidedDeviceFlashForm(forms.Form):
#     DEVICE_FAMILY_CHOICES = GuidedDeviceSelectForm.DEVICE_FAMILY_CHOICES
#
#     device_family = forms.ChoiceField(label="Device Family",
#                                       widget=forms.Select(attrs={'class': 'form-control',
#                                                                  'data-toggle': 'select'}),
#                                       choices=DEVICE_FAMILY_CHOICES, required=True)
#     should_flash_device = forms.BooleanField(widget=forms.HiddenInput, required=False, initial=False)
#
# 
开发者ID:thorrak,项目名称:fermentrack,代码行数:19,代码来源:forms.py

示例6: _add_form_fields

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def _add_form_fields(obj, lines):
    """Improve the documentation of a Django Form class.

    This highlights the available fields in the form.
    """
    lines.append("**Form fields:**")
    lines.append("")
    for name, field in obj.base_fields.items():
        field_type = "{}.{}".format(
            field.__class__.__module__, field.__class__.__name__
        )
        tpl = "* ``{name}``: {label} (:class:`~{field_type}`)"
        lines.append(
            tpl.format(
                name=name,
                field=field,
                label=field.label or name.replace("_", " ").title(),
                field_type=field_type,
            )
        ) 
开发者ID:edoburu,项目名称:sphinxcontrib-django,代码行数:22,代码来源:docstrings.py

示例7: after_form_validation

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def after_form_validation(self, form: forms.Form, transaction: Transaction):
        """
        Use this function to process the data collected with `form` and to update
        the state of the interactive flow so that the next call to
        ``DepositIntegration.content_for_transaction`` returns a dictionary
        containing the next form to render to the user, or returns None.

        Keep in mind that if a ``TransactionForm`` is submitted, Polaris will
        update the `amount_in` and `amount_fee` with the information collected.
        There is no need to implement that yourself.

        DO NOT update `transaction.status` here or in any other function for
        that matter. This column is managed by Polaris and is expected to have
        particular values at different points in the flow.

        If you need to store some data to determine which form to return next when
        ``DepositIntegration.content_for_transaction`` is called, store this
        data in a model not used by Polaris.

        :param form: the completed ``forms.Form`` submitted by the user
        :param transaction: the ``Transaction`` database object
        """
        pass 
开发者ID:stellar,项目名称:django-polaris,代码行数:25,代码来源:transactions.py

示例8: test_get_bound_form

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def test_get_bound_form(self, book_god_of_the_labyrinth, abstract_required, ddc, embargo, license_chooser):
        self.protocol.paper = book_god_of_the_labyrinth
        data = {
            'paper_pk' : book_god_of_the_labyrinth.pk
        }
        if abstract_required:
            data['abstract'] = 'Simple abstract'
        if ddc:
            data['ddc'] = ddc
        if license_chooser:
            data['license'] = license_chooser.pk
        if embargo == 'required':
            data['embargo'] = '2019-10-10'

        form = self.protocol.get_bound_form()
        if not form.is_valid():
            print(form.errors)
            raise AssertionError("Form not valid") 
开发者ID:dissemin,项目名称:dissemin,代码行数:20,代码来源:test_protocol.py

示例9: test_form_mutation_without_context

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def test_form_mutation_without_context():
    class TestForm(Form):
        a = IntegerField()

        def save(self, *args, **kwargs):
            return "hello"

    class TestMutation(FormMutation):
        class Meta:
            form_class = TestForm

    @strawberry.input
    class TestInput:
        a: int

    assert TestMutation.Mutation(None, TestInput(a=1)) == "hello" 
开发者ID:pythonitalia,项目名称:pycon,代码行数:18,代码来源:test_mutations.py

示例10: test_form_mutation_response_can_be_converted_using_transform_method

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def test_form_mutation_response_can_be_converted_using_transform_method():
    class TestForm(Form):
        a = IntegerField()

        def save(self, *args, **kwargs):
            return "hello"

    class TestMutation(FormMutation):
        @classmethod
        def transform(cls, result):
            return "world"

        class Meta:
            form_class = TestForm

    @strawberry.input
    class TestInput:
        a: int

    assert TestMutation.Mutation(None, TestInput(a=1)) == "world" 
开发者ID:pythonitalia,项目名称:pycon,代码行数:22,代码来源:test_mutations.py

示例11: test_form_mutation_transform_is_not_required

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def test_form_mutation_transform_is_not_required():
    class TestForm(Form):
        a = IntegerField()

        def save(self, *args, **kwargs):
            return "hello"

    class TestMutation(FormMutation):
        class Meta:
            form_class = TestForm

    @strawberry.input
    class TestInput:
        a: int

    assert TestMutation.Mutation(None, TestInput(a=1)) == "hello" 
开发者ID:pythonitalia,项目名称:pycon,代码行数:18,代码来源:test_mutations.py

示例12: done

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def done(self, form_list: List[Form], **kwargs: Any) -> HttpResponse:
        """
        Login the user and redirect to the desired page.

        We need to override this function so that we can redirect to
        realm.uri instead of '/'.
        """
        realm_uri = self.get_user().realm.uri
        # This mock.patch business is an unpleasant hack that we'd
        # ideally like to remove by instead patching the upstream
        # module to support better configurability of the
        # LOGIN_REDIRECT_URL setting.  But until then, it works.  We
        # import mock.patch here because mock has an expensive import
        # process involving pbr -> pkgresources (which is really slow).
        from unittest.mock import patch
        with patch.object(settings, 'LOGIN_REDIRECT_URL', realm_uri):
            return super().done(form_list, **kwargs) 
开发者ID:zulip,项目名称:zulip,代码行数:19,代码来源:auth.py

示例13: get_forms

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def get_forms(self):
        """Instantiate forms, return a list of tuples like get_operations(), but with Form objects and expanded prefix values."""
        retval = []

        for prefix, title, form_class, buttons, callback in self.get_operations():
            retval.append(
                (
                    prefix,
                    title,
                    form_class(
                        prefix=prefix,
                        data=self.request.POST
                        if self.request.method == "POST"
                        else None,
                    ),
                    buttons,
                    callback,
                )
            )

        return retval 
开发者ID:byro,项目名称:byro,代码行数:23,代码来源:members.py

示例14: errors_message

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def errors_message(form):
        """Form Errors.

        :param form forms.Form
        form.errors.get_json_data() django 2.0 or higher

        :return
        example
        {
        "error": {
            "file": "This field is required.",
            "test": "This field is required."
            }
        }
        """
        data = form.errors.get_json_data()
        for k, v in data.items():
            data[k] = ' '.join([value_detail['message'] for value_detail in v])
        return data 
开发者ID:MobSF,项目名称:Mobile-Security-Framework-MobSF,代码行数:21,代码来源:forms.py

示例15: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Form [as 别名]
def __init__(self, *args, data=None, **kwargs):
        """
        Adapt the search form to handle filters:
        - Fix the QueryDict value getter to properly handle multi-value parameters,
        - Add a field instance to the form for each filter,
        - Define the `states` property as it is used by several methods.
        """
        # QueryDict/MultiValueDict breaks lists: we need to fix it
        data_fixed = (
            {
                k: data.getlist(k)
                # Form fields are marked to expect lists as input or not as explained above
                if (k in FILTER_FIELDS and FILTER_FIELDS[k][1] is True) else v[0]
                for k, v in data.lists()
            }
            if data
            else {}
        )

        super().__init__(data=data_fixed, *args, **kwargs)
        self.fields.update({k: v[0] for k, v in FILTER_FIELDS.items()})
        self.states = None 
开发者ID:openfun,项目名称:richie,代码行数:24,代码来源:forms.py


注:本文中的django.forms.Form方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。