Ejemplo n.º 1
0
class SetDefault(jrlib.Method):
    user_id = jf.Int()
    age = jf.Int(required=True)
    gender = jf.Str(default="g")
    user_profile = UserProfile()
    address = jf.Obj(
        fields=dict(
            city=jf.Str(required=True),
            street=jf.Str(default="ul"),
            house=jf.Str(default=get_house),
        ),
        default=get_address,
    )

    # TODO: support this way for get default value
    def default_user_id(self):
        print("UUUUU")
        return 100

    def execute(self):
        return {
            "user_id": self.user_id,
            "age": self.age,
            "gender": self.gender,
            "user_profile": {
                "first_name": self.user_profile.first_name,
                "last_name": self.user_profile.last_name,
                "middle_name": self.user_profile.middle_name,
            },
            "address": {
                "city": self.address.city,
                "street": self.address.street,
                "house": self.address.house,
            },
        }
Ejemplo n.º 2
0
class Blank(jrlib.Method):
    name = jf.Str()
    gender = jf.Str(required=True, blank=False)
    email = jf.Email(blank=False)
    data = jf.Dict(blank=False)
    cities = jf.List(blank=False)
    profile_1 = jf.Obj(fields=dict(f1=jf.Str()), blank=False)
    profile_2 = Pr_2(blank=False)

    def execute(self):
        return {
            "name": self.name,
            "gender": self.gender,
            "email": self.email,
        }
Ejemplo n.º 3
0
class AuthCheck(jrlib.Method):
    auth = jf.Obj(
        fields=dict(
            username=jf.Str(required=True, nullable=False),
            password=jf.Str(required=True, nullable=False),
        ),
        required=True,
        nullable=False,
        order=-100,
    )

    @jrlib.order(-100)
    def __middle(self):
        user = USERS.get(self.auth.username)
        if not user or (user and user.get("password") != self.auth.password):
            raise ValueError("Access denied")
        self.method_cache["auth_user"] = user
Ejemplo n.º 4
0
class Order(
        BigOrderMiddle,
        MinusBigOrderMiddle,
        FirstOrderMiddle,
        Auth,
        CarMiddle1,
        Last1Middle,
        CarMiddle2,
        PassengerMiddle,
        Middle1WoutOrder,
        Last2Middle,
        Middle2WoutOrder,
        First1Middle,
        First2Middle,
):
    msg = jf.Str(required=True)
    city = jf.Str(required=True, order=50)
    car = CarField(order=40)
    passenger = jf.Obj(fields=dict(name=jf.Str(order=400),
                                   age=jf.Int(order=300)),
                       order=20)
    about = jf.Str()

    def execute(self):
        return self.msg

    def validate_msg(self, value):
        print("ext validator (msg) -")

    def validate_about(self, value):
        print("ext validator (about) -")

    def validate_city(self, value):
        print("ext validator (city) 5")

    def validate_car(self, value):
        print("ext validator (car) 4")

    def validate_passenger(self, value):
        print("ext validator (passenger) 2")
Ejemplo n.º 5
0
class SetObjFieldInline(jrlib.Method):
    user_id = jf.Int(required=True)
    user_profile = UserProfile()
    address = jf.Obj(
        fields=dict(city=jf.Str(required=True), street=jf.Str()),
        required=False,
    )

    def execute(self):
        print("sss")
        print(self.user_profile.first_name)
        print(self.user_profile.last_name)
        print("eee")
        return {
            "user_id": self.user_id,
            "user_profile": {
                "first_name": self.user_profile.first_name,
                "last_name": self.user_profile.last_name,
                "city": self.address.city,
                "street": self.address.street,
            },
        }