#100DaysOfCode in Python Transcripts
Chapter: Days 85-87: Fullstack web apps made easy
Lecture: Add document finale
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
It's great the we created this document but the experience wasn't super, like it didn't tell us the thing was created,
0:06
we put a bunch of code right into our form, things like that. So let's clean this up a little bit and let's begin by going over here
0:14
and creating a new module. I'll call this... I'll just call this utilities. Now over here we right code, this runs on the client-side
0:25
and it's going to do... This basically lets us put these methods wherever we need. So one the things we're going to need to do,
0:31
this will take a moment before it's obvious why, but we need to, when we're over here When we want to go home, we need the home form,
0:38
which we don't have access to, to basically run this code again, okay? How do we do that? Well what we can do is we can come over here
0:48
and say, import utilities We can go the the utilities and say, home_form = self so that we can always get back to it from within code over here.
1:01
So we'll have a home_form as None but of course it will be set soon the application starts. And let's just add a method, "Go home". How do we do that?
1:14
We say, home_form. Now it doesn't know what this is. We want to call this function here. Like that. That's all we got to do, super easy right?
1:30
We just wanted to call this function go here from wherever. So we need this import utilities over in our add_doc_form as well.
1:42
And let's go over here and we can just say, .go_home We've already created the document but let's take some of this code and make a little simpler.
1:50
Let's go over here and say, utilities.create. And let's pass that in there, okay? So we basically need to call this function
2:05
over in this utilities.create_doc, but there's a reason I want to do this. You'll see in just a second that it makes sense
2:10
to try to put these together. So it's find this. Remove that one simple call over here. Like that. And it's going to accomplish the same thing,
2:23
but we also would like to have one more function. refresh_data Now what I want to store is I want to store
2:35
the docs as a list and the categories as a list. And when we call this, I'd like to write that code that we had over here again.
2:50
Remember I said I didn't like this? Let's take this code and get rid of it and put it over here as well. So here we're going to go to the server
3:02
and we'll also do this for the documents. If you had a ton of documents that's not a good idea, but since we only have a few we'll go like this.
3:14
Okay, so we're going to set the categories and the documents and that means over here we can just go... We've got our list, let's say utilities
3:28
not categories. Now how do we know this is refreshed? Let's call it once when the app starts up and that's all we're going to do.
3:41
Alright so that should refresh the data and then any of the sub-forms will have access to the utilities dot categories or documents.
3:51
And here we'll call create_document and then we'll call go_home. And within create_document, final thing, the reason it's nice to have this here
3:57
is we can call refresh_data again and make sure that whenever the data is modified, we automatically get it updated
4:04
but otherwise, it just stays like it is. Let's go and test this, that it's still working. Apparently spelling is hard.
4:20
Alright, what happens when I click this? It's going to go to the utilities client-side module, call the create_document.
4:27
On the server it's going to create and insert the document, it'll come back and then it'll call Refresh so if for some reason the categories,
4:33
definitely the documents will have changed, we'll get those new ones. And then it's going to go to the home form, call go_home,
4:38
it should reload this and it will all work. Let's try it. Boom! On the server we created this new document, now we're home. We can add more of course.
4:49
I think it's about time to do the other ones where we can actually see the documents right?