[web2py] Re: check url agrs / vars after #

2020-06-30 Thread Massimo Di Pierro
You cannot because the browser does not send those to the server. Your only 
option is to inject some JS in the page that reads it from 
window.location.hash and POST to an API, after the page is loaded.

On Sunday, 28 June 2020 07:37:54 UTC-7, Ari Lion BR Sp wrote:
>
>
> Hi, how to get / check 
>
> url agrs / vars after # symbol.
>
>
> I want to re-wright url without reload and get thwe args/varss of it.
> I see it happends  after # symbol.
>
> Regards
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/b29efb97-860e-49ec-85ed-a3d34adee770o%40googlegroups.com.


[web2py] Re: Check box access

2018-12-09 Thread pradeep chauhan
yes if 
 if auth.user.first_name ="string":
 


On Sunday, December 9, 2018 at 1:48:35 PM UTC+5:30, 黄祥 wrote:
>
> think you can compare the logged in user with if else condition
> *ref:*
>
> http://web2py.com/books/default/chapter/29/02/the-python-language#if-elif-else
> http://web2py.com/books/default/chapter/29/09/access-control
> http://web2py.com/books/default/chapter/29/07/forms-and-validators
>
> 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: Check box access

2018-12-09 Thread 黄祥
think you can compare the logged in user with if else condition
*ref:*
http://web2py.com/books/default/chapter/29/02/the-python-language#if-elif-else
http://web2py.com/books/default/chapter/29/09/access-control
http://web2py.com/books/default/chapter/29/07/forms-and-validators

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: check boxes with is_in_set

2016-12-13 Thread 黄祥
it's work now, even in the tuple inside the list data type, my bad to treat 
the list data type in an unproper manner, hehe
*is_in_set list checkboxes refer to rows table database *
*e.g.*
def attendance_form():
target_response = "jQuery('#attendance_checkout').get(0).reload()"

rows_list_employee = db(db.employee.id > 0).iterselect()
list_employee = []
for row_list_employee in rows_list_employee:
data_employee = (row_list_employee.id, '%s' % (row_list_employee.name) )
list_employee.append(data_employee)

form = SQLFORM.factory(
Field('employee', 'list:string', 
 widget = SQLFORM.widgets.checkboxes.widget, 
 requires = [IS_IN_SET(list_employee, multiple = True), IS_NOT_EMPTY() ] ), 
)
if form.process(formname = 'form_detail').accepted:
response.flash = T('Form accepted')
for row_id in request.vars.employee:
id = int(row_id)
row_employee = db(db.employee.id == id).iterselect().first()

query_attendance = ((db.attendance.employee == row_employee.id) & 
(db.attendance.attendance_date == request.now) )
row_attendance = db(query_attendance).iterselect().first()

if row_attendance:
response.flash = T("Employee already insert today")
else:
basic_salary = int(row_employee.basic_salary)
meal = int(row_employee.meal)
transport = int(row_employee.transport)

total = basic_salary + meal + transport

session_attendance[id] = basic_salary, meal, transport, total
response.js =  target_response
elif form.errors:
response.flash = T('Form has errors')
return dict(form = form)

*is_in_set list checkboxes for view report (not related with database 
table) *
*e.g.*
def product_form():
redirect_url = 'report_product'

list_show_product = [('chart', T('Chart') ), 
('account', T('Account') ) ]

form = SQLFORM.factory(
Field("product", "reference product", 
 requires = IS_IN_DB(db, db.product.id, db.product._format, 
   zero = T('Choose One') ) ),
Field('show', 'list:string', 
 widget = SQLFORM.widgets.checkboxes.widget, 
 requires = IS_IN_SET(list_show_product, multiple = True) ) )
if form.process().accepted:
product = form.vars.product
show = form.vars.show
show.insert(0, product)

response.new_window = URL(redirect_url, args = show)
elif form.errors:
response.flash = T('Form has errors')
return dict(form = form)

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: check boxes with is_in_set

2016-12-12 Thread Jim Russell
In your example, list_chart is not a list of strings, it is a list of 
tuples.

In my code, hostnames is just a list of hostnames.  e.g. 
('hostname1.example.com','hostname2.example.com')

I assume that you are trying to make the checkboxes default to true. For 
me, they defaulted to being checked.

On Monday, December 12, 2016 at 3:50:58 PM UTC-6, 黄祥 wrote:
>
> trying the tricks but got error when the checkbox is empty (1 or all 
> checkbox is empty, when all checkbox is on its work) :
> *e.g.*
> def test_form():
> redirect_url = 'test'
>
> list_chart = [(True, 'line'), 
>  (True, 'pie'), 
>  (True, 'bar') ]
>
> form = SQLFORM.factory(
> Field('chart', 'list:string', 
>  default = list_chart,
>  widget = SQLFORM.widgets.checkboxes.widget, 
>  requires = [IS_IN_SET(list_chart, multiple = True) ] ) )
> if form.process().accepted:
> chart = form.vars.chart
> line = form.vars.line[0]
> pie = form.vars.pie[1]
> bar = form.vars.bar[2]
>
> response.new_window = URL(redirect_url, args = [chart] )
> #response.new_window = URL(redirect_url, args = [line, pie, bar] )
> elif form.errors:
> response.flash = T('Form has errors')
> return dict(form = form)
>
> *Traceback error:*
> line = form.vars.chart[0]
> IndexError: list index out of range
>
> any idea how to face it using web2py way?
>
> 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/d/optout.


[web2py] Re: check boxes with is_in_set

2016-12-12 Thread 黄祥
trying the tricks but got error when the checkbox is empty (1 or all 
checkbox is empty, when all checkbox is on its work) :
*e.g.*
def test_form():
redirect_url = 'test'

list_chart = [(True, 'line'), 
 (True, 'pie'), 
 (True, 'bar') ]

form = SQLFORM.factory(
Field('chart', 'list:string', 
 default = list_chart,
 widget = SQLFORM.widgets.checkboxes.widget, 
 requires = [IS_IN_SET(list_chart, multiple = True) ] ) )
if form.process().accepted:
chart = form.vars.chart
line = form.vars.line[0]
pie = form.vars.pie[1]
bar = form.vars.bar[2]

response.new_window = URL(redirect_url, args = [chart] )
#response.new_window = URL(redirect_url, args = [line, pie, bar] )
elif form.errors:
response.flash = T('Form has errors')
return dict(form = form)

*Traceback error:*
line = form.vars.chart[0]
IndexError: list index out of range

any idea how to face it using web2py way?

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/d/optout.


[web2py] Re: check boxes with is_in_set

2016-12-08 Thread Jim Russell
Rob,

I used this code to get a list with checkboxes.

form=SQLFORM.factory(
Field('hostnames',"list:string", 
default=hostnames,widget=SQLFORM.widgets.checkboxes.widget,requires=[IS_IN_SET(hostnames,multiple=True),IS_NOT_EMPTY()]))

hostnames is a list containing strings.

-- 
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: Check to establish whether or not a record exists

2016-11-25 Thread Massimo Di Pierro
db.mytable(name=s) 

is shortcut for

db(db.mytable.name==s).select(limitby=(0,1)).first()


On Monday, 21 November 2016 09:58:01 UTC-6, Ramos wrote:
>
> I used this compact way and i noticed it only returns one record.
>
> for example 
>
> table db.badass
> id   name   value
> 1trump   10
> 2trump   20
> 3hilary30
>
> db.badass(name="trump")
> only returns record with id =1
>
> Regards
> António
>
> 2016-11-21 15:47 GMT+00:00 Massimo Di Pierro :
>
>> It depends
>>
>> a query is always field==value so you can do
>>
>>query = db.table.field ==  value
>>row = db(query).select(limitby=(0,10)).first()
>>
>> or
>>
>>row = db.table(query)
>>
>> (they are equivalent)
>>
>> But db.table(...) can take an "implicit query"
>>
>>db.table(fieldname=value)
>>
>> which is a more compact way to do
>>
>>db.table(db.table.field==value)
>>
>> The most common way to use db.table(...) is this
>>
>>db.table(id)
>>
>> or
>>
>>db.table(id, fieldname=value) # returns the record only of the 
>> fieldname==value
>>
>> or 
>>
>>db.table(id, query) # returns the record only if the query is true.
>>
>>
>>
>> On Sunday, 20 November 2016 09:08:38 UTC-6, Meinolf wrote:
>>>
>>> Hi Massimo
>>>
>>> Just came across this post and got a bit alarmed, so when i check if a 
>>> record exists i don't have to use the usual '==' but instead '=' ?
>>>
>>> On Monday, October 10, 2011 at 3:55:27 PM UTC+2, Massimo Di Pierro wrote:

 row = db.postcode_cache(postcode=postcode) 
 if not row: 
 db.postcode_cache.insert(postcode=postcode,nearset=nearest) 
 elif not row.nearest: row.update_record(nearset=nearest) 
 else: pass # do nothing 

 On Oct 10, 8:22 am, Chris Rowson  wrote: 
 > Hi list, 
 > 
 > I have a database table which looks like this: 
 > 
 > postcode_cache 
 >  
 > postcode (UNIQUE) 
 > lat 
 > lon 
 > nearest 
 > 
 > I want to test first whether or not a record exists for 'postcode' 
 and 
 > if a record does exist, I want to check whether the 'nearest' field 
 > contains any data. 
 > 
 > I've tried this: 
 > 
 > if db(db.postcode_cache.postcode==postcode).select().first()==None: 
 > create_a_new_postcode_record() 
 > 
 > elif 
 db(db.postcode_cache.postcode==postcode).select(db.postcode_cache.nearest)=
  
 =None: 
 > populate_the_nearest_field() 
 > 
 > else: 
 > nothing_to_do() 
 > 
 > And while the check to establish whether or not a record exists seems 
 > to work, the check to see whether or not the 'nearest' field within 
 > the record is populated doesn't seem to work. 
 > 
 > Can anyone tell me what I'm doing wrong please? 
 > 
 > Thank you, 
 > 
 > Chris
>>>
>>> -- 
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to web2py+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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


Re: [web2py] Re: Check to establish whether or not a record exists

2016-11-21 Thread António Ramos
I used this compact way and i noticed it only returns one record.

for example

table db.badass
id   name   value
1trump   10
2trump   20
3hilary30

db.badass(name="trump")
only returns record with id =1

Regards
António

2016-11-21 15:47 GMT+00:00 Massimo Di Pierro :

> It depends
>
> a query is always field==value so you can do
>
>query = db.table.field ==  value
>row = db(query).select(limitby=(0,10)).first()
>
> or
>
>row = db.table(query)
>
> (they are equivalent)
>
> But db.table(...) can take an "implicit query"
>
>db.table(fieldname=value)
>
> which is a more compact way to do
>
>db.table(db.table.field==value)
>
> The most common way to use db.table(...) is this
>
>db.table(id)
>
> or
>
>db.table(id, fieldname=value) # returns the record only of the
> fieldname==value
>
> or
>
>db.table(id, query) # returns the record only if the query is true.
>
>
>
> On Sunday, 20 November 2016 09:08:38 UTC-6, Meinolf wrote:
>>
>> Hi Massimo
>>
>> Just came across this post and got a bit alarmed, so when i check if a
>> record exists i don't have to use the usual '==' but instead '=' ?
>>
>> On Monday, October 10, 2011 at 3:55:27 PM UTC+2, Massimo Di Pierro wrote:
>>>
>>> row = db.postcode_cache(postcode=postcode)
>>> if not row:
>>> db.postcode_cache.insert(postcode=postcode,nearset=nearest)
>>> elif not row.nearest: row.update_record(nearset=nearest)
>>> else: pass # do nothing
>>>
>>> On Oct 10, 8:22 am, Chris Rowson  wrote:
>>> > Hi list,
>>> >
>>> > I have a database table which looks like this:
>>> >
>>> > postcode_cache
>>> > 
>>> > postcode (UNIQUE)
>>> > lat
>>> > lon
>>> > nearest
>>> >
>>> > I want to test first whether or not a record exists for 'postcode' and
>>> > if a record does exist, I want to check whether the 'nearest' field
>>> > contains any data.
>>> >
>>> > I've tried this:
>>> >
>>> > if db(db.postcode_cache.postcode==postcode).select().first()==None:
>>> > create_a_new_postcode_record()
>>> >
>>> > elif 
>>> > db(db.postcode_cache.postcode==postcode).select(db.postcode_cache.nearest)=
>>> =None:
>>> > populate_the_nearest_field()
>>> >
>>> > else:
>>> > nothing_to_do()
>>> >
>>> > And while the check to establish whether or not a record exists seems
>>> > to work, the check to see whether or not the 'nearest' field within
>>> > the record is populated doesn't seem to work.
>>> >
>>> > Can anyone tell me what I'm doing wrong please?
>>> >
>>> > Thank you,
>>> >
>>> > Chris
>>
>> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


[web2py] Re: Check to establish whether or not a record exists

2016-11-21 Thread Massimo Di Pierro
It depends

a query is always field==value so you can do

   query = db.table.field ==  value
   row = db(query).select(limitby=(0,10)).first()

or

   row = db.table(query)

(they are equivalent)

But db.table(...) can take an "implicit query"

   db.table(fieldname=value)

which is a more compact way to do

   db.table(db.table.field==value)

The most common way to use db.table(...) is this

   db.table(id)

or

   db.table(id, fieldname=value) # returns the record only of the 
fieldname==value

or 

   db.table(id, query) # returns the record only if the query is true.



On Sunday, 20 November 2016 09:08:38 UTC-6, Meinolf wrote:
>
> Hi Massimo
>
> Just came across this post and got a bit alarmed, so when i check if a 
> record exists i don't have to use the usual '==' but instead '=' ?
>
> On Monday, October 10, 2011 at 3:55:27 PM UTC+2, Massimo Di Pierro wrote:
>>
>> row = db.postcode_cache(postcode=postcode) 
>> if not row: 
>> db.postcode_cache.insert(postcode=postcode,nearset=nearest) 
>> elif not row.nearest: row.update_record(nearset=nearest) 
>> else: pass # do nothing 
>>
>> On Oct 10, 8:22 am, Chris Rowson  wrote: 
>> > Hi list, 
>> > 
>> > I have a database table which looks like this: 
>> > 
>> > postcode_cache 
>> >  
>> > postcode (UNIQUE) 
>> > lat 
>> > lon 
>> > nearest 
>> > 
>> > I want to test first whether or not a record exists for 'postcode' and 
>> > if a record does exist, I want to check whether the 'nearest' field 
>> > contains any data. 
>> > 
>> > I've tried this: 
>> > 
>> > if db(db.postcode_cache.postcode==postcode).select().first()==None: 
>> > create_a_new_postcode_record() 
>> > 
>> > elif 
>> db(db.postcode_cache.postcode==postcode).select(db.postcode_cache.nearest)= 
>> =None: 
>> > populate_the_nearest_field() 
>> > 
>> > else: 
>> > nothing_to_do() 
>> > 
>> > And while the check to establish whether or not a record exists seems 
>> > to work, the check to see whether or not the 'nearest' field within 
>> > the record is populated doesn't seem to work. 
>> > 
>> > Can anyone tell me what I'm doing wrong please? 
>> > 
>> > Thank you, 
>> > 
>> > Chris
>
>

-- 
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: Check to establish whether or not a record exists

2016-11-20 Thread Meinolf
Hi Massimo

Just came across this post and got a bit alarmed, so when i check if a 
record exists i don't have to use the usual '==' but instead '=' ?

On Monday, October 10, 2011 at 3:55:27 PM UTC+2, Massimo Di Pierro wrote:
>
> row = db.postcode_cache(postcode=postcode) 
> if not row: 
> db.postcode_cache.insert(postcode=postcode,nearset=nearest) 
> elif not row.nearest: row.update_record(nearset=nearest) 
> else: pass # do nothing 
>
> On Oct 10, 8:22 am, Chris Rowson  wrote: 
> > Hi list, 
> > 
> > I have a database table which looks like this: 
> > 
> > postcode_cache 
> >  
> > postcode (UNIQUE) 
> > lat 
> > lon 
> > nearest 
> > 
> > I want to test first whether or not a record exists for 'postcode' and 
> > if a record does exist, I want to check whether the 'nearest' field 
> > contains any data. 
> > 
> > I've tried this: 
> > 
> > if db(db.postcode_cache.postcode==postcode).select().first()==None: 
> > create_a_new_postcode_record() 
> > 
> > elif 
> db(db.postcode_cache.postcode==postcode).select(db.postcode_cache.nearest)= 
> =None: 
> > populate_the_nearest_field() 
> > 
> > else: 
> > nothing_to_do() 
> > 
> > And while the check to establish whether or not a record exists seems 
> > to work, the check to see whether or not the 'nearest' field within 
> > the record is populated doesn't seem to work. 
> > 
> > Can anyone tell me what I'm doing wrong please? 
> > 
> > Thank you, 
> > 
> > Chris

-- 
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: Check to see if a field is in another table in a computed field

2016-02-12 Thread Greg White
At our facility we order a lot of unique items but also have an inventory 
of some items. I am trying to add some logic that when ordering an item, 
there is a check to see if the ordered item name is in the inventory 
(inventory.name). Then person ordering is made aware that a similar item is 
in inventory and maybe we need to pull that item out of inventory versus 
ordering that part if it is indeed the correct part, size, color etc... 

On Thursday, February 11, 2016 at 5:52:23 PM UTC-7, Anthony wrote:
>
> What are you trying to do? Do you want to store this information in the 
> POrequest table, or do you want to prevent inserts if the item is not in 
> the db.inventory table? If the latter, IS_IN_DB will certainly work, but 
> note that validators only get run if you are using SQLFORM or if you call 
> .validate_and_insert().
>
> Anthony
>
> On Thursday, February 11, 2016 at 6:02:16 PM UTC-5, Greg White wrote:
>>
>> I should have mentioned that I tried IS_IN_DB first off and it didn't work
>>
>> On Wednesday, February 10, 2016 at 4:25:48 PM UTC-7, Dave S wrote:
>>>
>>>
>>>
>>> On Wednesday, February 10, 2016 at 2:01:52 PM UTC-8, Greg White wrote:

 Want a computed field to show whether or not a field value exists in 
 another table

>>>
>>>
>>> I'm not sure that is the right approach.  I think that the standard 
>>> validator IS_IN_DB() is what you want, instead.
>>>
>>> >> http://web2py.com/books/default/chapter/29/07/forms-and-validators#Database-validators
>>> >
>>> (IS_IN_DB is the second validator in that section)
>>>
>>> The example shown appears to be similar to what I think you're trying to 
>>> do.
>>>
>>> /dps
>>>
>>>
 started with this...

 db.define_table(
 'inventory',
 Field('name'),
 Field('qty', label='Quantity'),
 Field('MatSize',label='Material Size'),
 format = '%(name)s') 

 db.define_table(
 'POrequest',
 Field('name', 'reference requestor', label='Requestor'),
 Field('JobNum', 'reference jobs', label='Job #'),
 Field('description', 'text', notnull=True),
 Field('InInventory', compute=lambda r: r['description'] IN r[
 db.inventory.name]),  <<< this row right here is what I need help with
 format = '%(name)s')

 trying to verify row by row in a computed field if 
 db.POrequest.description is in any row of db.inventory.name

 help please.

>>>

-- 
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: Check to see if a field is in another table in a computed field

2016-02-11 Thread Anthony
What are you trying to do? Do you want to store this information in the 
POrequest table, or do you want to prevent inserts if the item is not in 
the db.inventory table? If the latter, IS_IN_DB will certainly work, but 
note that validators only get run if you are using SQLFORM or if you call 
.validate_and_insert().

Anthony

On Thursday, February 11, 2016 at 6:02:16 PM UTC-5, Greg White wrote:
>
> I should have mentioned that I tried IS_IN_DB first off and it didn't work
>
> On Wednesday, February 10, 2016 at 4:25:48 PM UTC-7, Dave S wrote:
>>
>>
>>
>> On Wednesday, February 10, 2016 at 2:01:52 PM UTC-8, Greg White wrote:
>>>
>>> Want a computed field to show whether or not a field value exists in 
>>> another table
>>>
>>
>>
>> I'm not sure that is the right approach.  I think that the standard 
>> validator IS_IN_DB() is what you want, instead.
>>
>> > http://web2py.com/books/default/chapter/29/07/forms-and-validators#Database-validators
>> >
>> (IS_IN_DB is the second validator in that section)
>>
>> The example shown appears to be similar to what I think you're trying to 
>> do.
>>
>> /dps
>>
>>
>>> started with this...
>>>
>>> db.define_table(
>>> 'inventory',
>>> Field('name'),
>>> Field('qty', label='Quantity'),
>>> Field('MatSize',label='Material Size'),
>>> format = '%(name)s') 
>>>
>>> db.define_table(
>>> 'POrequest',
>>> Field('name', 'reference requestor', label='Requestor'),
>>> Field('JobNum', 'reference jobs', label='Job #'),
>>> Field('description', 'text', notnull=True),
>>> Field('InInventory', compute=lambda r: r['description'] IN r[
>>> db.inventory.name]),  <<< this row right here is what I need help with
>>> format = '%(name)s')
>>>
>>> trying to verify row by row in a computed field if 
>>> db.POrequest.description is in any row of db.inventory.name
>>>
>>> help please.
>>>
>>

-- 
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: Check to see if a field is in another table in a computed field

2016-02-11 Thread Greg White
I should have mentioned that I tried IS_IN_DB first off and it didn't work

On Wednesday, February 10, 2016 at 4:25:48 PM UTC-7, Dave S wrote:
>
>
>
> On Wednesday, February 10, 2016 at 2:01:52 PM UTC-8, Greg White wrote:
>>
>> Want a computed field to show whether or not a field value exists in 
>> another table
>>
>
>
> I'm not sure that is the right approach.  I think that the standard 
> validator IS_IN_DB() is what you want, instead.
>
>  http://web2py.com/books/default/chapter/29/07/forms-and-validators#Database-validators
> >
> (IS_IN_DB is the second validator in that section)
>
> The example shown appears to be similar to what I think you're trying to 
> do.
>
> /dps
>
>
>> started with this...
>>
>> db.define_table(
>> 'inventory',
>> Field('name'),
>> Field('qty', label='Quantity'),
>> Field('MatSize',label='Material Size'),
>> format = '%(name)s') 
>>
>> db.define_table(
>> 'POrequest',
>> Field('name', 'reference requestor', label='Requestor'),
>> Field('JobNum', 'reference jobs', label='Job #'),
>> Field('description', 'text', notnull=True),
>> Field('InInventory', compute=lambda r: r['description'] IN r[
>> db.inventory.name]),  <<< this row right here is what I need help with
>> format = '%(name)s')
>>
>> trying to verify row by row in a computed field if 
>> db.POrequest.description is in any row of db.inventory.name
>>
>> help please.
>>
>

-- 
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: Check to see if a field is in another table in a computed field

2016-02-11 Thread Anthony
On Wednesday, February 10, 2016 at 5:01:52 PM UTC-5, Greg White wrote:
>
> Want a computed field to show whether or not a field value exists in 
> another table
>
> started with this...
>
> db.define_table(
> 'inventory',
> Field('name'),
> Field('qty', label='Quantity'),
> Field('MatSize',label='Material Size'),
> format = '%(name)s') 
>
> db.define_table(
> 'POrequest',
> Field('name', 'reference requestor', label='Requestor'),
> Field('JobNum', 'reference jobs', label='Job #'),
> Field('description', 'text', notnull=True),
> Field('InInventory', compute=lambda r: r['description'] IN r[
> db.inventory.name]),  <<< this row right here is what I need help with
> format = '%(name)s')
>

compute=lambda r: not db(db.inventory.name == r.description).isempty() 

Anthony

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


[web2py] Re: Check to see if a field is in another table in a computed field

2016-02-10 Thread Dave S


On Wednesday, February 10, 2016 at 2:01:52 PM UTC-8, Greg White wrote:
>
> Want a computed field to show whether or not a field value exists in 
> another table
>


I'm not sure that is the right approach.  I think that the standard 
validator IS_IN_DB() is what you want, instead.


(IS_IN_DB is the second validator in that section)

The example shown appears to be similar to what I think you're trying to do.

/dps


> started with this...
>
> db.define_table(
> 'inventory',
> Field('name'),
> Field('qty', label='Quantity'),
> Field('MatSize',label='Material Size'),
> format = '%(name)s') 
>
> db.define_table(
> 'POrequest',
> Field('name', 'reference requestor', label='Requestor'),
> Field('JobNum', 'reference jobs', label='Job #'),
> Field('description', 'text', notnull=True),
> Field('InInventory', compute=lambda r: r['description'] IN r[
> db.inventory.name]),  <<< this row right here is what I need help with
> format = '%(name)s')
>
> trying to verify row by row in a computed field if 
> db.POrequest.description is in any row of db.inventory.name
>
> help please.
>

-- 
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: Check file size before upload process

2015-03-10 Thread William Chen
I believe you can use 'onvalidation' to check the file size before upload. 

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

-- 
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: Check is user is the owner of row (help with db query)

2014-09-10 Thread desta
Thanks Anthony, indeed I will have to evaluate the tradeoff of speed for 
complexity. I don't think that our site will have the amount of traffic 
that this would be a problem but its always good to know good practices!
A friend suggested to use

db((db.task.id == 5)  (db.task.ref_to_job == db.job.id)  
(db.job.ref_to_project == db.project.id)  (db.project.owner == 
auth.user_id))

I tried it and it works, but I am not sure how different it is from the one 
Leonel suggested. How does this work?
Also, you mentioned to check the timing of the query. Is there a web2py way 
to do that?

Thank you

On Monday, September 8, 2014 3:31:54 PM UTC+3, Anthony wrote:

 On Monday, September 8, 2014 4:47:57 AM UTC-4, Leonel Câmara wrote:

 Frankly, I would just store the user as the owner in all of those tables. 
 Probably using auth.signature().

 You could do a very inefficient recursive select but I don't see any 
 advantage.

 Something like:

 task = db.tasks[5]

 if task.job.project.owner != auth.user_id:  # You are doing a select for 
 each dot you see here:
 raise HTTP(403)  # Forbidden


 Before you go storing the user id in every table, you should check the 
 timing on the above query, and make the decision based on expected app 
 usage. While the above isn't the most efficient, if will probably be only a 
 few milliseconds, and if this app doesn't have heavy traffic or this 
 operation isn't very frequent, the inefficiency may be fine. You could also 
 see if it's faster to do a single multi table join rather than the 
 recursive select shown above (though the above is easier to write and 
 understand, so may not be worth making the change anyway).

 Anthony 


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


[web2py] Re: Check is user is the owner of row (help with db query)

2014-09-10 Thread Anthony


 db((db.task.id == 5)  (db.task.ref_to_job == db.job.id)  
 (db.job.ref_to_project == db.project.id)  (db.project.owner == 
 auth.user_id))

 I tried it and it works, but I am not sure how different it is from the 
 one Leonel suggested. How does this work?


The above does a join, so it gets the data in a single database request, 
whereas Leonel's example involved a recursive select (behind the scenes, 
task.job.project.owner does two additional queries, beyond the query to get 
the tasks records).
 

 Also, you mentioned to check the timing of the query. Is there a web2py 
 way to do that?


See 
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Timing-queries.
 
Note, db._timings shows the actual SQL code, not your DAL code, so you'll 
have to figure out what DAL code generated what SQL. Leonel's code will 
generate three separate database requests with three separate timings that 
must be added together. Your join example above will generate only a single 
database request.

Anthony

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


[web2py] Re: Check is user is the owner of row (help with db query)

2014-09-08 Thread Leonel Câmara
Frankly, I would just store the user as the owner in all of those tables. 
Probably using auth.signature().

You could do a very inefficient recursive select but I don't see any 
advantage.

Something like:

task = db.tasks[5]

if task.job.project.owner != auth.user_id:  # You are doing a select for 
each dot you see here:
raise HTTP(403)  # Forbidden

-- 
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: Check is user is the owner of row (help with db query)

2014-09-08 Thread desta
Thank you, so you mean is bad practice the way I implemented the tables? 
When I designed it like that, I thought it would be convenient in altering 
the relations between the records.

On Monday, September 8, 2014 11:47:57 AM UTC+3, Leonel Câmara wrote:

 Frankly, I would just store the user as the owner in all of those tables. 
 Probably using auth.signature().

 You could do a very inefficient recursive select but I don't see any 
 advantage.

 Something like:

 task = db.tasks[5]

 if task.job.project.owner != auth.user_id:  # You are doing a select for 
 each dot you see here:
 raise HTTP(403)  # Forbidden


-- 
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: Check is user is the owner of row (help with db query)

2014-09-08 Thread Leonel Câmara
It's not exactly bad practice, quite the contrary, usually you want to 
start with a database without redundancy. This is just a case where 
denormalization really yields fruits as it is very inefficient to have to 
query the jobs and projects table to know who is the owner of a task.  
  
An alternative, if you don't want to do this, is to cache the tasks of the 
user either in session or in cache disk and then you see if the task 
belongs to the set. You will then have to be careful and delete/update this 
cached version if there are new tasks for that user.

-- 
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: Check is user is the owner of row (help with db query)

2014-09-08 Thread Marin Pranjić
Make sure to read Authorization chapter in book:

http://web2py.com/books/default/chapter/29/09/access-control#Authorization

-- 
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: Check is user is the owner of row (help with db query)

2014-09-08 Thread desta
Thank you guys for your valuable answers.

On Monday, September 8, 2014 2:51:56 PM UTC+3, Marin Pranjić wrote:

 Make sure to read Authorization chapter in book:

 http://web2py.com/books/default/chapter/29/09/access-control#Authorization



-- 
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: Check is user is the owner of row (help with db query)

2014-09-08 Thread Anthony
On Monday, September 8, 2014 4:47:57 AM UTC-4, Leonel Câmara wrote:

 Frankly, I would just store the user as the owner in all of those tables. 
 Probably using auth.signature().

 You could do a very inefficient recursive select but I don't see any 
 advantage.

 Something like:

 task = db.tasks[5]

 if task.job.project.owner != auth.user_id:  # You are doing a select for 
 each dot you see here:
 raise HTTP(403)  # Forbidden


Before you go storing the user id in every table, you should check the 
timing on the above query, and make the decision based on expected app 
usage. While the above isn't the most efficient, if will probably be only a 
few milliseconds, and if this app doesn't have heave traffic or this 
operation isn't very frequent, the inefficiency may be fine. You could also 
see if it's faster to do a single multi table join rather than the 
recursive select shown above (though the above is easier to write and 
understand, so may not be worth making the change anyway).

Anthony 

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


[web2py] Re: Check to delete glitch in 2.9.6 and 2.9.7

2014-09-06 Thread Ide
Great, fixed on my server now. 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: Check to delete glitch in 2.9.6 and 2.9.7

2014-09-05 Thread Massimo Di Pierro
Good catch! fixed in trunk.

On Friday, 5 September 2014 08:07:42 UTC-5, Ide wrote:

 I have 2 applications which both seem to have a problem with the 'check to 
 delete' option in 2.9.6 and 2.9.7. The 'check to delete' label on this tick 
 box is now showing up as 'Check to deleteNone'. I don;t think it did this 
 when I was using 2.9.5, although that was a few months ago now, so I may 
 not remember fully.

 In both cases I am using the SQLFORM feature with the deletable=True 
 option and {{=BEAUTIFY(form)}} in the view. I have done a quick search in 
 the sqlhtml.py code, but there is no obvious typo in there to account for 
 it, so it seems like the None is getting added on to this label somewhere 
 along the line.

 My resulting html from the {{=BEAUTIFY(form)}} code is as below

 tr id=delete_record__row
   td class=w2p_fl
 label for=delete_record id=delete_record__labelCheck to 
 deleteNone/label
   /td
   td class=w2p_fw
 input class=delete cascade_delete id=delete_record name=
 delete_this_record type=checkbox value=on
   /td
   td class=w2p_fc/td
 /tr

 Any ideas what could be casuing 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/d/optout.


[web2py] Re: Check file size before upload process

2014-01-26 Thread Massimo Di Pierro
You cannot check before it is uploaded. If you use apache or nginx, then 
can check and block large uploads, but you would get a web server error, 
not a web2py error.


On Sunday, 26 January 2014 13:32:16 UTC-6, lesssugar wrote:

 I'm using IS_LENGTH in my model to validate file size of uploaded image:

 IS_LENGTH(2097152, 1, error_message='Max image size: 2MB')

 However, the size is being checked after the file's been uploaded, which 
 is not very user friendly when it comes to files larger than 2MB. How can I 
 first validate the file size and then - if it's lower than 2MB - proceed 
 with upload? Can it be done with Python or do I need JS for this?


-- 
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: check if db field is empty

2014-01-22 Thread Yebach
I tryied with 

eng_out = db(db.script.id == 
id_skripte).select(db.script.sc_engine_output)[0]['sc_engine_output']
print eng_out , eng_out

if eng_out is None:
print Ni podatkov


but I am sure there has to be a better way. 

thanx again

-- 
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: check if db field is empty

2014-01-22 Thread Anthony
How about:

if db((db.script.id == id_skripte)  (db.script.sc_engine != None)).select
():

Anthony

On Wednesday, January 22, 2014 9:30:45 AM UTC-5, Yebach wrote:

 I tryied with 

 eng_out = db(db.script.id == 
 id_skripte).select(db.script.sc_engine_output)[0]['sc_engine_output']
 print eng_out , eng_out
 
 if eng_out is None:
 print Ni podatkov


 but I am sure there has to be a better way. 

 thanx again


-- 
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: Check it out: PURE AJAX file uploads :D

2013-04-24 Thread Niphlod
why the base64 ? I want my files submitted as binaries, if possibile.

On Wednesday, April 24, 2013 5:31:48 PM UTC+2, select wrote:

 in your client side js code use the js file api (this is for one file, but 
 multi file upload can be done too)

 $('#datafile-uploadfield').change(function() {
 var upload_element = $(this)[0];
 var file = upload_element.files[0];
 if (file) {
   var reader = new FileReader();
   reader.readAsDataURL(file); //, UTF-8);//TODO what encoding 
 should be parsed???
   reader.onload = (function(theFile) {
 return function(evt) {
   $.ajax({
 url: '{{=URL(datafile_create)}}',
 data: {
   data: evt.target.result,
   name: theFile.name
 },
 type: 'POST',
 dataType: 'json',
 success: function(data) {
   addDatafile(data);
 }
   });
 };
   })(file);
   reader.onerror = function(evt) {
 alert(:( oh noo, we could not read your file);
   };
   //++counter;
 }
   });

 in you controller
 def datafile_create():
 splitcontents = request.vars.data.split(',')
 import base64
 file_content = base64.b64decode(splitcontents[1])
 # create file like object
 import StringIO
 filelike_obj = StringIO.StringIO(file_content)
 db_store = db.datafiles.file.store(filelike_obj, request.vars.name)
 record_id = db.datafiles.insert(file=db_store)


 in you db.py
 db.define_table('datafiles',
  Field('file', 'upload', requires=IS_NOT_EMPTY()),
  )

 == PURE AWESOMENESS



-- 

--- 
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: Check it out: PURE AJAX file uploads :D

2013-04-24 Thread select
readAsBinaryString and readAsArrayBuffer and readAsText
did not work, i just tested, but if you have a hint on how to make them 
work I would be very interested

On Wednesday, April 24, 2013 5:53:33 PM UTC+2, Niphlod wrote:

 why the base64 ? I want my files submitted as binaries, if possibile.

 On Wednesday, April 24, 2013 5:31:48 PM UTC+2, select wrote:

 in your client side js code use the js file api (this is for one file, 
 but multi file upload can be done too)

 $('#datafile-uploadfield').change(function() {
 var upload_element = $(this)[0];
 var file = upload_element.files[0];
 if (file) {
   var reader = new FileReader();
   reader.readAsDataURL(file); //, UTF-8);//TODO what encoding 
 should be parsed???
   reader.onload = (function(theFile) {
 return function(evt) {
   $.ajax({
 url: '{{=URL(datafile_create)}}',
 data: {
   data: evt.target.result,
   name: theFile.name
 },
 type: 'POST',
 dataType: 'json',
 success: function(data) {
   addDatafile(data);
 }
   });
 };
   })(file);
   reader.onerror = function(evt) {
 alert(:( oh noo, we could not read your file);
   };
   //++counter;
 }
   });

 in you controller
 def datafile_create():
 splitcontents = request.vars.data.split(',')
 import base64
 file_content = base64.b64decode(splitcontents[1])
 # create file like object
 import StringIO
 filelike_obj = StringIO.StringIO(file_content)
 db_store = db.datafiles.file.store(filelike_obj, request.vars.name)
 record_id = db.datafiles.insert(file=db_store)


 in you db.py
 db.define_table('datafiles',
  Field('file', 'upload', requires=IS_NOT_EMPTY()),
  )

 == PURE AWESOMENESS



-- 

--- 
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: Check it out: PURE AJAX file uploads :D

2013-04-24 Thread Niphlod
it's not that I don't like the use of native js api, but if the tradeoff is 
transmitting as base64 that's not an implementation I want to use (given 
that there are plenty of drop-loaders out there). 
Base64 the contents means wasting a net 33% of bandwith.

-- 

--- 
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: Check it out: PURE AJAX file uploads :D

2013-04-24 Thread select
so what do these drop loaders do to make pure ajax file uploads, i was not 
aware of that o_O

On Wednesday, April 24, 2013 6:19:09 PM UTC+2, Niphlod wrote:

 it's not that I don't like the use of native js api, but if the tradeoff 
 is transmitting as base64 that's not an implementation I want to use (given 
 that there are plenty of drop-loaders out there). 
 Base64 the contents means wasting a net 33% of bandwith.



-- 

--- 
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: Check it out: PURE AJAX file uploads :D

2013-04-24 Thread select
so i basically missed what is going on right now because I did not looked 
at the problem for half a year 
http://caniuse.com/xhr2
xhr2 is supported by almost all browsers and xhr2 supports sending files :D
implementations are here 
http://stackoverflow.com/a/10811427/1436151
http://stackoverflow.com/questions/4856917/jquery-upload-progress-and-ajax-file-upload/4943774#4943774


On Wednesday, April 24, 2013 6:24:55 PM UTC+2, select wrote:

 so what do these drop loaders do to make pure ajax file uploads, i was not 
 aware of that o_O

 On Wednesday, April 24, 2013 6:19:09 PM UTC+2, Niphlod wrote:

 it's not that I don't like the use of native js api, but if the tradeoff 
 is transmitting as base64 that's not an implementation I want to use (given 
 that there are plenty of drop-loaders out there). 
 Base64 the contents means wasting a net 33% of bandwith.



-- 

--- 
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: Check if exist table (dal)

2013-04-17 Thread damufo
Hi,
Thanks.

My solution was:

if self.table_name not in db._migrated:
self.install()


Best regards.

On Tuesday, April 16, 2013 3:31:12 PM UTC+2, dam...@gmail.com wrote:


 Hi,
 In my init class have a install() with create table.
 When creates second instance, fail.

 type 'exceptions.SyntaxError' table already defined: mytable Version 
 web2py™ Version 2.4.6-stable+timestamp.2013.04.06.17.37.38  Python Python 
 2.7.4: C:\Python27\python.exe (prefix: C:\Python27)
 How check is this exists this table?

 In this moment, i add

 try:
 self.install() #create table
 except:
 pass

 thanks!

-- 

--- 
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: Check if exist table (dal)

2013-04-16 Thread Niphlod
if you leverage db.define_table that doesn't happen.
If you do it all by hand, either you 
try: 
select 1 from table
except:
   pass

or you do what you're doing (or you store somewhere that you don't need to 
install() every time ^_^)

On Tuesday, April 16, 2013 3:31:12 PM UTC+2, dam...@gmail.com wrote:


 Hi,
 In my init class have a install() with create table.
 When creates second instance, fail.

 type 'exceptions.SyntaxError' table already defined: mytable Version 
 web2py™ Version 2.4.6-stable+timestamp.2013.04.06.17.37.38  Python Python 
 2.7.4: C:\Python27\python.exe (prefix: C:\Python27)
 How check is this exists this table?

 In this moment, i add

 try:
 self.install() #create table
 except:
 pass

 thanks!

-- 

--- 
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: Check if a from's boolean is true or false from the controller

2012-12-05 Thread Niphlod
and why should you need it ?

you can always do:

newthing = {}
if something:
 newthing = form.vars

dowhatever with newthing (it's an empty dict that in theory shouldn't hurt)

On Wednesday, December 5, 2012 1:49:00 AM UTC+1, Daniele wrote:

 How can I blank out all the **form.vars in the event that the 
 form.vars.is_tutor returns false? Is there a simple way to do this or 
 should I manually put in None for all the fields?


 On Tue, Dec 4, 2012 at 8:16 PM, Niphlod nip...@gmail.com javascript:wrote:

 depends on where do you use that kind of logic. If the user is already 
 logged, you need to UPDATE the corresponding auth_user row with the data 
 inserted, something among the lines of

 db(db.auth_user.id == auth.user_id).update(**form.vars)

 If instead you are requesting the user to fill that form without being 
 logged already, you'd need to CREATE the row, so you should use 
 insertin that case you should also ask for username/email and the 
 password.

 summary: form.vars holds a dictionary composed of fieldname -- values. 
 Both .insert() and .update() take a dictionary, in which case the columns 
 corresponding to a table are updated/created with the correct values. 

 On Tuesday, December 4, 2012 8:34:31 PM UTC+1, Daniele wrote:

 And the same goes for db.auth_user.insert() ... does it imply the logged 
 user or not?

 On Monday, December 3, 2012 2:27:29 PM UTC, Daniele wrote:

 Hey guys, I'm wondering if there's a way from the controller to know 
 whether a form's boolean field (checkbox) is selected or not. I only want 
 to add the info in the form to the database if the checkbox is selected, 
 otherwise the controller should not process that form.

 Thanks!

  -- 
  
  
  




-- 





[web2py] Re: Check if a from's boolean is true or false from the controller

2012-12-04 Thread Daniele
OK. So I removed what I had before (tables in a database) and moved to 
SQLFORM.factory. I now have this in my controller:

form = SQLFORM.factory(
Field('is_tutor', 'boolean'),
Field('image', 'upload', 
requires=IS_EMPTY_OR(IS_IMAGE(extensions=('jpeg', 'jpg', 'png', 'gif',
Field('location', 'list:string', requires=IS_NOT_EMPTY()),
Field('subjects', 'list:string', requires=IS_NOT_EMPTY()),
Field('qualifications', 'list:string', requires=IS_NOT_EMPTY()),
Field('biography', 'string', length=500),
Field('hourly_rate', 'decimal(7,2)', requires=IS_NOT_EMPTY()),
Field('modified_on', 'datetime', requires=IS_DATETIME(), 
writable=False, readable=False, default=request.utcnow),
table_name='tutor')

so when the form is submitted, I now need to check if the field is_tutor is 
True. If it is, I need to add that info to the current logged user's 
information. Do I need to modify auth to do this? If so, how?

On Monday, December 3, 2012 3:16:45 PM UTC, Niphlod wrote:

 if it's checked the corresponding var would be True. 
 If the form is submitted the controller will receive that field as 
 request.vars.fieldname or as form.vars.fieldname if you are using a form. 
 When you get to the form.process() line the value has been already been 
 shipped to the database. You must act before: there is the onvalidation 
 callback (but it's generally used for other things, like additional 
 validation).

 If you want to skip form processing at all (and possibly doing some other 
 custom logic) you can rely either on SQLFORM with process(dbio=False) or 
 with SQLFORM.factory. in either case you'll have to build (or not, 
 depending on the checkbox) the corresponding create/update record by hand 
 (not so hard with e.g. SQLFORM.factory because generally your form.vars 
 would be ready to be inserted into the table if the form has the same 
 structure of the table itself, e.g. db.table.insert(**form.vars))


 On Monday, December 3, 2012 3:27:29 PM UTC+1, Daniele wrote:

 Hey guys, I'm wondering if there's a way from the controller to know 
 whether a form's boolean field (checkbox) is selected or not. I only want 
 to add the info in the form to the database if the checkbox is selected, 
 otherwise the controller should not process that form.

 Thanks!



-- 





[web2py] Re: Check if a from's boolean is true or false from the controller

2012-12-04 Thread Niphlod
if form.process().accepted:
if form.vars.is_tutor:
...whatever, e.g. db.table.insert(**form.vars)

How do you structure your db to save this data is up to your application: 
if you need this stored next to the auth_user table the recommended way is 
extending auth_user with auth.settings.extra_fields

On Tuesday, December 4, 2012 5:21:59 PM UTC+1, Daniele wrote:

 OK. So I removed what I had before (tables in a database) and moved to 
 SQLFORM.factory. I now have this in my controller:

 form = SQLFORM.factory(
 Field('is_tutor', 'boolean'),
 Field('image', 'upload', 
 requires=IS_EMPTY_OR(IS_IMAGE(extensions=('jpeg', 'jpg', 'png', 'gif',
 Field('location', 'list:string', requires=IS_NOT_EMPTY()),
 Field('subjects', 'list:string', requires=IS_NOT_EMPTY()),
 Field('qualifications', 'list:string', requires=IS_NOT_EMPTY()),
 Field('biography', 'string', length=500),
 Field('hourly_rate', 'decimal(7,2)', requires=IS_NOT_EMPTY()),
 Field('modified_on', 'datetime', requires=IS_DATETIME(), 
 writable=False, readable=False, default=request.utcnow),
 table_name='tutor')

 so when the form is submitted, I now need to check if the field is_tutor 
 is True. If it is, I need to add that info to the current logged user's 
 information. Do I need to modify auth to do this? If so, how?

 On Monday, December 3, 2012 3:16:45 PM UTC, Niphlod wrote:

 if it's checked the corresponding var would be True. 
 If the form is submitted the controller will receive that field as 
 request.vars.fieldname or as form.vars.fieldname if you are using a form. 
 When you get to the form.process() line the value has been already been 
 shipped to the database. You must act before: there is the onvalidation 
 callback (but it's generally used for other things, like additional 
 validation).

 If you want to skip form processing at all (and possibly doing some other 
 custom logic) you can rely either on SQLFORM with process(dbio=False) or 
 with SQLFORM.factory. in either case you'll have to build (or not, 
 depending on the checkbox) the corresponding create/update record by hand 
 (not so hard with e.g. SQLFORM.factory because generally your form.vars 
 would be ready to be inserted into the table if the form has the same 
 structure of the table itself, e.g. db.table.insert(**form.vars))


 On Monday, December 3, 2012 3:27:29 PM UTC+1, Daniele wrote:

 Hey guys, I'm wondering if there's a way from the controller to know 
 whether a form's boolean field (checkbox) is selected or not. I only want 
 to add the info in the form to the database if the checkbox is selected, 
 otherwise the controller should not process that form.

 Thanks!



-- 





[web2py] Re: Check if a from's boolean is true or false from the controller

2012-12-04 Thread Daniele
Thanks that was super helpful!

On Tuesday, December 4, 2012 4:31:08 PM UTC, Niphlod wrote:

 if form.process().accepted:
 if form.vars.is_tutor:
 ...whatever, e.g. db.table.insert(**form.vars)

 How do you structure your db to save this data is up to your application: 
 if you need this stored next to the auth_user table the recommended way is 
 extending auth_user with auth.settings.extra_fields

 On Tuesday, December 4, 2012 5:21:59 PM UTC+1, Daniele wrote:

 OK. So I removed what I had before (tables in a database) and moved to 
 SQLFORM.factory. I now have this in my controller:

 form = SQLFORM.factory(
 Field('is_tutor', 'boolean'),
 Field('image', 'upload', 
 requires=IS_EMPTY_OR(IS_IMAGE(extensions=('jpeg', 'jpg', 'png', 'gif',
 Field('location', 'list:string', requires=IS_NOT_EMPTY()),
 Field('subjects', 'list:string', requires=IS_NOT_EMPTY()),
 Field('qualifications', 'list:string', requires=IS_NOT_EMPTY()),
 Field('biography', 'string', length=500),
 Field('hourly_rate', 'decimal(7,2)', requires=IS_NOT_EMPTY()),
 Field('modified_on', 'datetime', requires=IS_DATETIME(), 
 writable=False, readable=False, default=request.utcnow),
 table_name='tutor')

 so when the form is submitted, I now need to check if the field is_tutor 
 is True. If it is, I need to add that info to the current logged user's 
 information. Do I need to modify auth to do this? If so, how?

 On Monday, December 3, 2012 3:16:45 PM UTC, Niphlod wrote:

 if it's checked the corresponding var would be True. 
 If the form is submitted the controller will receive that field as 
 request.vars.fieldname or as form.vars.fieldname if you are using a form. 
 When you get to the form.process() line the value has been already been 
 shipped to the database. You must act before: there is the onvalidation 
 callback (but it's generally used for other things, like additional 
 validation).

 If you want to skip form processing at all (and possibly doing some 
 other custom logic) you can rely either on SQLFORM with process(dbio=False) 
 or with SQLFORM.factory. in either case you'll have to build (or not, 
 depending on the checkbox) the corresponding create/update record by hand 
 (not so hard with e.g. SQLFORM.factory because generally your form.vars 
 would be ready to be inserted into the table if the form has the same 
 structure of the table itself, e.g. db.table.insert(**form.vars))


 On Monday, December 3, 2012 3:27:29 PM UTC+1, Daniele wrote:

 Hey guys, I'm wondering if there's a way from the controller to know 
 whether a form's boolean field (checkbox) is selected or not. I only want 
 to add the info in the form to the database if the checkbox is selected, 
 otherwise the controller should not process that form.

 Thanks!



-- 





[web2py] Re: Check if a from's boolean is true or false from the controller

2012-12-04 Thread Daniele
Another question has come to mind...I have the following code in my 
controller now:

if tform.process().accepted:
if tform.vars.is_tutor:
auth.add_membership('Tutors')
db.auth_user.insert(
a_bunch_of_fields = tform.vars.a_bunch_of_fields)
else:
# check if the user has membership first
auth.del_membership('Tutors')
db.auth_user.delete()

In the last line, db.auth_user.delete(), I'd like to delete all the fields 
in the database that I'd write if the is_tutor boolean is checked. But I'm 
wondering, I'd have to specify that it only needs to delete these for the 
logged in user. How can I do this? Also, is deleting the correct thing to 
do or should I just reset the values to a default, like  or None ?

Thanks


On Monday, December 3, 2012 2:27:29 PM UTC, Daniele wrote:

 Hey guys, I'm wondering if there's a way from the controller to know 
 whether a form's boolean field (checkbox) is selected or not. I only want 
 to add the info in the form to the database if the checkbox is selected, 
 otherwise the controller should not process that form.

 Thanks!


-- 





[web2py] Re: Check if a from's boolean is true or false from the controller

2012-12-04 Thread Daniele
And the same goes for db.auth_user.insert() ... does it imply the logged 
user or not?

On Monday, December 3, 2012 2:27:29 PM UTC, Daniele wrote:

 Hey guys, I'm wondering if there's a way from the controller to know 
 whether a form's boolean field (checkbox) is selected or not. I only want 
 to add the info in the form to the database if the checkbox is selected, 
 otherwise the controller should not process that form.

 Thanks!


-- 





[web2py] Re: Check if a from's boolean is true or false from the controller

2012-12-04 Thread Niphlod
depends on where do you use that kind of logic. If the user is already 
logged, you need to UPDATE the corresponding auth_user row with the data 
inserted, something among the lines of

db(db.auth_user.id == auth.user_id).update(**form.vars)

If instead you are requesting the user to fill that form without being 
logged already, you'd need to CREATE the row, so you should use 
insertin that case you should also ask for username/email and the 
password.

summary: form.vars holds a dictionary composed of fieldname -- values. 
Both .insert() and .update() take a dictionary, in which case the columns 
corresponding to a table are updated/created with the correct values. 

On Tuesday, December 4, 2012 8:34:31 PM UTC+1, Daniele wrote:

 And the same goes for db.auth_user.insert() ... does it imply the logged 
 user or not?

 On Monday, December 3, 2012 2:27:29 PM UTC, Daniele wrote:

 Hey guys, I'm wondering if there's a way from the controller to know 
 whether a form's boolean field (checkbox) is selected or not. I only want 
 to add the info in the form to the database if the checkbox is selected, 
 otherwise the controller should not process that form.

 Thanks!



-- 





Re: [web2py] Re: Check if a from's boolean is true or false from the controller

2012-12-04 Thread Daniele Pestilli
How can I blank out all the **form.vars in the event that the
form.vars.is_tutor returns false? Is there a simple way to do this or
should I manually put in None for all the fields?


On Tue, Dec 4, 2012 at 8:16 PM, Niphlod niph...@gmail.com wrote:

 depends on where do you use that kind of logic. If the user is already
 logged, you need to UPDATE the corresponding auth_user row with the data
 inserted, something among the lines of

 db(db.auth_user.id == auth.user_id).update(**form.vars)

 If instead you are requesting the user to fill that form without being
 logged already, you'd need to CREATE the row, so you should use
 insertin that case you should also ask for username/email and the
 password.

 summary: form.vars holds a dictionary composed of fieldname -- values.
 Both .insert() and .update() take a dictionary, in which case the columns
 corresponding to a table are updated/created with the correct values.

 On Tuesday, December 4, 2012 8:34:31 PM UTC+1, Daniele wrote:

 And the same goes for db.auth_user.insert() ... does it imply the logged
 user or not?

 On Monday, December 3, 2012 2:27:29 PM UTC, Daniele wrote:

 Hey guys, I'm wondering if there's a way from the controller to know
 whether a form's boolean field (checkbox) is selected or not. I only want
 to add the info in the form to the database if the checkbox is selected,
 otherwise the controller should not process that form.

 Thanks!

  --





-- 





Re: [web2py] Re: Check if a from's boolean is true or false from the controller

2012-12-04 Thread Daniele Pestilli
There's some problem with what I'm doing now.

I have form = SQLFORM.factory() with all the fields in my controller.

In my db.py file, I am extending auth with


auth.settings.extra_fields['auth_user']= [

Field http://127.0.0.1:8000/examples/global/vars/Field('t_image'),

Field http://127.0.0.1:8000/examples/global/vars/Field('t_location'),

Field http://127.0.0.1:8000/examples/global/vars/Field('t_subjects'),

Field 
http://127.0.0.1:8000/examples/global/vars/Field('t_qualifications'),

Field http://127.0.0.1:8000/examples/global/vars/Field('t_biography'),

Field http://127.0.0.1:8000/examples/global/vars/Field('t_hourly_rate'),

Field http://127.0.0.1:8000/examples/global/vars/Field('t_modified_on'),

Field http://127.0.0.1:8000/examples/global/vars/Field('s_location')]

However, when I visit the page I am getting a bunch of 'None' fields
without input boxes. Am I supposed to somehow

put the SQLFORM.factory info in my db.py file? I can't understand why
it's doing this...




On Wed, Dec 5, 2012 at 12:49 AM, Daniele Pestilli byakugan...@gmail.comwrote:

 How can I blank out all the **form.vars in the event that the
 form.vars.is_tutor returns false? Is there a simple way to do this or
 should I manually put in None for all the fields?



 On Tue, Dec 4, 2012 at 8:16 PM, Niphlod niph...@gmail.com wrote:

 depends on where do you use that kind of logic. If the user is already
 logged, you need to UPDATE the corresponding auth_user row with the data
 inserted, something among the lines of

 db(db.auth_user.id == auth.user_id).update(**form.vars)

 If instead you are requesting the user to fill that form without being
 logged already, you'd need to CREATE the row, so you should use
 insertin that case you should also ask for username/email and the
 password.

 summary: form.vars holds a dictionary composed of fieldname -- values.
 Both .insert() and .update() take a dictionary, in which case the columns
 corresponding to a table are updated/created with the correct values.

 On Tuesday, December 4, 2012 8:34:31 PM UTC+1, Daniele wrote:

 And the same goes for db.auth_user.insert() ... does it imply the logged
 user or not?

 On Monday, December 3, 2012 2:27:29 PM UTC, Daniele wrote:

 Hey guys, I'm wondering if there's a way from the controller to know
 whether a form's boolean field (checkbox) is selected or not. I only want
 to add the info in the form to the database if the checkbox is selected,
 otherwise the controller should not process that form.

 Thanks!

  --







-- 





[web2py] Re: Check if a from's boolean is true or false from the controller

2012-12-03 Thread Niphlod
if it's checked the corresponding var would be True. 
If the form is submitted the controller will receive that field as 
request.vars.fieldname or as form.vars.fieldname if you are using a form. 
When you get to the form.process() line the value has been already been 
shipped to the database. You must act before: there is the onvalidation 
callback (but it's generally used for other things, like additional 
validation).

If you want to skip form processing at all (and possibly doing some other 
custom logic) you can rely either on SQLFORM with process(dbio=False) or 
with SQLFORM.factory. in either case you'll have to build (or not, 
depending on the checkbox) the corresponding create/update record by hand 
(not so hard with e.g. SQLFORM.factory because generally your form.vars 
would be ready to be inserted into the table if the form has the same 
structure of the table itself, e.g. db.table.insert(**form.vars))


On Monday, December 3, 2012 3:27:29 PM UTC+1, Daniele wrote:

 Hey guys, I'm wondering if there's a way from the controller to know 
 whether a form's boolean field (checkbox) is selected or not. I only want 
 to add the info in the form to the database if the checkbox is selected, 
 otherwise the controller should not process that form.

 Thanks!


-- 





[web2py] Re: Check for a value in a table

2012-09-18 Thread lcamara
There are lots of better ways, one would be:

count_value = db(db.table.fieldname == value)..count()
if not count_value:
# Value isn't in db do something

Terça-feira, 18 de Setembro de 2012 11:36:11 UTC+1, Hassan Alnatour 
escreveu:

 Dear ALL ,

 How can a check if a value for a Field in a table , now in this i do this 

 values = []
 for i in db().select(db.table.ALL): 
values.append(i.Field)

 then i check like this :
   if i in values:
   . .


 Is there a better way to do this ??

 Best Regards,



-- 





[web2py] Re: Check to delete:False

2012-03-29 Thread Alan Etkin
Looks like an error when typing or something like that. For me it should be 
only Check to delete

On Thursday, March 29, 2012 4:49:08 AM UTC-3, Annet wrote:

 After upgrading from 1.99.2 to 1.99.7 the check to delete label has 
 changed to check to delete: False 

 label id=delete_record__label for=delete_recordCheck to 
 delete:False/label

 Is there a reason for this?

 Kind regards,

 Annet



[web2py] Re: Check to delete:False

2012-03-29 Thread Anthony
SQLFORM takes delete_label and separator arguments. Previously (at 
least up to 1.99.2), delete_label defaulted to Check to delete:, and the 
separater was not appended. At some point since 1.99.2, it was changed -- 
now delete_label defaults to Check to delete, and separator (which 
defaults to : ) is appended. I think this was done (a) to correct the 
problem with the missing space after the : in the original label and (b) 
to make the separator for the delete record label consistent with the other 
labels. The default behavior is the same as before (except for the 
inclusion of the trailing space), but if you were doing something other 
than the default, the output could change. It looks like you might have 
separator=False, so False is getting appended to the label. If you just 
remove any explicit delete_label and separator arguments, you should 
get what you're looking for.

Anthony

which it concatenates to create the delete record label. If you set 
separator=False, it will

On Thursday, March 29, 2012 3:49:08 AM UTC-4, Annet wrote:

 After upgrading from 1.99.2 to 1.99.7 the check to delete label has 
 changed to check to delete: False 

 label id=delete_record__label for=delete_recordCheck to 
 delete:False/label

 Is there a reason for this?

 Kind regards,

 Annet



[web2py] Re: Check to delete:False

2012-03-29 Thread Annet
Hi Alan and Anthony,

I upgraded to 1.99.7 from 1.99.2 to solve my represent problem, to solve 
the check to delete problem I had to change separator=False to separator=''

@Anthony, thanks for your explanation. Seems like I chose the wrong 
solution on 02/08/2011 to solve the colon problem in SQLFORM.


Kind regards,

Annet


[web2py] Re: Check out my new site! (also trouble with routes.py)

2012-03-27 Thread lyn2py
Very nice theme!
Did you design it yourself? 

On Tuesday, March 27, 2012 7:46:02 PM UTC+8, vtgorilla wrote:

 I just launched it this morning: http://RosterBrain.com 

 I was having a lot of trouble getting routes.py to work with my form 
 submits so I just stripped it for the time being. Is there anything 
 wrong with the following syntax? 

 routers = dict( 
 BASE = dict( 
 default_application = 'welcome', 
 default_controller = 'default', 
 default_function = 'index' 
 ) 
 ) 

 This would sporadically give me invalid requests on form submits and 
 when using the admin interface. Any ideas? 

 Thanks, 
 Brad



[web2py] Re: Check out my new site! (also trouble with routes.py)

2012-03-27 Thread vtgorilla
Yes, but I borrowed inspiration heavily from another design.

On Mar 27, 8:15 am, lyn2py lyn...@gmail.com wrote:
 Very nice theme!
 Did you design it yourself?







 On Tuesday, March 27, 2012 7:46:02 PM UTC+8, vtgorilla wrote:

  I just launched it this morning:http://RosterBrain.com

  I was having a lot of trouble getting routes.py to work with my form
  submits so I just stripped it for the time being. Is there anything
  wrong with the following syntax?

  routers = dict(
      BASE = dict(
          default_application = 'welcome',
          default_controller = 'default',
          default_function = 'index'
      )
  )

  This would sporadically give me invalid requests on form submits and
  when using the admin interface. Any ideas?

  Thanks,
  Brad


[web2py] Re: Check out my new site! (also trouble with routes.py)

2012-03-27 Thread Massimo Di Pierro
:-)

On Tuesday, 27 March 2012 06:46:02 UTC-5, vtgorilla wrote:

 I just launched it this morning: http://RosterBrain.com 

 I was having a lot of trouble getting routes.py to work with my form 
 submits so I just stripped it for the time being. Is there anything 
 wrong with the following syntax? 

 routers = dict( 
 BASE = dict( 
 default_application = 'welcome', 
 default_controller = 'default', 
 default_function = 'index' 
 ) 
 ) 

 This would sporadically give me invalid requests on form submits and 
 when using the admin interface. Any ideas? 

 Thanks, 
 Brad



[web2py] Re: Check out my new site! (also trouble with routes.py)

2012-03-27 Thread Anthony
Nice. Just added to http://web2py.com/poweredby.

Routes looks OK -- is that the entire routes.py file? Any app-specific 
routes?

Anthony

On Tuesday, March 27, 2012 7:46:02 AM UTC-4, vtgorilla wrote:

 I just launched it this morning: http://RosterBrain.com 

 I was having a lot of trouble getting routes.py to work with my form 
 submits so I just stripped it for the time being. Is there anything 
 wrong with the following syntax? 

 routers = dict( 
 BASE = dict( 
 default_application = 'welcome', 
 default_controller = 'default', 
 default_function = 'index' 
 ) 
 ) 

 This would sporadically give me invalid requests on form submits and 
 when using the admin interface. Any ideas? 

 Thanks, 
 Brad



[web2py] Re: Check out my new site! (also trouble with routes.py)

2012-03-27 Thread vtgorilla
That was the entire file. I only have the one public facing app, so I
didn't try to do anything fancy with it yet.

I kept having trouble after I took the routes.py out, and I think my
issue was that web2py wasn't always figuring out my
redirect(URL('pagename'))'s correctly. I explicitly added in the app
and controller names to all the redirects and it solved whatever was
happening.

I had it up for testing on FluxFlex with no problem, but I have it on
WebFaction now and that's when the issues started.

Thanks for adding to the poweredby site! It's famous now!

On Mar 27, 10:35 am, Anthony abasta...@gmail.com wrote:
 Nice. Just added tohttp://web2py.com/poweredby.

 Routes looks OK -- is that the entire routes.py file? Any app-specific
 routes?

 Anthony







 On Tuesday, March 27, 2012 7:46:02 AM UTC-4, vtgorilla wrote:

  I just launched it this morning:http://RosterBrain.com

  I was having a lot of trouble getting routes.py to work with my form
  submits so I just stripped it for the time being. Is there anything
  wrong with the following syntax?

  routers = dict(
      BASE = dict(
          default_application = 'welcome',
          default_controller = 'default',
          default_function = 'index'
      )
  )

  This would sporadically give me invalid requests on form submits and
  when using the admin interface. Any ideas?

  Thanks,
  Brad


[web2py] Re: Check out my new site! (also trouble with routes.py)

2012-03-27 Thread Anthony


 I kept having trouble after I took the routes.py out, and I think my 
 issue was that web2py wasn't always figuring out my 
 redirect(URL('pagename'))'s correctly. I explicitly added in the app 
 and controller names to all the redirects and it solved whatever was 
 happening.


When you do URL('pagename') it takes 'pagename' as the function and assumes 
the current request.application and request.controller as the application 
and controller (it does *not* assume the default application and controller 
as specified in routes.py). If you're staying with the same app, you can 
safely exclude the app from URL(), but it's generally safest to include the 
controller (makes it easier to understand the code as well).

Anthony 


Re: [web2py] Re: Check out my new site! (also trouble with routes.py)

2012-03-27 Thread Jonathan Lundell
On Mar 27, 2012, at 7:35 AM, Anthony wrote:
 Routes looks OK -- is that the entire routes.py file? Any app-specific routes?

It does look OK, though keep in mind that setting the default a/c/f in a 
parametric router is subtly different from setting them outside the router.

Do you get any more information in the invalid-request messages? They've been 
enhanced (mostly, anyway) to give some indication of just what was invalid 
about them.

 
 Anthony
 
 On Tuesday, March 27, 2012 7:46:02 AM UTC-4, vtgorilla wrote:
 I just launched it this morning: http://RosterBrain.com 
 
 I was having a lot of trouble getting routes.py to work with my form 
 submits so I just stripped it for the time being. Is there anything 
 wrong with the following syntax? 
 
 routers = dict( 
 BASE = dict( 
 default_application = 'welcome', 
 default_controller = 'default', 
 default_function = 'index' 
 ) 
 ) 
 
 This would sporadically give me invalid requests on form submits and 
 when using the admin interface. Any ideas? 




[web2py] Re: Check if request method is post

2012-02-20 Thread Niphlod
the method is stored into request.env.request_method .
So request.env.request_method == 'POST' is what you're looking for


[web2py] Re: Check if request method is post

2012-02-20 Thread Anthony
Also, if request.post_vars is not None, then it is a post request -- so you 
could do something like:

if request.post_vars:
[do something with POST request variables]

Note, request.vars contains both request.get_vars and request.post_vars.

Anthony

On Monday, February 20, 2012 3:35:23 PM UTC-5, Niphlod wrote:

 the method is stored into request.env.request_method .
 So request.env.request_method == 'POST' is what you're looking for



[web2py] Re: Check if request method is post

2012-02-20 Thread Alan Etkin
This command returns a string with the method name (uppercase)

request.env.request_method

On 20 feb, 17:26, Hassan Alnatour halna...@gardeniatelco.com wrote:
 Dear All ,

 How can i check if the request method is post ?


[web2py] Re: Check to establish whether or not a record exists

2011-10-10 Thread Massimo Di Pierro
row = db.postcode_cache(postcode=postcode)
if not row:
db.postcode_cache.insert(postcode=postcode,nearset=nearest)
elif not row.nearest: row.update_record(nearset=nearest)
else: pass # do nothing

On Oct 10, 8:22 am, Chris Rowson christopherrow...@gmail.com wrote:
 Hi list,

 I have a database table which looks like this:

 postcode_cache
 
 postcode (UNIQUE)
 lat
 lon
 nearest

 I want to test first whether or not a record exists for 'postcode' and
 if a record does exist, I want to check whether the 'nearest' field
 contains any data.

 I've tried this:

 if db(db.postcode_cache.postcode==postcode).select().first()==None:
     create_a_new_postcode_record()

 elif 
 db(db.postcode_cache.postcode==postcode).select(db.postcode_cache.nearest)= 
 =None:
     populate_the_nearest_field()

 else:
     nothing_to_do()

 And while the check to establish whether or not a record exists seems
 to work, the check to see whether or not the 'nearest' field within
 the record is populated doesn't seem to work.

 Can anyone tell me what I'm doing wrong please?

 Thank you,

 Chris


Re: [web2py] Re: Check to establish whether or not a record exists

2011-10-10 Thread Chris Rowson
Thank you Massimo :-)

Chris

On Mon, Oct 10, 2011 at 2:55 PM, Massimo Di Pierro
massimo.dipie...@gmail.com wrote:
 row = db.postcode_cache(postcode=postcode)
 if not row:
 db.postcode_cache.insert(postcode=postcode,nearset=nearest)
 elif not row.nearest: row.update_record(nearset=nearest)
 else: pass # do nothing

 On Oct 10, 8:22 am, Chris Rowson christopherrow...@gmail.com wrote:
 Hi list,

 I have a database table which looks like this:

 postcode_cache
 
 postcode (UNIQUE)
 lat
 lon
 nearest

 I want to test first whether or not a record exists for 'postcode' and
 if a record does exist, I want to check whether the 'nearest' field
 contains any data.

 I've tried this:

 if db(db.postcode_cache.postcode==postcode).select().first()==None:
     create_a_new_postcode_record()

 elif 
 db(db.postcode_cache.postcode==postcode).select(db.postcode_cache.nearest)= 
 =None:
     populate_the_nearest_field()

 else:
     nothing_to_do()

 And while the check to establish whether or not a record exists seems
 to work, the check to see whether or not the 'nearest' field within
 the record is populated doesn't seem to work.

 Can anyone tell me what I'm doing wrong please?

 Thank you,

 Chris


[web2py] Re: Check out my new web2py website

2011-08-01 Thread Christopher Steel
Looks very promising weheh.

Chris



[web2py] Re: Check out my new web2py website

2011-08-01 Thread weheh
ninjaui looks good. but i'm using jquery ui

On Aug 1, 3:43 pm, Bruno Rocha rochacbr...@gmail.com wrote:
 are you using ninjaui?http://ninjaui.com/objects

 On Mon, Aug 1, 2011 at 9:06 AM, weheh richard_gor...@verizon.net wrote:
  I want to keep this low profile for now because there is still much to
  do. But if anyone is interested in trying my beta web2py website,
  please go ahead. It's athttp://beta.yakitome.com. Don't expect it to
  be super stable nor have all features available, but the basics are
  there. So far, it only handles .txt file uploads and the Mel voice is
  not installed. I do not guarantee that I will be keeping your data
  during the beta period. The legacy version athttp://www.yakitome.com
  is for that. It will be supported in parallel until the new site is
  solid. Feedback on the new site will be appreciated. Use the contact
  form. Thanks.

 --

 --
 Bruno Rocha
 [ About me:http://zerp.ly/rochacbruno]
 [ Aprenda a programar:http://CursoDePython.com.br]
 [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br]
 [ Consultoria em desenvolvimento web:http://www.blouweb.com]


[web2py] Re: Check

2011-07-07 Thread beedge
Apologises.

Stupid.  Double (differeing) definition of db in the model file,
before and after some custom auth tables.  Hence, app was pulling in
my apps tables, but I couldn't see the auth stuff and odd behaviour.



[web2py] Re: Check

2011-07-06 Thread Anthony
That doesn't sound right. Can you reproduce the behavior?
 
Are you using CAS (
https://groups.google.com/d/topic/web2py/Qcw6B1Y89JM/discussion), or regular 
Auth?
 
Anthony

On Wednesday, July 6, 2011 3:20:37 PM UTC-4, beedge wrote:

 Thanks for responses.  Point about definition of objects in the python 
 files accepted!  Can I just check something here, as I may have the 
 wrong end of the stick... 

 My understanding was that the Apps are all completely independent 
 (i.e. seperate authentication etc).  However, I'm seeing an account I 
 added in the new app I created appearing in the auth tables in the 
 Welcome app...  If this is anticipated behaviour, I think I need to do 
 a bit more reading before I try anything else...



[web2py] Re: Check

2011-07-06 Thread ron_m
If you started with a copy of the Welcome app did you change the database 
name? If both apps have the same database URL originally defined in the 
Welcome app in file models/db.py they will share tables.


[web2py] Re: check if len error in view

2011-05-13 Thread pbreit
If you're going to do it in the view, you need some {{pass}} statements to 
close up the for and the if blocks.

Re: [web2py] Re: check if len error in view

2011-05-13 Thread Stifan Kristi
it's my fault, thank you so much for corrected me pbreit.

On Sat, May 14, 2011 at 10:16 AM, pbreit pbreitenb...@gmail.com wrote:

 If you're going to do it in the view, you need some {{pass}} statements to
 close up the for and the if blocks.


[web2py] Re: Check if file has unsaved changes before loading new page

2011-04-14 Thread Massimo Di Pierro
Thank you Drise,

This is definitively possible. Could you please open a ticket on
google code so the request gets queued?


On Apr 14, 4:34 pm, Drise dris...@gmail.com wrote:
 In the past week, I have come to really love Web2Py and thank Massimo
 for his work. One thing I would find useful is when editing a file,
 and you have unsaved changes, you should be prompted to save or
 discard those changes before being able to browse to a new page.


[web2py] Re: 'check exists' option for reseting password

2011-04-11 Thread Brian Will
That seems to do it.

On Apr 11, 1:42 am, Brian Will brian.thomas.w...@gmail.com wrote:
 I'd rather my password reset form not check the db for the existence
 of the email and just blindly give an 'an email has been sent' message
 regardless of what email address is entered.

 In Auth.request_reset_password(), this should require simply making
 the second validator conditional upon an option:

 table_user.email.requires =
 [IS_EMAIL(error_message=self.messages.invalid_email)]
 if self.settings.request_reset_password_check_exists:
       table_user.email.requires.append(IS_IN_DB(self.db,
 table_user.email, error_message=self.messages.invalid_email))

 The settings.request_reset_password_check_exists option would default
 to True.


[web2py] Re: Check if a user has already rated

2011-04-11 Thread Drise
How would I go by doing that?

On Apr 11, 10:42 am, pbreit pbreitenb...@gmail.com wrote:
 I wasn't aware that validators could be used like that. Perhaps just query 
 the db?


Re: [web2py] Re: Check if a user has already rated

2011-04-11 Thread Kenneth Lundström

On 11.4.2011 18:59, Drise wrote:

How would I go by doing that?

On Apr 11, 10:42 am, pbreitpbreitenb...@gmail.com  wrote:

I wasn't aware that validators could be used like that. Perhaps just query the 
db?

Hello,

as pbreit commented validators can´t be used like that. They are used 
when you are using forms, to validate that the data you have 
entered/selected complies to some rules.


To check if a user has rated already you query the database and if no 
rows found the user can rate.


rated = db(db.hasrated.user == request.args[0]).select()

if len(rated) == 0:
#user can rate

else:
#user already rated, can´t rate anymore

Is this enough?


Kenneth






[web2py] Re: Check if a user has already rated

2011-04-11 Thread Drise
Hm.. so you are saying that I should store the has rated with the
user, and not the comment?

On Apr 11, 11:08 am, Kenneth Lundström kenneth.t.lundst...@gmail.com
wrote:
 On 11.4.2011 18:59, Drise wrote: How would I go by doing that?

  On Apr 11, 10:42 am, pbreitpbreitenb...@gmail.com  wrote:
  I wasn't aware that validators could be used like that. Perhaps just query 
  the db?

 Hello,

 as pbreit commented validators can t be used like that. They are used
 when you are using forms, to validate that the data you have
 entered/selected complies to some rules.

 To check if a user has rated already you query the database and if no
 rows found the user can rate.

 rated = db(db.hasrated.user == request.args[0]).select()

 if len(rated) == 0:
          #user can rate

 else:
          #user already rated, can t rate anymore

 Is this enough?

 Kenneth


[web2py] Re: Check if a user has already rated

2011-04-11 Thread pbreit
Either way. But I think the point is to just use a db().select() operation 
to determine if the users hasrated.

[web2py] Re: Check if a user has already rated

2011-04-11 Thread Arun K.Rajeevan
Have you tried http://www.web2pyslices.com/main/slices/take_slice/112

I remember it did check for already done rating and doesn't allow rate twice 
by the same user on same object.
May be you can just use it or look at the code and adapt it to your 
application.

That's really not that big, only a controller and a model with few lines. 
30-60 may be.



[web2py] Re: Check if a user has already rated

2011-04-11 Thread Arun K.Rajeevan
Have you tried http://www.web2pyslices.com/main/slices/take_slice/112

I remember it did check for already done rating and doesn't allow rate twice 
by the same user on same object.
May be you can just use it or look at the code and adapt it to your 
application.

That's really not that big, only a controller and a model with few lines. 
30-60 may be.



[web2py] Re: Check if a user has already rated

2011-04-11 Thread Drise
I will try that.

On Apr 11, 11:59 am, pbreit pbreitenb...@gmail.com wrote:
 Either way. But I think the point is to just use a db().select() operation
 to determine if the users hasrated.


[web2py] Re: check if file in form

2011-03-02 Thread Massimo Di Pierro

if isinstance(request.vars.image, cgi.FieldStorage) and
request.vars.image.file:
     redirect(URL('structure',args=['it', 'works']))

On Mar 2, 9:23 am, LightOfMooN vladsale...@yandex.ru wrote:
 How can I check if there is file in the sent form?

 if request.vars.image:
     redirect(URL('structure',args=['it', 'works']))

 doesn't work

 if request.vars.image.file rises an error, when no file sent


[web2py] Re: check if file in form

2011-03-02 Thread LightOfMooN
thanks!

On 2 мар, 20:56, Massimo Di Pierro massimo.dipie...@gmail.com wrote:
 if isinstance(request.vars.image, cgi.FieldStorage) and
 request.vars.image.file:
      redirect(URL('structure',args=['it', 'works']))

 On Mar 2, 9:23 am, LightOfMooN vladsale...@yandex.ru wrote:







  How can I check if there is file in the sent form?

  if request.vars.image:
      redirect(URL('structure',args=['it', 'works']))

  doesn't work

  if request.vars.image.file rises an error, when no file sent