[web2py] Re: Select rows

2014-12-23 Thread Oliver
I used this to get print


def printme():
response.view='list.html'
users = db(db.users).select(db.users.first_name,db.users.last_name)
return dict(users=users)


It's working for me now.  thanks


On Tuesday, December 23, 2014 1:24:12 AM UTC-5, Dave S wrote:
>
>
>
> On Wednesday, December 17, 2014 12:17:53 PM UTC-8, Oliver wrote:
>>
>> I'm getting "None" printed in the webpage. I'm trying to print all 
>> first_name in the users table database.  I'm trying to follow the select 
>> section in 
>> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Query--Set--Rows
>>
>> I'm using MySQL for database and have few test records inserted in the 
>> users table.  Please let me know what am I missing in the controller.  I 
>> appreciate your help.  Thanks
>>
>>
>> *My Model: *
>>
>> db.define_table('users',
>> Field('first_name', 'text'),
>> Field('last_name', 'text'))
>>
>> *My Controller:*
>>
>> def printall():
>> for row in db(db.users.id > 0).select(db.users.ALL):
>> print row.first_name
>>
>> or
>>
>> def printall():
>> for row in db().select(db.users.ALL):
>> print row.first_name
>>
>
>
> You are trying to print to the console for development purposes?
>
> If you are showing a "None" as your result, then it appears your query 
> isn't selecting any rows.  If you use the command line interface to your DB 
> (sqlite3?) can you form a SQL SELECT command that retrieves the records you 
> want?  If so, can you paste that command here?
>
> /dps
>
>

-- 
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: reddit clone - foreign key constraint failed

2014-12-23 Thread William Chen
Hi Chris, I had the same problem and found this thread when I was searching 
for a solution.

The solution is to simply create 1 or more comments using app admin. 

If table B references table A, then you need populate to populate table A 
before you populate table B, else there will be an error. In our case, the 
table comm references to itself in this line:
Field('parent_comm', 'reference comm')

So we need to manually add new comments, before we populate the table comm. 

Hope this helps.


On Wednesday, 28 May 2014 23:05:06 UTC+8, Chris Simpson wrote:
>
>
> Hi Uri,
>
> Did you ever find a solution to this?
> On Wednesday, May 14, 2014 12:01:29 PM UTC+2, Uri Tamir wrote:
>>
>> Hi all,
>> I've been following Massimo's video tutorials  
>> (which are *great!* thanks Massimo)
>>
>> when trying to build the reddit clone and populate it i get a ticket 
>> -  foreign key constraint failed
>>
>> the database was populated with users and posts but not with comments. I 
>> tried to make sure my code is exactly as the code Massimo showed but /w no 
>> success.
>>
>> any suggestions?
>>
>> db.define_table('category',
>> Field('name', requires = (IS_SLUG(), IS_LOWER(), 
>> IS_NOT_IN_DB(db, 'category.name'
>>
>> db.define_table('post',
>> Field('category', 'reference category', readable=False, 
>> writable=False),
>> Field('title', 'string', requires=IS_NOT_EMPTY()),
>> Field('url', requires=IS_EMPTY_OR(IS_URL())),
>> Field('body', 'text', requires=IS_NOT_EMPTY()),
>> Field('votes', 'integer', default=0, readable=False, 
>> writable=False),
>> auth.signature) # created_on, created_by, modified_on, 
>> modified_by, is_active
>>
>> db.define_table('post_vote',
>> Field('post', 'reference post'),
>> Field('score', 'integer', default=+1), # numerical 
>> representation of votes
>> auth.signature)
>>
>> db.define_table('comm',
>> Field('post', 'reference post'),
>> Field('parent_comm', 'reference comm'),
>> Field('votes', 'integer'),
>> Field('body', 'text'),
>> auth.signature)
>>
>> db.define_table('comm_vote',
>> Field('comm', 'reference comm'),
>> Field('score', 'integer', default=+1), # numerical 
>> representation of votes
>> auth.signature)
>>
>> from gluon.contrib.populate import populate
>> if db(db.auth_user).count()<2:
>> populate(db.auth_user, 100)
>> db.commit()
>> if db(db.post).count()<2:
>> populate(db.post, 500)
>> db.commit()
>> if db(db.comm).count()<2:
>> populate(db.comm, 1000)
>> db.commit()
>>
>>
>>

-- 
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: Bootstrap icons don't work with latest web2py?

2014-12-23 Thread DJ
I'm having trouble seeing the icons on the admin page - I also downloaded 
the latest version from the website: 
2.9.11-stable+timestamp.2014.09.15.23.35.11 


Has it been fixed? Thanks for your help!

-Sebastian

On Monday, September 22, 2014 11:26:31 AM UTC-4, Sif Baksh wrote:
>
> How do I download the fix, I just upgraded to version 
>  2.9.11-stable+timestamp.2014.09.15.23.35.11
>
> Do I need to download a file?
> Sorry very new to web2py and was testing glyphicons today
>
> Thanks,
> Sif
>
>
> On Saturday, September 22, 2012 9:24:12 AM UTC-6, Massimo Di Pierro wrote:
>>
>> Just fixed in trunk. Sorry my fault.
>>
>> On Saturday, 22 September 2012 01:51:13 UTC-5, LightDot wrote:
>>>
>>> I took a closer look and it seems that this is caused by the css 
>>> comments in the latest web2py_bootstrap.css commit. The /* */ style is the 
>>> only valid comment style for css, // isn't. I reported it.
>>>
>>> Regards,
>>> Ales
>>>
>>>
>>> On Saturday, September 22, 2012 2:43:10 AM UTC+2, LightDot wrote:

 Same issue here, I think. I stay closer to latest trunk so I know this 
 just happened now... the last commit to web2py_bootstrap.css seems to be 
 it, which is just a code cleanup. Probably just a typo somewhere but I 
 don't have time to look into the details until tomorrow.

 Alec, if you take the file from this commit:

 http://web2py.googlecode.com/hg-history/374c5ec18e9b242fad80029d82259317fb158b8c/applications/welcome/static/css/web2py_bootstrap.css

 you should have all the latest functionality & working glyphicons.

 Regards,
 Ales

 On Friday, September 21, 2012 6:18:46 PM UTC+2, Alec Taylor wrote:
>
> Upgrading an old project from 2.0.1 or so to the latest trunk. 
>
> I replaced my views/default and static folder with the ones from the 
> latest welcome app. Subsequently I made my modifications to them; 
> essentially copy and pasting blocks of code from my old layout.html to 
> the new one, same went for my views/default/index.html page. 
>
> Strangely enough none of my twitter-bootstrap icons are working. To 
> fully test I replaced my glyphicons-*.png files in static with the 
> latest ones from the twitter-bootstrap page, and tried once again in a 
> view with a single line: 
> {{=I(_class='icon-screenshot')}} 
>
> Still, nothing showed up. I've also tried clearing my cache. 
>
> Could you please fix the bootstrap icons? 
>
> Thanks, 
>
> Alec Taylor 
>


-- 
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] unescaped HTML code in wiki page

2014-12-23 Thread Manuele Pesenti
Hi *,
I'm trying to use auth_wiki together with plugin_ckeditor but creating
the view as suggested in documentation I can see the HTML code in my page.
So it seams the html code is unescaped during rendering of my wiki page.
How can avoid this? What I'm missing from the documentation?

Thanks a lot

Manuele

-- 
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: SQLFORM.factory with upload field - the operation is insecure

2014-12-23 Thread Cynthia Butler
Thank you, very helpful info to me.

On Sunday, December 21, 2014 7:25:46 PM UTC-7, Jim S wrote:
>
> Yes.  The issue was that I had it in a loaded component.  That is not 
> supported and doesn't work.  And,  I know better,  I've ran into this 
> before and just forgot about that restriction this time. 
>
> Jim
>  On Dec 21, 2014 12:18 PM, "Cynthia Butler"  > wrote:
>
>> Did you find an answer to this? Just curious. Thanks.
>>
>> On Monday, December 15, 2014 8:42:00 AM UTC-7, Jim S wrote:
>>>
>>> I've got an issue that is really puzzling me.
>>>
>>> I have a form, SQLFORM.factory with one field, an upload field.
>>>
>>> When I click on submit to submit the form (adding a new record), I get a 
>>> javascript error that flashes by quickly in Firebug.  All I can get from it 
>>> is that the text says 'the operation is insecure'.
>>>
>>> Here is the controller code:
>>>
>>> @auth.requires_permission('select', db.helpdesk)
>>> def attachments():
>>> ticket_id = request.vars['ticketId']
>>> ticket = db.ticket(ticket_id)
>>>
>>>
>>> updateQuery = db.ticket_attachment.ticket==ticket_id
>>>
>>>
>>> form = SQLFORM.factory(Field('attachment_file', 'upload', required=
>>> True,
>>>  uploadfolder='%s/tickets' % (
>>> connect_util.getFileLocation('uploads'))),
>>>table_name='ticket_attachment', submit_button
>>> ='Add', formstyle=my_formstyle, ui=grid_ui,
>>>formname='attachment_form', _id=
>>> 'attachment_form')
>>>
>>>
>>> if form.process(formname='attachment_form').accepted:
>>> attachment = form.vars.attachment_file
>>> db.ticket_attachment.insert(ticket=ticket_id, attachment=
>>> attachment)
>>>
>>>
>>> ticket_notification(ticket_id, 'new tag added',
>>> 'Tag %s added.' % (helpdesk_tag.tag),
>>> log_activity=True)
>>> else:
>>> print 'err'
>>>
>>>
>>> Here is the view
>>>
>>> 
>>> function delete_attachment(ticket_attachment_id) {
>>> $.ajax({url: "{{=URL('ticket','delete_ticket_attachment',user_
>>> signature=True)}}",
>>> data: {ticket_attachment_id:ticket_attachment_id }})
>>> .fail(function() {
>>> alert('There was a problem removing the attachment from 
>>> this ticket.  Please contact support.');
>>> })
>>> .success(function(msg) {
>>> location.reload();
>>> });
>>> }
>>> 
>>> 
>>> 
>>> {{=form.custom.begin}}
>>> 
>>> {{=form.custom.widget.attachment_file}}
>>> {{=form.custom.submit}}
>>> 
>>> {{=form.custom.end}}
>>> 
>>> {{for attachment in ticket_attachments:}}
>>> 
>>> 
>>> {{=attachment.attachment}}
>>> 
>>> {{if can_delete:}}
>>> 
>>> 
>>> 
>>> {{pass}}
>>> 
>>> {{pass}}
>>> 
>>> 
>>>
>>>
>>> Any ideas on what may be causing this or how to capture the javascript 
>>> error?
>>>
>>> -Jim
>>>
>>>
>>>
>>>  -- 
>> 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/NGmfPpUVvds/unsubscribe.
>> 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/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: Dumb Question/Bug

2014-12-23 Thread Mark Billion
Thanks guys -- that makes a ton of sense.  I really appreciate it.

On Tue, Dec 23, 2014 at 2:54 PM, Anthony  wrote:

> More specifically, when you provide the "next" argument to
> SQLFORM.process(), it ultimately calls redirect(), which raises an HTTP
> exception. If you put the .process() call inside a try/except, that HTTP
> exception will get caught, and in your case, you are then ignoring it. We
> should probably spell this out more clearly in the book.
>
> You could instead do something like:
>
> except Exception as e:
> if isinstance(e, HTTP):
> raise e # re-raise the exception in case of a redirect
> redirect(URL('index'))
>
> But generally it is much better to catch specific exceptions.
>
> Anthony
>
>
> On Tuesday, December 23, 2014 2:44:57 PM UTC-5, Niphlod wrote:
>>
>> are you aware that in web2py any HTTP is a subclass of exception ? Never,
>> never, never use an exception without specifying what exception your code
>> may raise.
>>
>> On Tuesday, December 23, 2014 7:34:45 PM UTC+1, Mark Billion wrote:
>>>
>>> Why are you using an except without specifying the exception? Trying to
>>> catch all possible exceptions.
>>>
>>> On Tuesday, December 23, 2014 1:31:21 PM UTC-5, Leonel Câmara wrote:

 Why are you using an except without specifying the exception? Anyway
 just do this:

 @auth.requires_login()
 def cli_add():
 db.client.au_usr.default = auth.user_id
 form = SQLFORM(db.client, fields = ['d_fn', 'd_ln', 'd_aka',
 'd_ss'], labels = {'d_ss': 'Social Security', 'd_aka': 'Any Aliases',
 'd_65': 'Older than 65'}).process(next=URL('clients'))
 return dict(form=form)

  --
> 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/hWvrDzyR49M/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.
>



-- 
Mark M. Billion
1904 N. Lincoln
Wilmington, DE 19806
302.416.2199

-- 
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: Select rows

2014-12-23 Thread Tim Richardson


On Tuesday, 23 December 2014 17:24:12 UTC+11, Dave S wrote:
>
>
>
> On Wednesday, December 17, 2014 12:17:53 PM UTC-8, Oliver wrote:
>>
>> I'm getting "None" printed in the webpage. I'm trying to print all 
>> first_name in the users table database.  I'm trying to follow the select 
>> section in 
>> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Query--Set--Rows
>>
>> I'm using MySQL for database and have few test records inserted in the 
>> users table.  Please let me know what am I missing in the controller.  I 
>> appreciate your help.  Thanks
>>
>

Just to pick up on what Dave said ... where are you looking to see the 
output from 'print'?
in web2py controllers usually return variables which are packed into an 
HTML page via a view (in development mode, running on a local server such 
as the one built in to web2py, default views work fine). 
Because you are not returning any value, the view shows None. 

Carefully re-read the introductory parts of the book if this doesn't make 
sense. You may notice that you can do
return locals()
at the end of your controller, which with a default developer view will 
show all your local variables. 
you could then do

rows = db.select()
return locals()

The rows will then show up in your view.




You can use print. It will write output to the python console. Where you 
see this depends on what your development environment is. 


 

>
>>
>> *My Model: *
>>
>> db.define_table('users',
>> Field('first_name', 'text'),
>> Field('last_name', 'text'))
>>
>> *My Controller:*
>>
>> def printall():
>> for row in db(db.users.id > 0).select(db.users.ALL):
>> print row.first_name
>>
>> or
>>
>> def printall():
>> for row in db().select(db.users.ALL):
>> print row.first_name
>>
>
>
> You are trying to print to the console for development purposes?
>
> If you are showing a "None" as your result, then it appears your query 
> isn't selecting any rows.  If you use the command line interface to your DB 
> (sqlite3?) can you form a SQL SELECT command that retrieves the records you 
> want?  If so, can you paste that command here?
>
> /dps
>
>

-- 
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: Daily task on production: scheduler or cron?

2014-12-23 Thread Tim Richardson
I use the scheduler for activities that run daily to some that run every 15 
minutes. 
It doesn't do day-of-the-week yet so you would need to check for that in 
your daily code. I for example have an app which sends SMS every hour, but 
the task checks that it is in office hours before doing any work. 
The scheduler is a good tool, and once you've learnt it, you have a 
cross-platform tool at your disposal. It's easy to manipulate in web2py 
since there is an API (which basically updates records; this will make it 
easy to meet your requirement that the user chooses when to start the 
task). It has a simple logging approach (output is saved in tables) and it 
scales to multiple workers easily.

I think the references to "cron must die" refer to a web2py deprecated 
feature unfortunately named cron; don't confuse it with the system cron 
built in your server OS. 
Therefore you may decide to use cron. In which case...
You can run web2py scripts in the context of your application using the 
web2py command line 
python web2py -S {app} -R <{path_prefix}/mymodule.py 
(see documentation in the book; the -S option needs to be used as well). 

You could for example put your code in a module, and have code in the 
global context (if __name__ == "__main__" ...) which will be run when you 
execute the command line. 








On Wednesday, 24 December 2014 01:18:09 UTC+11, Lisandro wrote:
>
> I've been reading about web2py's cron and sheduler ([1] and [2])
> Also, I've read a post where Massimo says "Please use the scheduler, not 
> cron. Cron must die." [3]
>
> Now I'm creating a web2py app and I want the user to be able to configure 
> a daily background task. The task consist in sending a newsletter to 
> subscribers. The task doesn't take too much time to complete (because the 
> app doesn't use smpt; it connects to an API so the sending is handled by an 
> external service). So the task only makes some query to the database, 
> connect to the API, give the order to send, and disconnect.
> The thing is: I want the user to be able to configure the time that the 
> newsletter is sent. For example, the user may configure the sending of the 
> newsletter from monday to friday at 8am, but not saturdays o sundays. 
>
> In this scenario, I first thought that cron would be the way to go. 
> However I read that Massimo's comment ("cron must die") so I don't know 
> what to use. 
> I find that scheduler is very complete and robust, but I don't know if 
> it's the best option for this case, considering that the task runs in very 
> little time and only once a day. I'm worried about resource consumption, 
> because the same app is installed multiple times on production, serving 
> multiple websites, so there would be multiple workers running on background 
> (maybe idle workers, however they would take some memory space I guess).
>
> Any tip or comments? Does anyone dealed with something similar? I want to 
> remark the idea that the user must be able to change configuration about 
> the scheduled task.
> Thanks in advance!
>
> [1]  
> http://web2py.com/books/default/chapter/29/04/the-core#Running-tasks-in-the-background
> [2]  
> http://web2py.com/books/default/chapter/29/13/deployment-recipes#Start-the-scheduler-as-a-Linux-service--upstart-
> [3]  
> https://groups.google.com/forum/#!searchin/web2py/cron$20must$20die/web2py/qW_ODOj3nMM/8hbZ6etJsvcJ
>
>

-- 
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: Dumb Question/Bug

2014-12-23 Thread Anthony
More specifically, when you provide the "next" argument to 
SQLFORM.process(), it ultimately calls redirect(), which raises an HTTP 
exception. If you put the .process() call inside a try/except, that HTTP 
exception will get caught, and in your case, you are then ignoring it. We 
should probably spell this out more clearly in the book.

You could instead do something like:

except Exception as e:
if isinstance(e, HTTP):
raise e # re-raise the exception in case of a redirect
redirect(URL('index'))

But generally it is much better to catch specific exceptions.

Anthony

On Tuesday, December 23, 2014 2:44:57 PM UTC-5, Niphlod wrote:
>
> are you aware that in web2py any HTTP is a subclass of exception ? Never, 
> never, never use an exception without specifying what exception your code 
> may raise.
>
> On Tuesday, December 23, 2014 7:34:45 PM UTC+1, Mark Billion wrote:
>>
>> Why are you using an except without specifying the exception? Trying to 
>> catch all possible exceptions.  
>>
>> On Tuesday, December 23, 2014 1:31:21 PM UTC-5, Leonel Câmara wrote:
>>>
>>> Why are you using an except without specifying the exception? Anyway 
>>> just do this:
>>>
>>> @auth.requires_login()
>>> def cli_add():
>>> db.client.au_usr.default = auth.user_id
>>> form = SQLFORM(db.client, fields = ['d_fn', 'd_ln', 'd_aka', 
>>> 'd_ss'], labels = {'d_ss': 'Social Security', 'd_aka': 'Any Aliases', 
>>> 'd_65': 'Older than 65'}).process(next=URL('clients'))
>>> return dict(form=form)
>>>
>>>

-- 
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: Dumb Question/Bug

2014-12-23 Thread Niphlod
are you aware that in web2py any HTTP is a subclass of exception ? Never, 
never, never use an exception without specifying what exception your code 
may raise.

On Tuesday, December 23, 2014 7:34:45 PM UTC+1, Mark Billion wrote:
>
> Why are you using an except without specifying the exception? Trying to 
> catch all possible exceptions.  
>
> On Tuesday, December 23, 2014 1:31:21 PM UTC-5, Leonel Câmara wrote:
>>
>> Why are you using an except without specifying the exception? Anyway just 
>> do this:
>>
>> @auth.requires_login()
>> def cli_add():
>> db.client.au_usr.default = auth.user_id
>> form = SQLFORM(db.client, fields = ['d_fn', 'd_ln', 'd_aka', 'd_ss'], 
>> labels = {'d_ss': 'Social Security', 'd_aka': 'Any Aliases', 'd_65': 'Older 
>> than 65'}).process(next=URL('clients'))
>> return dict(form=form)
>>
>>

-- 
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: Dumb Question/Bug

2014-12-23 Thread Mark Billion
Why are you using an except without specifying the exception? Trying to 
catch all possible exceptions.  

On Tuesday, December 23, 2014 1:31:21 PM UTC-5, Leonel Câmara wrote:
>
> Why are you using an except without specifying the exception? Anyway just 
> do this:
>
> @auth.requires_login()
> def cli_add():
> db.client.au_usr.default = auth.user_id
> form = SQLFORM(db.client, fields = ['d_fn', 'd_ln', 'd_aka', 'd_ss'], 
> labels = {'d_ss': 'Social Security', 'd_aka': 'Any Aliases', 'd_65': 'Older 
> than 65'}).process(next=URL('clients'))
> return dict(form=form)
>
>

-- 
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: Dumb Question/Bug

2014-12-23 Thread Leonel Câmara
Why are you using an except without specifying the exception? Anyway just 
do this:

@auth.requires_login()
def cli_add():
db.client.au_usr.default = auth.user_id
form = SQLFORM(db.client, fields = ['d_fn', 'd_ln', 'd_aka', 'd_ss'], 
labels = {'d_ss': 'Social Security', 'd_aka': 'Any Aliases', 'd_65': 'Older 
than 65'}).process(next=URL('clients'))
return dict(form=form)

-- 
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] Dumb Question/Bug

2014-12-23 Thread Mark Billion
Works Just Fine

def cli_add():
try:
db.client.au_usr.default = auth.user_id
except:
redirect(URL('index'))
form = SQLFORM(db.client, fields = ['d_fn', 'd_ln', 'd_aka', 'd_ss'], 
labels = {'d_ss': 'Social Security', 'd_aka': 'Any Aliases', 'd_65': 'Older 
than 65'}).process(next=URL('clients'))
return dict(form=form)

BUT WHEN I MOVE THE FORM CALL INTO THE TRY LOOP:

def cli_add():
try:
db.client.au_usr.default = auth.user_id
form = SQLFORM(db.client, fields = ['d_fn', 'd_ln', 'd_aka', 
'd_ss'], labels = {'d_ss': 'Social Security', 'd_aka': 'Any Aliases', 
'd_65': 'Older than 65'}).process(next=URL('clients'))
except:
redirect(URL('index'))

return dict(form=form)

The look fails into the except redirect.

Any thoughts?

-- 
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: Domain model and web2py DAL

2014-12-23 Thread Alan Evangelista


> It might be easier if you provide a concrete example of what you are 
> trying to achieve (perhaps using the syntax of an existing ORM or using 
> pseudo-code) and explain how the DAL falls short.
>

Using SQLAlchemy as data mapper below.


MyItem class (models.myitem):

class MyItem(object):

def __init__(self, name, description, priority, state, creator, 
department, notification_users):

self.id = None
self.name = name
self.description = description
self.priority = priority
self.state = state
self.creator = creator
self.department = department
self.notification_users = notification_users

 (methods that implement MyItem behavior)

Similarly, there are User, Department and ItemNotificationRecipient classes.


MyItem data mapper (persistence.myitem_data_mapper):

metadata = MetaData()

# create mapper between MyItem class and my_items table
my_items_table = Table('my_items', metadata,
 Column('id', Integer, primary_key=True),
 Column('name', String(100)),
 Column('description', String(400)),
 Column('priority', Integer),
 Column('creator_id', ForeignKey('users.id', ondelete='SET NULL')),
 Column('dept_id', ForeignKey('departments.id', ondelete='SET 
NULL')),
 )
mapper(MyItem, my_items_table, properties={
'notifications' : relationship(ItemNotificationRecipient, 
backref='my_item',
cascade="all,delete")
})


Persistence manager code:

def init():

db_engine = create_engine(db_server, echo=False)
Session = sessionmaker(bind=db_engine)
self.session = Session()

def add(model_type, *attributes):

return obj

def get_all(model_type):

return objs

def get(model_type, id)

return obj

def search(model_type, filters, fields, order_by)

return objs

def update(obj)
self.session.commit()

def delete(obj)


Implementing these operations *in a generic way* to 
add/delete/update/search data in only one table is rather simple using DAL, 
foreign keys make it more complicated. There are several algorithms and 
design patterns to handle this generically (eg 
http://martinfowler.com/eaaCatalog/ ), but that's exactly what an ORM such 
as SQLAlchemy does. How would you implement this in web2py?

-- 
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] Daily task on production: scheduler or cron?

2014-12-23 Thread Lisandro
I've been reading about web2py's cron and sheduler ([1] and [2])
Also, I've read a post where Massimo says "Please use the scheduler, not 
cron. Cron must die." [3]

Now I'm creating a web2py app and I want the user to be able to configure a 
daily background task. The task consist in sending a newsletter to 
subscribers. The task doesn't take too much time to complete (because the 
app doesn't use smpt; it connects to an API so the sending is handled by an 
external service). So the task only makes some query to the database, 
connect to the API, give the order to send, and disconnect.
The thing is: I want the user to be able to configure the time that the 
newsletter is sent. For example, the user may configure the sending of the 
newsletter from monday to friday at 8am, but not saturdays o sundays. 

In this scenario, I first thought that cron would be the way to go. However 
I read that Massimo's comment ("cron must die") so I don't know what to 
use. 
I find that scheduler is very complete and robust, but I don't know if it's 
the best option for this case, considering that the task runs in very 
little time and only once a day. I'm worried about resource consumption, 
because the same app is installed multiple times on production, serving 
multiple websites, so there would be multiple workers running on background 
(maybe idle workers, however they would take some memory space I guess).

Any tip or comments? Does anyone dealed with something similar? I want to 
remark the idea that the user must be able to change configuration about 
the scheduled task.
Thanks in advance!

[1] 
 
http://web2py.com/books/default/chapter/29/04/the-core#Running-tasks-in-the-background
[2] 
 
http://web2py.com/books/default/chapter/29/13/deployment-recipes#Start-the-scheduler-as-a-Linux-service--upstart-
[3] 
 
https://groups.google.com/forum/#!searchin/web2py/cron$20must$20die/web2py/qW_ODOj3nMM/8hbZ6etJsvcJ

-- 
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: json empty with jquery

2014-12-23 Thread Jacinto Parga
First of all thanks so much for your help, Leonel. I finally got it.

I had a concept mistake. I had to declare a variable to get the data of the 
client wiht the same structure of the data. I used  datos = 
str(request.vars), it is correct because I can retrieve data: {'key':'value
','key2':'value2'} as a string, but it is not the proper way. The proper 
way is  
datos = str(request.vars.key),str(request.vars.key2)]

So I can get the values at the client with 
data.datos[0], data.datos[1]

That is solved. The second issue I had was tha I wanted to send the values 
to the controller, to store them in a database. I finally use the jquery 
set val () and send it through a form field.
$("#test").val(data.datos[0])

That's it.


El miércoles, 17 de diciembre de 2014 13:30:03 UTC+1, Leonel Câmara 
escribió:
>
> What do I mean what do I suggest I see nothing wrong with it.
>
> Do you want to change the HTML after getting the response? If it's that 
> you can do something like this:
>
> {{extend 'layout.html'}}
> Template default/test2.html
>
>
> 
>   Key
>   
>   Key2
>   
> 
>
> 
>   $(document).ready(function(){
>   $.ajax({
> type: 'POST',
> url:'http://127.0.0.1:8000/MFREG/default/test2.json',
> contentType: "application/json; charset=utf-8",
> data: {'key':'value','key2':'value2'},
> dataType: 'json',
> success:  function(data){
> for (var key in data) {
> $('#' + key).text = data[key];
> }
> }
> });
>   });
> 
>

-- 
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: Datetime Grid Filtering ignores localized format and timezone

2014-12-23 Thread Niphlod
nope! 
the issue is that SQLFORM.build_query can't understand localized dates.

On Tuesday, December 23, 2014 8:35:28 AM UTC+1, Paolo Valleri wrote:
>
> Hi,
> the issue is here 
> https://github.com/web2py/web2py/blob/master/gluon/sqlhtml.py#L1830
> can you try to replace that line with the following:
> iso_format = {'_data-w2p_datetime_format' : T('%Y-%m-%d %H:%M:%S')}
>
> Paolo
>
> On Monday, December 22, 2014 11:02:00 PM UTC+1, mcamel wrote:
>>
>> Hi all,
>>
>> I use frequently spanish localization, so dates are formated like 
>> day/month/year.
>>
>> Everything works fine if this is located at languages/es.py: '%Y-%m-%d 
>> %H:%M:%S': '%d/%m/%Y %H:%M:%S'. Represents, validators and widgets, follow 
>> this rule.
>>
>> But if you try to filter a grid by datetime with spanish format, it 
>> doesn't work. You have to especify the query with Iso format, which is 
>> annoying.
>> Even more, if you use 'w2p_timezone_plugin' to use local time zone, 
>> datetime filter also ignores it, so you have to specify UTC timezone.
>>
>> So, datetime filters at grids only works with ISO format and UTC timezone.
>>
>> Anyone knows a trick to make this work?.
>>
>> 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: Datetime Grid Filtering ignores localized format and timezone

2014-12-23 Thread mcamel
Hello,

Sounded promising, but fails. Changed web2py/gluon/sqlhtml.py with v2.9.11 
and with trunk version. Even fails if a use literal translated string as in:

iso_format = {'_data-w2p_datetime_format' : '%d/%m/%Y %H:%M:%S'}

Code to reproduce:

def dt():
from datetime import datetime
T.force('es')

db = DAL('sqlite:memory:')
db.define_table('event',
Field('name', 'string'),
Field('day_and_time', 'datetime'),
)
db.event.insert(name='Birthday1', day_and_time=datetime(1999, 1, 1, 0, 0
, 0))
db.event.insert(name='Birthday2', day_and_time=datetime(2000, 1, 1, 0, 0
, 0))

grid = SQLFORM.grid(db.event)

return dict(grid=grid)

It fails with: event.day_and_time >= "01/01/2000 00:00:00"

It works with: event.day_and_time >= "2000-01-01 00:00:00"

Regards.


El martes, 23 de diciembre de 2014 08:35:28 UTC+1, Paolo Valleri escribió:
>
> Hi,
> the issue is here 
> https://github.com/web2py/web2py/blob/master/gluon/sqlhtml.py#L1830
> can you try to replace that line with the following:
> iso_format = {'_data-w2p_datetime_format' : T('%Y-%m-%d %H:%M:%S')}
>
> Paolo
>
> On Monday, December 22, 2014 11:02:00 PM UTC+1, mcamel wrote:
>>
>> Hi all,
>>
>> I use frequently spanish localization, so dates are formated like 
>> day/month/year.
>>
>> Everything works fine if this is located at languages/es.py: '%Y-%m-%d 
>> %H:%M:%S': '%d/%m/%Y %H:%M:%S'. Represents, validators and widgets, follow 
>> this rule.
>>
>> But if you try to filter a grid by datetime with spanish format, it 
>> doesn't work. You have to especify the query with Iso format, which is 
>> annoying.
>> Even more, if you use 'w2p_timezone_plugin' to use local time zone, 
>> datetime filter also ignores it, so you have to specify UTC timezone.
>>
>> So, datetime filters at grids only works with ISO format and UTC timezone.
>>
>> Anyone knows a trick to make this work?.
>>
>> 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: Lazy options widget

2014-12-23 Thread Leonel Câmara
Hey Gael,

It should be auth.settings.expiration instead of auth.expiration.

-- 
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: Computed field not computed at INSERT ?

2014-12-23 Thread Mirek Zvolský
I am sorry, today I have found that this was my mistake.

I have string values from SQLFORM - and compute evaluates properly.

But I have different FORM for bulk insert of many records, where 
in form.process().accepted I have integer values:
compute in DAL is wrapper into try/except - and it fails for integer values.

It is a little misleading, that 
db.table.insert(string_basefield=integer_value) will not fail and record is 
created,
but compute function fails invisibly, so the computed_field remain None.

But it was completly my mistake.

-- 
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] Open Redirect Vulnerability and auth.settings

2014-12-23 Thread Prasad Muley
Hi All,

We're using web2py_2.9 and There is open redirect vulnerability 
exist following pages:

  *1) **Change Profile: *
https://127.0.0.1:8000/asdf/default/user/profile?_next=http%3A%2F%2Fgoogle.com

  *2) Change Password: *
https://127.0.0.1:8000/asdf/default/user/change_password?_next=http%3A%2F%2Fgoogle.com

  *3) Log out*: 
https://127.0.0.1:8000/asdf/default/user/logout?_next=http%3A%2F%2Fgoogle.com


It successfully redirects to www.google.com 

I've set default URL for redirection in auth settings but it isn't working

*Models/db.py*

auth.settings.logout_next=URL('user', args='login')
auth.settings.profile_next=URL('index')
auth.settings.password_next=URL('index')

*Is there any way to check URL (_next) contains valid controllers function?*
   *for eg:* URL _next='http%3A%2F%2Fgoogle.com' isn't valid controllers 
function.
 but URL _next='asdf/default/index' is valid controllers 
function.

  

-- 
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.