1
1

00:00:00,390  -->  00:00:01,590
<v Jose>In this video we're going to</v>
2

2

00:00:01,590  -->  00:00:03,510
look at the app structure.
3

3

00:00:03,510  -->  00:00:06,460
What the app is going to do in this section
4

4

00:00:06,460  -->  00:00:09,780
is it's going to tell our users when an item
5

5

00:00:09,780  -->  00:00:14,740
that they want to buy online goes under their desired price.
6

6

00:00:14,740  -->  00:00:18,460
For example, if they have their favourite department store,
7

7

00:00:18,460  -->  00:00:21,700
they can go into the website, find the web address
8

8

00:00:21,700  -->  00:00:24,960
of the item they're interested in, give it to us,
9

9

00:00:24,960  -->  00:00:26,930
and tell us how to find the price
10

10

00:00:26,930  -->  00:00:31,100
of the item on the website, and then we will message them
11

11

00:00:31,100  -->  00:00:33,540
later on when there's a sale or something like that.
12

12

00:00:33,540  -->  00:00:35,340
So that's the purpose of the app,
13

13

00:00:35,340  -->  00:00:38,060
and how we're gonna do this is by
14

14

00:00:38,980  -->  00:00:42,010
allowing the user to give us all the information we need,
15

15

00:00:42,010  -->  00:00:44,750
storing it, and the every now and then,
16

16

00:00:44,750  -->  00:00:46,910
maybe every day, maybe every hour,
17

17

00:00:46,910  -->  00:00:50,650
run a programme that will check the pricing
18

18

00:00:50,650  -->  00:00:52,233
and send the users an email.
19

19

00:00:53,320  -->  00:00:58,320
In order to create the app, we're going to use the MVC
20

20

00:00:58,430  -->  00:01:01,410
model for structuring a web application like this one.
21

21

00:01:01,410  -->  00:01:04,820
MVC stands for model view controller.
22

22

00:01:04,820  -->  00:01:07,370
Those three things are important things
23

23

00:01:07,370  -->  00:01:09,320
in a web application like this one.
24

24

00:01:09,320  -->  00:01:12,000
It's a very popular way of structuring an app.
25

25

00:01:12,000  -->  00:01:16,680
So the models define what the application
26

26

00:01:16,680  -->  00:01:20,220
understands about the things that it deals with.
27

27

00:01:20,220  -->  00:01:22,900
For example, in this application, we can have models
28

28

00:01:22,900  -->  00:01:26,090
such as the item the user's interested in,
29

29

00:01:26,090  -->  00:01:29,840
the store that an item is a part of,
30

30

00:01:29,840  -->  00:01:31,680
an alert,
31

31

00:01:31,680  -->  00:01:35,660
what price a user's interested in for a certain item.
32

32

00:01:35,660  -->  00:01:38,090
Those things could be models,
33

33

00:01:38,090  -->  00:01:39,170
because those are things
34

34

00:01:39,170  -->  00:01:42,700
that our application deals with internally.
35

35

00:01:42,700  -->  00:01:44,807
Then we've got the views,
36

36

00:01:44,807  -->  00:01:47,280
and a view in one of these apps
37

37

00:01:47,280  -->  00:01:50,190
is what the user sees and interacts with.
38

38

00:01:50,190  -->  00:01:53,360
So in this case, we're gonna be creating a web app,
39

39

00:01:53,360  -->  00:01:57,120
so the user is going to be looking at a web view.
40

40

00:01:57,120  -->  00:01:59,630
Something that they can look at on their browser.
41

41

00:01:59,630  -->  00:02:02,060
It's gonna be using HTML and CSS
42

42

00:02:02,060  -->  00:02:04,030
and so on in order to display.
43

43

00:02:04,030  -->  00:02:06,520
And our Flask application is going to be responsible
44

44

00:02:06,520  -->  00:02:09,010
for serving those views to our user
45

45

00:02:09,010  -->  00:02:10,260
so they can look at them.
46

46

00:02:11,120  -->  00:02:12,500
So that's the M and the V,
47

47

00:02:12,500  -->  00:02:15,070
and finally we've got the C, which is controller.
48

48

00:02:15,070  -->  00:02:18,110
A controller is essentially everything else
49

49

00:02:18,110  -->  00:02:19,680
in an application like this one.
50

50

00:02:19,680  -->  00:02:22,400
So once we have the view that the user interacts with
51

51

00:02:22,400  -->  00:02:25,420
and the models that our programme understands
52

52

00:02:25,420  -->  00:02:28,260
about the context it's in for this application,
53

53

00:02:28,260  -->  00:02:29,500
the controller is responsible
54

54

00:02:29,500  -->  00:02:34,270
for handling user inputs, for dispatching user outputs,
55

55

00:02:34,270  -->  00:02:36,650
it's responsible for creating models
56

56

00:02:36,650  -->  00:02:39,410
and storing them in data bases, and making sure
57

57

00:02:39,410  -->  00:02:43,760
that the models are valid and for retrieving prices
58

58

00:02:43,760  -->  00:02:46,250
from the websites that our users are interested in,
59

59

00:02:46,250  -->  00:02:47,083
that sort of stuff.
60

60

00:02:47,083  -->  00:02:49,810
So the controller is sort of the engine
61

61

00:02:49,810  -->  00:02:51,560
that runs the whole app.
62

62

00:02:51,560  -->  00:02:54,210
Okay, enough about what these things are.
63

63

00:02:54,210  -->  00:02:57,630
We are gonna start by creating the different folders,
64

64

00:02:57,630  -->  00:02:59,660
and we're gonna go for Python Packages
65

65

00:02:59,660  -->  00:03:02,420
and I'm gonna have a common Python Package.
66

66

00:03:02,420  -->  00:03:04,270
If you go to Python Package using PyCharm,
67

67

00:03:04,270  -->  00:03:07,440
what you end up is a dunder init file,
68

68

00:03:07,440  -->  00:03:09,950
so that's underscore underscore init, underscore underscore.
69

69

00:03:09,950  -->  00:03:11,430
Two underscores on each side,
70

70

00:03:11,430  -->  00:03:13,960
and that tells Python that this is a package
71

71

00:03:13,960  -->  00:03:15,910
that you can import things from.
72

72

00:03:15,910  -->  00:03:17,670
If you don't put the dunder init file,
73

73

00:03:17,670  -->  00:03:20,270
then you cannot import things from it.
74

74

00:03:20,270  -->  00:03:22,850
So that's important, so that's our common package,
75

75

00:03:22,850  -->  00:03:24,500
where you're gonna put things like
76

76

00:03:24,500  -->  00:03:26,050
a date of interaction files,
77

77

00:03:26,050  -->  00:03:28,860
or any utils like to
78

78

00:03:28,860  -->  00:03:32,800
hash passwords or check validity of emails
79

79

00:03:32,800  -->  00:03:34,100
and things like that.
80

80

00:03:34,100  -->  00:03:36,040
Things that you can use throughout your application
81

81

00:03:36,040  -->  00:03:39,430
and aren't really a model view or a controller.
82

82

00:03:39,430  -->  00:03:41,220
Then we're gonna have our models.
83

83

00:03:41,220  -->  00:03:44,870
Then we are going to have our templates
84

84

00:03:44,870  -->  00:03:48,150
which are essentially, I'm gonna say the view,
85

85

00:03:48,150  -->  00:03:50,540
but this is what the user's going to look at.
86

86

00:03:50,540  -->  00:03:52,150
This is the HTML files
87

87

00:03:52,150  -->  00:03:54,350
that our users are going to be served.
88

88

00:03:54,350  -->  00:03:57,820
And finally I'm going to create a package called the views.
89

89

00:03:57,820  -->  00:04:00,640
And I'm calling it views instead of controllers,
90

90

00:04:00,640  -->  00:04:03,390
and there's a specific reason for that.
91

91

00:04:03,390  -->  00:04:07,610
In this application, the controllers
92

92

00:04:07,610  -->  00:04:11,260
are really just going to be serving the user
93

93

00:04:11,260  -->  00:04:12,983
with the templates.
94

94

00:04:13,906  -->  00:04:17,380
And to some extent they're also going to be receiving
95

95

00:04:17,380  -->  00:04:20,160
in some cases some data from a template,
96

96

00:04:20,160  -->  00:04:23,700
like a form, like HTML form that the user can submit.
97

97

00:04:23,700  -->  00:04:27,750
But we don't have any separate controllers
98

98

00:04:27,750  -->  00:04:31,030
outside of sending the user our templates
99

99

00:04:31,030  -->  00:04:33,490
and receiving data from those templates.
100

100

00:04:33,490  -->  00:04:37,270
So in this application, the views on the templates
101

101

00:04:37,270  -->  00:04:39,180
work very closely together
102

102

00:04:39,180  -->  00:04:42,270
such that I'm calling my controllers views
103

103

00:04:42,270  -->  00:04:46,150
because they're only responsible for serving the views.
104

104

00:04:46,150  -->  00:04:48,180
You can choose to call this controllers,
105

105

00:04:48,180  -->  00:04:49,340
and these views.
106

106

00:04:49,340  -->  00:04:52,800
If you want, I know that this is a little bit confusing,
107

107

00:04:52,800  -->  00:04:55,000
but I'm sure it'll be clearer as we develop
108

108

00:04:55,000  -->  00:04:57,110
exactly what these are doing.
109

109

00:04:57,110  -->  00:05:00,510
Alright, so this is the structure of our application.
110

110

00:05:00,510  -->  00:05:02,560
We are going to have our app.py,
111

111

00:05:02,560  -->  00:05:04,510
and then our views and templates,
112

112

00:05:04,510  -->  00:05:06,150
which our responsible for handling
113

113

00:05:06,150  -->  00:05:08,400
what the user sees and what the user sends us.
114

114

00:05:08,400  -->  00:05:10,920
Then we've got the models, which are going to contain
115

115

00:05:10,920  -->  00:05:14,000
what our application understands about the context it's in,
116

116

00:05:14,000  -->  00:05:17,440
such as the items, stores, alerts, et cetera.
117

117

00:05:17,440  -->  00:05:19,240
And then we've got some common files
118

118

00:05:19,240  -->  00:05:21,980
which are going to deal with common things
119

119

00:05:21,980  -->  00:05:24,277
like data interactions and so on.
120

120

00:05:24,277  -->  00:05:25,730
That's it for this video.
121

121

00:05:25,730  -->  00:05:26,890
Thank you for joining me.
122

122

00:05:26,890  -->  00:05:28,280
Let's continue in the next one.
123

123

00:05:28,280  -->  00:05:29,230
I'll see you there.
