Detailed Notes
This lesson takes a look at using session variables instead of query parameters for storing and passing values.
You can view source for today and all prior days by reviewing the tag Day 36 at this GitHub: https://github.com/robbroadhead/develpreneur-pythontutorial
Transcript Text
[Music] well hello and welcome back we are going to clean up a little bit we're continuing to look at some sort of the background data that we want to track uh lately we've been working our way into passing values in so as we uh go in here we added a road map and then we for example want to create a new time frame then we are pre-populating our our road map but we're doing it here by sending variables in and we're going to do i'm going to take a look at another approach to doing this which is um probably cleaner to some extent but it does have some some issues that you can run into based on browser but at least wanted to touch on it and that's the idea of putting stuff into the session and the way we're going to do this is we're going to uh whoops let me jump over here when we select a roadmap then we're going to set a session value of our current id and what we're going to do there is and it's not too complicated to do so we've got let's look at roadmap so we list we can either create one or we can edit one now creating one is we're going to need the id of what we built and when we create one we actually ended up let's go look at this real quick because i don't think we need it so if we come here and create a new road map i'm going to do let's do annual goals 2022 get ahead of ourselves a little bit and save a record and so here it's going to bring us back here so we don't really have to worry about it on the create we're just going to do it on the edit which is awesome because we know exactly what the idea is we don't have to do something where we um insert a record and then get the returned id we actually have this so we go into edit roadmap because they're going to click here and they give us an id so all we're going to do is right away say if they're authenticated then we can actually do something here and we're going to just say request whoops if i can spell it right dot session and we're going to call this uh we'll just call it rmid equals id so now we have set a session variable and what we can do is uh here when we do edit and then for example create before we were tacking in attacking on the rd the id we don't need to do that anymore so when we go to roadmap edit and we go here we're creating this uh rm equals arm id and i'm going to actually get rid of that so now we're just going to create a time frame and when we do create time frame which is tf which let's make sure i got that right that goes to create time frame great time frame there we go so we want to do here is we're looking for it in the request now we're going to look for it in the session and we're really only going to change this a little bit is we're just going to say request.session and we called it uh rmid and we do it like that so now we're going to check that within the session now there's some things we could do um we could create like a essentially a function that checks a session and pulls some values in um but we're just going to keep this as part of so we could we could take these little things and bundle this text up and do it as part of something we return back um you know do these checkings and settings but we're not going to bother with that right now we're just going to keep it very simple inline code there will be some duplication so we'll look at like create time frame and there will probably be let's see if we do like an edit time frame edit time frame oh well i guess in that case we don't have to worry about it in the edit time frame um well we did do it here so let's change that up so here we said if it was in the session uh that's going to be well what did we have before let's take a look at that real quick before oh which is actually a problem there because we have we were checking in the get but it actually should have been in the post so called a bug there um that should be in the post oh because we pass a road map in so here we can do actually this is in both of these so we're going to do a request dot session and we're gonna do we gotta clean this up a little bit so if rmid and request.session actually is that the same thing then we can take that oh so let's go back to that was at the bottom so if we go here i think that was at the bottom yeah here we go so let's just go ahead and sort of steal that code and clean that up so else this was if let's see if he's there but here he's going to do the well we can just do this we want to call him roadmap uh rmid equals that okay and then here we can do the same if he's in the co and actually now we don't have to check whether it's in the post or the um the get now we can just simply come through here and say regardless we're going to say if it's in the session then we're going to go ahead and pull that thing out so that gives us for uh editing so now and we can probably find so that was within well we're probably in pretty good shape so if we go to here if we go to i think we're probably good let's see i'll go test it out so now let's go and if we edit let's go edit here and this is our overall annual goals let's edit this and let's say overall let's see personal we do personal goals and it's an annual so we're going to save that record and oh that's interesting we ended up posting here so now it's so annual goals here if we look here oh we didn't say oh oh i'm sorry because this is a road map and then we go to personal goals and we go here and let's see does this return to 2021 it does oh let's take a look at that link real quick make sure that we've got yep we're not setting it up there if we do create time frame are we sending it here we are so if we look at uh this is time frame with child oh because that's the oh that is the road map so let's fix that one i thought we had that somewhere else so let's go here and we do edit time frame uh we had that i think we also need a we had another create time frame let's edit did we call it yeah here it is down here at the bottom create time frame we oh we've got that one fixed so okay so we're probably all right we can go to the time frame i believe it's time frame edit and we don't have to send the roadmap anymore and we also had it here so we don't have to do it as a part of the edit so let's make sure we got both of those i think we did so there's create time frame and edit time frame and that's where we clean that up so we should be good there so we've got personal goals and let's go back up here and let's create um oh this is gonna be uh annual personal goals and he doesn't have a time frame parent uh we're gonna save the record and then um oh we got to clean this one up so when we do a oh this is all time frames so let's take it we'll take a look at that in a second well not in a second but we'll take a look at a little bit later so now let's go back to our roadmap uh we have our personal goals we're going to create a tank time frame which is going to be uh professional goals and we'll call it annual professional goals well we'll just keep that because it is an annual time frame we've got a road map we're gonna save a record and uh we can create a time frame here so let's do that oh so here we go id expected so here where we do this p we're not getting something back so let's take a look at that let's back it up so when we do create time frame of this one let's take a look at this guy so this guy is over here he doesn't have anything if we go to edit professional goals and do create a child time frame uh let's see so one i'm still saying this rm equals one so we've got to fix that so that was in edit i guess yes so editing a road map is still got a bad a link that we don't need let's see here so we don't need that anymore and then we went to edit professional goals create time frame i think this one that broke oh no it didn't so why was the p oh i think when we created we were not properly filling this out so that's what we need to do and so that's a little bug that we'll fix we'll come into that next time actually because what we'll do is when we create a new time frame we can't immediately do this create time frame so we need to have something where it doesn't display this until we have a a time frame id if we're creating a new one then we don't have the values because here this create time frame is actually filling this out and actually what we're going to do is we're going to correct that as well so everywhere we have this p we're going to also have so we have uh create a time frame record here so this is going to be uh where we have this we're actually going to be let's call this we're just going to do it tfid i assume that is the oh that's the parent so let's do that we'll keep it there um we'll call it p we'll keep it that way so parent is question session uh if he is in that request.session then we're gonna do request.session p and then dated.parents so we need to find where we were using parent oops let's do it that way and let's see so here it was in the post of a time frame and so let's see if request.pose time frame which was going to be the parent so this is an editing okay so well we want to tweak this a little bit so when we come into a task editing a task then a parent is here but what we need to do is say as we get through so if we get a if we get one then we need to do the uh question.session whoops i need to set its parent is going to be equal to oh i'm sorry it was a p is going to be data dot uh where did i set that where did i set that data dot parent i think it's just data apparent so let's do that oh but it's not oh it's not it's called it's going to be actually data. time frame we'll take a look at that guy real quick and so here we're going to have to finish this one up next time so that's a time frame period but a task has a yes is a time frame so we get down to here we need to set here it's going to be his so that'll be the parent that's like basically the time frame where we're currently in and we're going to this is going to get a little more complicated because we could have uh essentially a task a a series of these going in so i think what i want to do is wait and tackle that next time around so hold that thought and we will uh we'll come back in our next episode and we're going to continue working on this and this is going to be two things we're going to look at our time frames being able to access a current parent and then with the tasks making sure that we're updating that parent as we go which again is where the session management of stuff can get a little bit complicated but that being said i'll let you get back to it so have yourself a great day a great week and we will talk to you next time you
Transcript Segments
[Music]
well hello and welcome back
we are going to clean up a little bit
we're continuing to look at
some sort of the background data that we
want to track
uh lately we've been working our way
into passing values in so as we
uh go in here we added a road map
and then we for example want to create a
new time frame then we are
pre-populating
our our road map but we're doing it here
by sending variables in and we're going
to do i'm going to take a look at
another approach to doing this which is
um probably cleaner to some extent but
it does have some
some issues that you can run into based
on
browser but at least wanted to touch on
it and that's the idea of putting stuff
into the session
and the way we're going to do this is
we're going to uh whoops let me jump
over here
when we select a roadmap
then we're going to set a session value
of our current
id and what we're going to do there
is and it's not too complicated to do so
we've got
let's look at roadmap so we list
we can either create one or we can edit
one
now creating one is we're going to need
the id
of what we built and when we create one
we actually
ended up let's go look at this real
quick because i don't think we need it
so if we come here and create a new road
map i'm going to do let's do annual
goals
2022 get ahead of ourselves a little bit
and save a record and so here it's going
to bring us back here so
we don't really have to worry about it
on the create we're just going to do it
on the edit
which is awesome because we know exactly
what the idea is we don't have to do
something where we um insert a record
and then get the returned id
we actually have this so we go into edit
roadmap
because they're going to click here and
they give us an id so all we're going to
do is right away say if they're
authenticated then we can actually do
something here
and we're going to just say request
whoops if i can spell it right
dot session and we're going to call
this uh we'll just call it rmid
equals id so now we have set
a session variable and what we can do
is uh here when we do edit
and then for example create before we
were tacking in
attacking on the rd the id we don't need
to do that anymore so when we go
to roadmap edit
and we go here we're creating this
uh rm equals arm id and i'm going to
actually get rid of that
so now we're just going to create a time
frame
and when we do create time frame which
is tf which let's make sure i got that
right that goes to create time frame
great time frame there we go so we want
to do here
is we're looking for it in the request
now we're going to look for it in the
session
and we're really only going to change
this a little bit is we're just going to
say request.session
and we called it uh rmid
and we do it like that so now we're
going to check that within the session
now there's some things we could do
um we could create like a
essentially a function that checks a
session and pulls some values in
um but we're just going to keep this as
part of
so we could we could take these little
things and bundle this text up
and do it as part of something we return
back um
you know do these checkings and settings
but we're not going to bother with that
right now we're just going to keep it
very simple inline code
there will be some duplication so we'll
look at like create time frame
and there will probably be let's see if
we do like an edit time frame
edit time frame
oh well i guess in that case we don't
have to worry about it in the edit time
frame
um well we did do it here
so let's change that up
so here we said if it was in the session
uh that's going to be
well what did we have before let's take
a look at that real quick before
oh which is actually a problem there
because we have we were checking in the
get
but it actually should have been in the
post
so called a bug there um that should be
in the post
oh because we pass a road map in so here
we can do
actually this is in both of these so
we're going to do a request dot session
and we're gonna do we gotta clean this
up a little bit so if rmid
and request.session
actually is that the same thing then we
can take that
oh so let's go back to that was at the
bottom
so if we go here i think that was at the
bottom
yeah here we go
so let's just go ahead and sort of steal
that code and clean that up so else this
was if
let's see if
he's there but here he's going to do the
well we can just do this we want to call
him roadmap
uh rmid equals that okay and then here
we can do the same if he's in the co and
actually now we don't have to check
whether it's in the post
or the um the get
now we can just simply come through here
and say regardless we're going to say if
it's in the session
then we're going to go ahead and pull
that thing out
so that gives us for uh editing
so now
and we can probably find so that was
within
well we're probably in pretty good shape
so if we go to here if we go to
i think we're probably good let's see
i'll go test it out so now let's go
and if we edit
let's go edit here and this is our
overall
annual goals let's edit this and let's
say
overall let's see personal
we do personal goals
and it's an annual so we're going to
save that record
and oh that's interesting we ended up
posting here so now it's
so annual goals here if we look here
oh we didn't say oh oh i'm sorry because
this is a road map and then we go to
personal goals and we go here
and let's see does this return to 2021
it does
oh let's take a look at that link real
quick
make sure that we've got yep we're not
setting it up there
if we do create time frame are we
sending it here
we are so if we look at uh this is
time frame with child oh because that's
the oh that is the road map so
let's fix that one i thought we had that
somewhere else so let's go here
and we do edit time frame uh we had that
i think we also need a we had another
create time frame
let's edit did we call it yeah here it
is
down here at the bottom create time
frame
we oh we've got that one fixed
so okay so we're probably all right
we can go to the time frame i believe
it's time frame edit and we don't
have to send the roadmap
anymore and we also had it here
so we don't have to do it as
a part of the edit so let's make sure we
got both of those i think we did
so there's create time frame and edit
time frame
and that's where we clean that up so we
should be good there
so we've got personal goals and let's go
back up here and let's create
um
oh this is gonna be uh annual
personal goals and he doesn't have a
time frame parent uh we're gonna save
the record
and then um oh we got to clean this one
up
so when we do a oh this is all time
frames
so let's take it we'll take a look at
that in a second well not in a second
but
we'll take a look at a little bit later
so now let's go back to our roadmap
uh we have our personal goals we're
going to create a tank time frame
which is going to be uh
professional goals
and we'll call it annual professional
goals well we'll just keep
that because it is an annual time frame
we've got a road map
we're gonna save a record and
uh we can create a time frame here so
let's do that oh
so here we go id expected so here where
we do this p
we're not getting something back so
let's take a look at that
let's back it up so when we do create
time frame of this one
let's take a look at this guy so this
guy
is over here he doesn't have anything if
we go to edit professional goals
and do create a child time frame
uh let's see so one i'm still saying
this rm equals one so we've got to fix
that
so that was in
edit i guess
yes so editing a road map is still got a
bad a link that we don't need
let's see here
so we don't need that anymore
and then we went to edit professional
goals
create time frame i think this one that
broke oh no it didn't
so why was the p oh i think when we
created we were not
properly filling this out so that's what
we need to do and so that's a little bug
that we'll fix
we'll come into that next time actually
because what we'll do is when we create
a new
time frame we can't immediately do this
create time frame
so we need to have something where it
doesn't display this until
we have a a time frame id if we're
creating a new one
then we don't have the values because
here this create time frame
is actually filling this out and
actually what we're going to do is we're
going to correct that
as well so everywhere we have this
p we're going to also have
so we have uh create a time frame record
here so this is going to be
uh where we have this we're actually
going to be let's call this we're just
going to do it
tfid
i assume that is the oh that's the
parent
so let's do that we'll keep it there um
we'll call it p
we'll keep it that way so parent is
question
session uh if he is in that
request.session then we're gonna do
request.session
p and then dated.parents so we need to
find where we were using
parent
oops let's do it that way and let's see
so here it was in the post of a time
frame
and so let's see if request.pose time
frame which was going to be the parent
so this is an editing okay so
well we want to tweak this a little bit
so when we come into a task
editing a task
then a parent is here but what we need
to do
is say as we get through
so if we get a if we get one then we
need to do
the uh question.session
whoops
i need to set its parent
is going to be equal to oh i'm sorry it
was a p
is going to be data
dot
uh where did i set that where did i set
that data dot
parent i think it's just data apparent
so let's do that
oh but it's not oh it's not it's called
it's going to be actually data. time
frame we'll take a look at that guy real
quick
and so here we're going to have to
finish this one up next time so that's a
time frame period but a task
has a yes is a time frame
so we get down to here we need to set
here it's going to be his
so that'll be the parent that's like
basically the time frame where we're
currently in
and we're going to this is going to get
a little more complicated because we
could have
uh essentially a task a a
series of these going in so i think what
i want to do is wait and tackle that
next time around so hold that thought
and we will uh we'll come back in our
next episode and we're going to continue
working on this and this is going to be
two things we're going to look at our
time frames being able to access a
current parent
and then with the tasks making sure that
we're updating that parent as we go
which again
is where the session management of stuff
can get a little bit
complicated but that being said i'll let
you get back to it so have yourself a
great day
a great week and we will talk to you
next time
you