Exemple #1
0
class DateTriples(mf.Form):
    year = mf.Int()
    month = mf.Int()
    day = mf.Int()

    def make_object(self, data):
        from datetime import date
        return date(data["year"], data["month"], data["day"])
Exemple #2
0
class DateTriple(mf.Form):
    year = mf.Int(doc="year of date", widget="int")
    month = mf.Int(doc="month of date", widget="int")
    day = mf.Int(doc="day of date", widget="int")

    def make_object(self, data):
        from datetime import date
        return date(data["year"], data["month"], data["day"])
Exemple #3
0
        class DateTriple(self._getTarget()):
            year = mf.Int()
            month = mf.Int()
            day = mf.Int()

            def make_object(self, data):
                try:
                    return date(**data)
                except:
                    return data
Exemple #4
0
class DateTriple(mf.Form):
    year = mf.Int()
    month = mf.Int()
    day = mf.Int()

    def make_object(self, data):
        try:
            return date(**data)
        except:
            return None

    @mf.Form.validator
    def datecheck(self, data):
        try:
            date(**data)
        except:
            raise ValidationError("invalid paramaters: {}".format(data))
Exemple #5
0
class StudentForm(mf.Form):
    name = mf.String(placeholder="foo")
    age = mf.Int(placeholder="0")
    color = mf.Select([
        (i, c) for i, c in enumerate(["red", "blue", "green", "yellow"])
    ])
    group = mf.Select([("group1", [("a", "a"), ("b", "b")]),
                       ("group2", [("x", "x"), ("y", "y")])],
                      optgroup=True)
Exemple #6
0
class PersonForm(mf.Form):
    name = mf.String()
    age = mf.Int()
Exemple #7
0
class DateTriple(mf.Form):
    year = mf.Int()
    month = mf.Int()
    day = mf.Int()
Exemple #8
0
 class HasNameForm(Class):
     name = mf.Int()
Exemple #9
0
class PersonForm(mf.Form):
    name = mf.String(__call__=input_tag, type="text")
    age = mf.Int(__call__=input_tag, type="number")
Exemple #10
0
# -*- coding:utf-8 -*-
import marshmallow_form as mf


class StudentForm(mf.Form):
    color = mf.Select([])
    name = mf.Str()

form = StudentForm()
form.color.metadata["pairs"] = [("red", "red"), ("blue", "blue")]
form.color["pairs"]  # => [('red', 'red'), ('blue', 'blue')]


form = StudentForm(initial={"grade": 3})
form.add_field("grade", mf.Int(label="学年"))
form.grade.value  # => 3
form.grade["label"]  # => "学年"

[f.name for f in form]  # => ['color', 'name', 'grade']


form = StudentForm()
form.remove_field("color")
[f.name for f in form]  # => ['name']
Exemple #11
0
        class PersonForm(Class):
            name = mf.String()
            age = mf.Int()

            def make_object(self, kwargs):
                return Person(**kwargs)
Exemple #12
0
 class Date(Class):
     year = mf.Int()
     month = mf.Int()
     day = mf.Int()
Exemple #13
0
 class Age(Class):
     age = mf.Int()
Exemple #14
0
 class Inherited(Base):
     name = mf.Int(doc="inherited")
     age = mf.Int()
Exemple #15
0
 class Inherited(Base):
     age = mf.Int()
Exemple #16
0
class PersonForm(mf.Form):
    name = mf.Str()
    age = mf.Int()

    def make_object(self, data):
        return Person(**data)