[web2py] Implementing A Large Scale Engineering Equations Calculator in web2py

2014-08-13 Thread Richard
Nice idea :).
I would create a database with the equations including metadata and create 
froms dynamically like sqlform.
A table would have all the equations referring to an other tabel having the 
equation components als calulated fields.

Think from a database driven design rather than a view based design. Web2py 
allows you to prototype with the database very fast.
So start out testing the tips and your own ideas by building the app. When you 
have your equation frame work you can improve the layout and style.

Richard D

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Strange ajax problem

2014-08-13 Thread Cliff Kachinske
Here's how I do it and I assume Web2py does something similar when it, for 
example, resets the "Working" caption on buttons.

The Javascript/Jquery whatever in the client changes the state of the 
button. I do it before sending the ajax post. I don't know how Web2py does 
it.

It doesn't matter whether it's JQuery's ajax or Web2py's ajax. The syntax 
is a little different between the two, but the overall process is the same. 
The client sends a request that gets routed to a function. The function 
returns a response.

In that response you would include, assuming JQuery has been loaded on the 
page, something like 
"$('#somentity_on_page').whatever_attribute_needs_changing('new state of 
the attribute');

Web2py isn't intercepting anything. You push a button, click a link, 
whatever, the browser sends a request. The request goes to your web server, 
be it Rocket, Apache, Nginx, any other. The web server sends the request to 
Web2py because the server is set up that way. Web2py then processes the 
request and returns a response. 

Excuse me if I'm interpreting incorrectly, but your questions suggest a 
certain misunderstanding about what's going on. Chapters 1, 3 and 4 of the 
Web2py manual provide a pretty good overview of how this all works. If I 
recall correctly, Wikipedia has some reasonably good articles about http, 
http requests and http responses.

On Wednesday, August 13, 2014 6:51:59 PM UTC-4, Michael Beller wrote:
>
> Thanks ...
>
> Niphlod - I'll try to create a minimal app to reproduce.
>
> Cliff - are you suggesting to use the web2py ajax function rather 
> the jQuery post?
>
> I'm also trying to understand why web2py is intercepting the event and why 
> it doesn't think the response is succesful which I assume is why the button 
> is not re-enabled.
>
> On Wednesday, August 13, 2014 5:18:42 PM UTC-4, Cliff Kachinske wrote:
>>
>> get rid of the target in your ajax call and use ':eval' instead.
>>
>> Then reset the button in your response.
>>
>> On Sunday, May 4, 2014 9:33:05 AM UTC-4, John Drake wrote:
>>>
>>> I've created a simple ajax form to update a "post" database.  For some 
>>> strange reason when I post a new message, the button greys out.
>>>
>>> Here is the model:
>>>
>>> db.define_table('t_post',
>>> Field('f_post', type='text',
>>>   label=T('Post')),
>>> auth.signature,
>>> format='%(f_post)s')
>>>
>>> Here are my controller functions.
>>>
>>> def ajax_post():
>>> posts = crud.select(db.t_post, fields=['f_post'], query = 
>>> db.t_post.created_by == auth.user,
>>>headers={'t_post.f_post': 'Post'}, orderby = 
>>> ~db.t_post.created_on)
>>> search = crud.search(db.t_post)
>>> return dict(posts=posts, search=search)
>>>
>>> def new_post():
>>> postdata = request.vars.post
>>> db.t_post.insert(f_post = postdata)
>>> posts = crud.select(db.t_post, fields=['f_post'], query = 
>>> db.t_post.created_by == auth.user,
>>>headers={'t_post.f_post': 'Post'}, orderby = 
>>> ~db.t_post.created_on)
>>> return posts
>>>
>>> Here is the model:
>>>
>>> {{extend 'layout.html'}}
>>> This is the default/ajax_post.html template
>>> 
>>> Post : 
>>> Post 
>>> Message
>>> 
>>> 
>>> {{=posts}}
>>> 
>>> 
>>> {{=search[0]}}
>>> 
>>>
>>> At first I used an input field with type "submit" for the submit 
>>> button.  When that happened, it would 
>>> grey out and the value would set to "Working".  At least now button 
>>> text doesn't change, but it
>>> it still grey's out.  Inspecting the element in Firefox I get:
>>>
>>> >> onclick="ajax('new_post', ['post'],'results')">Post Message
>>>
>>> Why?  I didn't ask it to change the button's class to disabled.  And it 
>>> stays greyed even though
>>> the results have returned and my "results" div has been properly 
>>> updated.  I can still click on
>>> the button, but it just appears disabled. 
>>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Strange ajax problem

2014-08-13 Thread Michael Beller
Thanks ...

Niphlod - I'll try to create a minimal app to reproduce.

Cliff - are you suggesting to use the web2py ajax function rather 
the jQuery post?

I'm also trying to understand why web2py is intercepting the event and why 
it doesn't think the response is succesful which I assume is why the button 
is not re-enabled.

On Wednesday, August 13, 2014 5:18:42 PM UTC-4, Cliff Kachinske wrote:
>
> get rid of the target in your ajax call and use ':eval' instead.
>
> Then reset the button in your response.
>
> On Sunday, May 4, 2014 9:33:05 AM UTC-4, John Drake wrote:
>>
>> I've created a simple ajax form to update a "post" database.  For some 
>> strange reason when I post a new message, the button greys out.
>>
>> Here is the model:
>>
>> db.define_table('t_post',
>> Field('f_post', type='text',
>>   label=T('Post')),
>> auth.signature,
>> format='%(f_post)s')
>>
>> Here are my controller functions.
>>
>> def ajax_post():
>> posts = crud.select(db.t_post, fields=['f_post'], query = 
>> db.t_post.created_by == auth.user,
>>headers={'t_post.f_post': 'Post'}, orderby = 
>> ~db.t_post.created_on)
>> search = crud.search(db.t_post)
>> return dict(posts=posts, search=search)
>>
>> def new_post():
>> postdata = request.vars.post
>> db.t_post.insert(f_post = postdata)
>> posts = crud.select(db.t_post, fields=['f_post'], query = 
>> db.t_post.created_by == auth.user,
>>headers={'t_post.f_post': 'Post'}, orderby = 
>> ~db.t_post.created_on)
>> return posts
>>
>> Here is the model:
>>
>> {{extend 'layout.html'}}
>> This is the default/ajax_post.html template
>> 
>> Post : 
>> Post 
>> Message
>> 
>> 
>> {{=posts}}
>> 
>> 
>> {{=search[0]}}
>> 
>>
>> At first I used an input field with type "submit" for the submit button.  
>> When that happened, it would 
>> grey out and the value would set to "Working".  At least now button 
>> text doesn't change, but it
>> it still grey's out.  Inspecting the element in Firefox I get:
>>
>> Post Message
>>
>> Why?  I didn't ask it to change the button's class to disabled.  And it 
>> stays greyed even though
>> the results have returned and my "results" div has been properly 
>> updated.  I can still click on
>> the button, but it just appears disabled. 
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Can I create an RSS Reader like Techi in web2py?

2014-08-13 Thread Ricardo Pedroso
Next weekend I can share the code. I have to cleanning it a little bit.

Ricardo


On 8/11/14, Gideon George  wrote:
>
>>
>> WOW! That's really great to hear. I don't even know how to start
>> appreciating right now.
>
> I am really grateful for that, Absolutely grateful! I will love to learn
> and implement it. it's gonna help me alot.
> Thank you very much and I pray that God grant you all your heart desires,
> Amen.
>
> It's my very first web2py app and I am really learning and excited. I want
> to be one of the best in Africa, and I am on my way...I just can't wait to
> start!
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: bootstrap 3 - if you care help test trunk now

2014-08-13 Thread Ricardo Pedroso
I can make a patch in next friday/weekend, but you want a patch against what?

What I've attached was a simple app showing two bootstrap3 formstyle
alternatives.

Should I patch the formstyle_bootstrap3 in sqlhtml.py?

Ricardo


On 8/11/14, Massimo Di Pierro  wrote:
> Would you send me this as a patch? I too would prefer to default to NO
> col-lg-*
>
> On Sunday, 10 August 2014 17:25:51 UTC-5, Ricardo Pedroso wrote:
>>
>> On 8/10/14, Massimo Di Pierro  wrote:
>> > https://github.com/web2py/web2py/archive/master.zip
>> >
>> > note, you have to use formstyle. For auth forms this is now set by
>> default
>> > in db.py.
>> >
>> > form = SQLFORM(..., formstyle = SQLFORM.formstyles.bootstrap3)
>>
>> I only test SQLFORM.
>> I don't like to see the col-lg-'s hardcoded in the bootstrap3 formstyle
>>
>> I've attached a small app with two bootstrap3 formstyles.
>> One is for horizontal forms and the other is for vertical forms
>> It's more close to what I would like to have in web2py.
>>
>> Just unzip in web2py/applications folder. It will create an app named
>> "bs3"
>> Then:
>> http://localhost:8000/bs3
>>
>> Ricardo
>>
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Hypermedia API and Collection+JSON in web2py

2014-08-13 Thread Cliff Kachinske
Massimo,

The new recipe you propose is "bottle+dal+validators+auth+collection"

Could it be "bottle++validators+auth+collection?  

I have found myself needing to execute complex SQL queries. In this 
situation, in my opinion, psycopg2 would serve me just as well as dal.

On Sunday, June 22, 2014 4:45:06 PM UTC-4, Massimo Di Pierro wrote:
>
> I added Hypermedia API support to web2py using Collection+JSON. 
> Experimental.
> Collection+JSON is a standard for self documenting RESTful API.
> Read more: http://amundsen.com/media-types/collection/
>
> Example
> =
>
> Let's say you have a model:
>  
> db.define_table('thing',Field('name'))
>
> and in controller default.py you add
>
> def api():
>  from gluon.contrib.hypermedia import Collection
>  rules = {
> 'thing': {
> 'GET':{'query':None,'fields':['id', 'name']},
> 'POST':{'query':None,'fields':['name']},
> 'PUT':{'query':None,'fields':['name']},
> 'DELETE':{'query':None},
>}}
> return Collection(db).process(request,response,rules)
>
> And now by magic your table "thing" is fully exposed using the 
> Collection+JSON API. The API is self documenting and supports GET, POST, 
> PUT, DELETE, etc.
>
> For example you can do things like:
>
> curl http://127.0.0.1:8000/app/default/api/thing
> curl http://127.0.0.1:8000/app/default/api/thing/1
> curl http://127.0.0.1:8000/app/default/api/thing?id=1
> curl 
> http://127.0.0.1:8000/app/default/api/thing?name=Box&id.gt=10&_offest=10&_limit=30
> curl -X POST -d name="Box" http://127.0.0.1:8000/app/default/api/thing
> curl -X PUT -d name="Chair" http://127.0.0.1:8000/app/default/api/thing
> ?name=Box
> curl -X DELETE 
> http://127.0.0.1:8000/super/collections/conform/thing?name=Chair
>
> The API are completely self documenting as explained here 
> http://amundsen.com/media-types/collection/
>
> It is customizable
> ==
>
>rules = {
> 'thing': {
> 'GET':{'query':None,'fields':['id', 'name']},
> 'POST':{'query':None,'fields':['name']},
> 'PUT':{'query':None,'fields':['name']},
> 'DELETE':{'query':None},
>}}
>
> Let you specify which tables are exposed, which methods are available and 
> which fields are exposed for each method. The query property lets you 
> specify optional filters for example  { 
> 'query':db.thing.name.startswith('A'),} will only exposed things 
> starting with letter A. Fields can be conditional and different for 
> different users or for the same user in different stages of a workflow (the 
> communication is stateless, but the server is not).
>
> Supports complex queries
> =
> http:/./{table}
> http:/./{table}/{id}
> http:/./{table}?{field}=value
> http:/./{table}?{field}.gt=value # field>value
> http:/./{table}?{field}.le=value # field<=value
> ...
> http:/./{table}?_orderby={field}
> http:/./{table}?_limitby=value
> http:/./{table}?_offset=value
> ...
> and combinations there of. They are mapped directly into DAL queries. More 
> examples are in the API response itself.
>
> The bigger picture
> ===
>
> This API provide enough information to generate forms and tables and grid 
> completely client side. Recently we stumbled against the problem of moving 
> from Bootstrap 2 to Bootstrap 3 because so much of the form and grid logic 
> is server side. My plan is to move most of the logic in the JS library and 
> allow users to customize them  for different CSS frameworks.
>
> Eventually (in dreams) I would like to have a very slim framework based on 
> bottle+dal+validators+auth+collection and have client side only templates 
> (based on jquery, sugar, and ractive.js) that can generate forms and grids 
> based the collection API. This framework could ship with web2py and allow 
> you to program using same web interface that we all love. There are many 
> design decisions to make to get there. Your suggestions are welcome.
>
> How can you help?
> ===
> 1) test it.
> 2) there are many existing client side tools for Collection+JSON. Try them 
> with web2py.
> 3) blog about it and suggest improvements.
>
>
> I said, it is experimental
> ===
>
> Collection+JSON has limits:
> - it is very verbose JSON. This is my my implementation has  compact=True 
> option that breaks the protocol but makes much smaller JSON messages.
> - it does not convey field type information and constraints. This is why I 
> extended to do so but more work is needed because DAL types do not map into 
> HTML5 input types (this of list:string or list:reference).
>
> More extensions of the protocol are required. Extensions are allowed. Yet 
> they may change the API in the near future.
>
> Massimo
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Docum

[web2py] Re: Strange ajax problem

2014-08-13 Thread Cliff Kachinske
get rid of the target in your ajax call and use ':eval' instead.

Then reset the button in your response.

On Sunday, May 4, 2014 9:33:05 AM UTC-4, John Drake wrote:
>
> I've created a simple ajax form to update a "post" database.  For some 
> strange reason when I post a new message, the button greys out.
>
> Here is the model:
>
> db.define_table('t_post',
> Field('f_post', type='text',
>   label=T('Post')),
> auth.signature,
> format='%(f_post)s')
>
> Here are my controller functions.
>
> def ajax_post():
> posts = crud.select(db.t_post, fields=['f_post'], query = 
> db.t_post.created_by == auth.user,
>headers={'t_post.f_post': 'Post'}, orderby = 
> ~db.t_post.created_on)
> search = crud.search(db.t_post)
> return dict(posts=posts, search=search)
>
> def new_post():
> postdata = request.vars.post
> db.t_post.insert(f_post = postdata)
> posts = crud.select(db.t_post, fields=['f_post'], query = 
> db.t_post.created_by == auth.user,
>headers={'t_post.f_post': 'Post'}, orderby = 
> ~db.t_post.created_on)
> return posts
>
> Here is the model:
>
> {{extend 'layout.html'}}
> This is the default/ajax_post.html template
> 
> Post : 
> Post 
> Message
> 
> 
> {{=posts}}
> 
> 
> {{=search[0]}}
> 
>
> At first I used an input field with type "submit" for the submit button.  
> When that happened, it would 
> grey out and the value would set to "Working".  At least now button 
> text doesn't change, but it
> it still grey's out.  Inspecting the element in Firefox I get:
>
> Post Message
>
> Why?  I didn't ask it to change the button's class to disabled.  And it 
> stays greyed even though
> the results have returned and my "results" div has been properly updated.  
> I can still click on
> the button, but it just appears disabled. 
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: What is the right way to serve static files through a CDN ?

2014-08-13 Thread Cliff Kachinske
If, like me, you use the same static files on every page, just hard code 
them into layout.html.

I realize this may make upgrading more, um, interesting, but it's much 
simpler than pattern-based routing.

On Wednesday, August 13, 2014 11:23:52 AM UTC-4, Louis Amon wrote:
>
> I am using a CDN and am trying to configure web2py to use it instead of 
> the classic static file service.
>
> So far I've been using pattern-based routes like this :
>
> cdn = 'https://xxx.cloudfront.net'
>
> routes_in = (...
>  ('/static/$anything', cdn + '/static/$anything'),
>  ...
>  )
>
> routes_out = (...
>  ('/static/$anything', cdn + '/static/$anything'),
>  ...
>  )
>
> This basically works, but this has to be implemented on a pattern-based 
> routes.py which means I lose many cool features like map_hyphen, 
> default_application, default_controller mappings...
>
> Is there a way to use a CDN with a parametric router ?
>
> I read somewhere that the host parameter in URL can also be used to setup 
> a CDN, but it seems a bit tedious to find all URL and rewrite them.
>
> Isn't there a variable in gluon.rewrite that I can mess with to trick 
> web2py into serving CDN-based content ?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Strange ajax problem

2014-08-13 Thread Niphlod
you can use whatever you like it just needs to accomodate how web2py 
handles ajax.
Without a complete example I can't tell what's going wrong with your own 
implementation. If you can, pack a minimal app to reproduce the behaviour

On Wednesday, August 13, 2014 10:50:54 PM UTC+2, Michael Beller wrote:
>
> Thanks Niphlod,
>
> I'm not using inline JS or explicitly using web2py.js.
>
> I'm using a Bootstrap Modal pretty much verbatim from the Bootstrap 
> examples.  It appears that web2py js is capturing the submit and disabling 
> the button but not detecting the response and enabling the submit - is that 
> correct? should I not use the Bootstrap js?
>
> Here's my function:
> $('#note-form').submit(function(e) {
> e.preventDefault();
> $form= $(this);
> $.post("/app/controller/action.json",
>{formdata: $form.serialize(),
> note_id: $('#note-id').val(),
> note_text: $('#note-text').val()
>},
>function(data) {
>$('#form-feedback').html(data.notes).fadeIn(500);
>$form[0].reset();
>}
>);
>});
>
>
> On Wednesday, August 13, 2014 4:29:47 PM UTC-4, Niphlod wrote:
>>
>> the logic behind is suppressing double submission. web2py disables the 
>> submit button when you click on it until a proper response is returned. 
>> Don't EVER use inline javascript, and don't use web2py.js internal 
>> functions without proper knowledge of the inner workings :-P  
>>
>> On Wednesday, August 13, 2014 8:52:25 PM UTC+2, Michael Beller wrote:
>>>
>>> I just encountered the same problem.  I'm using a Bootstrap Modal form 
>>> and encountering the same problem - the form sends and receives data via 
>>> AJAX but then adds the 'disabled' class to the button.
>>>
>>> I found this logic in web2py.js but I'm not clear on what's happening 
>>> and why:
>>>
>>> // Form input elements disabled during form submission
>>> disableSelector: 'input, button, textarea, select',
>>>// Form input elements re-enabled after form submission
>>> enableSelector: 'input:disabled, button:disabled, 
>>> textarea:disabled, select:disabled',
>>>
>>> Have either of you found a solution?
>>>
>>> On Sunday, August 3, 2014 2:53:50 PM UTC-4, Reza Amindarbari wrote:

 Did you figure out what was wrong? I faced the same issue. Everything 
 works fine when I take out the ajax function.

 On Sunday, May 4, 2014 9:33:05 AM UTC-4, John Drake wrote:
>
> I've created a simple ajax form to update a "post" database.  For some 
> strange reason when I post a new message, the button greys out.
>
> Here is the model:
>
> db.define_table('t_post',
> Field('f_post', type='text',
>   label=T('Post')),
> auth.signature,
> format='%(f_post)s')
>
> Here are my controller functions.
>
> def ajax_post():
> posts = crud.select(db.t_post, fields=['f_post'], query = 
> db.t_post.created_by == auth.user,
>headers={'t_post.f_post': 'Post'}, orderby = 
> ~db.t_post.created_on)
> search = crud.search(db.t_post)
> return dict(posts=posts, search=search)
>
> def new_post():
> postdata = request.vars.post
> db.t_post.insert(f_post = postdata)
> posts = crud.select(db.t_post, fields=['f_post'], query = 
> db.t_post.created_by == auth.user,
>headers={'t_post.f_post': 'Post'}, orderby = 
> ~db.t_post.created_on)
> return posts
>
> Here is the model:
>
> {{extend 'layout.html'}}
> This is the default/ajax_post.html template
> 
> Post : 
> Post 
> Message
> 
> 
> {{=posts}}
> 
> 
> {{=search[0]}}
> 
>
> At first I used an input field with type "submit" for the submit 
> button.  When that happened, it would 
> grey out and the value would set to "Working".  At least now 
> button text doesn't change, but it
> it still grey's out.  Inspecting the element in Firefox I get:
>
>  onclick="ajax('new_post', ['post'],'results')">Post Message
>
> Why?  I didn't ask it to change the button's class to disabled.  And 
> it stays greyed even though
> the results have returned and my "results" div has been properly 
> updated.  I can still click on
> the button, but it just appears disabled. 
>


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Strange ajax problem

2014-08-13 Thread Michael Beller
Thanks Niphlod,

I'm not using inline JS or explicitly using web2py.js.

I'm using a Bootstrap Modal pretty much verbatim from the Bootstrap 
examples.  It appears that web2py js is capturing the submit and disabling 
the button but not detecting the response and enabling the submit - is that 
correct? should I not use the Bootstrap js?

Here's my function:
$('#note-form').submit(function(e) {
e.preventDefault();
$form= $(this);
$.post("/app/controller/action.json",
   {formdata: $form.serialize(),
note_id: $('#note-id').val(),
note_text: $('#note-text').val()
   },
   function(data) {
   $('#form-feedback').html(data.notes).fadeIn(500);
   $form[0].reset();
   }
   );
   });


On Wednesday, August 13, 2014 4:29:47 PM UTC-4, Niphlod wrote:
>
> the logic behind is suppressing double submission. web2py disables the 
> submit button when you click on it until a proper response is returned. 
> Don't EVER use inline javascript, and don't use web2py.js internal 
> functions without proper knowledge of the inner workings :-P  
>
> On Wednesday, August 13, 2014 8:52:25 PM UTC+2, Michael Beller wrote:
>>
>> I just encountered the same problem.  I'm using a Bootstrap Modal form 
>> and encountering the same problem - the form sends and receives data via 
>> AJAX but then adds the 'disabled' class to the button.
>>
>> I found this logic in web2py.js but I'm not clear on what's happening and 
>> why:
>>
>> // Form input elements disabled during form submission
>> disableSelector: 'input, button, textarea, select',
>>// Form input elements re-enabled after form submission
>> enableSelector: 'input:disabled, button:disabled, textarea:disabled, 
>> select:disabled',
>>
>> Have either of you found a solution?
>>
>> On Sunday, August 3, 2014 2:53:50 PM UTC-4, Reza Amindarbari wrote:
>>>
>>> Did you figure out what was wrong? I faced the same issue. Everything 
>>> works fine when I take out the ajax function.
>>>
>>> On Sunday, May 4, 2014 9:33:05 AM UTC-4, John Drake wrote:

 I've created a simple ajax form to update a "post" database.  For some 
 strange reason when I post a new message, the button greys out.

 Here is the model:

 db.define_table('t_post',
 Field('f_post', type='text',
   label=T('Post')),
 auth.signature,
 format='%(f_post)s')

 Here are my controller functions.

 def ajax_post():
 posts = crud.select(db.t_post, fields=['f_post'], query = 
 db.t_post.created_by == auth.user,
headers={'t_post.f_post': 'Post'}, orderby = 
 ~db.t_post.created_on)
 search = crud.search(db.t_post)
 return dict(posts=posts, search=search)

 def new_post():
 postdata = request.vars.post
 db.t_post.insert(f_post = postdata)
 posts = crud.select(db.t_post, fields=['f_post'], query = 
 db.t_post.created_by == auth.user,
headers={'t_post.f_post': 'Post'}, orderby = 
 ~db.t_post.created_on)
 return posts

 Here is the model:

 {{extend 'layout.html'}}
 This is the default/ajax_post.html template
 
 Post : 
 Post 
 Message
 
 
 {{=posts}}
 
 
 {{=search[0]}}
 

 At first I used an input field with type "submit" for the submit 
 button.  When that happened, it would 
 grey out and the value would set to "Working".  At least now button 
 text doesn't change, but it
 it still grey's out.  Inspecting the element in Firefox I get:

 >>> onclick="ajax('new_post', ['post'],'results')">Post Message

 Why?  I didn't ask it to change the button's class to disabled.  And it 
 stays greyed even though
 the results have returned and my "results" div has been properly 
 updated.  I can still click on
 the button, but it just appears disabled. 

>>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Strange ajax problem

2014-08-13 Thread Niphlod
the logic behind is suppressing double submission. web2py disables the 
submit button when you click on it until a proper response is returned. 
Don't EVER use inline javascript, and don't use web2py.js internal 
functions without proper knowledge of the inner workings :-P  

On Wednesday, August 13, 2014 8:52:25 PM UTC+2, Michael Beller wrote:
>
> I just encountered the same problem.  I'm using a Bootstrap Modal form and 
> encountering the same problem - the form sends and receives data via AJAX 
> but then adds the 'disabled' class to the button.
>
> I found this logic in web2py.js but I'm not clear on what's happening and 
> why:
>
> // Form input elements disabled during form submission
> disableSelector: 'input, button, textarea, select',
> // Form input elements re-enabled after form submission
> enableSelector: 'input:disabled, button:disabled, textarea:disabled, 
> select:disabled',
>
> Have either of you found a solution?
>
> On Sunday, August 3, 2014 2:53:50 PM UTC-4, Reza Amindarbari wrote:
>>
>> Did you figure out what was wrong? I faced the same issue. Everything 
>> works fine when I take out the ajax function.
>>
>> On Sunday, May 4, 2014 9:33:05 AM UTC-4, John Drake wrote:
>>>
>>> I've created a simple ajax form to update a "post" database.  For some 
>>> strange reason when I post a new message, the button greys out.
>>>
>>> Here is the model:
>>>
>>> db.define_table('t_post',
>>> Field('f_post', type='text',
>>>   label=T('Post')),
>>> auth.signature,
>>> format='%(f_post)s')
>>>
>>> Here are my controller functions.
>>>
>>> def ajax_post():
>>> posts = crud.select(db.t_post, fields=['f_post'], query = 
>>> db.t_post.created_by == auth.user,
>>>headers={'t_post.f_post': 'Post'}, orderby = 
>>> ~db.t_post.created_on)
>>> search = crud.search(db.t_post)
>>> return dict(posts=posts, search=search)
>>>
>>> def new_post():
>>> postdata = request.vars.post
>>> db.t_post.insert(f_post = postdata)
>>> posts = crud.select(db.t_post, fields=['f_post'], query = 
>>> db.t_post.created_by == auth.user,
>>>headers={'t_post.f_post': 'Post'}, orderby = 
>>> ~db.t_post.created_on)
>>> return posts
>>>
>>> Here is the model:
>>>
>>> {{extend 'layout.html'}}
>>> This is the default/ajax_post.html template
>>> 
>>> Post : 
>>> Post 
>>> Message
>>> 
>>> 
>>> {{=posts}}
>>> 
>>> 
>>> {{=search[0]}}
>>> 
>>>
>>> At first I used an input field with type "submit" for the submit 
>>> button.  When that happened, it would 
>>> grey out and the value would set to "Working".  At least now button 
>>> text doesn't change, but it
>>> it still grey's out.  Inspecting the element in Firefox I get:
>>>
>>> >> onclick="ajax('new_post', ['post'],'results')">Post Message
>>>
>>> Why?  I didn't ask it to change the button's class to disabled.  And it 
>>> stays greyed even though
>>> the results have returned and my "results" div has been properly 
>>> updated.  I can still click on
>>> the button, but it just appears disabled. 
>>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: question about db.mytable.update_or_insert()

2014-08-13 Thread Niphlod
there's no other way around it, in every programming language. You want to 
do something in a transaction, the db won't let you do it, you catch the 
exception (rollbacking) and deal with it.

On Wednesday, August 13, 2014 7:30:58 PM UTC+2, Jack Kuan wrote:
>
> How does one usually deal with such conflict? (two identical(except for 
> id's) inserts causing a violation of an unique constraint)
>
> Isolating the insert into its own transaction and then do a db.commit(), 
> catch any exception and then ignore?
>
> Thanks
>
> On Wednesday, August 13, 2014 10:57:13 AM UTC-4, Niphlod wrote:
>>
>> the problem in concurrency (andduplication) isn't the update part, it's 
>> the insert part
>>
>> On Wednesday, August 13, 2014 1:39:56 PM UTC+2, Leonel Câmara wrote:
>>>
>>> Couldn't he use a _for_update argument there to make this work in some 
>>> adapters?
>>>
>>> db.mytable.update_or_insert(q, name='test', _for_update=True)
>>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Seeking Experienced web2py Functional Tester

2014-08-13 Thread Mark Graves
Hey everyone!

We are looking for a functional test script to be written for a web2py 
application for a small fee.

We will provide a test environment, user access control list, list of 
URL's, expected results, and actual results.

Results are behavioral in nature and will include modals.

We are looking to use gluon.contrib.webclient, lettuce, or selenium.

If you are free and have experience in this area, we'd love to hear from 
you!  Feel free to email me directly for more details.

Otherwise, this will be posted on elance and o-desk.

Thanks!

-Mark

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] web2py grid select all filtred rows

2014-08-13 Thread keiser1080
thanks for you reply.
I will check tomorro at work.
so on the controler i can get the rows by doing grid.rows?
The query is also stored on an accessible grid proprety ?




>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Strange ajax problem

2014-08-13 Thread Michael Beller
I just encountered the same problem.  I'm using a Bootstrap Modal form and 
encountering the same problem - the form sends and receives data via AJAX 
but then adds the 'disabled' class to the button.

I found this logic in web2py.js but I'm not clear on what's happening and 
why:

// Form input elements disabled during form submission
disableSelector: 'input, button, textarea, select',
// Form input elements re-enabled after form submission
enableSelector: 'input:disabled, button:disabled, textarea:disabled, 
select:disabled',

Have either of you found a solution?

On Sunday, August 3, 2014 2:53:50 PM UTC-4, Reza Amindarbari wrote:
>
> Did you figure out what was wrong? I faced the same issue. Everything 
> works fine when I take out the ajax function.
>
> On Sunday, May 4, 2014 9:33:05 AM UTC-4, John Drake wrote:
>>
>> I've created a simple ajax form to update a "post" database.  For some 
>> strange reason when I post a new message, the button greys out.
>>
>> Here is the model:
>>
>> db.define_table('t_post',
>> Field('f_post', type='text',
>>   label=T('Post')),
>> auth.signature,
>> format='%(f_post)s')
>>
>> Here are my controller functions.
>>
>> def ajax_post():
>> posts = crud.select(db.t_post, fields=['f_post'], query = 
>> db.t_post.created_by == auth.user,
>>headers={'t_post.f_post': 'Post'}, orderby = 
>> ~db.t_post.created_on)
>> search = crud.search(db.t_post)
>> return dict(posts=posts, search=search)
>>
>> def new_post():
>> postdata = request.vars.post
>> db.t_post.insert(f_post = postdata)
>> posts = crud.select(db.t_post, fields=['f_post'], query = 
>> db.t_post.created_by == auth.user,
>>headers={'t_post.f_post': 'Post'}, orderby = 
>> ~db.t_post.created_on)
>> return posts
>>
>> Here is the model:
>>
>> {{extend 'layout.html'}}
>> This is the default/ajax_post.html template
>> 
>> Post : 
>> Post 
>> Message
>> 
>> 
>> {{=posts}}
>> 
>> 
>> {{=search[0]}}
>> 
>>
>> At first I used an input field with type "submit" for the submit button.  
>> When that happened, it would 
>> grey out and the value would set to "Working".  At least now button 
>> text doesn't change, but it
>> it still grey's out.  Inspecting the element in Firefox I get:
>>
>> Post Message
>>
>> Why?  I didn't ask it to change the button's class to disabled.  And it 
>> stays greyed even though
>> the results have returned and my "results" div has been properly 
>> updated.  I can still click on
>> the button, but it just appears disabled. 
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Issue 1961; redirect, response.headers and CAS

2014-08-13 Thread Massimo Di Pierro
Can you point me to any documentation?

On Wednesday, 13 August 2014 04:52:00 UTC-5, Remco Boerma wrote:
>
> Thanks Massimo, 
>
> Well, with CORS it depends. I used these to get CORS working with at IE11 
> and Chrome (latest)
>
> response.headers['Access-Control-Allow-Origin'] 
> response.headers['Access-Control-Allow-Methods'] 
> response.headers['Access-Control-Allow-Headers'] 
>
> Maybe something more dynamic like 
> auth.cas_allowed_headers_on_redirect = ['Acces-Co...',...]
>
> though it would require more tuning and more work and less out of the box 
> functionality. 
>
> For what i have seen it needs these headers on every contact with the 
> requesting browser, since the entire process is done using ajax that means 
> all redirects would probably apply. And if not, probably you'll want to 
> setup a structure to allow CORS on those redirects anyway. 
> If you really need to know which redirects are used in my situation (i 
> don't use the form based authentication obviously, so that might save me a 
> few redirects) i can debug the lot and see what i can come up with. 
>
> With kind regards. 
>
> Op woensdag 13 augustus 2014 07:29:43 UTC+2 schreef Massimo Di Pierro:
>>
>> Looking into this but I need your help. We cannot preserve all the 
>> headers because some of them may contain sensitive information that should 
>> not be sent cross domain (for example session cookies). So the question is, 
>> which headers should be preserved by which redirects:
>>
>> There are two redirects in gluon/contrib/login_methods/cas_auth.py
>>
>> There are two redirects in gluon/tools.py in Auth allow_access.
>>
>> Do you know which ones need the headers? Which headers?
>>
>> On Tuesday, 12 August 2014 03:05:27 UTC-5, Remco Boerma wrote:
>>>
>>> Thanks Massimo, 
>>>
>>> Concerning https://code.google.com/p/web2py/issues/detail?id=1961&can=1 
>>>
>>> The CAS structure uses redirect() internally. Can you update the call in 
>>> the CAS code to send the request.headers? That's why i proposed a change on 
>>> all redirect calls. This allows the CAS to be CORS compliant if the user 
>>> provides the proper headers on the controller level 
>>>
>>> With kind regards. 
>>>
>>> Remco
>>>
>>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: web2py shell vs terminal shell

2014-08-13 Thread Massimo Di Pierro
Please open a ticket about this. This is a major issue. Perhaps we should 
remove the web based shell.

On Wednesday, 13 August 2014 02:41:17 UTC-5, Giacomo Dorigo wrote:
>
> Today I discovered an other problem with the admin shell.
> If I execute command 1
> and then command 2, at this point it will re-execute command 1 too.
> If then I execute command 3, it will execute again also 1 and 2.
>
> This is while running web2py from source code on Windows with simple 
> python web2py.py 
>
>
>
> On Saturday, April 6, 2013 6:09:40 AM UTC+2, Massimo Di Pierro wrote:
>>
>> The admin shell has problems maintaining state. I do not consider it 
>> reliable. The terminal shell is rock solid. It is a normal pyhton shell.
>>
>> On Friday, 5 April 2013 16:48:50 UTC-5, Michael Herman wrote:
>>>
>>> yes. so when working with DAL directly from the shell it's better to 
>>> work from the web2py shell in the terminal rather than the admin app 
>>> shell? any idea why? 
>>>
>>> On Fri, Apr 5, 2013 at 2:43 PM, Anthony  wrote: 
>>> > 
>>> > By "built-in" shell, do you mean the one in the admin app? I think 
>>> there are sometimes problems with that (particularly with database 
>>> operations), so I tend to use the web2py shell in the terminal, which you 
>>> can start as follows from the web2py directory: 
>>> > 
>>> > python web2py.py -S yourapp/[optional controller] -M 
>>> > 
>>> > But you may fine the admin shell works just fine for you, in which 
>>> case, use it. 
>>> > 
>>> > Anthony 
>>> > 
>>> > 
>>> > On Friday, April 5, 2013 4:57:49 PM UTC-4, Michael Herman wrote: 
>>> >> 
>>> >> i remember reading somewhere that it's better to use the built-in 
>>> shell in web2py, but i can't find the article/post. anyone know (1) if it 
>>> is "better", and, (2)  if so, why? 
>>> > 
>>> > -- 
>>> > 
>>> > --- 
>>> > You received this message because you are subscribed to a topic in the 
>>> Google Groups "web2py-users" group. 
>>> > To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/web2py/XWMt1Pb_2wk/unsubscribe?hl=en. 
>>> > To unsubscribe from this group and all its topics, send an email to 
>>> web2py+un...@googlegroups.com. 
>>> > For more options, visit https://groups.google.com/groups/opt_out. 
>>> > 
>>> > 
>>>
>>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: question about db.mytable.update_or_insert()

2014-08-13 Thread Jack Kuan
How does one usually deal with such conflict? (two identical(except for 
id's) inserts causing a violation of an unique constraint)

Isolating the insert into its own transaction and then do a db.commit(), 
catch any exception and then ignore?

Thanks

On Wednesday, August 13, 2014 10:57:13 AM UTC-4, Niphlod wrote:
>
> the problem in concurrency (andduplication) isn't the update part, it's 
> the insert part
>
> On Wednesday, August 13, 2014 1:39:56 PM UTC+2, Leonel Câmara wrote:
>>
>> Couldn't he use a _for_update argument there to make this work in some 
>> adapters?
>>
>> db.mytable.update_or_insert(q, name='test', _for_update=True)
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: web2py shell vs terminal shell

2014-08-13 Thread Giacomo Dorigo
Today I discovered an other problem with the admin shell.
If I execute command 1
and then command 2, at this point it will re-execute command 1 too.
If then I execute command 3, it will execute again also 1 and 2.

This is while running web2py from source code on Windows with simple 
python web2py.py 



On Saturday, April 6, 2013 6:09:40 AM UTC+2, Massimo Di Pierro wrote:
>
> The admin shell has problems maintaining state. I do not consider it 
> reliable. The terminal shell is rock solid. It is a normal pyhton shell.
>
> On Friday, 5 April 2013 16:48:50 UTC-5, Michael Herman wrote:
>>
>> yes. so when working with DAL directly from the shell it's better to 
>> work from the web2py shell in the terminal rather than the admin app 
>> shell? any idea why? 
>>
>> On Fri, Apr 5, 2013 at 2:43 PM, Anthony  wrote: 
>> > 
>> > By "built-in" shell, do you mean the one in the admin app? I think 
>> there are sometimes problems with that (particularly with database 
>> operations), so I tend to use the web2py shell in the terminal, which you 
>> can start as follows from the web2py directory: 
>> > 
>> > python web2py.py -S yourapp/[optional controller] -M 
>> > 
>> > But you may fine the admin shell works just fine for you, in which 
>> case, use it. 
>> > 
>> > Anthony 
>> > 
>> > 
>> > On Friday, April 5, 2013 4:57:49 PM UTC-4, Michael Herman wrote: 
>> >> 
>> >> i remember reading somewhere that it's better to use the built-in 
>> shell in web2py, but i can't find the article/post. anyone know (1) if it 
>> is "better", and, (2)  if so, why? 
>> > 
>> > -- 
>> > 
>> > --- 
>> > You received this message because you are subscribed to a topic in the 
>> Google Groups "web2py-users" group. 
>> > To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/web2py/XWMt1Pb_2wk/unsubscribe?hl=en. 
>> > To unsubscribe from this group and all its topics, send an email to 
>> web2py+un...@googlegroups.com. 
>> > For more options, visit https://groups.google.com/groups/opt_out. 
>> > 
>> > 
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Login restricted based on subscription

2014-08-13 Thread Rufus
On Tuesday, August 12, 2014 4:28:11 PM UTC-4, Kenneth wrote:
>
> Hello everyone,
>
> I'm building a site that clients subscribes to so I need to limit their 
> login based on the subscription. Is there a built in feature to limit login 
> to a date range?
>
>
> Kenneth
>
>
Can't your successful login action check the date and redirect to an 
"account expired" page and log the user off?
Or better, to a "To continue/reinstate your subscription..." page.

 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] What is the right way to serve static files through a CDN ?

2014-08-13 Thread Louis Amon
I am using a CDN and am trying to configure web2py to use it instead of the 
classic static file service.

So far I've been using pattern-based routes like this :

cdn = 'https://xxx.cloudfront.net'

routes_in = (...
 ('/static/$anything', cdn + '/static/$anything'),
 ...
 )

routes_out = (...
 ('/static/$anything', cdn + '/static/$anything'),
 ...
 )

This basically works, but this has to be implemented on a pattern-based 
routes.py which means I lose many cool features like map_hyphen, 
default_application, default_controller mappings...

Is there a way to use a CDN with a parametric router ?

I read somewhere that the host parameter in URL can also be used to setup a 
CDN, but it seems a bit tedious to find all URL and rewrite them.

Isn't there a variable in gluon.rewrite that I can mess with to trick 
web2py into serving CDN-based content ?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: add static files to header from a module

2014-08-13 Thread Pablo Angulo
I also tried to place the
> current.response.files.append(URL('static',
> 'jqplot/jquery.jqplot.min.js'))
> current.response.files.append(URL('static',
> 'jqplot/jquery.jqplot.min.css'))
> current.response.files.append(URL('static',
> 'jqplot/plugins/jqplot.barRenderer.min.js'))
> current.response.files.append(URL('static',
> 'jqplot/plugins/jqplot.categoryAxisRenderer.min.js'))
> current.response.files.append(URL('static',
> 'jqplot/plugins/jqplot.pointLabels.min.js'))
in the xml method, but it didn't make to the response either.

El 13/08/14 a las #4, Pablo Angulo escribió:
> El 13/08/14 a las #4, Anthony escribió:
>> Can you show your module code? Are you doing the appending at the top
>> level in the module, or within a function/method?
> The latter:
>
>> # -*- coding: utf-8 -*-
>> # (C) Copyright (C) 2012-14 Pablo Angulo
>> # This file is part of karakolas .
>>
>> # karakolas is free software: you can redistribute it and/or modify
>> # it under the terms of the GNU Affero General Public License as
>> # published by the Free Software Foundation, either version 3 of the
>> # License, or (at your option) any later version.
>>
>> # karakolas is distributed in the hope that it will be useful,
>> # but WITHOUT ANY WARRANTY; without even the implied warranty of
>> # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> # GNU General Public License for more details.
>>
>> # You should have received a copy of the GNU Affero General Public
>> # License along with karakolas.  If not, see
>> # .
>>
>> from gluon.html import URL, FORM
>> from gluon import current
>> from collections import defaultdict
>>
>> class JQPlot(FORM):
>>
>> def __init__(self, query,
>>  row_field, col_field, data_field,
>>  row_ids=None, col_ids=None,
>>  row_represent=None, col_represent=None,
>> data_represent=None,
>>  _id='',
>>  **attributes):
>> '''Muestra una gráfica ligeramente interactiva para visualizar
>> una relacion que representa una funcion (ref1,ref2) -> valor
>> '''
>> FORM.__init__(self, **attributes)
>> current.response.files.append(URL('static',
>> 'jqplot/jquery.jqplot.min.js'))
>> current.response.files.append(URL('static',
>> 'jqplot/jquery.jqplot.min.css'))
>> current.response.files.append(URL('static',
>> 'jqplot/plugins/jqplot.barRenderer.min.js'))
>> current.response.files.append(URL('static',
>> 'jqplot/plugins/jqplot.categoryAxisRenderer.min.js'))
>> current.response.files.append(URL('static',
>> 'jqplot/plugins/jqplot.pointLabels.min.js'))
>>
>> self.query  = query
>> self.row_field  = row_field
>> self.col_field  = col_field
>> self.data_field = data_field
>>
>> self.row_represent = row_represent or row_field.represent or
>> (lambda x:x)
>> self.col_represent = col_represent or col_field.represent or
>> (lambda x:x)
>> try:
>> self.data_represent = data_represent or
>> data_field.represent or (lambda x:x)
>> except AttributeError:
>> #A f.sum() or f.count() doesn't have a represent attribute
>> self.data_represent = (lambda x:x)
>>
>> self.row_ids   = row_ids or [r[row_field] for r in
>> current.db(query).select(row_field, groupby=row_field)]
>> self.row_names = [self.row_represent(rid) for rid in self.row_ids]
>> self.col_ids   = col_ids or [r[col_field] for r in
>> current.db(query).select(col_field, groupby=col_field)]
>> self.col_names = [self.col_represent(cid) for cid in self.col_ids]
>>
>> def xml(self):
>>
>> d = defaultdict(float)
>> recs = current.db(self.query).select(
>> self.row_field, self.col_field, self.data_field,
>> groupby=self.row_field|self.col_field
>>)
>>
>> for row in recs:
>> d[row[self.row_field],
>> row[self.col_field]]=row[self.data_field]
>>
>> data = [[float(d[r,c]) for c in self.col_ids] for r in
>> self.row_ids]
>> series_labels = ','.join("{label:'%s'}"%self.row_represent(r)
>> for r in self.row_ids)
>> ticks = self.col_names
>>
>> d = dict(data=data,ticks=ticks, series_labels=series_labels)
>> return current.response.render('jqplot.html', d)

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: add static files to header from a module

2014-08-13 Thread Pablo Angulo
El 13/08/14 a las #4, Leonel Câmara escribió:
> Simply adding to current.response.files may not works if the request
> is ajax (say your module is loaded).

But it's not loaded via ajax, I call it like this:

> @requires_get_arguments(('grupo', db.grupo),
> ('productor', db.productor),
> _consistency= (
> ((db.grupo.id==db.grupoXred.grupo) &
> 
> (db.productor.grupo==db.grupoXred.red)),
> 
> (db.productor.grupo==db.grupo.id) )
>)
> @auth.requires_membership('admins_%s'%request.vars.grupo)
> def grafica_grupo_productor():
> '''Muestra tabla y grafica de productos x fecha_pedido para un
> productor fijo,
> con la cantidad total que se pide de cada producto en cada fecha
> '''
>
> iproductor = int(request.vars.productor)
> productor  = db.productor[iproductor]
> igrupo = int(request.vars.grupo)
> grupo  = db.grupo(igrupo)
>
> response.title = T('Estadísticas del grupo %s con
> %s')%(grupo.nombre, productor.nombre)
>
> def row_represent(pid):
> return db.producto[pid].nombre
> args = ((db.item.productoXpedido==db.productoXpedido.id) &
> (db.productoXpedido.pedido==db.pedido.id) &
> (db.pedido.productor==iproductor) &
> (db.item.grupo==igrupo),
> db.productoXpedido.producto,
> db.pedido.fecha_reparto,
> db.item.cantidad.sum())
> sheet = ROSheet(*args,
> row_represent=row_represent,
> col_totals=True)
> jqplot = JQPlot(*args,
> row_represent=row_represent,
> col_represent=str)
> return dict(sheet=sheet, jqplot=jqplot,
>  nombre_productor=productor.nombre,
>  grupo=grupo)

and the view is:

> {{extend 'layout.html'}}
> ... etc ...
> {{=jqplot}}
> {{=sheet}}
> ... etc ...


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: add static files to header from a module

2014-08-13 Thread Pablo Angulo
El 13/08/14 a las #4, Anthony escribió:
> Can you show your module code? Are you doing the appending at the top
> level in the module, or within a function/method?

The latter:

> # -*- coding: utf-8 -*-
> # (C) Copyright (C) 2012-14 Pablo Angulo
> # This file is part of karakolas .
>
> # karakolas is free software: you can redistribute it and/or modify
> # it under the terms of the GNU Affero General Public License as
> # published by the Free Software Foundation, either version 3 of the
> # License, or (at your option) any later version.
>
> # karakolas is distributed in the hope that it will be useful,
> # but WITHOUT ANY WARRANTY; without even the implied warranty of
> # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> # GNU General Public License for more details.
>
> # You should have received a copy of the GNU Affero General Public
> # License along with karakolas.  If not, see
> # .
>
> from gluon.html import URL, FORM
> from gluon import current
> from collections import defaultdict
>
> class JQPlot(FORM):
>
> def __init__(self, query,
>  row_field, col_field, data_field,
>  row_ids=None, col_ids=None,
>  row_represent=None, col_represent=None,
> data_represent=None,
>  _id='',
>  **attributes):
> '''Muestra una gráfica ligeramente interactiva para visualizar
> una relacion que representa una funcion (ref1,ref2) -> valor
> '''
> FORM.__init__(self, **attributes)
> current.response.files.append(URL('static',
> 'jqplot/jquery.jqplot.min.js'))
> current.response.files.append(URL('static',
> 'jqplot/jquery.jqplot.min.css'))
> current.response.files.append(URL('static',
> 'jqplot/plugins/jqplot.barRenderer.min.js'))
> current.response.files.append(URL('static',
> 'jqplot/plugins/jqplot.categoryAxisRenderer.min.js'))
> current.response.files.append(URL('static',
> 'jqplot/plugins/jqplot.pointLabels.min.js'))
>
> self.query  = query
> self.row_field  = row_field
> self.col_field  = col_field
> self.data_field = data_field
>
> self.row_represent = row_represent or row_field.represent or
> (lambda x:x)
> self.col_represent = col_represent or col_field.represent or
> (lambda x:x)
> try:
> self.data_represent = data_represent or
> data_field.represent or (lambda x:x)
> except AttributeError:
> #A f.sum() or f.count() doesn't have a represent attribute
> self.data_represent = (lambda x:x)
>
> self.row_ids   = row_ids or [r[row_field] for r in
> current.db(query).select(row_field, groupby=row_field)]
> self.row_names = [self.row_represent(rid) for rid in self.row_ids]
> self.col_ids   = col_ids or [r[col_field] for r in
> current.db(query).select(col_field, groupby=col_field)]
> self.col_names = [self.col_represent(cid) for cid in self.col_ids]
>
> def xml(self):
>
> d = defaultdict(float)
> recs = current.db(self.query).select(
> self.row_field, self.col_field, self.data_field,
> groupby=self.row_field|self.col_field
>)
>
> for row in recs:
> d[row[self.row_field],
> row[self.col_field]]=row[self.data_field]
>
> data = [[float(d[r,c]) for c in self.col_ids] for r in
> self.row_ids]
> series_labels = ','.join("{label:'%s'}"%self.row_represent(r)
> for r in self.row_ids)
> ticks = self.col_names
>
> d = dict(data=data,ticks=ticks, series_labels=series_labels)
> return current.response.render('jqplot.html', d)

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: question about db.mytable.update_or_insert()

2014-08-13 Thread Niphlod
the problem in concurrency (andduplication) isn't the update part, it's the 
insert part

On Wednesday, August 13, 2014 1:39:56 PM UTC+2, Leonel Câmara wrote:
>
> Couldn't he use a _for_update argument there to make this work in some 
> adapters?
>
> db.mytable.update_or_insert(q, name='test', _for_update=True)
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: menu creation error

2014-08-13 Thread ocascante
The problem was the alphabetical order of models, thanks for the help

El lunes, 11 de agosto de 2014 12:12:08 UTC-6, Leonel Câmara escribió:
>
> You made a typo:
>
> for row in db(db.categorias*.id > 0*).select():
> response.menu.append((T(row.nombre)))
>
> Fix in bold.
>
> BTW you probably want something like this
>
> for row in db(db.categorias.id > 0).select():
> response.menu.append((T(row.nombre), request.vars.category == 
> row.nombre, URL('default', 'index', vars={'category': row.nombre})))
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: What am i doing wrong here? (virtualfields)

2014-08-13 Thread Anthony


> def new_style_virtual_field_test():

db = DAL('sqlite:memory',pool_size=1)
> db.define_table('myorder',
> Field('a','integer'),
> Field('b','integer')
> )
> db.myorder.c = Field.Virtual(lambda row:row.a * row.b)
> db.myorder.insert(a=2,b=3)
> return db().select(db.myorder.ALL).first().as_json()
> # {"a": 2, "id": 1, "b": 3}
>

Are you sure that's the exact code you have run, because row.a * row.b is 
not the correct syntax and should result in an exception as soon as you do 
a select. Instead, it should be:

db.myorder.c = Field.Virtual('c', lambda row: row.myorder.a * row.myorder.b)

In the function, you must include the table name when accessing fields in 
the row. Also, note that even when creating the virtual field via 
assignment, you should still specify the name of the virtual field within 
Field.Virtual() -- otherwise the "name" attribute of the virtual field will 
be set to "unknown", which may cause problems in some contexts.

return db().select(db.myorder.a, db.myorder.b, 
> db.myorder.c).first().as_json()
> #  no such column: None.unknown
> # (self=, *a=('SELECT myorder.a, 
> myorder.b, None.unknown FROM myorder;',), **b={})
> 
> # where has my C field gone to? 
>
 
Virtual fields are not stored in the database but are calculated after 
records are pulled from the database, so they are not to be listed in the 
call to .select().

def old_style_virtual_field_test1():
> db = DAL('sqlite:memory',pool_size=1)
> db.define_table('myorder',
> Field('a','integer'),
> Field('b','integer')
> )
> class MyVirtualFields(object):
> def c(self):
> return self.myorder.a * self.myorder.b
> db.myorder.virtualfields.append(MyVirtualFields())
> db.myorder.insert(a=2,b=3)
> # return db().select(db.myorder.ALL).first().as_json()
> # {"a": 2, "id": 1, "b": 3}
> # where is c? 
>

Don't know. When I run the exact code above, I get:

{"a": 2, "c": 6, "b": 3, "id": 1}

 

> return db().select(db.myorder.a, db.myorder.b, 
> db.myorder.c).first().as_json()
> # AttributeError: 'Table' object has no attribute 'c'
>
> # it doesn't ? I thought i declared to be virutally present
>

Old style virtual fields work differently -- they don't result in 
individual "field" attributes being added to the table object. Rather, they 
are stored in the "virtualfields" attribute of the table.
 

> db.myorder.setvirtualfields(myorder=MyVirtualFields())
> #  'Table' object has no attribute 
> 'setvirtualfields'
> # maybe a bit more clarity in the documentation would be nice. I 
> understand the purpose
> # but it's easily overlooked.
>

The book seems fairly clear to me on this point. The only example it shows 
using .setvirtualfields() is in the context of creating virtual fields on 
the result of a join, with the following code:

rows.setvirtualfields(order_item=MyVirtualFields())

It then says (highlights added):

Notice how in this case the syntax is different. The virtual field accesses 
both self.item.unit_price and self.order_item.quantity which belong to the 
join select. The virtual field is attached to the rows of the table using 
the setvirtualfields method of the rows object.
 

> rows = db(db.myorder).select()
> # now i have to apply them after selecting? That's counter intuitive
> # i thought it would be in the model, not the controller 
> rows.setvirtualfields(myorder=MyVirtualFields())
> # also note the setvirtualfields has to be applied to the rows, not to 
> a single row.
>

There is no need to use .setvirtualfields() in the above example given that 
you are selecting from a single table. The primary purpose of that method 
is when you want to apply virtual fields to the result of a join of 
multiple tables (so, you must apply the virtual fields to the rows rather 
than to an individual table).

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: add static files to header from a module

2014-08-13 Thread Anthony
Can you show your module code? Are you doing the appending at the top level 
in the module, or within a function/method?

On Wednesday, August 13, 2014 7:14:46 AM UTC-4, pa...@cancamusa.net wrote:
>
>
> Dear all:
> In the process of moving functionality from models to modules, I'm trying 
> to add some filesto the header. When the file was in models, I did:
>
> response.files.append(URL('static', 'jqplot/jquery.jqplot.min.js'))
> response.files.append(URL('static', 
> 'jqplot/jquery.jqplot.min.css'))
>
> now that it's in modules, I tried:
>
> current.response.files.append(URL('static', 
> 'jqplot/jquery.jqplot.min.js'))
> current.response.files.append(URL('static', 
> 'jqplot/jquery.jqplot.min.css'))
>
> but it doesn't work...
> I've found a workaround, the last line in JQPlot.xml was:
>
> return current.response.render('jqplot.html', d)
>
> so I can add "script" html tags to the template jqplot.html:
>
> 
> 
>
> but I'm sure it can be done better...
> Thanks

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: add static files to header from a module

2014-08-13 Thread Leonel Câmara
Simply adding to current.response.files may not works if the request is 
ajax (say your module is loaded).

In my modules I like to use a function the plugins in s-cubism.com use to 
set files:

def _set_files(files):
if current.request.ajax:
current.response.js = (current.response.js or '') + """;(function 
($) {
var srcs = $('script').map(function(){return $(this).attr('src');}),
hrefs = $('link').map(function(){return $(this).attr('href');});
$.each(%s, function() {
if ((this.slice(-3) == '.js') && ($.inArray(this.toString(), srcs) == 
-1)) {
var el = document.createElement('script'); el.type = 
'text/javascript'; el.src = this;
document.body.appendChild(el);
} else if ((this.slice(-4) == '.css') && ($.inArray(this.toString(), 
hrefs) == -1)) {
$('').prependTo('head');
if (/* for IE */ 
document.createStyleSheet){document.createStyleSheet(this);}
}});})(jQuery);""" % ('[%s]' % ','.join(["'%s'" % f.lower().split('?')[0] 
for f in files]))
else:
current.response.files[:0] = [f for f in files if f not in 
current.response.files]


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: question about db.mytable.update_or_insert()

2014-08-13 Thread Leonel Câmara
Couldn't he use a _for_update argument there to make this work in some 
adapters?

db.mytable.update_or_insert(q, name='test', _for_update=True)

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: add static files to header from a module

2014-08-13 Thread Pablo Angulo
If I understand, you mean that whenever I call JQPlot

jqplot = JQPlot(*args, col_represent=str)

I have to append the following lines:

response.files.append(URL('static', 'jqplot/jquery.jqplot.min.js'))
response.files.append(URL('static', 'jqplot/jquery.jqplot.min.css'))
response.files.append(URL('static',
'jqplot/plugins/jqplot.barRenderer.min.js'))
response.files.append(URL('static',
'jqplot/plugins/jqplot.categoryAxisRenderer.min.js'))
response.files.append(URL('static',
'jqplot/plugins/jqplot.pointLabels.min.js'))

or at least a call like

jqplot = JQPlot(*args, col_represent=str)
add_jqplot_static_files()

to avoid repetition.

yeah, that would sure work, but still: any other ideas?

I'm specifically interested in knowing why

current.response.files.append(URL('static',
'jqplot/jquery.jqplot.min.js'))
current.response.files.append(URL('static',
'jqplot/jquery.jqplot.min.css'))
current.response.files.append(URL('static',
'jqplot/plugins/jqplot.barRenderer.min.js'))
current.response.files.append(URL('static',
'jqplot/plugins/jqplot.categoryAxisRenderer.min.js'))
current.response.files.append(URL('static',
'jqplot/plugins/jqplot.pointLabels.min.js'))

in the module does not work. I get the feeling that I will stump into
that wall more times if I just hack my way around the problem now.

El 13/08/14 a las #4, Cliff Kachinske escribió:
> Put the appending code in the controller.
>
> On Wednesday, August 13, 2014 7:14:46 AM UTC-4, pa...@cancamusa.net
> wrote:
>
>
> Dear all:
> In the process of moving functionality from models to modules, I'm
> trying to add some filesto the header. When the file was in
> models, I did:
>
> response.files.append(URL('static',
> 'jqplot/jquery.jqplot.min.js'))
> response.files.append(URL('static',
> 'jqplot/jquery.jqplot.min.css'))
>
> now that it's in modules, I tried:
>
> current.response.files.append(URL('static',
> 'jqplot/jquery.jqplot.min.js'))
> current.response.files.append(URL('static',
> 'jqplot/jquery.jqplot.min.css'))
>
> but it doesn't work...
> I've found a workaround, the last line in JQPlot.xml was:
>
> return current.response.render('jqplot.html', d)
>
> so I can add "script" html tags to the template jqplot.html:
>
> 
> 
>
> but I'm sure it can be done better...
> Thanks
>
> -- 
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/1h3Ni_iywzY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: add static files to header from a module

2014-08-13 Thread Cliff Kachinske
Put the appending code in the controller.

On Wednesday, August 13, 2014 7:14:46 AM UTC-4, pa...@cancamusa.net wrote:
>
>
> Dear all:
> In the process of moving functionality from models to modules, I'm trying 
> to add some filesto the header. When the file was in models, I did:
>
> response.files.append(URL('static', 'jqplot/jquery.jqplot.min.js'))
> response.files.append(URL('static', 
> 'jqplot/jquery.jqplot.min.css'))
>
> now that it's in modules, I tried:
>
> current.response.files.append(URL('static', 
> 'jqplot/jquery.jqplot.min.js'))
> current.response.files.append(URL('static', 
> 'jqplot/jquery.jqplot.min.css'))
>
> but it doesn't work...
> I've found a workaround, the last line in JQPlot.xml was:
>
> return current.response.render('jqplot.html', d)
>
> so I can add "script" html tags to the template jqplot.html:
>
> 
> 
>
> but I'm sure it can be done better...
> Thanks

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] add static files to header from a module

2014-08-13 Thread pang

Dear all:
In the process of moving functionality from models to modules, I'm trying 
to add some filesto the header. When the file was in models, I did:

response.files.append(URL('static', 'jqplot/jquery.jqplot.min.js'))
response.files.append(URL('static', 'jqplot/jquery.jqplot.min.css'))

now that it's in modules, I tried:

current.response.files.append(URL('static', 
'jqplot/jquery.jqplot.min.js'))
current.response.files.append(URL('static', 
'jqplot/jquery.jqplot.min.css'))

but it doesn't work...
I've found a workaround, the last line in JQPlot.xml was:

return current.response.render('jqplot.html', d)

so I can add "script" html tags to the template jqplot.html:




but I'm sure it can be done better...
Thanks

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: RESTful PATCH request not working

2014-08-13 Thread Leonel Câmara
I've made some confusion with request.args, but the point still stands that 
you should be using args instead of request.args.

I can tell you the restful decorator doesn't care if it's a PUT or a PATCH 
as it gets the method from request.env.http_method.

So you're probably on the right track and your webserver may not be 
accepting it, maybe for overly cautious security configurations. I know 
nginx has a limit_except option and Apache also has a Limit and LimitExcept 
directive. I'm not sure if these give you a 400 error so it's also possible 
that something in your request is exceeding size limits on the webserver 
and that would give you a 400.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Issue 1961; redirect, response.headers and CAS

2014-08-13 Thread Remco Boerma
Thanks Massimo, 

Well, with CORS it depends. I used these to get CORS working with at IE11 
and Chrome (latest)

response.headers['Access-Control-Allow-Origin'] 
response.headers['Access-Control-Allow-Methods'] 
response.headers['Access-Control-Allow-Headers'] 

Maybe something more dynamic like 
auth.cas_allowed_headers_on_redirect = ['Acces-Co...',...]

though it would require more tuning and more work and less out of the box 
functionality. 

For what i have seen it needs these headers on every contact with the 
requesting browser, since the entire process is done using ajax that means 
all redirects would probably apply. And if not, probably you'll want to 
setup a structure to allow CORS on those redirects anyway. 
If you really need to know which redirects are used in my situation (i 
don't use the form based authentication obviously, so that might save me a 
few redirects) i can debug the lot and see what i can come up with. 

With kind regards. 

Op woensdag 13 augustus 2014 07:29:43 UTC+2 schreef Massimo Di Pierro:
>
> Looking into this but I need your help. We cannot preserve all the headers 
> because some of them may contain sensitive information that should not be 
> sent cross domain (for example session cookies). So the question is, which 
> headers should be preserved by which redirects:
>
> There are two redirects in gluon/contrib/login_methods/cas_auth.py
>
> There are two redirects in gluon/tools.py in Auth allow_access.
>
> Do you know which ones need the headers? Which headers?
>
> On Tuesday, 12 August 2014 03:05:27 UTC-5, Remco Boerma wrote:
>>
>> Thanks Massimo, 
>>
>> Concerning https://code.google.com/p/web2py/issues/detail?id=1961&can=1 
>>
>> The CAS structure uses redirect() internally. Can you update the call in the 
>> CAS code to send the request.headers? That's why i proposed a change on all 
>> redirect calls. This allows the CAS to be CORS compliant if the user 
>> provides the proper headers on the controller level 
>>
>> With kind regards. 
>>
>> Remco
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] What am i doing wrong here? (virtualfields)

2014-08-13 Thread Remco Boerma
Hi all, 

I don't get the following errors and results. My goal is to have a virtual 
field and i can't get it to work the way i want it - and what i think is 
described in the book as it should work. What am i doing wrong here? 

Below are serveral independent samples of what i thought had to work, 
though old_style_virtual_field_test2 will never work and is obvious. 

Thanks for helping out. 
Remco Boerma

# web2py 2.9.5-stable+timestamp.2014.03.16.02.35.39

def new_style_virtual_field_test():
db = DAL('sqlite:memory',pool_size=1)
db.define_table('myorder',
Field('a','integer'),
Field('b','integer')
)
db.myorder.c = Field.Virtual(lambda row:row.a * row.b)
db.myorder.insert(a=2,b=3)
return db().select(db.myorder.ALL).first().as_json()
# {"a": 2, "id": 1, "b": 3}
# where is c?

return db().select(db.myorder.a, db.myorder.b, 
db.myorder.c).first().as_json()
#  no such column: None.unknown
# (self=, *a=('SELECT myorder.a, 
myorder.b, None.unknown FROM myorder;',), **b={})

# where has my C field gone to? 


def old_style_virtual_field_test1():
db = DAL('sqlite:memory',pool_size=1)
db.define_table('myorder',
Field('a','integer'),
Field('b','integer')
)
class MyVirtualFields(object):
def c(self):
return self.myorder.a * self.myorder.b
db.myorder.virtualfields.append(MyVirtualFields())
db.myorder.insert(a=2,b=3)
# return db().select(db.myorder.ALL).first().as_json()
# {"a": 2, "id": 1, "b": 3}
# where is c? 

return db().select(db.myorder.a, db.myorder.b, 
db.myorder.c).first().as_json()
# AttributeError: 'Table' object has no attribute 'c'

# it doesn't ? I thought i declared to be virutally present

def old_style_virtual_field_test2():
db = DAL('sqlite:memory',pool_size=1)
db.define_table('myorder',
Field('a','integer'),
Field('b','integer')
)
class MyVirtualFields(object):
def c(self):
return self.myorder.a * self.myorder.b
db.myorder.setvirtualfields(myorder=MyVirtualFields())
#  'Table' object has no attribute 
'setvirtualfields'
# maybe a bit more clarity in the documentation would be nice. I 
understand the purpose
# but it's easily overlooked. 

def old_style_virtual_field_test3():
db = DAL('sqlite:memory',pool_size=1)
db.define_table('myorder',
Field('a','integer'),
Field('b','integer')
)
class MyVirtualFields(object):
def c(self):
return self.myorder.a * self.myorder.b
db.myorder.insert(a=2,b=3)

rows = db(db.myorder).select()
# now i have to apply them after selecting? That's counter intuitive
# i thought it would be in the model, not the controller 
rows.setvirtualfields(myorder=MyVirtualFields())
# also note the setvirtualfields has to be applied to the rows, not to 
a single row. 

return rows.first().as_json();
# {"a": 2, "c": 6, "b": 3, "id": 1} 
# yeey!!



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: RESTful PATCH request not working

2014-08-13 Thread Falko Delarue
Ok just I tried this
@request.restful()
def page():  
def PATCH(*args, **vars):
if args[0]:
print 'PATCH args: ', args

But I still get a 400 "Bad Request" error (it does not say 400 "invalid 
arguments") that why I think it does not even come to this point.
Also request.args() should work since I can use 
def PUT(*args, **vars):
if request.args(0):
print request.args(0)
without a problem.

The real problem must be that rest_action or some function much earlier 
(maybe even in the underlying werbserver) does not accept PATCH requests


On Tuesday, August 12, 2014 7:18:14 PM UTC+2, Leonel Câmara wrote:
>
> request is available but the restful wrapper cleans request.args and calls 
> the function with them as args, you should not use request.args because 
> request.args have stuff that isn't exactly an argument, namely the method 
> 'PATCH' which is what would be in request.args(0).
>
>
> > As you may have read I am getting a 400 error not a 500, that means 
> there is no error stack trace. 
>
> That's not exactly true, the thing is, you want the rest API to inform the 
> caller if it's calling it wrong, and that's what web2py thinks it's 
> happening.
>
> Rest actions are run this way:
>
> try:
> return rest_action(*_self.args, **getattr(_self, 
> 'vars', {}))
> except TypeError, e:
> exc_type, exc_value, exc_traceback = sys.exc_info()
> if len(traceback.extract_tb(exc_traceback)) == 1:
> raise HTTP(400, "invalid arguments")
>
> There you can see where the HTTP 400 comes from.  
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: question about db.mytable.update_or_insert()

2014-08-13 Thread Niphlod
that's basic versioning theory of databases. 
If you do two operations in two separate transactions that, in "english" 
can be translated as "if you don't find this record, please insert it", the 
two will happily succeed one after another if they are concurrent. 
That's why unique constraints are a builtin feature that every backend has.

On Tuesday, August 12, 2014 10:24:48 PM UTC+2, Jack Kuan wrote:
>
> Hi,
>
> When using  update_or_insert(), say for example:  
> db.mytable.update_or_insert(q, name='test')
>
> Let's say the query, q, results in not finding any row in mytable, is it 
> possible that in another transaction in another request that when the same 
> update_or_insert(...) is called that it also doesn't find any row and thus 
> at the end, the two transcations both try to commit an insert, which could 
> result in duplicated rows(with different id's) or an integrity error(eg, if 
> there's an unique constraint)? Or is web2py smart enough to generate an 
> insert that is safe?
>
> Thanks
> Jack
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Use of mail.send in Scheduler

2014-08-13 Thread Prasad Muley
Hi,
   I want to use mail.send in Scheduler. Is there any way to use it in 
scheduler?
AFAIK task which queued in scheduler.queue_task must be present in 
models/scheduler.py 
So how can I override mail.send() in models/scheduler.py
 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Dynamic menu update

2014-08-13 Thread Richard
My conclusion is that the menu is becoming too large any performance 
improvement will have minimal user experience improvement. I'll create 
other menus's on locations where users are working at that time. 

Richard D

On Tuesday, August 12, 2014 11:56:35 AM UTC+2, Richard wrote:
>
> Hello,
>
> I  have a farely large menu structure in a page through buttons with 
> dropdown menu's which are changed dynamically. A refresh of the whole page 
> take about 5 seconds which is too long. Now I want to split this using 
> components. These components must be reloaded depending on additions to the 
> database through a SQLFORM.factory.
>
> navigation.load:
>
> 
> {{=LOAD('default', 'menu_identity.load', ajax=False, 
> ajax_trap=False, vars=request.vars, target='menu_identity') }}
>
> menu_identity.load:
>  {{=A(T("Add local 
> EV"),_href=URL('internal','add_local_ev.load', 
>vars=dict(com=com, sif=sif)), 
> cid='internal_data_div' ) }}
>
> add_local_ev.load:
>  {{=LOAD('internal', 'process_add_local_ev', 
> ajax=True, ajax_trap=True, vars=request.vars )}}
>
>
> internal.py:
>  if 
> form_add_local_ev.process(formname='add_lev').accepted:
> .
>  response.js = "jQuery('#%s').get(0).reload()" 
> % 'menu_identity'
>
> I think I am making the design to complicated and does not give the needed 
> functionality.
> Any assist is welcome.
>
> Richard D
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.