Adding a CMS to Your Pyramid Web App Transcripts
Chapter: Course conclusion
Lecture: Review: ViewModels

Login or purchase this course to watch this video and the rest of the course contents.
0:00 in our Web app, and especially in the admin section where we're editing redirects and editing pages. We use this view model pattern now.
0:08 This came to us from the website. It was already using this pattern, but we kept working with it, and I highly recommend you adopt this.
0:16 So that idea is we have a request. Come in here, I said. It's a post to register. That means they're submitting the register form.
0:23 And it's really in these forms scenarios where view model their most powerful but not the only place use him what a lot of people do A lot of coded bought examples tutorials on the Internet and other sites I've seen is they just have these huge, massive, you methods where there's all the code that's going to process this request.
0:41 That is not the way we want to write our programs. It's gonna be hard to maintain.
0:45 Gonna be hard to know where to look, to find what we're working on, right? If you have bugs Mike, it go duplication, and none of those things are fun.
0:55 So what we decided to do instead is use this view model pattern, which takes a lot of what makes the view method, big data exchange, data conversion and data validation.
1:06 We move that to its own thing, its own class called a view model. So instead we have, ah, small little method.
1:13 And it works with this other class, this other bit of code called the View model to get some data into it, validate it and then get the converted data back.
1:21 That means it's much easier to do unit tasked against these view models. It's much cleaner.
1:26 It's obvious what the entirety of the data being exchanged with the page, all of those things.
1:31 So you model pattern definitely recommended for your Web APS, and we made good use of it here.


Talk Python's Mastodon Michael Kennedy's Mastodon