Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Client and server-side validation
Lecture: Viewmodel validation

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Saw the one job of these view models and that's to do the data exchange. The other is validation. So, let's look at that now.
0:09 Here we have our gathering of data, right. We're creating this view model based on a request and it's populating even normalizing some of our data
0:18 like first name, last name, and email. Great but on the POST side of things where we're taking this data in and we're doing a operation based on
0:27 assuming that we have good data like that they actually set the name they set the email and so on. We want to do validation.
0:34 So that's where this error thing comes in. So we're going to do this validate and we're going to say check the first name or last name
0:42 and if either of them are empty we'll say you must specify your full name. If there's no email you must specify an email address.
0:49 If you don't specify a password similarly you get a message that says that. So, we set these errors and then the action method or the view method
0:59 its job will be to make sure that there's no errors before it actually does its operation. We can even do things that interact with the database.
1:09 So, here this is a registration operation. We did basic validation on the form values. First name, last name exist and are not empty.
1:17 Email is set, we could do regular expression to say this is a valid email or something simpler like check for @ and. A few things like that.
1:26 But here we're actually going alright once you pass all the basic validation let's go to the database and see if there is a user with the email address
1:34 that you're trying to register as because if there is we're not going to let you do that. The user already exists, right.
1:41 So, we have these sort of basic validation and higher level validation we can do.


Talk Python's Mastodon Michael Kennedy's Mastodon