propagating form data: session management

4 views
Skip to first unread message

Terrence Brannon

unread,
Oct 21, 2018, 3:29:06 AM10/21/18
to Reahl discuss
I am trying to create a simple web app:
  1. It displays 3 input fields and a submit button on a form
  2. When submit is pressed, the program uses the data in the 3 input fields to render an OutputBox.

Iwan Vosloo

unread,
Oct 21, 2018, 12:34:21 PM10/21/18
to reahl-...@googlegroups.com
Hi Terrence,

On 21/10/2018 09:29, Terrence Brannon wrote:
> I am trying to create a simple web app:
>
> 1. It displays 3 input fields and a submit button on a form
> 2. When submit is pressed, the program uses the data in the 3 input
> fields to render an OutputBox
> <https://github.com/metaperl/python-web-framework-comparison/blob/master/001-simple-tr/reahl/simple-tr/simple_tr.py#L88>.
>
> I simply want to take the form input data
> <https://github.com/metaperl/python-web-framework-comparison/blob/master/001-simple-tr/reahl/simple-tr/simple_tr.py#L61>
> and process that info to render a new field
> <https://github.com/metaperl/python-web-framework-comparison/blob/master/001-simple-tr/reahl/simple-tr/simple_tr.py#L88>.

From what I can see that is what your code does. What is your question?

-i


--

Reahl, the Python only web framework / www.reahl.org

Terrence Brannon

unread,
Oct 21, 2018, 2:47:14 PM10/21/18
to reahl-...@googlegroups.com
On Sun, Oct 21, 2018 at 10:34 AM Iwan Vosloo <iw...@reahl.org> wrote:
Hi Terrence,

On 21/10/2018 09:29, Terrence Brannon wrote:
> I am trying to create a simple web app:
>
>  1. It displays 3 input fields and a submit button on a form
>  2. When submit is pressed, the program uses the data in the 3 input
>     fields to render an OutputBox
>     <https://github.com/metaperl/python-web-framework-comparison/blob/master/001-simple-tr/reahl/simple-tr/simple_tr.py#L88>.

 From what I can see that is what your code does. What is your question?


  1. Currently the way to save state between page refreshes is being handled by this save method.  This save method suffers from the following flaws (1) it stores new data each time save is called. The only point of saving the data is so that the same page can retrieve and then process it after is called. Most web frameworks have some sort of session dictionary that you can throw things into and then get things out, and you are guaranteed of of having 0 or 1 data element. The current save method keeps adding more and more data.
  2. Retrieving the data after form submission involves getting the latest inserted data by using a descending sort. This is a design flaw. In most web frameworks, I would just be picking the data out of a singleton session stash. 
  3. So I would like to improve this code in two very different ways:
    1. I want to rectify the above two design flaws to show how easy it is to pop something into a Reahl session stash and then grab it on the next page invocation. Presumably this involves using @session_scoped, but I struggled for hours with that to no avail.
    2. Instead of having the page refresh, a very different design would simply grab the data from the first three form fields and use them to calculate what should go in the Output box and populate it, with no page refresh.
So, I would like to see implementations of both of these, preferably as pull requests on the repository. 

Also, what options do I have for paid commercial support with a guaranteed 24-hour response time, which might involve logging in and/or sharing screens/instant messaging?

- T

Iwan Vosloo

unread,
Oct 22, 2018, 1:56:52 AM10/22/18
to reahl-...@googlegroups.com
Hi Terrence,

On 21/10/2018 20:47, Terrence Brannon wrote:
> 3. So I would like to improve this code in two very different ways:
> 1. I want to rectify the above two design flaws to show how easy it
> is to pop something into a Reahl session stash and then grab it
> on the next page invocation. Presumably this involves
> using @session_scoped, but I struggled for hours with that to no
> avail.

Ok, yes, I have a few suggestions for how you can improve what you have
there and @session_scoped is one of them. Github seems to be having
issues currently - I will make suggestions in your project once it is OK
again.

In the mean time, @session_scoped is documented here:
https://www.reahl.org/docs/4.0/component/sqlalchemysupport.d.html

And here: https://www.reahl.org/docs/4.0/tutorial/sessions.d.html

Your "TR" would basically be used like LoginSession is used in the
tutorial example.

So, you'd be able to say:

tr = TR.for_current_session() and always get one.

This means TR should be able to be created with a NO arg constructor though.

> 2. Instead of having the page refresh, a very different design
> would simply grab the data from the first three form fields and
> use them to calculate what should go in the Output box and
> populate it, with no page refresh.

This would relate to having your output panel have Widget arguments
(explained here:
https://www.reahl.org/docs/4.0/tutorial/whathappenedtoajax.d.html )

As is released currently though, Widget arguments can only be used with
Bookmarks (and hence links) and I dont think you will be able to do with
that what you want. We are working on changing that though, which means
that Widget arguments can be passed from form Inputs and be triggered by
the onchange events of inputs on the page. In that scenario, your
outputpanel could change each time you tab out of one of your inputs.
Since we're still working on this stuff things are still evolving...but
you can have a look at
https://github.com/IwanVosloo/reahl/blob/iwan-responsive/reahl-web/reahl/web_dev/inputandvalidation/test_responsive_disclosure.py
if you want.

>
> So, I would like to see implementations of both of these, preferably as
> pull requests on the repository.

Yes, was planning to do that - will chat to you there more.

>
> Also, what options do I have for paid commercial support with a
> guaranteed 24-hour response time, which might involve logging in and/or
> sharing screens/instant messaging?
>

For that, please chat to me privately and we can set up something
suitable for you.
Reply all
Reply to author
Forward
0 new messages