Adding a CMS to Your Pyramid Web App Transcripts
Chapter: Advanced Markdown templates
Lecture: Marking pages as shared (editor level)

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now that our database supports this concept of a shared page and a standalone page, let's make that possible or visible in our editor.
0:09 So all we really need to do is and one more field here, a check box that says Is it shared or not?
0:16 And then just push that back into the view model and then have the view model pass it over to the CMS service when it creates or updates the page.
0:22 So here we are in that page we're looking at right there. And before this text area, we're gonna start by putting a label on a check box.
0:30 So we'll say input. I be cools. Check box name equals is shared. That's good animal. Do a label and it's gonna be four is shared like that.
0:45 I'll just say something like shared content, nonpublic. Something like that.
0:50 I say we're going to start by doing this because there is one minor change we need to make was going look and see how this looks. Well, that's weird.
0:56 Like, why is that way over there? And if we look at it, why is it so super huge?
1:01 See how it takes up the whole thing, and then so does, uh this is not quite because apparently it's display styles in line block instead of in line instead of block.
1:10 But this one is really huge, and that's little bit weird. The problem that we're gonna run into is if you look over at the CSS.
1:17 It says something like All the stuff in here is 100% across within the admin block. If there's a text eerie or input, it's 100% across.
1:26 Now let's be a little more careful here. Let's go here and say within the form that immediately contains this.
1:33 So what that means is here's a form and the very next item is either an input or text Eri and then this one We can just put it into a container to say, You know what?
1:42 These need to be on one line like so let's give that a run. Ah, yeah, there we go.
1:47 So we've got these nice and wide, all 100% across, but this thing right here is not causing this trouble.
1:54 All right, well, this is good, but it's not being set Now. It turns out setting this check box in the community in trouble.
2:02 It's a little bit annoying, actually. Really, really. Love the chameleon templates is Petey Files. I think they're super super nice. They're so clean.
2:11 And what I really like about them compared to Ginger or Jingo is what you put in here is still valid.
2:17 HTML, for example, this one will see this one here. This conditionally shows or hides the error message depending on whether there is an air. Right.
2:28 Well, this is still validation, Mellick.
2:30 This doesn't make sense, but it still pars is as HTML as opposed to ginger, which has, you know, the percent percent full.
2:40 Uh, if error close it off, you got to put an end if at the end I really don't like that style.
2:47 But this one part right here, it would be better if there's a better way to do this.
2:51 And I think it's also a limitation of the check boxes because what I want to do is I want to set the value you gotta do.
2:57 You have to say check and it doesn't matter what you said it Teoh if it if this thing is here than its checked, So there's not really a great way to say, make this attributes appear or disappear Community that I've figured out maybe all got it.
3:13 But so what we're gonna do is where it's going to say that someone say we have a checked one on like this, and then we're gonna be tal Cold condition is shared and they were gonna have one that's not checked.
3:27 And that one's only gonna be visible if it's not shared. So it's sort of annoying to have this duplication.
3:33 Only one will ever appear at a time because here's the condition and the not condition.
3:38 But nonetheless, we do have Teoh address that now if we try to run it right away, it's not gonna work Super.
3:44 Well, the reason is, if we go and refresh this, it crash. And again we turned off our deductible are so gonna look down here for the air.
3:52 But the air is we're missing. This is shared here, So let's go over and work our way back up.
4:00 It appears that we go over here to this edge it at a page view model, and then we have self dot is shared, equals, start false.
4:08 And then if there's a page, will say self that is shared equals. Ah, self top page is shared. Remember that we already put in the database.
4:17 We just need to carry it along. And then, of course, we need to do the reverse over here. We need to say self that is shared, equals careful.
4:26 Gets little weird. They get It's shared. Is that what we want? What values does it have? Is it true or false? Like it probably really should be? No.
4:38 Is it checked or not checked like you set over here? Check versus Not checked?
4:44 No, the the way this gets submitted to the form is it gets submitted back as either on or off. So we're gonna say it's shared.
4:56 If the value get back, is the string on? OK, so it's a little not obvious going to just play around to figure that out. But let's give this a try.
5:03 We probably can actually go and check these things over. We refresh this, we can now edit it. Ah, let's see that one says it shared.
5:12 Is that what we want? Let's go back here. I did this one. Okay. This one is not shared. Yeah, This one's also not shared. Okay, cool.
5:24 And if we check it off, we can save it back. But it's not getting pushed over to the database.
5:30 So that's the next thing to Dio is over in our admin controller Over here wouldn't more calling Update Page. We need to have V. M.
5:40 Bhatt is shared, and similarly, one more creating the page. We want to specify if it's shared, so let's go on.
5:46 Add those two things and this should be the final step. But here's the Create Page one and the update page as well.
6:01 It's good and put these type hints on here. There we go.
6:12 And I guess we could go ahead and return the page just in case somebody wants the page that got updated back. All right, I think that I'll do it.
6:20 Let's try. If we got everything right, we should now be able to edit whether or not our pages were shared. Okay, let's go back to the admin section.
6:30 Viewer pages. Let's mark this one as shared and hit. Save if we look at it again. Yes, it's shared. If we go back here and look at this one not shared.
6:43 If we update it good. Look at it again. Yep. Still not shared. Okay, it looks like that's working.
6:48 We didn't do the create one, but that one will work as well, I'm sure.
6:53 Now the other final thing like you can't tell looking this page summer shared and some are not shared. So we want toe. Also, distinguish that.
7:00 Remember, what are the primary important things about whether or not we were looking or these shared elements is we want to not pollute our structure.
7:09 It says here the pages that make up your site. We don't one of these little reusable bits in there because they don't really make up our site. Exactly.
7:16 We want this kind of partitioned into two lists.

Talk Python's Mastodon Michael Kennedy's Mastodon