[web2py] Re: how do I create, multiple forms and precess them, using 'for' statement?

2013-12-21 Thread Ivo
I got it resolved... ashamed to say it but I missed the = in 
the {{form.custom.end}} tag :(

On Friday, December 20, 2013 3:16:34 PM UTC+1, Ivo wrote:

 I have chosen to go the custom form way.
 The only issue I have is that upon hitting submit, the button submits all 
 the forms on the page instead of just the one owning the button. I think 
 this also screws up my validation and it prevents records from being 
 inserted to the db.  

 controller:
 def show_form():
 
 users_1 = 
 db(db.people.id.belongs(session.people.keys())).select(db.people.user_id)
 users_2=[]
 for user in users_1:
 if user not in users_2:
 users_2.append(user)
 else:
 pass

 forms=[]  
 for user in users_2:
 usr= db(db.auth_user.id
 ==user.user_id).select(db.auth_user.username,db.auth_user.id)[0]
 usr1=usr.username
 usr2=usr.id
 key=str(usr2)
 fields = [
   Field('key',default=key,writable=False),
   Field('username',default=usr1,writable=False),
   Field('address',default='Fill in your 
 address',type='text')
   ]

 form=SQLFORM.factory(*fields, 
 table_name=key,hidden=dict(ss_id=key),
  buttons=[
   BUTTON(Save Changes, 
 _class=btn btn-primary)])
 if form.process(formname=key, hideerror=True).accepted:
 db.parking.insert(name=usr1, address=form.vars.address)
 forms.append(form)
 
 return dict(forms=forms)



 view:
 {{for form in forms:}}
 {{=form.custom.begin}}
 User: {{=form.custom.widget.username}} br
 Address: {{=form.custom.widget.address}} br
 {{form.custom.end}}brbr
 {{pass}}


 On Wednesday, December 18, 2013 9:45:14 PM UTC+1, Niphlod wrote:

 form.process adds little bits to the form to be able to actually process 
 the posted data.

 in pseudo-code you need to

 list_of_forms = []
 for something in list_of_values:
  key = something_unique
  form = SQLFORM()
  if form.process(formname=something_unique).accepted:
.code dealing with the posted values, such as form.vars, 
 etc
  elif form.errors:
.code dealing with form errors

  list_of_forms.append(form)
 ..
 return dict(list_of_forms=list_of_forms, )

 In the view, you can then:

 {{for single_form in list_of_forms:}}
 div class=row
 {{=single_form}} #or {{single_form.custom.etc etc etc}}
 /div
 hr /
 {{pass}}



-- 
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/groups/opt_out.


[web2py] Re: how do I create, multiple forms and precess them, using 'for' statement?

2013-12-20 Thread Ivo
I have chosen to go the custom form way.
The only issue I have is that upon hitting submit, the button submits all 
the forms on the page instead of just the one owning the button. I think 
this also screws up my validation and it prevents records from being 
inserted to the db.  

controller:
def show_form():

users_1 = 
db(db.people.id.belongs(session.people.keys())).select(db.people.user_id)
users_2=[]
for user in users_1:
if user not in users_2:
users_2.append(user)
else:
pass

forms=[]  
for user in users_2:
usr= db(db.auth_user.id==user.user_id).select(db.auth_user.username,
db.auth_user.id)[0]
usr1=usr.username
usr2=usr.id
key=str(usr2)
fields = [
  Field('key',default=key,writable=False),
  Field('username',default=usr1,writable=False),
  Field('address',default='Fill in your 
address',type='text')
  ]

form=SQLFORM.factory(*fields, table_name=key,hidden=dict(ss_id=key),
 buttons=[
  BUTTON(Save Changes, 
_class=btn btn-primary)])
if form.process(formname=key, hideerror=True).accepted:
db.parking.insert(name=usr1, address=form.vars.address)
forms.append(form)

return dict(forms=forms)



view:
{{for form in forms:}}
{{=form.custom.begin}}
User: {{=form.custom.widget.username}} br
Address: {{=form.custom.widget.address}} br
{{form.custom.end}}brbr
{{pass}}


On Wednesday, December 18, 2013 9:45:14 PM UTC+1, Niphlod wrote:

 form.process adds little bits to the form to be able to actually process 
 the posted data.

 in pseudo-code you need to

 list_of_forms = []
 for something in list_of_values:
  key = something_unique
  form = SQLFORM()
  if form.process(formname=something_unique).accepted:
.code dealing with the posted values, such as form.vars, etc
  elif form.errors:
.code dealing with form errors

  list_of_forms.append(form)
 ..
 return dict(list_of_forms=list_of_forms, )

 In the view, you can then:

 {{for single_form in list_of_forms:}}
 div class=row
 {{=single_form}} #or {{single_form.custom.etc etc etc}}
 /div
 hr /
 {{pass}}


-- 
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/groups/opt_out.


[web2py] Re: how do I create, multiple forms and precess them, using 'for' statement?

2013-12-18 Thread Ivo
Hi Niphlod,
I studied your example, but can't quite get it to work yet. I also tried 
taking a look at your view but it's to complicated for me.
The only issue I'm having now is that the key isn't incrementing from the 
view side. Can I pass the key in the view like {{=form+key}} or something? 
Maybe I'm screwing up my controller.

controller:
def show_form():

users_1 = 
db(db.people.id.belongs(session.people.keys())).select(db.people.user_id)
users_2=[]
for user in users_1:
if user not in users_2:
users_2.append(user)
else:
pass

   
for user in users_2:
usr= 
db(db.auth_user.id==user.user_id).select(db.auth_user.username,db.auth_user.id)[0]
usr1=usr.username
usr2=usr.id
key=str(usr2)
fields = [
  Field('username',default=usr1,writable=False)
  ]
form=SQLFORM.factory(*fields, table_name=key,hidden=dict(ss_id=key))

return dict(form=form, users_2=users_2,usr1=usr1,usr2=usr2,key=key)


View:
{{extend 'layout.html'}}
h1Form:/h1
{{for user in users_2:}}

{{=form}}
{{pass}}

!-- returns a form for each user but uses the same key for every form; 
result is that the default value is the same for every form--

h1
custom form:
/h1
{{=form.custom.begin}}

{{for user in users_2:}}

User: {{=form.custom.widget.user}}br

{{pass}}
{{form.custom.end}}
!-- returns a form for each user but uses the same key for every form; 
result is that the default value is the same for every form--

h1
manual form: gives the correct results
/h1
{{for user in users_2:}}
{{
usr= 
db(db.auth_user.id==user.user_id).select(db.auth_user.username,db.auth_user.id)[0]
usr1=usr.username
usr2=usr.id
key=str(usr2)
}}
KEY:{{=key}}br !-- here to check that the key changes correctly --
form action=# enctype=multipart/form-data method=posttabletr 
id={{=key}}_user__rowtd class=w2p_fllabel for={{=key}}_user 
id={{=key}}_user__labelusername: /label/tdtd 
class=w2p_fw{{=usr1}}/tdtd class=w2p_fc/td/trtr 
id=submit_record__rowtd class=w2p_fl/tdtd class=w2p_fwinput 
type=submit value=Submit //tdtd 
class=w2p_fc/td/tr/tablediv style=display:none;input 
name=ss_id type=hidden value={{=key}} //div/form
{{pass}}



I prefer to use the {{form.custom.widget[Field]}} tags.
Can you tell me what I'm doing wrong?

On Tuesday, December 17, 2013 11:21:32 PM UTC+1, Niphlod wrote:

 you just need to figure out a key to separate different forms, and use 
 formname accordingly as stated in the book.
 I do it in w2p_tvseries already, you can take a look at 
 https://github.com/niphlod/w2p_tvseries/blob/master/controllers/manage.py
 specifically, see lines #169, #239 and #266



-- 
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/groups/opt_out.


[web2py] Re: how do I create, multiple forms and precess them, using 'for' statement?

2013-12-18 Thread Ivo
Thanks, I understand what you mean.
I left the form.accepts out as it wasn't relevant to my question (and am 
still designing it) but thanks for pointing it out anyway!

I'm going to struggle with the unpacking part for a while and  thanks for 
not spoonfeeding me the code! The goal is me actually learning something ;) 
after a few months I'm finally at a point where I can grasp the concepts 
and code somewhat.


On Wednesday, December 18, 2013 8:41:11 PM UTC+1, Niphlod wrote:

 you are returning only the last form... you need to make a dict or a 
 list out of the single form you generate in the for loop, and then in the 
 view you can unpack them separately

 in my code, you can see on #L296 how every single form is appended to 
 forms, that is a list and that list is returned to the view. 

 Also, you're leaving out  form.accepts (or form.process )... you can't 
 access form data in your controller without it


-- 
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/groups/opt_out.


[web2py] how do I create, multiple forms and precess them, using 'for' statement?

2013-12-17 Thread Ivo
I want to create multiple forms with a 'for' statement and validate/process 
them.
the amount of forms to generate is dependent on a list containing user id's.
the list is dynamic; so I have a function generating a list, 'users', which 
contains: user:1L, user:4L, etc...
now I want to create a form for each of them and after 'submit' process 
them.

Normally I would just create a form in the controller like:
def show_form():
   form = SQLFORM.x()
   return dict(form=form)
and process it with:
   if form.accepts

however this would only generate one form... 
using:
def sow_form():
for user in users:
form = SQLFORM.x()
   return dict(form=form) 
and calling it from the view with {{=form}} doesn't work either because of 
'form' being static.

Creating the form from the view is a lot easier to do with:
{{for user in users:}}
(my form)
{{pass}}

but how do I process it?
I can give the form a unique name from the view with name={{=user}}
but then what?

The form is mostly prepopulated with vars created/calculated from the view 
but a part of those can be created/calculated from the controller. the form 
requires a uuid which needed in the processing of the form.

What is the best way to achieve this?
would:
def show_form():
for user in users:
form[user] = SQLFORM.x()
work? and how can I populate that form?

Please point me in the right direction.


-- 
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/groups/opt_out.


[web2py] Re: how do I create, multiple forms and precess them, using 'for' statement?

2013-12-17 Thread Ivo
I understand that I need to use different formnames, I just don't 
understand how I would syntax it do that automatically.
A single form will not suffice; I think is has to be different forms. I 
need a uuid for each user and create/update several records for each user.
Basically I need to use something like:

def show_form():
for user in users:
form= SQLFORM.factory()
return dict(form=form)
But then in a way that works. I tried several ways, but am still 
unsuccessful...
I read (, re-read and re-re-read) the chapter on forms in 'the book' but 
there's no mention on how to achieve something like this, neither in the 
examples.
I tried digging through a lot of the sample apps too but nothing.

I understand this is not the basic way forms are designed to be used but is 
it that uncommon to do this?
I also tried:
for user in users:
form[user]= SQLFORM.factory()
return dict(form[user]=form[user])
this throws a global name form is not defined.

I also tried:
for user in users:
form = SQLFORM.factory()
form[user] = form

any ideas?

On Tuesday, December 17, 2013 9:03:50 PM UTC+1, Massimo Di Pierro wrote:

 What does the model look like? You amy want to create a single form with 
 fields for each user.

 On Tuesday, 17 December 2013 05:14:25 UTC-6, Ivo wrote:

 I want to create multiple forms with a 'for' statement and 
 validate/process them.
 the amount of forms to generate is dependent on a list containing user 
 id's.
 the list is dynamic; so I have a function generating a list, 'users', 
 which contains: user:1L, user:4L, etc...
 now I want to create a form for each of them and after 'submit' process 
 them.

 Normally I would just create a form in the controller like:
 def show_form():
form = SQLFORM.x()
return dict(form=form)
 and process it with:
if form.accepts

 however this would only generate one form... 
 using:
 def sow_form():
 for user in users:
 form = SQLFORM.x()
return dict(form=form) 
 and calling it from the view with {{=form}} doesn't work either because 
 of 'form' being static.

 Creating the form from the view is a lot easier to do with:
 {{for user in users:}}
 (my form)
 {{pass}}

 but how do I process it?
 I can give the form a unique name from the view with name={{=user}}
 but then what?

 The form is mostly prepopulated with vars created/calculated from the 
 view but a part of those can be created/calculated from the controller. 
 the form requires a uuid which needed in the processing of the form.

 What is the best way to achieve this?
 would:
 def show_form():
 for user in users:
 form[user] = SQLFORM.x()
 work? and how can I populate that form?

 Please point me in the right direction.




-- 
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/groups/opt_out.


Re: [web2py] Re: how do I create, multiple forms and precess them, using 'for' statement?

2013-12-17 Thread ivo . nijenhuis
Thank you! Will spend tomorrow figuring it out. Thanks for the example!

Sent from my iPhone

On 17 dec. 2013, at 23:21, Niphlod niph...@gmail.com wrote:

 you just need to figure out a key to separate different forms, and use 
 formname accordingly as stated in the book.
 I do it in w2p_tvseries already, you can take a look at 
 https://github.com/niphlod/w2p_tvseries/blob/master/controllers/manage.py
 specifically, see lines #169, #239 and #266
 
 -- 
 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/7O1sR3M4BRw/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/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/groups/opt_out.


[web2py] count amount of times a field is present in selection and fetch a record for each

2013-12-13 Thread Ivo
I have a list containing record id's and need to select those records from 
a table. then I need to count how many different values are contained in 
the fields and for each select the first record of an other table.

ids = session.people.keys()
persons = {}

for id in ids: persons[id]=db(db.people.id==id).select()[0]

the rows contain a field user_name
now I want to check(count) how many different user_name's are in my 
selected records.
(and retrieve the first record, with a bool set to False, from db.parking 
for each. 
db.parking records contain a bool which I want to toggle to true)

can someone help me (with at least the counting part)?


-- 
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/groups/opt_out.


[web2py] Re: count amount of times a field is present in selection and fetch a record for each

2013-12-13 Thread Ivo
sorry for being unclear.
I want to assign a parkingspot_code for each user_name in either a form or 
a grid and populate it with some other data from the people db

The db.parking table contains:
db.define_table('parking',
Field('parkingspot_code', 'string', unique=True),
Field('used', 'boolean', default=False))

I think I either need to togle the boolean to true if a code is used or I 
need to select the first record in the db, copy the code value and delete 
the record. The parkingspot_code's are pre generated and 1 time use only. 
The resulting form or grid is stored in an other table

I hope this clarifies it a bit.

On Friday, December 13, 2013 6:16:44 PM UTC+1, Leonel Câmara wrote:

 You need to be more clear with what you're trying to do, I also don't know 
 what the hell is in db.parking table or in db.people. This makes it very 
 difficult to help you.

 BTW you could just do this to get a list of persons:

 persons = db(db.people.id.belongs(session.people.keys())).select()



 Sexta-feira, 13 de Dezembro de 2013 12:04:43 UTC, Ivo escreveu:

 I have a list containing record id's and need to select those records 
 from a table. then I need to count how many different values are contained 
 in the fields and for each select the first record of an other table.

 ids = session.people.keys()
 persons = {}

 for id in ids: persons[id]=db(db.people.id==id).select()[0]
 person_list[]
 for id,person in persons.items():
 person=people.user_name
 person_list.append(person)


 now I want retrieve the first record, with a bool set to False, from 
 db.parking for each. 
 db.parking records contain a bool which I want to toggle to 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/groups/opt_out.


[web2py] Re: get a controller function in default view

2013-12-09 Thread Ivo
Thank you for the reply.
This goes a bit above my (web2)py skills for the moment.
I resolved it by declaring the entire function inside the view.
that way it's always available when I call the html.

On Monday, December 9, 2013 2:39:16 AM UTC+1, Anthony wrote:

 It would help if you show layout_1.html and how it is included in the 
 view, but you can refer to a variable returned by the controller in any 
 included view:

 In myfunction.html:

 {{extend 'layout.html'}}

 {{include 'layout_1.html'}}

 Then in layout_1.html:

 {{=myresult}}

 Or if you need to check whether myresult exists:

 {{=globals().get('myresult', '')}}

 Anthony

 On Sunday, December 8, 2013 11:41:01 AM UTC-5, Ivo wrote:

 I'm not quite sure what you mean or how I should do that.
 The layout_1.html serves as the template on how items are displayed. 
 (it's not a replacement for layout.html)
 Layout_1.html is included in several other views as the basis of how to 
 display the items.

 It has a table inside which dictates how the items are shown.
 I need to add the my_result inside that table.

 I'm going to try to copy the function to a model as well. that should 
 make it globally available. 
 Since I'm new to all of this I'm not sure on how things should be done 
 and what's best practice.


 On Sunday, December 8, 2013 5:14:19 PM UTC+1, 黄祥 wrote:

 why not extend the layout_1.html in your view?
 e.g.
 {{extend 'layout_1.html'}}

 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/groups/opt_out.


[web2py] having troubles with scheduler in 2.8.2

2013-12-08 Thread Ivo
I'm trying to get the scheduler up and running but it keeps giving me 
failed and then stops.
-D0 gives me:

DEBUG:web2py.scheduler.mac.linuxmce#16946:   task starting
DEBUG:web2py.scheduler.mac.linuxmce#16946:task started
DEBUG:web2py.scheduler.mac.linuxmce#16946:recording heartbeat 
(RUNNING)
DEBUG:web2py.scheduler.mac.linuxmce#16973:new task report: FAILED
DEBUG:web2py.scheduler.mac.linuxmce#16973:   traceback: Traceback (most 
recent call last):
  File /Applications/web2py 
2/web2py-2.8.2/web2py.app/Contents/Resources/gluon/scheduler.py, line 238, 
in executor
result = dumps(_function(*args, **vars))
  File applications/test_app/models/tasks.py, line 108, in update
db.people.commit()
  File /Applications/web2py 
2/web2py-2.8.2/web2py.app/Contents/Resources/gluon/dal.py, line 8817, in 
__getitem__
return ogetattr(self, str(key))
AttributeError: 'Table' object has no attribute 'commit'

Traceback (most recent call last):
  File 
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.py,
 
line 266, in _feed
send(obj)
PicklingError: Can't pickle class '__restricted__.TaskReport': import of 
module __restricted__ failed
DEBUG:web2py.scheduler.mac.linuxmce#16946:task stopped
DEBUG:web2py.scheduler.mac.linuxmce#16946:new task report: STOPPED
DEBUG:web2py.scheduler.mac.linuxmce#16946:   result: None
DEBUG:web2py.scheduler.mac.linuxmce#16946: recording task report in db 
(STOPPED)
INFO:web2py.scheduler.mac.linuxmce#16946:task completed (STOPPED)



-used db is SQLite
-tasks.py:

def update():
rows=db(db.people.id == 1).select()
row=rows[0]
row.update_record(name = John)
db.people.commit()
return locals()

anyone?

-- 
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/groups/opt_out.


[web2py] Re: foreign key constraint failed ???

2013-12-08 Thread Ivo
though it may not be the preferred solution I resolved it by adding:
adapter_args=dict(foreign_keys=False) to db = 
DAL('sqlite://storage.sqlite') in db.py


On Sunday, December 8, 2013 3:16:36 PM UTC+1, Ivan Gazzola wrote:

 I can't resolve this ticket in my app. I try to insert in 
 Pazienti_Consulenza from appadmin but i've always this error:
 
 class 'sqlite3.IntegrityError' foreign key constraint failed
 

 This is my model:

 db.define_table('Nominativi',
 Field('nome',notnull=True, represent=lambda nome:nome.title()),
 Field('categoria',db.Categorie_Nominativi,default='1'),
 Field('sesso',requires=IS_EMPTY_OR(IS_IN_SET(['maschio','femmina']))),
 Field('mail',requires=IS_EMPTY_OR(IS_EMAIL(error_message=T('Inserire 
 Una Mail Valida',
 Field('indirizzo'),
 Field('localita', label='Località'),
 Field('cap',requires=IS_EMPTY_OR(IS_LENGTH(5,5, 
 error_message=T('Inserire Un CAP valido',
 Field('provincia',requires=IS_EMPTY_OR(IS_IN_SET(Elenco_Province, 
 zero=T('Selezionare una Provincia',
 Field('codice_fiscale',length=20),
 Field('partita_iva',length=20),
 Field('data_di_nascita','date'),
 Field('professione'),
 Field('padre'),
 Field('madre'),
 Field('inviato_da'),
 Field('id_precendente','integer'),
 format=lambda 
 r:r.nome.title()+'--'+db.Categorie_Nominativi(r.categoria)['categoria'])

 db.Nominativi.nome.filter_in = lambda value : w2p_encrypt(value,key=chiave)
 db.Nominativi.nome.filter_out = lambda value : 
 w2p_decrypt(value,key=chiave)
 db.Nominativi.mail.filter_in = lambda value : w2p_encrypt(value,key=chiave)
 db.Nominativi.mail.filter_out = lambda value : 
 w2p_decrypt(value,key=chiave)
 db.Nominativi.indirizzo.filter_in = lambda value : 
 w2p_encrypt(value,key=chiave)
 db.Nominativi.indirizzo.filter_out = lambda value : 
 w2p_decrypt(value,key=chiave)
 db.Nominativi.localita.filter_in = lambda value : 
 w2p_encrypt(value,key=chiave)
 db.Nominativi.localita.filter_out = lambda value : 
 w2p_decrypt(value,key=chiave)
 db.Nominativi.cap.filter_in = lambda value : w2p_encrypt(value,key=chiave)
 db.Nominativi.cap.filter_out = lambda value : w2p_decrypt(value,key=chiave)
 db.Nominativi.codice_fiscale.filter_in = lambda value : 
 w2p_encrypt(value,key=chiave)
 db.Nominativi.codice_fiscale.filter_out = lambda value : 
 w2p_decrypt(value,key=chiave)
 db.Nominativi.padre.filter_in = lambda value : 
 w2p_encrypt(value,key=chiave)
 db.Nominativi.padre.filter_out = lambda value : 
 w2p_decrypt(value,key=chiave)
 db.Nominativi.madre.filter_in = lambda value : 
 w2p_encrypt(value,key=chiave)
 db.Nominativi.madre.filter_out = lambda value : 
 w2p_decrypt(value,key=chiave)

 db.Nominativi.categoria.requires=IS_IN_DB(db,'Categorie_Nominativi.id','%(categoria)s',zero=None)
 db.Nominativi.categoria.represent = lambda id,row: row.categoria
 db.Nominativi.nome.represent = lambda nome,row: nome.title()

 db.Nominativi.inviato_da.widget=SQLFORM.widgets.autocomplete(request,db.Nominativi.nome)

 db.define_table('Relazioni',
 Field('nominativo',db.Nominativi,required=True,requires=[IS_IN_DB(db, 
 'Nominativi.id')]),
 Field('referente',db.Nominativi,required=True,requires=[IS_IN_DB(db, 
 'Nominativi.id')]),
 Field('tipo_relazione',label='Tipo di relazione'))

 db.Relazioni.tipo_relazione.widget = lambda field,value: \
  SQLFORM.widgets.string.widget(field,value,_placeholder=Inserire il 
 tipo di relazione)

 db.Relazioni.referente.widget=SQLFORM.widgets.autocomplete(request,db.Nominativi.nome,id_field=
 db.Nominativi.id,limitby=(0,10), min_length=3)


 db.define_table(Consulenze,
 Field('dentista',db.Nominativi,required=True),
 Field('data_inizio_collaborazione','date'),
 Field('data_fine_collaborazione','date'),
 Field('id_precedente','integer'),
 format=lambda r:db.Nominativi(r.dentista)['nome'])
 odontoiatri=db(db.Nominativi.categoria==2)

 db.Consulenze.dentista.requires=IS_IN_DB(odontoiatri,'Nominativi.id','%(nome)s')

 db.define_table(Pazienti_Consulenza,
 Field('dentista',db.Consulenze, required=True),
 Field('paziente',db.Nominativi,required=True, unique=True))

 everything worked fine when I've added the table.
 I can't see what is wrong in the last table ...

 Thx


-- 
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/groups/opt_out.


[web2py] get a controller function in default view

2013-12-08 Thread Ivo
I need to get dictionary item which is located in 
default.py in to a view. to be more specific:

default.py:

def my function():
my_result = 'my result' 
return dict(my_result=my_result)

the view is accessed from default/my_function.html, 
but my_result is also needed in a html above that (views/layout_1.html) 
how do I 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/groups/opt_out.


[web2py] Re: get a controller function in default view

2013-12-08 Thread Ivo
I'm not quite sure what you mean or how I should do that.
The layout_1.html serves as the template on how items are displayed. (it's 
not a replacement for layout.html)
Layout_1.html is included in several other views as the basis of how to 
display the items.

It has a table inside which dictates how the items are shown.
I need to add the my_result inside that table.

I'm going to try to copy the function to a model as well. that should make 
it globally available. 
Since I'm new to all of this I'm not sure on how things should be done and 
what's best practice.


On Sunday, December 8, 2013 5:14:19 PM UTC+1, 黄祥 wrote:

 why not extend the layout_1.html in your view?
 e.g.
 {{extend 'layout_1.html'}}

 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/groups/opt_out.


[web2py] Re: get a controller function in default view

2013-12-08 Thread Ivo
Any one know how I can do this.
I tried creating a model but still no joy...

On Sunday, December 8, 2013 5:41:01 PM UTC+1, Ivo wrote:

 I'm not quite sure what you mean or how I should do that.
 The layout_1.html serves as the template on how items are displayed. (it's 
 not a replacement for layout.html)
 Layout_1.html is included in several other views as the basis of how to 
 display the items.

 It has a table inside which dictates how the items are shown.
 I need to add the my_result inside that table.

 I'm going to try to copy the function to a model as well. that should make 
 it globally available. 
 Since I'm new to all of this I'm not sure on how things should be done and 
 what's best practice.


 On Sunday, December 8, 2013 5:14:19 PM UTC+1, 黄祥 wrote:

 why not extend the layout_1.html in your view?
 e.g.
 {{extend 'layout_1.html'}}

 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/groups/opt_out.


[web2py] Re: app not working after install 2.8.2 is_mobile error

2013-12-08 Thread Ivo
I searched for one as well but just took the risk because I backed up my 
apps.
however I do propose that the upgrade script includes clearing out sessions 
and cache this will save a lot time and questions. Also the impact should 
be mentioned. For example the foreign key error a lot of us are having.

On Monday, December 9, 2013 5:11:40 AM UTC+1, Vinhthuy wrote:

 Massimo: I feel really scared reading this.  In fact, I haven't upgraded 
 to the latest version yet, partly because exactly what you said.  I haven't 
 kept up with this reading list, and I am afraid that after the upgrade my 
 apps won't work because I fail to do certain things that were discussed 
 here.

 Can you please enforce a policy that whatever we need to do after an 
 upgrade would be listed in CHANGES?  Thanks.



 On Friday, December 6, 2013 8:38:25 PM UTC-6, Massimo Di Pierro wrote:

 You missed a few threads discussing this. ;-)
 You need to clear/remove the sessions. The format of the session storage 
 has changed.

 On Friday, 6 December 2013 17:55:52 UTC-6, Ivo wrote:

 I tried upgrading the web2py to 2.8.2 that was a bad idea...
 it totally killed the web2py app.
 I redownloaded a clean version and copied over my app now it throws the 
 weirdest error:
 type 'exceptions.NameError''dict' object has no attribute 'is_mobile'
 it traces to user.html, but in reality it's caused by layout.htm
 the welcome app is working so I had a look inside the layout.html 
 basicly the same except for a few mods I made that are unrelated.

 what am I missing? 



-- 
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/groups/opt_out.


[web2py] Re: Direct access to a SQLFORM.grid single record view

2013-12-07 Thread Ivo
Ah yes forgot about that.
If you don't mind you can turn off the signature in grid (it's there for 
security)
do you have multiple users?

On Friday, December 6, 2013 2:59:46 PM UTC+1, Gael Princivalle wrote:

 Hello all.

 Is it possible to call a function/page with an SQLFORM.grid asking for the 
 single view mode instead of the list mode ?

 Something like ...
 {{=A('test link', _href=URL('products_listing/view/products/717'))}}

 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/groups/opt_out.


[web2py] Re: app not working after install 2.8.2 is_mobile error

2013-12-07 Thread Ivo
Oops... sorry I didn't catch that
I could have thought of that myself :(
thanks massimo!

On Saturday, December 7, 2013 3:38:25 AM UTC+1, Massimo Di Pierro wrote:

 You missed a few threads discussing this. ;-)
 You need to clear/remove the sessions. The format of the session storage 
 has changed.

 On Friday, 6 December 2013 17:55:52 UTC-6, Ivo wrote:

 I tried upgrading the web2py to 2.8.2 that was a bad idea...
 it totally killed the web2py app.
 I redownloaded a clean version and copied over my app now it throws the 
 weirdest error:
 type 'exceptions.NameError''dict' object has no attribute 'is_mobile'
 it traces to user.html, but in reality it's caused by layout.htm
 the welcome app is working so I had a look inside the layout.html basicly 
 the same except for a few mods I made that are unrelated.

 what am I missing? 



-- 
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/groups/opt_out.


[web2py] Re: Scheduler in Windows

2013-12-07 Thread Ivo
I was just about to open the same thread just replace windows with OSX :) 
anyone? 

On Saturday, December 7, 2013 1:38:18 AM UTC+1, Massimo Mascaro wrote:

 Hi,
 I'm fairly new to web2py but I've developed a couple of apps already under 
 Linux and had no issues so far.
 I was delighted to see my apps work like a charm under a Windows 7 machine 
 as well, until... I started using the scheduler.

 I went through the docs I found, and I read and reread the topics on this 
 post. On my version of web2py (2.8.2) I simply don't manage to get any 
 scheduler worker running:
 When I try manually to start a worker with the -K option, it gets totally 
 ignored and I get the usual GUI popping up as if I didn't specify it at 
 all. Note BTW that the GUI has a inspiring Scheduler option, but that 
 doesn't seem to be implemented yet. I tried this both on the source version 
 and on the compiled windows version.
 The fact that it gets ignored is inferred by the fact that in the console 
 output I don't see any message to specify that a worker has been started, 
 and the normal server seems instead to take over...

 Can somebody give me a hint?

 Many thanks,
 (another) Massimo


-- 
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/groups/opt_out.


[web2py] SQLFORM.grid edit form pre populate field

2013-12-06 Thread Ivo
Does anyone know how to pre populate a field when using the SQLFORM.grid 
edit function?

I know that for a new record you can use:
if request.args[-3] == edit:
db.table.field.default = 'foo'

but if the field already contains a value it gets ignored. 

so I tried:
value = auth.user.value
if request.args[-3] == edit:
db.table.field.default = value
this throws a
Object exists and cannot be redefined:
I am searching for the SQLFORM.grid equivalent of form.vars.field='' 

-- 
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/groups/opt_out.


[web2py] Re: Direct access to a SQLFORM.grid single record view

2013-12-06 Thread Ivo
Why don't you pass the product id as an arg[product_id]?
You can have a link like this _href=URL(r=request, 
c='products_listing/view', f='products', args=[product_id]) 
you know it's not really userfriendly to manipulate the grid view form.

On Friday, December 6, 2013 2:59:46 PM UTC+1, Gael Princivalle wrote:

 Hello all.

 Is it possible to call a function/page with an SQLFORM.grid asking for the 
 single view mode instead of the list mode ?

 Something like ...
 {{=A('test link', _href=URL('products_listing/view/products/717'))}}

 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/groups/opt_out.


[web2py] Re: SQLFORM.grid edit form pre populate field

2013-12-06 Thread Ivo
Hi Stifan
I'm trying to retrieve the contents of 
auth.settings.extra_fields['auth_user']= [
Field('value')
]
I hope that clarifies it a bit :)
sorry if I'm unclear; still learning to code and thus how to properly 
formulate my questions in an understandable way


On Friday, December 6, 2013 3:15:12 PM UTC+1, 黄祥 wrote:

 value = auth.user.value


 i'm not sure what do you want to retrieve in here.
 if you want to retrieve the value of current user id, i think you can 
 achieve it using :
 current_user_id = auth.user_id

 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/groups/opt_out.


[web2py] Re: SQLFORM.grid edit form pre populate field

2013-12-06 Thread Ivo
that's exatly how far I got :)
I want to get db.authuser.value and apply it to a corresponding field in 
the edit form function of SQLFORM.grid.
The problem is the last part not the first.
thanks for the thread reference by the way.

On Friday, December 6, 2013 4:17:20 PM UTC+1, 黄祥 wrote:

 i think you can achieve it by simply doing :
 db.auth_user.value
 assumption you have the field name value in your auth_user table.

 for reference, please take a look at :
 https://groups.google.com/forum/#!topic/web2py/9H5ANdSzzVU

 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/groups/opt_out.


[web2py] app not working after install 2.8.2 is_mobile error

2013-12-06 Thread Ivo
I tried upgrading the web2py to 2.8.2 that was a bad idea...
it totally killed the web2py app.
I redownloaded a clean version and copied over my app now it throws the 
weirdest error:
type 'exceptions.NameError''dict' object has no attribute 'is_mobile'
it traces to user.html, but in reality it's caused by layout.htm
the welcome app is working so I had a look inside the layout.html basicly 
the same except for a few mods I made that are unrelated.

what am I missing? 

-- 
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/groups/opt_out.


[web2py] did precion get implemented? decimal(7,3)

2013-12-05 Thread Ivo
hi did precision get implement? I can not seem to find it in the gluon 
folder.
do I need to import it explicitly?

-- 
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/groups/opt_out.


[web2py] unable to default SQLFORM option widget to current field value

2013-12-04 Thread Ivo
Is there a way to default the option widget to the current field value?
The thing is that when you edit a form, the option widget always defaults 
to empty (you need to make a selection even if the field already contains a 
value). I'm quite sure a lot of users will not notice that the select is 
empty, overriding the existing value upon save. They should however need to 
be able to change the value if they choose to. I prefer to do it from the 
controller side if possible.

-- 
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/groups/opt_out.


[web2py] Re: resizing uploaded image file upload using gluon.contrib.imageutils

2013-12-04 Thread Ivo
Hi,
I'm having the same kind of troubles but haven't bothered yet on resolving 
them.

Do you have jpeg decoder installed?
I think that could solve your problems

On Tuesday, December 3, 2013 7:49:40 AM UTC+1, 黄祥 wrote:

 hi,

 i'm trying to resizing uploaded image file upload using 
 gluon.contrib.imageutils but nothing happens (no error occured and the 
 image didn't resized). 

 i'm testing it on windows 7 32 bit using web2py 2.8.2 both source and 
 binary version, python 2.7.6, Pillow-2.2.1.win32-py2.7.

 my code is :
 *models/db_wizard_3_product.py*
 from gluon.contrib.imageutils import RESIZE

 db.product.image.requires = [IS_IMAGE(), RESIZE(220, 220)]

 *controllers/master.py*
 auth.requires_login()(lambda: None)()
 def product():
 grid=SQLFORM.grid(db.product)
 return locals()

 what should i do to resizing uploaded image file upload using 
 gluon.contrib.imageutils?

 thanks and 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/groups/opt_out.


Re: [web2py] Re: SQLFORM.grid edit form restrictions

2013-12-04 Thread Ivo
Thanks Stifan

do you by any chance know how I can manipulate field values for the edit 
view, for example change the form labels and field values if they are read 
only? 

On Wednesday, December 4, 2013 9:00:23 AM UTC+1, 黄祥 wrote:

 i think you can figure it out by yourself where the 'edit' is passed in 
 request.args. the minus part of list is tell that you must sort it backward 
 (from right), so if it : request.args[-3] == 'edit'
 the edit must be the 3rd args from the right part 

 for your case e.g.
 App/default/product/edit/(record id)?(hmac)
 so the request.args[-2] == 'edit'

 for the suggestion i gave to you above is taken from my code that is using 
 sqlform.smartgrid and in your case you are using sqlform.grid, so please 
 try request.args[-2] == 'edit'.

 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/groups/opt_out.


[web2py] Re: unable to default SQLFORM option widget to current field value

2013-12-04 Thread Ivo
default.py:
def products():
edit_in_form = 'edit' in request.args
db.product.price.writable = not edit_in_form

grid = SQLFORM.grid(db.product, 
columns=[
 db.product.name,
 db.product.price,
 ],
)

return dict(
buttons=grid.gridbuttons,
grid=grid)

db.py:
db.define_table('product',
   
   Field('name',length=512),
   Field('user_id', db.auth_user),
   Field('category'), #db.category
   Field('price'),
   )
db.product.category.widget = category.select_widget()

here's the widget itself:

def select_widget(self):
categories = self._db().select(
self._db[self._tablename].ALL, 
orderby=self._db[self._tablename].lft
)
def widget(field, value, **attributes):
rgt = []

tree = []

attr = OptionsWidget._attributes(field, {}, **attributes)

values = re.compile('[\w\-:]+').findall(str(value))

if hasattr(field.requires, 'options'):
opts = []
options = field.requires.options()
tree.append(OPTION(_value=, _class=branch))
for cat in categories:
if len(rgt)  0:
if rgt[-1]  cat.rgt:
# open UL
pass
while rgt[-1]  cat.rgt:
rgt.pop()
if len(rgt) == 0:
break
 
s = 
for i in range(len(rgt)):
s += nbsp;nbsp;nbsp;nbsp;
s += cat.name
branch = OPTION(
XML(s),
_value=cat.id,
_class=branch,
)

tree.append(branch)   
rgt.append(cat.rgt)

seed = SELECT(**attr)
  
for branch in tree:
seed.append(branch)

return seed
return widget




On Wednesday, December 4, 2013 2:56:24 PM UTC+1, Anthony wrote:

 Doesn't sound right. Can you show your code?

 On Wednesday, December 4, 2013 5:11:25 AM UTC-5, Ivo wrote:

 Is there a way to default the option widget to the current field value?
 The thing is that when you edit a form, the option widget always defaults 
 to empty (you need to make a selection even if the field already contains a 
 value). I'm quite sure a lot of users will not notice that the select is 
 empty, overriding the existing value upon save. They should however need to 
 be able to change the value if they choose to. I prefer to do it from the 
 controller side if possible.



-- 
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/groups/opt_out.


[web2py] Re: unable to default SQLFORM option widget to current field value

2013-12-04 Thread Ivo
Thank you Anthony that works perfectly!

On Wednesday, December 4, 2013 4:44:13 PM UTC+1, Anthony wrote:

 You have created a custom widget, but the widget code doesn't set the 
 default value of the widget based on the value argument to the widget. 
 Try changing:

 seed = SELECT(**attr)
 for branch in tree:
 seed.append(branch)

 to:

 seed = SELECT(*tree, value=value, **attr)

 Anthony

 On Wednesday, December 4, 2013 9:29:22 AM UTC-5, Ivo wrote:

 default.py:
 def products():
 edit_in_form = 'edit' in request.args
 db.product.price.writable = not edit_in_form

 grid = SQLFORM.grid(db.product, 
 columns=[
  db.product.name,
  db.product.price,
  ],
 )

 return dict(
 buttons=grid.gridbuttons,
 grid=grid)

 db.py:
 db.define_table('product',

Field('name',length=512),
Field('user_id', db.auth_user),
Field('category'), #db.category
Field('price'),
)
 db.product.category.widget = category.select_widget()

 here's the widget itself:

 def select_widget(self):
 categories = self._db().select(
 self._db[self._tablename].ALL, 
 orderby=self._db[self._tablename].lft
 )
 def widget(field, value, **attributes):
 rgt = []
 
 tree = []
 
 attr = OptionsWidget._attributes(field, {}, **attributes)
 
 values = re.compile('[\w\-:]+').findall(str(value))
 
 if hasattr(field.requires, 'options'):
 opts = []
 options = field.requires.options()
 tree.append(OPTION(_value=, _class=branch))
 for cat in categories:
 if len(rgt)  0:
 if rgt[-1]  cat.rgt:
 # open UL
 pass
 while rgt[-1]  cat.rgt:
 rgt.pop()
 if len(rgt) == 0:
 break
  
 s = 
 for i in range(len(rgt)):
 s += nbsp;nbsp;nbsp;nbsp;
 s += cat.name
 branch = OPTION(
 XML(s),
 _value=cat.id,
 _class=branch,
 )
 
 tree.append(branch)   
 rgt.append(cat.rgt)
 
 seed = SELECT(**attr)
   
 for branch in tree:
 seed.append(branch)
 
 return seed
 return widget




 On Wednesday, December 4, 2013 2:56:24 PM UTC+1, Anthony wrote:

 Doesn't sound right. Can you show your code?

 On Wednesday, December 4, 2013 5:11:25 AM UTC-5, Ivo wrote:

 Is there a way to default the option widget to the current field value?
 The thing is that when you edit a form, the option widget always 
 defaults to empty (you need to make a selection even if the field already 
 contains a value). I'm quite sure a lot of users will not notice that the 
 select is empty, overriding the existing value upon save. They should 
 however need to be able to change the value if they choose to. I prefer to 
 do it from the controller side if possible.



-- 
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/groups/opt_out.


[web2py] SQLFORM.grid edit form restrictions

2013-12-03 Thread Ivo
Hi,
I have want to set some restrictions on editable fields in a edit form grid.

This is the form
def product():
grid = SQLFORM.grid(db.product, 
columns=[
 db.product.name,
 db.product.description,
 db.product.price,
 ],)

when I try to add:
if request.args[-3] == 'edit':
db.product.price.writable=False
I get an error 
type 'exceptions.IndexError' list index out of range
That traces to the if statement.
however is I load the grid form, and then apply the change and save, the 
statement works as expected.

I also tried adding:
else:
pass
but it doesn't help.

what am I doing wrong or not doing?


-- 
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/groups/opt_out.


Re: [web2py] Re: SQLFORM.grid edit form restrictions

2013-12-03 Thread ivo . nijenhuis
I tried the sugested methods prior to posting because I came across a post 
which had that solution in it. It doesn't throw the error, but ignores it 
totally.
I think the issue is because the url of the form is 
App/default/product/
And the edit function creates a url like
App/default/product/edit/(record id)?(hmac)

I'm not quite sure how to get the diagnostic print/logs.
I'm kind of new to w2p and py in general

Thanks for the replies so far

Sent from my phone

On 4 dec. 2013, at 00:38, Dave S snidely@gmail.com wrote:

 
 
 On Tuesday, December 3, 2013 3:25:06 PM UTC-8, 黄祥 wrote:
 
 please try not tested :
 edit_in_form = 'edit' in request.args
 db.product.price.writable = not edit_in_form 
 
 or
 
 edit_in_form = request.args[-3] == 'edit'
 db.product.price.writable = not edit_in_form 
 
 I'd expect the 2nd suggestion to be problematic in the same way as the OP's 
 formulation, if request.args doesn't have the expected len.
 maybe a diagnostic print/log to examine the size?
 
 /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 a topic in the Google 
 Groups web2py-users group.
 To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/web2py/0yA3-T9MesY/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/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/groups/opt_out.


Re: [web2py] Re: SQLFORM.grid edit form restrictions

2013-12-03 Thread Ivo
黄祥 you were right!
I fixed the issue just by copy pasting your first solution.
Very stange as I tries a almost identical solution that failed.
I tried something like:
edit_in_form = 'edit' in request.args
db.product.price.readable = db.product.price.writable = not edit_in_form

your second solution fails though I think it's because the request.args[-3] 
== 'edit' is always false and edit is not contained in de normal url it's 
only [-3] after you click the edit button. edit doesn't exist until then.

the thing I don't understand is why it errors out on me. it should just 
pass it when the condition is False.

At least I got it to work thank you so much! 

On Wednesday, December 4, 2013 1:11:25 AM UTC+1, 黄祥 wrote:

 App/default/product/edit/(record id)?(hmac)


 if my logic is correct the edit is args so :
 edit_in_form = 'edit' in request.args
 or
 edit_in_form = request.args[-3] == 'edit'
 should work

 are you sure? i've tested right now, both is work in mine. tested in 
 web2py 2.8.2 windows binary on windows 7.

 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/groups/opt_out.


Re: [web2py] need syntax help

2013-09-03 Thread Ivo
after strugeling to get find a way on how to access the console I used this 
method:
since I'm working on ubuntu web2py is located at /usr/share/web2py, however 
if you start web2py with the desktop shortcut and you create an app it is 
located in the ~/web2py/applications folder. so copied it over and tried to 
run it, this didn't go smooth so I re-read the book again and found out you 
can acces the shell through the webinterface by doing 
127.0.0.1:8000/admin/shell/index/app.

so after inputting d = Kojn(key).charge(amount_in_fiat=100,currency='btc')
I get the same error:
 
In [2] : d = Kojn(key).charge(amount_in_fiat=100,currency='btc')
Traceback (most recent call last):
  File /usr/lib/pymodules/python2.7/gluon/contrib/shell.py, line 233, in 
run
exec compiled in statement_module.__dict__
  File string, line 1, in module
  File applications/kojncomm/models/kojn.py, line 46, in charge
return simplejson.loads(u.read())
  File /usr/lib/python2.7/dist-packages/simplejson/__init__.py, line 413, 
in loads
return _default_decoder.decode(s)
  File /usr/lib/python2.7/dist-packages/simplejson/decoder.py, line 402, 
in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File /usr/lib/python2.7/dist-packages/simplejson/decoder.py, line 420, 
in raw_decode
raise JSONDecodeError(No JSON object could be decoded, s, idx)
JSONDecodeError: No JSON object could be decoded: line 1 column 0 (char 0)

Which if I'm correct means my error is due to koj.py trying to load json 
and the response is not json encoded.
How do I change the line so it just shows me the receeived response?

On Monday, September 2, 2013 3:08:55 PM UTC+2, viniciusban wrote:

 On Mon, Sep 2, 2013 at 5:19 AM, Ivo ivo.ni...@gmail.com javascript: 
 wrote: 
  
  
  I don't know how to see what the response is is I get. 

 A simple way is using print. So your print will be in the console window. 


-- 

--- 
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/groups/opt_out.


Re: [web2py] need syntax help

2013-09-02 Thread Ivo
Thank you for the response,
I removed the initial paste from the post.

here is the pay.py:
http://pastebin.com/B8FyD9Md

he is the default.py:
http://pastebin.com/Sc1DQijh

I also tried a different way to receive the data which also failed; 
index2().

anyway the error for index is the following:

class 'simplejson.decoder.JSONDecodeError' No JSON object could be 
decoded: line 1 column 0 (char 0) Version  web2py™ (1, 99, 4, 
datetime.datetime(2011, 12, 14, 14, 46, 14), 'stable')  Python Python 
2.7.3: /usr/bin/python  Traceback 

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.

Traceback (most recent call last):
  File /usr/lib/pymodules/python2.7/gluon/restricted.py, line 204, in 
restricted
exec ccode in environment
  File /home/crypto/web2py/applications/kojncomm/controllers/default.py 
http://127.0.0.1:8000/admin/default/edit/kojncomm/controllers/default.py, 
line 110, in module
  File /usr/lib/pymodules/python2.7/gluon/globals.py, line 172, in lambda
self._caller = lambda f: f()
  File /home/crypto/web2py/applications/kojncomm/controllers/default.py 
http://127.0.0.1:8000/admin/default/edit/kojncomm/controllers/default.py, 
line 53, in index
description='test charge')
  File /home/crypto/web2py/applications/kojncomm/models/kojn.py 
http://127.0.0.1:8000/admin/default/edit/kojncomm/models/kojn.py, line 46, in 
charge
return simplejson.loads(u.read())
  File /usr/lib/python2.7/dist-packages/simplejson/__init__.py, line 413, in 
loads
return _default_decoder.decode(s)
  File /usr/lib/python2.7/dist-packages/simplejson/decoder.py, line 402, in 
decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File /usr/lib/python2.7/dist-packages/simplejson/decoder.py, line 420, in 
raw_decode
raise JSONDecodeError(No JSON object could be decoded, s, idx)
JSONDecodeError: No JSON object could be decoded: line 1 column 0 (char 0)

 Error snapshot [image: help]  

class 'simplejson.decoder.JSONDecodeError'(No JSON object could be 
decoded: line 1 column 0 (char 0)) 

I don't know how to see what the response is is I get.



On Sunday, September 1, 2013 5:42:25 AM UTC+2, viniciusban wrote:

 First things, first. 

 1) Paste your code in a pastebin service, like pastebin.com and tell 
 us the url. In python, indentation is important. 
 2) Paste all your error, telling in which line the error occurred. 
 3) If your message says no JSON object could be decoded, probably 
 you didn't get a string with json formatting. See what is returning to 
 you. 


 On Sat, Aug 31, 2013 at 8:19 AM, Ivo ivo.ni...@gmail.com javascript: 
 wrote: 
  hi all, 
  I need some syntax help. 
  I need to talk to a remote server, post a request adn receive the 
 answer. I 
  thought I would use the Stipe.py as a basis because it almost suits my 
  needs. 
  I need an equivalent of this curl statement to receive a list of my 
 invoices 
  the 8e7659 is the api of my account: 
  
  curl -i -H Content-type: application/json -X GET \ 
  -u 8e76598954566f453ceac1d4e8aed304: \https://test.nl/api/invoices 
  
  and I also need to be able to post an equivilent of: 
  
curl -i -H Content-type: application/json -X POST \ 
 -u 8e76598954566f453ceac1d4e8aed304: \ 
 -d '{invoice:{external_id:101,currency:usd, 
  amount_in_fiat:2.00}}' \ 
 https://test.nl/api/invoices 
  
  This would trigger a response someting like this: 
  
{address=mvztT9xTaqkEmcu2wjLTuLTARS33AJvK4S, 
   currency=usd, 
   amount=0.03853, 
   amount_in_fiat=2.0, 
   exchange_rate=51.90739, 
   internal_id=ff702c579c99947a5542398372b96d60, 
  
  redirect_uri=
 https://test.nl/invoice/mvztT9xTaqkEmcu2wjLTuLTARS33AJvK4S} 
  
  I need to beable to retreive the fields from this. 
  so to get me started I created a pay.py and placed it in the models 
 folder, 
  it looks like this: 
  
  import urllib 
  import simplejson 
  
  
  class Pay: 
   
  Usage: 
  key='api key' 
  d = Pay(key).charge( 
  amount_in_fiat=100, 
  currency='usd', 
  
  description='test charge') 
  print d 
  print Pay(key).check(d['id']) 
  print Pay(key).refund(d['id']) 
  
   
  
  URL_CHARGE = 'https://%s:@Test.nl/api/invoices' 
  URL_CHECK = 'https://%s:@Test.nl/api/invoices/%s' 
  
  def __init__(self, key): 
  self.key = key 
  
  def charge(self, 
 amount_in_fiat, 
 currency='usd', 
 description='test charge', 
 more=None): 
  if more: 
  d.update(mode) 
  params = urllib.urlencode(d) 
  u = urllib.urlopen(self.URL_CHARGE % self.key, params) 
  return simplejson.loads(u.read()) 
  else: 
  d = {'amount_in_fiat': amount_in_fiat, 
   'currency': currency, 
   'description': description} 
  
  
  def check(self, charge_id): 
  u = urllib.urlopen(self.URL_CHECK % (self.key, charge_id)) 
  return simplejson.loads(u.read

[web2py] need syntax help

2013-08-31 Thread Ivo
hi all,
I need some syntax help.
I need to talk to a remote server, post a request adn receive the answer. I 
thought I would use the Stipe.py as a basis because it almost suits my 
needs.
I need an equivalent of this curl statement to receive a list of my 
invoices the 8e7659 is the api of my account:


   1. curl -i -H Content-type: application/json -X GET \
   2. -u 8e76598954566f453ceac1d4e8aed304: \https://test.nl/api/invoices

and I also need to be able to post an equivilent of:


   1.   curl -i -H Content-type: application/json -X POST \
   2.-u 8e76598954566f453ceac1d4e8aed304: \
   3.-d '{invoice:{external_id:101,currency:usd, 
amount_in_fiat:2.00}}' \
   4.https://test.nl/api/invoices

This would trigger a response someting like this:


   1.   {address=mvztT9xTaqkEmcu2wjLTuLTARS33AJvK4S,
   2.  currency=usd,
   3.  amount=0.03853,
   4.  amount_in_fiat=2.0,
   5.  exchange_rate=51.90739,
   6.  internal_id=ff702c579c99947a5542398372b96d60,
   7.  
redirect_uri=https://test.nl/invoice/mvztT9xTaqkEmcu2wjLTuLTARS33AJvK4S}

I need to beable to retreive the fields from this.
so to get me started I created a pay.py and placed it in the models folder, 
it looks like this: 

import urllib
import simplejson


class Pay:

Usage:
key='api key'
d = Pay(key).charge(
amount_in_fiat=100,
currency='usd',

description='test charge')
print d
print Pay(key).check(d['id'])
print Pay(key).refund(d['id'])



URL_CHARGE = 'https://%s:@Test.nl/api/invoices'
URL_CHECK = 'https://%s:@Test.nl/api/invoices/%s'

def __init__(self, key):
self.key = key

def charge(self,
   amount_in_fiat,
   currency='usd',
   description='test charge',
   more=None):
if more:
d.update(mode)
params = urllib.urlencode(d)
u = urllib.urlopen(self.URL_CHARGE % self.key, params)
return simplejson.loads(u.read())
else:
d = {'amount_in_fiat': amount_in_fiat,
 'currency': currency,
 'description': description}


def check(self, charge_id):
u = urllib.urlopen(self.URL_CHECK % (self.key, charge_id))
return simplejson.loads(u.read())



if __name__ == '__main__':
key = raw_input('user')
d = Kojn(key).charge(100)
print 'charged', d['paid']
s = Kojn(key).check(d[u'id'])
print 'paid', s['paid'], s['amount_in_fiat'], s['currency']




default.py:

def index():
key='8e76598954566f453ceac1d4e8aed304'
d = Pay(key).charge(
amount_in_fiat=100,
currency='usd',

description='test charge')
return dict(d=d)



However this doesn't work gives me the error:
class 'simplejson.decoder.JSONDecodeError'(No JSON object could be 
decoded: line 1 column 0 (char 0))

I'm not yet a programmer and don't see all the relations within web2py yet 
so please explain your answers.
Thanks,
Ivo

-- 

--- 
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/groups/opt_out.


[web2py] feed not updating on the page

2013-08-24 Thread Ivo
Hi,

I'm trying to display a feed on my page that needs to update about every 10 
seconds without refreshing the entire page. I get the feed to display but 
not as it should.
an other thing is the page loads after 10 seconds and I think the sleep(10) 
is responsible for this. I'm not a programmer (yet) so please sort of spoon 
feed any help with comments of how and why so I can learn from it. 
Thanks,
Ivo

default.py:
import urllib, json
from time import sleep

def index():
Feed = feed()
return dict(Feed=Feed)

def feed()
#all the parameters needed to get the feed
url = 'http://blabla.com/' + currency +'/'
currency = EUR
fields = ['return', 'last', 'value']

while True:
try:
f = urllib.urlopen(url)
data = f.read()
feed1 = json.loads(data)
rate = feed1
for field in fields:
rate = rate[field]
rate = float(rate)
except (ValueError, KeyError):
print unable to parse
except IOError:
print unable to access
sleept(10)
return rate



index.html:

{{extend 'layout.html'}}
h1display rate/h1
{{=Feed}}

-- 

--- 
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/groups/opt_out.