Adding a CMS to Your Flask Web App Transcripts
Chapter: The redirects (our bit.ly)
Lecture: Editing a redirect

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Well, we got the ad work. Let's see how and it works. So we got this year. Let's try to edit this one.
0:07 I'm not as amazing as I was hoping for a four cause we obviously don't have
0:12 anything for that. Your girl And what we're gonna do is it's gonna be nearly
0:16 identical to this, and it redirects Let's go over here and change all of the ads. Edits What's the euro gonna be?
0:28 Not just it it redirect, but remember, it has the redirect I d over here and we'll go ahead and explicitly say This
0:37 has to be an integer and let's copy. That's over. Well, it add that No, it won't out. It would be cool. Major act I d and cool.
1:01 All right, Great. So let's pass this over. Remember, this has to get to our view model. Go here and check this out.
1:08 So let's do it like this Private bus. Twice we go and say there is this reader act i d,
1:12 which is an integer which starts out as none say it starts out at zero, and I guess we don't really need to get it this way,
1:22 do we? Because not really coming from that dictionary. We're just passing it, so ah, mistake that I put it that way,
1:29 but we still want to hold it So we'll say self dot Redirect I d Well is the redirect, Eddie?
1:35 Perfect. So now we've got this being passed over because it has a default value When we don't pass one up here,
1:44 it's gonna be OK. But when we do down here, it's going to take it super. All right, So I think this should be working.
1:53 And what else do we need to dio we need? I guess we could say really quickly here. If not v m dot or redirect right?
2:06 You try to edit something doesn't exist. It's good and say you're never gonna be able to edit that, so we'll put it there. Nice.
2:13 And for this one gonna validate it instead of create. We want to do an update. And over here, we're gonna need to pass the vm dot i d redirect idea
2:26 as well. That looks actually like all we really need. We just gotta create this function, which is gonna be not terribly different,
2:36 this one. Lets see. So this is gonna be kind of the opposite. So we'll have redirect equals get redirect by I d like so then there's this little
2:51 weird educates we're gonna have to deal with, Like, you might think we could just do this and we can We can come over and say, All right,
2:56 we're gonna change the redirects short URL to be the short euro fine and the euro and the name that's actually gonna change it in the database.
3:11 But the one thing that's a big problem is if we changed the short, you're all remember, it's still stored in this larger dictionary,
3:19 this thing as the short girl. So we got to do something a little bit funky like this to say, Remove whatever it It's current. Short.
3:32 You're Ellis. So I want to take it out of the database, change it, and then we're gonna put it back.
3:39 Looks like a little bit extra work that seems unnecessary. But if you change the short euro,
3:43 you would end up with a copy of the same data the new 100 old short euro and the current one under its new short euro.
3:53 Right, So I know that I ran through this once and it was weird. Okay, so this should update the existing one.
3:59 I guess we kind of want the opposite of this is Well, we want to have a check to make sure this makes some sense. Well, if not redirect, uh,
4:09 cannot update didn't exist. Let's go and try to edit some stuff. This is where it should all be coming together. First of all, yes, close.
4:23 So close. Well, if those were filled out, that would have been amazing. But it's not. And there's one more thing we're missing here,
4:34 so we're gonna go and get this back. But we want to say, basically, if there is a redirect, we need to pre populate it with the data because
4:42 in the initial load, this is all gonna be empty. But what we need to do is say, Look, if there's a redirect, were editing Self dot Name is self,
4:50 not reader acted. I get name and so on. All right. Not much of a change, but that should get our form looting right off the bat,
4:59 just like that. Perfect. So let's go back and start over. So add a redirect this talk Python one. Now it's here Let's see if we can edit it.
5:10 Fingers crossed. Oh, yeah. Look at that. It is. Call it. Talk Python to me and let's make it talk,
5:19 Python. Something like that. And I guess we can just edit this just to make sure that is taking all these into account. All right, so talk Python.
5:33 No, it didn't do that, did it? What has gone on here? We missed something. Ah, I know what we missed. What we did here is ah,
5:45 we accidentally threw away the data that we've loaded from the form. So we're going to change the order here?
5:53 Sure. So let's make this a separate function. Death. We still need to have these in here just for Pythons.
6:03 Sick as nothing. Otherwise it might not work, as we're expecting. You know, we might expect that variability there.
6:14 That's a good commission. But that means over here in these two form places where we have to say process form in the two posts.
6:28 All right, one more time through this adventure, let's see if we can do it. Over here go the read rex at a new redirect dot Python talk.
6:40 All right, it's there. It works. now edit it. Okay, It's loaded to me. Talk to and Mr Mark. Source equals seven. My seven eagles seven. Whatever.
6:54 Yes. Look at that. Now we're able to edit it. It's like that back tested the sources up there, just like you would hope. All right,
7:04 let's put it back cause that's wrong. It's this and the source thing is not here. But it's so cold. Talk with onto me.
7:15 Perfect. Looks like we got our edit as well as our create working.


Talk Python's Mastodon Michael Kennedy's Mastodon