[web2py] unittest application modules

2014-08-03 Thread Manuele Pesenti
Hi *,
reading the manual I couldn't understand how to do what I need or at
least if I'm looking in the wrong direction...
I want to write some unittests for an application module that uses
current.db so I think it needs to be run under my application
environment. What's the right way to do it?

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.


[web2py] Re: Hide a form field in view

2014-08-03 Thread desta
I don't think I can use it because 'show_if' still happens in the 
controller.

On Sunday, August 3, 2014 4:03:59 AM UTC+3, 黄祥 wrote:

 perhaps you can use, show_if.

 ref:

 http://web2py.com/books/default/chapter/29/07/forms-and-validators#Conditional-fields

 best regards,
 stifan


-- 
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: Hide a form field in view

2014-08-03 Thread Anthony
Haven't tried it, but maybe add the value to form.vars via an onvalidation 
function:

def add_dynamic_value(form):
form.vars.dynamic_field = [value calculated from existing form.vars]

form = SQLFORM(db.mytable).process(onvalidation=add_dynamic_value)

Anthony

On Sunday, August 3, 2014 1:28:46 AM UTC+2, desta wrote:

 Is it possible, when creating a form with SQLFORM to set a field as hidden?

 In my application I have a form which one of its fields, has to be 
 completed automatically i.e. not by the user. The problem is that the data 
 that goes into that field is dynamic (depends on the actions of the user) 
 and it is not known when the form is constructed in the controller. That 
 means that the field has to be in the html and hidden. *readable=False* 
 and *writable=False* don't work in this case.

 Any suggestions?

 Thank you.


-- 
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] Switch off cookies unless the user logs in?

2014-08-03 Thread Thomas Wimmer
How can i switch off (session) cookies unless a user logs in?

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: Switch off cookies unless the user logs in?

2014-08-03 Thread LightDot
In the beginning of your controller (e.g.):

def index():
if not auth.is_logged_in():
session.forget(response)

Regards

On Sunday, August 3, 2014 2:11:29 PM UTC+2, Thomas Wimmer wrote:

 How can i switch off (session) cookies unless a user logs in?

 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: Scheduler, modules, and database calls

2014-08-03 Thread Niphlod
there's nothing different in running the function in the web2py shell. 
global variables defined in models are available in the scheduler.

On Friday, August 1, 2014 11:36:36 PM UTC+2, Bilal Hasan wrote:

 So I'm trying to set up a scheduler, which makes calls to the module. 
 Problem is, it keeps failing. And since it's the scheduler, it's super hard 
 to debug if not almost impossible.

 Within the module, it makes db calls.

 Now since db is a global variable, which module CANNOT access. I have to 
 pass in db through its function calls.

 So I have that part figured out. My question is, when scheduler runs its 
 function, does it have accses to the same global db instance that's a part 
 of web2py?

 Since scheduler runs on its own process I have reason to believe whenever 
 scheduler runs, it doesn't have access to db, request, etc.

 Any ideas on what's a good way of going about running a scheduler that 
 calls a function in a module which makes calls to the database using the 
 global db variable.


-- 
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: How do you gracefully terminate a scheduled task

2014-08-03 Thread Niphlod
task status is normally set to failed if the task raises an exception. You 
can't however ask a thing made to run over and over in a loop (the 
scheduler) to stop at the first task that raises an exception, else every 
other queued task won't be processed.

On Friday, August 1, 2014 5:01:56 PM UTC+2, Stephen Weiss wrote:


 I understand that's what stetting STOP_TASK to do.

 However, what I'm in search of is a way for the worker task to cleanly 
 stop processing on its own, setting the state to FAILED.


-- 
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: SQLFORM.grid, how to edit non-visible field in the onvalidate function?

2014-08-03 Thread Mirek Zvolský
Thank you very much.
But seems following works for me too:

form = SQLFORM.factory(
Field('find_contact_string', label=Choose from contacts),
Field('contact_id', readable=False, writable=False),
hidden=dict(contact_id='')
)
if form.process(onvalidation=_validate_form).accepted:
db.invoice[request.args(0)] = dict(contact_id=form.vars.contact_id)
redirect(URL(..))
return dict(form=form)

def _validate_form(form):
if request.vars.contact_id:
form.vars.contact_id = request.vars.contact_id
else:
form.errors.find_contact_string = Enter a text to find the 
customer

I assign the errors message to the visible field (find_contact_string).
contact_id I change with jQuery:
$('[name=contact_id]').val(2);





Dne neděle, 9. února 2014 17:26:27 UTC+1 A36_Marty napsal(a):

 A little more progress -- hopefully to help someone else that Googles for 
 this and ends up stumped like I was...  I've spent an inordinate amount of 
 time and frustration figuring out little nuances that I wouldn't wish upon 
 anyone...   

 Gotca's that I learned:

 1) To hide a field, first remove it from the fields to be shown in the 
 SQLFORM, then add it back with the hidden= attribute.  Just specifying it 
 as hidden does not remove it.

 i.e. This does NOT work, the field 'hidden' is shown to the user:
 db.define_table('person',
Field('name', 'string'),
Field('hidden', 'string'))

 def index():
form = SQLFORM(db.person, hidden=dict(hidden=Default hidden text))

 form.vars.hidden = request.vars.


 This DOES work:

 db.define_table('person',
   Field('name', 'string'),
   Field('hidden', 'string'))

 def index():
   form = SQLFORM(db.person, fields=['name'], hidden=dict(hidden=Default 
 hidden text))

 form.vars.hidden = request.vars.


 2) To get a list of fields to show (from a larger table definition, so as 
 to not hand-type each field name), you must get a copy of the fields from 
 the table object, not just a reference to the fields.

 i.e. This DOES NOT work.  The field will be be removed and unseen by the 
 user, however since Python works by reference, the field is removed from 
 the table definition and the form.accepted() will fail as web2py will try 
 to insert a value into field that no longer exists.

 db.define_table('person',
   Field('name', 'string'),
   Field('hidden', 'string'))

 def index():

   fields_to_show = db.person.fields
   fields_to_show.remove('hidden')

   form = SQLFORM(db.person, fields= fields_to_show, 
 hidden=dict(hidden=Default 
 hidden text))



 form.vars.hidden = request.vars.Enter code here...

 This DOES work (only 3 characters difference) - making a copy of the 
 fields list instead of getting it by reference:

 db.define_table('person',
   Field('name', 'string'),
   Field('hidden', 'string'))

 def index():

   fields_to_show = db.person.fields*[:]*
   fields_to_show.remove('hidden')

   form = SQLFORM(db.person, fields= fields_to_show, 
 hidden=dict(hidden=Default 
 hidden text))



 form.vars.hidden = request.vars.Enter code here...


 3. To update the value of the hidden fields (or any fields), the form.vars 
 modification must be before the form.process call.

 i.e. This DOES NOT work.

 db.define_table('person',
 Field('name', 'string'),
 Field('hidden', 'string'))

 def index():
 form = SQLFORM(db.person, fields=['name'], hidden=dict(hidden=Default 
 hidden text))

 form.vars.hidden = request.vars.
 
 if form.process(onvalidation=validate_form).accepted:
 pass

 return dict(form=form)

 def validate_form(form):

 *form.vars.hidden = Changed hidden text   #Never gets written to 
 database*
 form.accepted = True

 This does work:

 db.define_table('person',
 Field('name', 'string'),
 Field('hidden', 'string'))

 def index():
 form = SQLFORM(db.person, fields=['name'], hidden=dict(hidden=Default 
 hidden text))

 form.vars.hidden = request.vars.

 *form.vars.hidden = Changed hidden text   #Successfully written to 
 database*
 
 if form.process(onvalidation=validate_form).accepted:
 pass

 return dict(form=form)

 def validate_form(form):

 form.accepted = True

 Take care...




-- 
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] emailing a pdf view as an attachment

2014-08-03 Thread 'sasogeek' via web2py-users
I have a form, and i display the details entered in the form on .pdf views 
page. Is it possible to use web2py to email that generated pdf page to 
someone? what I want to achieve is to allow users to fill the form and then 
click a button to send the pdf containing the entered details without 
downloading the pdf and re-uploading it... it's about the best solution 
I've come up with so far but that's not what I want to achieve. It'll be 
too much hustle for users (even I wouldn't want to do that)

-- 
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] Web2Py on BeagleBone Black Rev C - Debian

2014-08-03 Thread Patrick Walters
Anyone had success getting Web2Py running as the default site (port 80) on 
a BB Rev C running debian?

I used the ubuntu install script from the Web2Py docs and seem to have a 
conflict with the default website that comes pre-installed on the BBB Rev 
C. 
The script seems to have completed successfully, but I can't connect to the 
web2py admin page.

Any suggestions on how to validate the install and config or to look for 
where conflicts can occur (maybe competing web servers?) would be much 
appreciated.

Thanks for the help,
-p

-- 
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] cvs web2py model

2014-08-03 Thread eric cuver
hello,

i tried tu create webpy model from csv file with this command :
/home/csvstudio# for line in open('db_departement.py','r'): print line, 

the terminal answer-   bash: Erreur de syntaxe près du symbole inattendu « 
( »

somebody look where my error.

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: Question about FORM

2014-08-03 Thread tiraen
Yes, thank you, it is the second way to get. First, as I understand it is 
more suitable for the form, which is filled. 

The only time The blue button is turned. And underlined font, that I did 
not point


суббота, 2 августа 2014 г., 22:43:00 UTC+3 пользователь Massimo Di Pierro 
написал:

 form = FORM()
 makes a form but you are making a form that contains no 
 input/select/texarea/buttons.

 form.add_button('Click', URL ('first'))
 adds a button after the submit button in the previous form, but that form 
 does not have a submit button.

 If you really want a form, you should put something in the form:

 form = FORM(INPUT(_type=Submit)
 form.add_button('Click', URL ('first'))

 or do not use a form but, for example, a DIV

 form = DIV()
 form.append(A('Click', _href=URL ('first')))



 On Saturday, 2 August 2014 12:58:04 UTC-5, tir...@gmail.com wrote:

 Good evening, I just started learning this fremvork because questions 
 may seem childish, but still. 
 task: 
 Create a jump button (just to another page) 

 My solution, I wrote a similar code kontoroller
  
 def index (): 
  form = FORM () 
  form.add_button ('Click', URL ('first')) 
  return dict (form = form) 
 the error is 

 AttributeError: 'NoneType' object has no attribute 'parent'

 Although the official documentation of such a method is listed as a way 
 to create simple buttons. I would be grateful for your help



-- 
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] PeerQuiz

2014-08-03 Thread eric cuver
hello ,

everybody,
i looking for peerquiz web2py source http://vimeo.com/83536698  . i dont 
find in github. 
somebody know where i can find it ?

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: Strange ajax problem

2014-08-03 Thread Reza Amindarbari
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'}}
 h1This is the default/ajax_post.html template/h1
 form onsubmit=return false
 divPost : input name=post//div
 divbutton onclick=ajax('new_post', ['post'],'results')Post 
 Message/button/div
 /form
 div id=results
 {{=posts}}
 /div
 div
 {{=search[0]}}
 /div

 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:

 button value=Working... class=btn disabled onclick=ajax('new_post', 
 ['post'],'results')Post Message/button

 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.