|
List Info
Thread: 'c' variable between redirects
|
|
| 'c' variable between redirects |

|
2007-08-24 07:33:07 |
|
Hi there!
Whatever variable attached to 'c';, it is available in the template when rendered via 'render_response('x.tmpl')'.
I often however use redirects 'h.redirect_to(another_action)' to reuse controller's code. And the 'c';-attached variables are not present in the redirected template.
As I understand 'c'; is always reset before any controller's action - what is not fun for me, as in my app one "user" request/click is often 2 (or more) Pylons controllers' actions, hence http redirects..
What other options instead of putting variables to http session does one have for passing variables through redirects?
T.
-- _i______'simplicity_is_the_key'__________tomasz_nazar
_ii____9;i_am_concern_oriented'________________JKM-UPR _iii__'patsystem.sf.net';___________________linux_user _'aspectized.com
';___________________________prevayler
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss googlegroups.com To unsubscribe from this group, send email to pylons-discuss-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
|
| Re: 'c' variable between redirects |
  Germany |
2007-08-24 07:39:57 |
On Fri, Aug 24, 2007 at 02:33:07PM +0200, Tomasz Nazar
wrote:
> Whatever variable attached to 'c', it is available in
the template when
> rendered via 'render_response('x.tmpl')'.
>
> I often however use redirects
'h.redirect_to(another_action)' to reuse
> controller's code. And the 'c'-attached variables are
not present in the
> redirected template.
Correct. A redirect issues a "Location:" header to
be sent to the
browser and that concludes the current HTTP communication.
The browser
will then start a new HTTP request with the new location.
> As I understand 'c' is always reset before any
controller's action - what is
> not fun for me, as in my app one "user"
request/click is often 2 (or more)
> Pylons controllers' actions, hence http redirects..
Without knowing your application I dare say that this sounds
like you
are using redirect_to in the wrong places. If the
application is
supposed to do multiple things when a user does a certain
HTTP request
then why can't one controller's action do that alone?
> What other options instead of putting variables to http
session does one have
> for passing variables through redirects?
The "session" dictionary.
Christoph
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "pylons-discuss" group.
To post to this group, send email to pylons-discuss googlegroups.com
To unsubscribe from this group, send email to
pylons-discuss-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: 'c' variable between redirects |
  United Kingdom |
2007-08-24 08:22:51 |
>> As I understand 'c' is always reset before any
controller's action
>> - what is
>> not fun for me, as in my app one "user"
request/click is often 2
>> (or more)
>> Pylons controllers' actions, hence http
redirects..
>
> Without knowing your application I dare say that this
sounds like you
> are using redirect_to in the wrong places. If the
application is
> supposed to do multiple things when a user does a
certain HTTP request
> then why can't one controller's action do that alone?
Actually, I was in such a situation not too long ago, so I'm
curious
what the best solution actually is.
The situation itself is as follows:
- user edits form
- submit triggers controller+action.
I use the same action when posting as when asking for the
form,
differentiating between POST and GET requests.
- If the POST data does not validate, the rest of the action
is
executed (having set a c.errors variable), which leads
again
to the form, but this time with errors indicated. The
user can now
correct these.
- If the POST data validates, I redirect (to prevent the
'reload post
data?' question) to the form again, which then executes the
GET part.
This is done so that the user can edit more if he/she wants.
Perhaps
this is where I go wrong, but I feel it makes sense in my
case. To
indicate things have changed, some text on the top of the
webpage
says 'your data have been updated; you can chance more below
if you
like'. This text appears if a global variable is set
(g.something),
which is set just before the redirection. I immediately
remove the
'something' attribute after doing this (actually, before
rendering,
but having set c.something = g.something), so that next time
the user
(re)loads the form webpage, the message disappears.
So perhaps, the last redirect should go to a different
webpage?
Should that page then have a link 'please click here if you
want to
change things further'. And one would still like to inform
the user
that 'your data have been updated', so there's still some
need of
passing a variable (a simple boolean flag) between
redirects.
>> What other options instead of putting variables to
http session
>> does one have
>> for passing variables through redirects?
> The "session" dictionary.
As mentioned, I'm using the g variable (removing the
attribute when
not needed), not session. Which one would be better? Is g
perhaps
tied to the application, ie if multiple users use it, they
all use
the same g variable, but session is still
(browser/ip-address) user-
dependent? Sorry, I'm still a newbie, so I'm not t0o clear
on this.
Cheers,
Evert
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "pylons-discuss" group.
To post to this group, send email to pylons-discuss googlegroups.com
To unsubscribe from this group, send email to
pylons-discuss-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: 'c' variable between redirects |
  Canada |
2007-08-24 12:56:49 |
Evert Rol wrote:
> As mentioned, I'm using the g variable (removing the
attribute when
> not needed), not session. Which one would be better? Is
g perhaps
> tied to the application, ie if multiple users use it,
they all use
> the same g variable, but session is still
(browser/ip-address) user-
> dependent? Sorry, I'm still a newbie, so I'm not t0o
clear on this.
You definitely don't want to use g, which is truly
application-global.
That means separate threads see the same g, and certainly
separate
requests even if they come from different users.
Sessions are tied to the user, which means (roughly) that
regardless of
threads you'll get the correct information about the user.
Everything else you're doing sounds quite reasonable and
clean and nice
for the user, so if you just switch to sessions you'll be
quite
reasonable and clean and nice *and* safe.
-Peter
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "pylons-discuss" group.
To post to this group, send email to pylons-discuss googlegroups.com
To unsubscribe from this group, send email to
pylons-discuss-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: 'c' variable between redirects |

|
2007-08-24 14:50:41 |
|
On 8/24/07, Christoph Haas < email christoph-haas.de">email christoph-haas.de> wrote:
> As I understand 'c'; is always reset before any controller's action - what is > not fun for me, as in my app one "user" request/click is often 2 (or more) > Pylons controllers' actions, hence http redirects..
Without knowing your application I dare say that this sounds like you are using redirect_to in the wrong places. If the application is supposed to do multiple things when a user does a certain HTTP request
then why can't one controller's action do that alone?
Christoph
Simple said, because of the duplication of some parts of the code.
Let's have this example from my app for discussion:
Usecase 1: "Go to Home Page" -> issues 'controller: home/home' -> renders 'home.mako' Usecase 2: "Send email to a friend, and show Home Page" -> issues 'controller: email/send', then redirects to 'controller: home/home' -> renders '
home.mako'
Of course 'home' action of controller 'home' does some specific logic, like showing current user's data from DB. That is a reason, I just can't show 'home.mako' in 'email/send' page after sending an email.
And it is really bad to implement that logic twice in different places..
Though I sometimes handle such situations by just _calling_ (not redirecting) 2nd action from a controller, only when 2 actions used are in the same controller.
Hmm...however when I think about that now, I think I could also not to redirect, but could try to call 'home/home' action from another controller ('email') class/object.. could I? Can I access that object somehow?
Tomasz
ps. session is somehow too global for my needs. That's 'c'; is the thing to use I think ps2. In Java/Struts I've used "forms" for storing that kind of data, that is nor "sesion global", nor "http request specific".
-- _i______'simplicity_is_the_key'__________tomasz_nazar _ii____'i_am_concern_oriented'________________JKM-UPR _iii__'patsystem.sf.net
39;___________________linux_user _'aspectized.com'___________________________prevayler
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss googlegroups.com To unsubscribe from this group, send email to pylons-discuss-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
|
| Re: 'c' variable between redirects |
  United States |
2007-08-25 11:42:06 |
|
Tomasz Nazar wrote:
mail.gmail.com"
type="cite">
On 8/24/07, Christoph Haas <christoph-haas.de">email christoph-haas.de>
wrote:
> As I understand 'c' is always reset before any controller's action
- what is
> not fun for me, as in my app one "user" request/click is often 2
(or more)
> Pylons controllers' actions, hence http redirects..
Without knowing your application I dare say that this sounds like you
are using redirect_to in the wrong places. If the application is
supposed to do multiple things when a user does a certain HTTP request
then why can't one controller's action do that alone?
Christoph
Simple said, because of the duplication of some parts of the code.
Let's have this example from my app for discussion:
Usecase 1: "Go to Home Page" -> issues 'controller: home/home' ->
renders 'home.mako'
Usecase 2: "Send email to a friend, and show Home Page" -> issues
'controller: email/send', then redirects to 'controller: home/home'
-> renders '
home.mako'
Of course 'home' action of controller 'home' does some specific logic,
like showing current user's data from DB. That is a reason, I just
can't show 'home.mako' in 'email/send' page after sending an email.
And it is really bad to implement that logic twice in different places..
Rather then using return redirect_to('home') in your email controller,
why not just call home directly return self.home(), of course that
assumes that home and email are in the same controller which they might
not be, but you should be able to simply import what ever actions you
need from waht ever controllers you you've already written. Or did I
miss something very fundamental in the the conversation?
Jose
mail.gmail.com"
type="cite">
Though I sometimes handle such situations by just _calling_ (not
redirecting) 2nd action from a controller, only when 2 actions used are
in the same controller.
Hmm...however when I think about that now, I think I could also not to
redirect, but could try to call 'home/home' action from another
controller ('email') class/object.. could I? Can I access that object
somehow?
Tomasz
ps. session is somehow too global for my needs. That's 'c' is the thing
to use I think
ps2. In Java/Struts I've used "forms" for storing that kind of data,
that is nor "sesion global", nor "http request specific".
--
_i______'simplicity_is_the_key'__________tomasz_nazar
_ii____'i_am_concern_oriented'________________JKM-UPR
_iii__'patsystem.sf.net
'___________________linux_user
_'aspectized.com'___________________________prevayler
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss googlegroups.com To unsubscribe from this group, send email to pylons-discuss-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
|
| Re: 'c' variable between redirects |
  United States |
2007-08-25 11:42:06 |
|
Tomasz Nazar wrote:
mail.gmail.com"
type="cite">
On 8/24/07, Christoph Haas <christoph-haas.de">email christoph-haas.de>
wrote:
> As I understand 'c' is always reset before any controller's action
- what is
> not fun for me, as in my app one "user" request/click is often 2
(or more)
> Pylons controllers' actions, hence http redirects..
Without knowing your application I dare say that this sounds like you
are using redirect_to in the wrong places. If the application is
supposed to do multiple things when a user does a certain HTTP request
then why can't one controller's action do that alone?
Christoph
Simple said, because of the duplication of some parts of the code.
Let's have this example from my app for discussion:
Usecase 1: "Go to Home Page" -> issues 'controller: home/home' ->
renders 'home.mako'
Usecase 2: "Send email to a friend, and show Home Page" -> issues
'controller: email/send', then redirects to 'controller: home/home'
-> renders '
home.mako'
Of course 'home' action of controller 'home' does some specific logic,
like showing current user's data from DB. That is a reason, I just
can't show 'home.mako' in 'email/send' page after sending an email.
And it is really bad to implement that logic twice in different places..
Rather then using return redirect_to('home') in your email controller,
why not just call home directly return self.home(), of course that
assumes that home and email are in the same controller which they might
not be, but you should be able to simply import what ever actions you
need from waht ever controllers you you've already written. Or did I
miss something very fundamental in the the conversation?
Jose
mail.gmail.com"
type="cite">
Though I sometimes handle such situations by just _calling_ (not
redirecting) 2nd action from a controller, only when 2 actions used are
in the same controller.
Hmm...however when I think about that now, I think I could also not to
redirect, but could try to call 'home/home' action from another
controller ('email') class/object.. could I? Can I access that object
somehow?
Tomasz
ps. session is somehow too global for my needs. That's 'c' is the thing
to use I think
ps2. In Java/Struts I've used "forms" for storing that kind of data,
that is nor "sesion global", nor "http request specific".
--
_i______'simplicity_is_the_key'__________tomasz_nazar
_ii____'i_am_concern_oriented'________________JKM-UPR
_iii__'patsystem.sf.net
'___________________linux_user
_'aspectized.com'___________________________prevayler
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss googlegroups.com To unsubscribe from this group, send email to pylons-discuss-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
|
| Re: 'c' variable between redirects |

|
2007-08-25 12:40:15 |
|
On 8/25/07, Jose Galvez < jj.galvez gmail.com">jj.galvez gmail.com> wrote:
Tomasz Nazar wrote:
On 8/24/07, Christoph Haas < email christoph-haas.de" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">email christoph-haas.de
>
wrote:
> As I understand 'c'; is always reset before any controller's action
- what is
> not fun for me, as in my app one "user" request/click is often 2
(or more)
> Pylons controllers' actions, hence http redirects..
Without knowing your application I dare say that this sounds like you
are using redirect_to in the wrong places. If the application is
supposed to do multiple things when a user does a certain HTTP request
then why can't one controller's action do that alone?
Christoph
Simple said, because of the duplication of some parts of the code.
Let';s have this example from my app for discussion:
Usecase 1: "Go to Home Page" -> issues 'controller: home/home' ->
renders 'home.mako'
Usecase 2: "Send email to a friend, and show Home Page" -> issues
39;controller: email/send', then redirects to 'controller: home/home'
-> renders '
home.mako'
Of course 'home' action of controller 'home' does some specific logic,
like showing current user's data from DB. That is a reason, I just
can't show 'home.mako' in 'email/send' page after sending an email.
And it is really bad to implement that logic twice in different places..
Rather then using return redirect_to('home') in your email controller,
why not just call home directly return self.home(), of course that
assumes that home and email are in the same controller which they might
not be, but you should be able to simply import what ever actions you
need from waht ever controllers you you've already written. Or did I
miss something very fundamental in the the conversation?
Jose
That is exactly what I was thinking of during writing my reply.. (see below). If it works I could like it..
Though I sometimes handle such situations by just _calling_ (not
redirecting) 2nd action from a controller, only when 2 actions used are
in the same controller.
Hmm...however when I think about that now, I think I could also not to
redirect, but could try to call 'home/home' action from another
controller ('email') class/object.. could I? Can I access that object
somehow?
Tomasz
-- _i______'simplicity_is_the_key'__________tomasz_nazar _ii____'i_am_concern_oriented'________________JKM-UPR _iii__'
patsystem.sf.net39;___________________linux_user _'aspectized.com'___________________________prevayler
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss googlegroups.com To unsubscribe from this group, send email to pylons-discuss-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
|
[1-8]
|
|