1 00:00:00,420 --> 00:00:05,240 Okay, so let's build this user_stream.html template, and 2 00:00:05,240 --> 00:00:07,790 then check this whole thing out, see how it works. 3 00:00:07,790 --> 00:00:14,234 So let's go back to templates, make a new file, user_stream.html. 4 00:00:15,820 --> 00:00:18,570 And, so this one's a little bit different. 5 00:00:18,570 --> 00:00:19,950 You may not have seen us do, 6 00:00:19,950 --> 00:00:22,110 actually you've not seen me do something like this yet. 7 00:00:23,180 --> 00:00:28,261 So it's going to extend stream.html, not layout. 8 00:00:28,261 --> 00:00:31,450 I mean, ultimately it extends layout because stream extends layout. 9 00:00:32,570 --> 00:00:33,800 But not on its own. 10 00:00:35,350 --> 00:00:36,660 And block content. 11 00:00:36,660 --> 00:00:38,210 So, I'm gonna add new things to the block. 12 00:00:39,650 --> 00:00:41,925 And we're gonna add in some statistics. 13 00:00:41,925 --> 00:00:50,113 [SOUND] And class equals grid-25. 14 00:00:50,113 --> 00:00:51,490 And. 15 00:00:53,730 --> 00:00:56,300 H one is user.username. 16 00:00:57,440 --> 00:01:04,861 And then we're gonna do div class equals grid-50. 17 00:01:04,861 --> 00:01:07,611 Div class equals grid-33. 18 00:01:10,690 --> 00:01:12,830 H5 and we're gonna say posts. 19 00:01:14,880 --> 00:01:20,495 So I'm gonna do a P and we'll say user.post.count cuz we wanna. 20 00:01:20,495 --> 00:01:24,415 Count out the number of posts that they have, and I actually wanna take this. 21 00:01:24,415 --> 00:01:26,015 I'm gonna make two more copies of it. 22 00:01:26,015 --> 00:01:31,985 And we're gonna change the second one here from posts to followers. 23 00:01:33,515 --> 00:01:34,795 We don't have followers yet. 24 00:01:34,795 --> 00:01:36,375 So we're can just take that out. 25 00:01:36,375 --> 00:01:37,345 And we'll just say zero. 26 00:01:37,345 --> 00:01:41,670 And then here, I wanna change this to following. 27 00:01:41,670 --> 00:01:43,800 And we don't have those yet either. 28 00:01:43,800 --> 00:01:47,370 So that's also going to be 0. 29 00:01:47,370 --> 00:01:49,800 All right, and then down here below, our div-50, 30 00:01:49,800 --> 00:01:53,900 we're gonna do another div class equals grid-25. 31 00:01:53,900 --> 00:01:59,430 And that's it for now cuz this is where our follow button's gonna go. 32 00:02:00,740 --> 00:02:02,850 We'll put in note, follow unfollow button. 33 00:02:02,850 --> 00:02:06,080 That's what's gonna go there. 34 00:02:06,080 --> 00:02:09,310 So now we've got all this stuff inside of our block. 35 00:02:09,310 --> 00:02:12,410 I wanna come down here and I wanna call super. 36 00:02:13,590 --> 00:02:15,090 And then, endblock. 37 00:02:15,090 --> 00:02:18,250 So you remember, if you did Flask Basics, when we call super, 38 00:02:18,250 --> 00:02:22,340 it brings in the content of the block from the parent template. 39 00:02:22,340 --> 00:02:25,110 So, stream.html is our parent template. 40 00:02:26,870 --> 00:02:31,330 Block content, the content here, is all this stuff from the stream. 41 00:02:31,330 --> 00:02:32,300 So, awesome. 42 00:02:32,300 --> 00:02:35,610 And you know what, if I look at this, we don't use the user anywhere. 43 00:02:35,610 --> 00:02:38,582 But I bet we're gonna use the user up here. 44 00:02:38,582 --> 00:02:41,210 Actually we are, we're using the user here. 45 00:02:41,210 --> 00:02:43,560 So, okay. 46 00:02:43,560 --> 00:02:44,530 Let's try this out. 47 00:02:44,530 --> 00:02:45,330 Let's make a new post. 48 00:02:46,810 --> 00:02:49,319 Recording my course. 49 00:02:49,319 --> 00:02:53,490 Can't believe we've done so much. 50 00:02:53,490 --> 00:02:55,820 I want a couple more Os in there. 51 00:02:56,820 --> 00:02:57,660 All right. Let's hit Post. 52 00:02:59,640 --> 00:03:00,530 Oh, no such table. 53 00:03:00,530 --> 00:03:01,510 Post. 54 00:03:01,510 --> 00:03:02,340 Why is that? 55 00:03:02,340 --> 00:03:04,937 Here in models.py, in our initialize. 56 00:03:04,937 --> 00:03:05,910 . 57 00:03:05,910 --> 00:03:08,620 We forgot to initialize post. 58 00:03:09,820 --> 00:03:11,280 So we need to do that. 59 00:03:11,280 --> 00:03:16,050 The second one is a little harder to find and it's over here in app.py. 60 00:03:16,050 --> 00:03:19,190 So we have this try and pass. 61 00:03:19,190 --> 00:03:24,260 And it's weird because I expected this to just go through, but 62 00:03:24,260 --> 00:03:29,380 it seemed like if it created one that didn't work, and it hit that value error, 63 00:03:29,380 --> 00:03:32,760 our database would be locked, and we couldn't do anything with our database. 64 00:03:32,760 --> 00:03:34,560 So, we need to add one thing here. 65 00:03:34,560 --> 00:03:42,050 So, we're gonna say with models.database.transaction. 66 00:03:42,050 --> 00:03:47,270 Then we're gonna take all of this, tab that in. 67 00:03:47,270 --> 00:03:48,140 So what does this do? 68 00:03:48,140 --> 00:03:54,630 Well, so a transaction says try this thing out, if it works, awesome. 69 00:03:54,630 --> 00:03:55,650 Keep going. 70 00:03:55,650 --> 00:03:59,430 If it doesn't work, remove what everything you just did. 71 00:03:59,430 --> 00:04:02,430 So, maybe our user gets like halfway created. 72 00:04:02,430 --> 00:04:05,350 We don't want that to happen, we want that to just come right back out. 73 00:04:05,350 --> 00:04:08,980 Now it'd probably make more sense now that I'm looking at this, for 74 00:04:08,980 --> 00:04:14,370 us to do it in our create thing. 75 00:04:14,370 --> 00:04:15,410 So let's do it there. 76 00:04:15,410 --> 00:04:16,610 Let's actually take this out. 77 00:04:18,500 --> 00:04:23,420 Oh, the joys of designing while you're coding. 78 00:04:23,420 --> 00:04:25,870 And let's do it here. 79 00:04:25,870 --> 00:04:32,141 So we'll say with DATABASE.transaction(). 80 00:04:32,141 --> 00:04:35,410 And if that fails, if it raises this integrity error, whatever, that's fine, 81 00:04:35,410 --> 00:04:39,750 we'll still return the value error, but try doing this. 82 00:04:39,750 --> 00:04:42,930 So now, let's check and see. 83 00:04:44,290 --> 00:04:45,240 I'm logged in. 84 00:04:46,440 --> 00:04:47,830 Sorry, that was a test thing I did. 85 00:04:47,830 --> 00:04:50,280 Let's hit Create New Post. 86 00:04:50,280 --> 00:04:51,810 And let's see if we can post. 87 00:04:51,810 --> 00:04:56,940 So let's do recording my second Flask course. 88 00:04:56,940 --> 00:05:00,460 Can't believe how much we've learned. 89 00:05:01,880 --> 00:05:03,320 Let's hit post. 90 00:05:03,320 --> 00:05:03,850 Sweet. 91 00:05:03,850 --> 00:05:05,600 Took us to the homepage. 92 00:05:05,600 --> 00:05:07,320 And here is this. 93 00:05:07,320 --> 00:05:09,280 So now if I was to click on my name. 94 00:05:10,580 --> 00:05:12,860 Then it goes to my stream page. 95 00:05:13,920 --> 00:05:15,750 I've made one post. 96 00:05:15,750 --> 00:05:16,560 There's my name. 97 00:05:16,560 --> 00:05:18,650 There's all that stuff. 98 00:05:18,650 --> 00:05:19,320 If we hit all. 99 00:05:20,380 --> 00:05:21,880 Goes to there. 100 00:05:21,880 --> 00:05:27,320 And I think we can actually go ahead and add in one more link to our layout. 101 00:05:28,450 --> 00:05:30,670 So let's go over here and look at our layout. 102 00:05:32,070 --> 00:05:38,590 And what we wanna do is we want to add a link to a page for our own stream. 103 00:05:39,740 --> 00:05:42,730 So let's go here, a href. 104 00:05:42,730 --> 00:05:45,290 And we do URL for and we wanna say stream. 105 00:05:45,290 --> 00:05:53,562 And we wanna say username equals current_user.username. 106 00:05:53,562 --> 00:05:54,720 And we'll say here, 107 00:05:54,720 --> 00:05:59,990 we'll say following because this is the stuff that you're following, right. 108 00:05:59,990 --> 00:06:03,220 Let's refresh this and we can go to Following. 109 00:06:03,220 --> 00:06:04,548 We can go to All. 110 00:06:04,548 --> 00:06:06,263 Okay. 111 00:06:06,263 --> 00:06:07,978 Cool. 112 00:06:07,978 --> 00:06:10,480 So same as me clicking my own name, but 113 00:06:10,480 --> 00:06:14,720 when there's other users, me clicking my own name won't do anything there. 114 00:06:16,620 --> 00:06:17,220 Great. 115 00:06:17,220 --> 00:06:18,430 Once we get the social things in, 116 00:06:18,430 --> 00:06:21,840 we'll add in the posts from the people that you follow to the stream page. 117 00:06:21,840 --> 00:06:24,810 In fact, I think we're ready to do the stream stuff now, and of course, 118 00:06:24,810 --> 00:06:26,720 by now I mean in the next stage.