Adding a CMS to Your Pyramid Web App Transcripts
Chapter: Saving content to a database
Lecture: Using the new redirect class in our app

Login or purchase this course to watch this video and the rest of the course contents.
0:00 now that we've updated the CMS service to use our redirect class from sequel alchemy rather than just dictionaries from our fake data source, this is gonna take a little tiny bit of cleanup.
0:10 So let's go try to run it, and it'll just tell us where it doesn't work. So Goater admin section click on Reader X in How we didn't get any back.
0:19 Wow, how interesting. Let's actually look over there and see what's going on because I guess we gotta let's just try to add one.
0:26 I will add a new redirect. The name of the redirect is, Let's say the short your l is just gonna be talk, and it's gonna just take us to talk.
0:38 Walk, crash. Well, looks like we're not setting of the right information that's creating user. Okay. Great.
0:45 Well ah, it was not exactly the part Expected a break, but is really good that it did, because that means we're not setting all the data we thought we needed to over here.
0:56 Now we want to In addition to adding that information, we need to add user name, which is a string so we can find out where we're calling that by just saying find usages, which is right there.
1:09 You remember this is making sure that we have the permissions to call it, which means we must be logged in, right?
1:18 Our view model already has a user, and then we can Let's pass, maybe have the email like that. Either name or email you get to pick.
1:27 You were gonna create it. Now with this extra information mean that looked like that was gonna work.
1:31 Let's give it a try over here and resubmit the same data. Oh, you know, it's great to pass it in. You still have to set it. Onda.
1:44 We call that email didn't way or we passed email. Okay, great. Try one more time. Luckily, the brothers holding on, let us submit it again. Who?
1:56 Look at that slash talk first. Redirect. We edit it. No, this is ah where we're going with this sort of thing.
2:05 So we're coming over here, and this is all the places that we're doing dot Get So let's go over here to this redirect, and it knows I'm pretty sure.
2:13 Yeah, it knows it's a redirect object, which is great because we told this one. It returned an optional redirect.
2:20 But now we can just go there and say short. You're actually this is nicer. It just requires a change. So here there's just not euro and dot name.
2:30 And then, yeah, I think that might actually be it.
2:34 This getting is not from the data visit from the submitted form, which still has to be a dictionary like this. All right, I think we might be ready.
2:44 Let's go and try to edit it. Yeah, the Rio first redirect are quite felon and talk, and then this.
2:50 We haven't yet written the part where we're actually going and updating this. We're gonna do that. But let's go and see if we can do our listening.
2:58 Now you are listening. It's not pages. Our redirects actually works. Great. Okay, So super super.
3:05 Let's go and write that last little part here about updating the redirect. Now we have this cool trick.
3:10 We got the redirect using a function we already wrote, and then we just made changes to it because it was in memory.
3:17 Now, remember, we're closing the session and we don't really have access to the session when we call it this way anyway.
3:23 so we kind of got a do it from scratch. Let's go over here and just take this.
3:29 So number here will say session dot clothes do it like this will be a little bit nicer. Try finally session dot Close.
3:48 There we go. Maybe we should do that. Up here is well for some of them, but whatever, we'll leave it now Over here, we want to set the values.
3:57 So we get our session back when I say redirect. What are we passing in? Name equals name dot Strip Put your l lower. That's trip and what's left.
4:15 You are all no. In the lower cases, Maybe this one matters. Then we just say session dot Commit like that. You were okay. I think we're ready.
4:24 So we're gonna come in here. I'm gonna get the redirect my i d. If it works great, we're gonna keep changing.
4:30 Otherwise, we just bail out and close the session. Now we're going to make the changes, push them back to the database. All right.
4:37 I think we might be ready. Try to edit one of these.
4:41 Let's edit add a new when it edit it, But say this is gonna be Python bites and this will be a fight, all right of him? Great.
4:54 Maybe we said, Oh, you know, that was supposed to be bites. So let's go over here and change it to bites plural.
5:00 And it's exclamation mark just to show some stuff. It's changing home now. Final thing to do with our reader, Rex is to see if we go to slash bites.
5:09 It goes somewhere already. Test it. No, this is one last thing. So let's see where this went wrong. It's again.
5:18 We're just thinking of the redirect as a dictionary, which it no longer is.
5:22 So this is your el I think that might be it wasn't a lot to it, but let's go now try bites again.
5:31 it looks like our redirect stuff in the database is working. Great. Go to admin. Get of you. Redirect.
5:38 We saw that we can edit it, and when we test, it goes, and I guess, Final thing. Let's just go look at the data base. Make sure it's in here.
5:50 Super cool. Check that out. So we've got our i d one r i D to created date is basically now used to creating user Michael at talk by Thunder FM.
5:59 Short your l. Here's the name. Yeah, this is great. We're now storing this in the database, which is, of course, the way we want to do it.
6:07 Just wanted to focus on building the redirect infrastructure and admin section and all the ideas before we got to this.
6:13 Well, it's great that we're here.


Talk Python's Mastodon Michael Kennedy's Mastodon