request for comments

61 views
Skip to first unread message

Massimo DiPierro

unread,
Mar 16, 2015, 1:26:47 PM3/16/15
to web2py-d...@googlegroups.com
I have been working on this:


- {% …. %} web2py templates
- {{ …. }} are ractive client side templates
- forms are generated client-side and always submitted via Ajax
- controllers decorated with @ractive pass the dict(…) to JS ractive.data when ractive.fire(‘save’) the ractive.data.forms[….] are submitted back to the controller via Ajax postbacks.
- does not use any serverside helpers
- forms are customizable in ractive+html  https://github.com/mdipierro/w3/blob/master/views/forms.bs3.html

Massimo

Leonel Câmara

unread,
Mar 16, 2015, 2:00:48 PM3/16/15
to web2py-d...@googlegroups.com
I like very much the idea of having a base form with no HTML whatsoever. This would be easy to extend if I wanted a form that would generate the HTML for me. Of course it's missing some functionality like onvalidation, but the idea is good.

I don't like that this is a completely SPA. I find SPA to be good for very very specific applications, most applications that have broader functionality will want more than one page. I have web2py applications using ractive, usually I have more than one page that does it's specific task in a SPA like manner, for instance, I can have a debate area doing that, I can also have a classifieds area in the application doing it too, it doesn't make sense, to me, for them to be in the same page.  
  
I also notice that you didn't get rid of the problem of forms being different for different CSS frameworks, you just moved it to ractive. Arguably it may make sense if we evaluate that it's easier to make different ractive templates and include them. However, is the need to render forms in HTML server side really going away?

The code could use some comments describing the "why" (the ractive decorator for instance) otherwise I will need more time to understand it and give you better input.




Kiran Subbaraman

unread,
Mar 16, 2015, 2:01:43 PM3/16/15
to web2py-d...@googlegroups.com
Would like to try this out; it is a combination (web2py, ractive) that I would like to use, if possible.
I encounter this error though, and not sure how to proceed:

<type 'exceptions.ImportError'> No module named osutils
Version
web2py™     Version 2.9.12-stable+timestamp.2015.01.17.06.11.03
Python     Python 2.7.9: D:\programs\open\python27\python.exe (prefix: D:\programs\open\python27)
Traceback
Traceback (most recent call last):
  File "C:\Users\subbaraman\Downloads\web2py_src\web2py\gluon\restricted.py", line 224, in restricted
    exec ccode in environment
  File "C:/Users/subbaraman/Downloads/web2py_src/web2py/applications/w3/controllers/default.py", line 3, in <module>
    from osutils import get_files
  File "C:\Users\subbaraman\Downloads\web2py_src\web2py\gluon\custom_import.py", line 92, in custom_importer
    return base_importer(pname, globals, locals, fromlist, level)
ImportError: No module named osutils
________________________________________
Kiran Subbaraman
http://subbaraman.wordpress.com/about/
--
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
---
You received this message because you are subscribed to the Google Groups "web2py-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py-develop...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Massimo DiPierro

unread,
Mar 16, 2015, 2:04:45 PM3/16/15
to web2py-d...@googlegroups.com
This is not SPA. Every controller has its own page, very much like web2py does normally. In fact I provide examples of 3 different pages. 

It does solve the problems of forms being different for different CSS frameworks, except that the widgets are designed in ractive and not in Python.

Ractive is a required dependency but nothing else is.

Massimo DiPierro

unread,
Mar 16, 2015, 2:05:41 PM3/16/15
to web2py-d...@googlegroups.com
Sorry. I added the missing files.

Richard Vézina

unread,
Mar 16, 2015, 2:18:12 PM3/16/15
to web2py-d...@googlegroups.com
How validations will occure? Will the ajax get callback with "kind of regular" web2py validators constraints that didn't pass? How about case where you want complex form with conditional field that depending of selected values modified the whole form, so some fields has to be nullable... Actually it is really painful to avoid wizard for complex form, but I hate wizard and think it something from the pass...

Like the idea!!

Richard

Massimo DiPierro

unread,
Mar 16, 2015, 2:20:44 PM3/16/15
to web2py-d...@googlegroups.com
When you edit the form and press [submit] the form is submitted via ajax to the same action that generated the page. Then Form(..) validates using our beloved validators and returns a json response with a new form content that may include form errors. They are displayed by ractive as it redraws the form, but without reloading the page. From a user prospective and a programmer prospective is not different from now. It is just much faster and cleaner and magic.

Check the form.html page.

Richard Vézina

unread,
Mar 16, 2015, 2:41:53 PM3/16/15
to web2py-d...@googlegroups.com
Ok, that's great... Going JS, I would have a way to modify validator dynamically or avoid them... I guess since the form is in "JS" removing input field from HTML with ractive.js or other mean you solve the issue I am talking about... I guess each field/input are submitted individually (?) as and when they are completed... Or the whole form is still submit in one single action?

Until know, the only way I workaround dynamic form had to hide field/input and set field as nullable at model level... The main drawback was that I can't make sure some field/input are completed because I can't change the validator dynamically... The only remaining way I explore was going more dynamic with ractive.js, though I had to rely on HTML to force field/input to be completed and lost uniformity with the rest of form validation for fields that are required depending of the context of the form... I am sure my use case is not unique... Sure I can workaround this differently, mean using an other form system... 

But I really enjoy web2py!!

:D

So, having a mechanism to dynamically control validator would be great... I don't know which kind of security issues this could bring, but having this possibility would solve a big limitation I face that prevent me going next step very often because the overload of work doing so would generate...

Thanks

Richard

Massimo DiPierro

unread,
Mar 16, 2015, 3:03:29 PM3/16/15
to web2py-d...@googlegroups.com
On Mar 16, 2015, at 1:41 PM, Richard Vézina <ml.richa...@gmail.com> wrote:

Ok, that's great... Going JS, I would have a way to modify validator dynamically or avoid them... I guess since the form is in "JS" removing input field from HTML with ractive.js or other mean you solve the issue I am talking about... I guess each field/input are submitted individually (?) as and when they are completed... Or the whole form is still submit in one single action?

You can do both but in the example the form is submitted at once when you press the [submit] button.
All validators are server side so you can change them there as you normally do in web2py.
You can then add client side validation. I will add some.

Richard Vézina

unread,
Mar 16, 2015, 3:46:03 PM3/16/15
to web2py-d...@googlegroups.com
So, we now can change validators once form is generated since it is now decoupled from the controller it has been generated from??

Richard

Niphlod

unread,
Mar 16, 2015, 6:22:43 PM3/16/15
to web2py-d...@googlegroups.com
uhm. ATM the demo is pretty unusable: what are you running this app into ? sure it's web2py ? :D

{{=URL('static', '')}} isn't a proper way to return the base url for static files........ corrected to a fixed /w3/static/ ....
osutils's get_files isn't there .... mocked with a [a for a in os.listdir(path)], at least I can reach the app's index without errors.
markmin data isn't there....

ok, it's a POC, I fixed it to reach the "index" page ..... then, what should I do ? :D

got the forms base idea... ractive supports ie8+, JSON.stringify is available on ie8 (altough only in standards mode), so we are covered from ie8 onwards.
fast notes:
- too much globals around, available and hackable by whatever js lib is included
- there's a lot of ractive templating niceties around... but I'm not sure I'll be proficient with it in less than 2 weeks, and I worked with ractive before...guess I'll need to learn another template language
- file submission and ajax don't really play nice: there would be a taddle bit of machinery to support it out of the box with the current ractive features
- still need to see if my wonderful plugins for inputs (taggers, select2-like autocomplete, etc) are ractive-compatible: reinventing the wheel takes time, and nobody seems to care for ractive plugins ecosystem (in comparison with, e.g., react or angular)
- forms are not implemented with the correct logic regarding errors....hopefully a form-group {{#error}}has-error{{/error}} should fix that but.......that file is going to be shipped with every page requesting a form....a logic to fetch only the needed bits (AMD like) could take a while to implement
- double-submission!

less important...messages dropdown including errors.......took ages to find it!

BTW: what's smartramcache for ?

Massimo DiPierro

unread,
Mar 16, 2015, 6:29:45 PM3/16/15
to web2py-d...@googlegroups.com
On Mar 16, 2015, at 5:22 PM, Niphlod <nip...@gmail.com> wrote:

uhm. ATM the demo is pretty unusable: what are you running this app into ? sure it's web2py ? :D

{{=URL('static', '')}} isn't a proper way to return the base url for static files........ corrected to a fixed /w3/static/ ....
osutils's get_files isn't there .... mocked with a [a for a in os.listdir(path)], at least I can reach the app's index without errors.
markmin data isn't there….

works with trunk. I know it is an odd syntax but the reason is that I want some parts of this to be easily portable to other frameworks.


ok, it's a POC, I fixed it to reach the "index" page ..... then, what should I do ? :D

got the forms base idea... ractive supports ie8+, JSON.stringify is available on ie8 (altough only in standards mode), so we are covered from ie8 onwards.

:-)

fast notes:
- too much globals around, available and hackable by whatever js lib is included
- there's a lot of ractive templating niceties around... but I'm not sure I'll be proficient with it in less than 2 weeks, and I worked with ractive before...guess I'll need to learn another template language
- file submission and ajax don't really play nice: there would be a taddle bit of machinery to support it out of the box with the current ractive features
- still need to see if my wonderful plugins for inputs (taggers, select2-like autocomplete, etc) are ractive-compatible: reinventing the wheel takes time, and nobody seems to care for ractive plugins ecosystem (in comparison with, e.g., react or angular)
- forms are not implemented with the correct logic regarding errors....hopefully a form-group {{#error}}has-error{{/error}} should fix that but.......that file is going to be shipped with every page requesting a form....a logic to fetch only the needed bits (AMD like) could take a while to implement
- double-submission!

less important...messages dropdown including errors.......took ages to find it!
BTW: what's smartramcache for ?

I want to cache in ram session on db when they are sticky. Not currently used.

Niphlod

unread,
Mar 16, 2015, 6:51:02 PM3/16/15
to web2py-d...@googlegroups.com


On Monday, March 16, 2015 at 11:29:45 PM UTC+1, Massimo Di Pierro wrote:

works with trunk. I know it is an odd syntax but the reason is that I want some parts of this to be easily portable to other frameworks.

trunk is failing all tests with that change to URL(), did you notice ?
 

I want to cache in ram session on db when they are sticky. Not currently used.


I'd have a lot of doubts it can be stable but let's leave it out of the picture.

Massimo DiPierro

unread,
Mar 16, 2015, 7:08:05 PM3/16/15
to web2py-d...@googlegroups.com
oops. No i did not notice. I will revert.

Massimo

Massimo DiPierro

unread,
Mar 16, 2015, 7:28:05 PM3/16/15
to web2py-d...@googlegroups.com
On Mar 16, 2015, at 5:29 PM, Massimo DiPierro <massimo....@gmail.com> wrote:


On Mar 16, 2015, at 5:22 PM, Niphlod <nip...@gmail.com> wrote:
[…]

fast notes:
- too much globals around, available and hackable by whatever js lib is included

Any client-side app is “hackable” by js files. ;-)

- there's a lot of ractive templating niceties around... but I'm not sure I'll be proficient with it in less than 2 weeks, and I worked with ractive before...guess I'll need to learn another template language
- file submission and ajax don't really play nice: there would be a taddle bit of machinery to support it out of the box with the current ractive features

I am leaning towards not allowing “uploads” as part of normal forms but have separate forms just for file uploads (for this app only).

- still need to see if my wonderful plugins for inputs (taggers, select2-like autocomplete, etc) are ractive-compatible: reinventing the wheel takes time, and nobody seems to care for ractive plugins ecosystem (in comparison with, e.g., react or angular)

they will work as long the ractive partials are not refreshed. They they will break (for example if there are errors in the form). There is a way around. But clearly this is a departure from the “web2py way” and I expect most stuff to break.

- forms are not implemented with the correct logic regarding errors....hopefully a form-group {{#error}}has-error{{/error}} should fix that but.......that file is going to be shipped with every page requesting a form....a logic to fetch only the needed bits (AMD like) could take a while to implement

True.

- double-submission!

right. working on it.


less important...messages dropdown including errors.......took ages to find it!

I am trying to have that open by default.

Niphlod

unread,
Mar 16, 2015, 8:05:31 PM3/16/15
to web2py-d...@googlegroups.com


On Tuesday, March 17, 2015 at 12:28:05 AM UTC+1, Massimo Di Pierro wrote:

On Mar 16, 2015, at 5:29 PM, Massimo DiPierro <massimo....@gmail.com> wrote:


On Mar 16, 2015, at 5:22 PM, Niphlod <nip...@gmail.com> wrote:
[…]
fast notes:
- too much globals around, available and hackable by whatever js lib is included

Any client-side app is “hackable” by js files. ;-)

well, any app at that point. jm2c, collisions and hacks are a lot easier with a global DATA object than an object defined in an IIFE.

Massimo DiPierro

unread,
Mar 16, 2015, 8:15:55 PM3/16/15
to web2py-d...@googlegroups.com
What’s IIFE?

Jonathan Lundell

unread,
Mar 16, 2015, 8:21:46 PM3/16/15
to web2py-d...@googlegroups.com
On 16 Mar 2015, at 5:15 PM, Massimo DiPierro <massimo....@gmail.com> wrote:

What’s IIFE?

Niphlod

unread,
Mar 16, 2015, 8:23:46 PM3/16/15
to web2py-d...@googlegroups.com
http://en.wikipedia.org/wiki/Immediately-invoked_function_expression .
And yes, after a lot of struggles, we have a - kind of, it needed hookability too - form of it in web2py.js !

Massimo DiPierro

unread,
Mar 16, 2015, 8:24:47 PM3/16/15
to web2py-d...@googlegroups.com
Thanks Jonathan.

there are only 3 global objects:
STATIC, DATA, PATH and ractive. 

The first three can be eliminated. The last one can be but into an IIFE but I really want to have it exposed so that used can register events using it. That’s the whole point.
Reply all
Reply to author
Forward
0 new messages