Pylons: Model Level Data Validation

I appreciate some of the web application frameworks there, and finally, two of the biggest bidders (in my opinion) are Ruby on Rails and Pylons. To better understand these two structures without spending too much time, I decided to follow a non-trivial tutorial on using in one environment and try to repeat the same with another. I hope this exercise highlights the obvious differences.

In my experiment, I chose the Ruby on Rails Tutorial . I finished the application in Rails, and now I started to do it in Pylons. I went to chapter 6 without much drama (given that these are mostly static pages up to this point, this is not surprising). Now I need to implement a model for users and add validation logic to the model. The first part is simple, but I'm stuck on the second part.

From what I see, Pylons takes an approach to performing form level validation. Through some research, I have seen many people suggest that the point at which you accept form input is the right place to validate input. I also did a lot of pylon projects on github, and I could not find a single project that handled data validation at the model level. The closest I saw is where the developers stored their forms along with the data at the model level, but this is fraud, in my opinion. I would not mind not following the writing guide and following the crowd, but I agree with this tutorial. For the model under consideration, checks are performed in the right place: by checking the length of the password, the length of the username and checking that the email is actually email, everyone considersthat these are model level limitations. In addition, if I have at least two forms that will add data to this model (creating a new user and changing information), and repeating the same check in two different forms does not sound like that.

( TL;DR): , , , SQLAlchemy/formencode? , , , . , , , , . , , , , .

+3
2

, -, . , / , ( ) .. , , .

, , , , formencode SqlAlchemy (SA), SA () . , , . , :

person = Session.Query(People).get(10)
person.fname = request.params['fname']
person.lname = request.params['lname']

- :

person = Session.Query(People).get(10)
person.populate(request.params)

, , .

, , , , .

+2

SQLAlchemy , + mapper. ?

, , , , , .

+1

Source: https://habr.com/ru/post/1772947/


All Articles