1
1

00:00:01,130  -->  00:00:02,390
<v ->Hi and welcome back.</v>
2

2

00:00:02,390  -->  00:00:04,680
In this video we're going to continue
3

3

00:00:04,680  -->  00:00:06,790
using stores in our application
4

4

00:00:06,790  -->  00:00:08,650
and we're gonna remove the ability
5

5

00:00:08,650  -->  00:00:11,680
for users to create items.
6

6

00:00:11,680  -->  00:00:13,930
We're going to start in app dot PY.
7

7

00:00:13,930  -->  00:00:17,590
We're just gonna delete the item blueprint from here.
8

8

00:00:17,590  -->  00:00:18,670
Why's that?
9

9

00:00:18,670  -->  00:00:21,430
Well, items are gonna be used internally now.
10

10

00:00:21,430  -->  00:00:24,420
Users are not going to be creating items
11

11

00:00:24,420  -->  00:00:26,550
or retrieving items, or anything like that,
12

12

00:00:26,550  -->  00:00:28,820
because we're gonna create them
13

13

00:00:28,820  -->  00:00:30,420
when we create an alert
14

14

00:00:30,420  -->  00:00:33,750
and we're gonna use the data stored in the store models
15

15

00:00:33,750  -->  00:00:37,150
instead of having the user creating items.
16

16

00:00:37,150  -->  00:00:38,853
So we no longer need them there.
17

17

00:00:40,260  -->  00:00:42,170
Now in the alert form,
18

18

00:00:42,170  -->  00:00:43,400
where we create a new alert,
19

19

00:00:43,400  -->  00:00:45,650
we're no longer going to take an item ID.
20

20

00:00:45,650  -->  00:00:46,910
We know this was silly
21

21

00:00:46,910  -->  00:00:50,170
because the user was never gonna know the item ID.
22

22

00:00:50,170  -->  00:00:52,773
Instead we're gonna take in an item URL.
23

23

00:00:53,760  -->  00:00:57,210
And the reason for that is we're gonna use the item URL
24

24

00:00:57,210  -->  00:01:00,200
to find the related store in our database
25

25

00:01:00,200  -->  00:01:03,590
and with that store, we're going to find the URL,
26

26

00:01:03,590  -->  00:01:06,573
sorry, the tag name, and the query.
27

27

00:01:09,560  -->  00:01:11,500
Now if we take this away
28

28

00:01:11,500  -->  00:01:16,180
then we do have to go into our alert views
29

29

00:01:16,180  -->  00:01:18,610
and instead of taking in an item ID,
30

30

00:01:18,610  -->  00:01:20,210
we're gonna take in an item URL.
31

31

00:01:21,130  -->  00:01:23,920
And the value of that is item URL in the form
32

32

00:01:23,920  -->  00:01:27,740
and the alert is now going to have to find
33

33

00:01:28,880  -->  00:01:30,530
the item in the database.
34

34

00:01:30,530  -->  00:01:32,190
So, how's it gonna go?
35

35

00:01:32,190  -->  00:01:34,860
We're gonna say that the store is going to be
36

36

00:01:34,860  -->  00:01:37,570
store dot find by URL
37

37

00:01:37,570  -->  00:01:39,420
and we're gonna give it the item URL.
38

38

00:01:40,270  -->  00:01:44,020
And then we're gonna create an item for that.
39

39

00:01:44,020  -->  00:01:47,860
So the item is gonna have the item URL that we want
40

40

00:01:47,860  -->  00:01:51,003
and the store tag name and the store query.
41

41

00:01:51,950  -->  00:01:54,830
Then we're gonna save that item to MongoDB.
42

42

00:01:54,830  -->  00:01:57,210
And then the alert we create is gonna have the
43

43

00:01:57,210  -->  00:02:00,600
items dot underscore ID property.
44

44

00:02:00,600  -->  00:02:02,670
Now PyCharm is gonna complain when you do this.
45

45

00:02:02,670  -->  00:02:05,020
It says access to a protected member underscore ID
46

46

00:02:05,020  -->  00:02:06,010
of a class.
47

47

00:02:06,010  -->  00:02:08,060
But that is okay in Python.
48

48

00:02:08,060  -->  00:02:09,320
This is just a warning.
49

49

00:02:09,320  -->  00:02:10,340
It's something you can do.
50

50

00:02:10,340  -->  00:02:11,240
It's not a problem.
51

51

00:02:11,240  -->  00:02:12,593
It's not anti-Pythonic.
52

52

00:02:13,560  -->  00:02:16,120
The main reason why we have private variables
53

53

00:02:16,120  -->  00:02:17,650
or things that we signal as private
54

54

00:02:17,650  -->  00:02:19,140
with the underscore in front
55

55

00:02:19,140  -->  00:02:22,580
is because we don't want other people to change them.
56

56

00:02:22,580  -->  00:02:23,730
And we're not changing it here.
57

57

00:02:23,730  -->  00:02:25,220
We're just using it and reading it.
58

58

00:02:25,220  -->  00:02:26,173
So this is fine.
59

59

00:02:27,520  -->  00:02:29,720
We don't need this JSON import.
60

60

00:02:29,720  -->  00:02:31,300
Not sure why that's there,
61

61

00:02:31,300  -->  00:02:35,543
but we do need to do the other imports.
62

62

00:02:40,720  -->  00:02:41,553
Like that.
63

63

00:02:42,420  -->  00:02:44,190
Now again, this warning will stay there,
64

64

00:02:44,190  -->  00:02:46,360
but that's okay.
65

65

00:02:46,360  -->  00:02:47,800
What else do we not need?
66

66

00:02:47,800  -->  00:02:50,150
Well, we don't actually need any
67

67

00:02:50,150  -->  00:02:52,080
of the item templates anymore.
68

68

00:02:52,080  -->  00:02:54,810
Because we're just not gonna use them.
69

69

00:02:54,810  -->  00:02:57,290
Our user is not going to be dealing with this stuff
70

70

00:02:57,290  -->  00:02:59,700
so we can delete that entirely
71

71

00:02:59,700  -->  00:03:03,040
and we can also delete the item views.
72

72

00:03:03,040  -->  00:03:03,873
So that's it.
73

73

00:03:03,873  -->  00:03:04,740
They're gone.
74

74

00:03:04,740  -->  00:03:07,670
And this is one of the best feelings in programming,
75

75

00:03:07,670  -->  00:03:10,060
which is when you get delete a bunch of code.
76

76

00:03:10,060  -->  00:03:11,550
Code you don't need anymore
77

77

00:03:11,550  -->  00:03:13,510
because you've got a better way,
78

78

00:03:13,510  -->  00:03:16,740
or at least a simpler way of doing things.
79

79

00:03:16,740  -->  00:03:20,330
We've added a little bit of complexity for ourselves,
80

80

00:03:20,330  -->  00:03:24,290
but in exchange we've made it much easier for users.
81

81

00:03:24,290  -->  00:03:27,400
Of course, we do need a way to add stores to our database,
82

82

00:03:27,400  -->  00:03:28,653
so we will be doing that.
83

83

00:03:29,610  -->  00:03:32,700
But now what we've done is we have made the changes
84

84

00:03:32,700  -->  00:03:36,550
that we needed to make in order to stop using items
85

85

00:03:36,550  -->  00:03:37,920
and it's stopped our users
86

86

00:03:37,920  -->  00:03:39,650
having to give us item information
87

87

00:03:39,650  -->  00:03:42,230
and instead they just give us an item URL.
88

88

00:03:42,230  -->  00:03:44,920
We then find the store with that URL
89

89

00:03:44,920  -->  00:03:47,620
and then we create an item object internally
90

90

00:03:47,620  -->  00:03:50,060
only for ourselves, only for our application
91

91

00:03:50,060  -->  00:03:52,310
that uses the item URL they want
92

92

00:03:52,310  -->  00:03:55,260
and the store, tag name, and query.
93

93

00:03:55,260  -->  00:03:57,670
If they give us something like
94

94

00:03:57,670  -->  00:04:01,240
HTTPS www dot johnlewis dot com
95

95

00:04:01,240  -->  00:04:04,140
slash item slash bla dot HTML
96

96

00:04:04,140  -->  00:04:06,110
then we're going to find a store
97

97

00:04:06,110  -->  00:04:08,583
that matches this URL prefix,
98

98

00:04:09,600  -->  00:04:11,500
which if we add it to our database
99

99

00:04:11,500  -->  00:04:13,820
will give us an actual store
100

100

00:04:13,820  -->  00:04:16,580
and that store will have the information needed
101

101

00:04:16,580  -->  00:04:18,920
to extract information from pages
102

102

00:04:18,920  -->  00:04:21,070
that use this URL structure.
103

103

00:04:21,070  -->  00:04:23,350
So it's gonna have a tag name of P
104

104

00:04:23,350  -->  00:04:27,820
and a query of class price price dash dash large.
105

105

00:04:27,820  -->  00:04:30,310
With that information, we will then be able
106

106

00:04:30,310  -->  00:04:33,683
to retrieve the item price when we come to it.
107

107

00:04:34,790  -->  00:04:37,840
All right, so we're going to be testing this out,
108

108

00:04:37,840  -->  00:04:39,950
we're gonna do that, in the next video.
109

109

00:04:39,950  -->  00:04:41,260
Thank you for joining me.
110

110

00:04:41,260  -->  00:04:42,210
I'll see you there.
