[web2py] Re: Adding checkboxes to sqlform.factory and form validation based on another table

2014-02-05 Thread Apple Mason
 
 I forgot to highlight code samples in my last post. Sorry about that.



If we have these simple models:

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

db.define_table('common_allergies',
Field('name', 'string'))



The common_allergies is a table full of common allergies that people may 
have like 'peanuts' or 'bee stings'. This table is pre-populated by the 
system.

When a user fills out a form, the form asks two things: the person's name 
and the person's allergies.

The form for the person's name is a simple string text input. But the list 
of allergies the person can select needs to be checkboxes. 


I have something like this:

fields = []
allergies = db().select(db.common_allergies.ALL)

for allergy in allergies:
fields.append(Field('allergy', 'boolean', default=allergy.name))

form = SQLFORM.factory(db.person, *fields)

if form.process().accepted:
  # Check to make sure the list of values returned from the allergy 
checkboxes exist in the common_allergies table. If it doesn't exist, fail 
the form validation

  # If all checks went well, insert this person's data into respective 
database tables.



There are two problems with this:
 
  - The boolean fields 'allergy' only shows one checkbox, which is the last 
one in the list when I do {{=form.custom.widget.allergy}} in the view. How 
do I get back a list of allergies that have been checked by the user?

  - The value of the checkbox can be changed on the clientside and then 
submitted. How would I check against this and make sure that the submitted 
allergy values exist in the database table? Assuming I have a list returned 
to me, I could do something like this inside form.process().accepted:

if form.process().accepted:
 should_save = True
 for allergy in checked_allergies:
   check = db(db.common_allergies.name==allergy).select()
   if check.is_empty():
 # error the form
 should_save = False
   
 if should_save:
  # Save the user's data



But this seems a bit messy and complicated.

How would I generate the checkboxes for the common_allergies table and how 
would these checkbox values be validated against the database table to 
prevent client-side tampering?

-- 
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] Adding checkboxes to sqlform.factory and form validation based on another table

2014-02-05 Thread Apple Mason
If we have these simple models:

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

db.define_table('common_allergies',
Field('name', 'string'))

The common_allergies is a table full of common allergies that people may 
have like 'peanuts' or 'bee stings'. This table is pre-populated by the 
system.

When a user fills out a form, the form asks two things: the person's name 
and the person's allergies.

The form for the person's name is a simple string text input. But the list 
of allergies the person can select needs to be checkboxes. 


I have something like this:

fields = []
allergies = db().select(db.common_allergies.ALL)

for allergy in allergies:
fields.append(Field('allergy', 'boolean', default=allergy.name))

form = SQLFORM.factory(db.person, *fields)

if form.process().accepted:
  # Check to make sure the list of values returned from the allergy 
checkboxes exist in the common_allergies table. If it doesn't exist, fail 
the form validation

  # If all checks went well, insert this person's data into respective 
database tables.

There are two problems with this:
 
  - The boolean fields 'allergy' only shows one checkbox, which is the last 
one in the list when I do {{=form.custom.widget.allergy}} in the view. How 
do I get back a list of allergies that have been checked by the user?

  - The value of the checkbox can be changed on the clientside and then 
submitted. How would I check against this and make sure that the submitted 
allergy values exist in the database table? Assuming I have a list returned 
to me, I could do something like this inside form.process().accepted:

if form.process().accepted:
 should_save = True
 for allergy in checked_allergies:
   check = db(db.common_allergies.name==allergy).select()
   if check.is_empty():
 # error the form
 should_save = False
   
 if should_save:
  # Save the user's data

But this seems a bit messy and complicated.

How would I generate the checkboxes for the common_allergies table and how 
would these checkbox values be validated against the database table to 
prevent client-side tampering?

-- 
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: Querying rows over several many-to-many tables.

2014-01-29 Thread Apple Mason
Can you quickly explain the difference between:

(db.clothing.id==db.clothing_person.clothing_Id) &
(db.person.id==db.clothing_person.person_id)

and 

(db.clothing_person.clothing_id==db.clothing.id) &
(db.clothing_person.person_id==db.person.id)



On Wednesday, January 29, 2014 5:15:51 PM UTC-5, Niphlod wrote:
>
> You can't achieve it without a "custom function", but it's not that hard 
> to write
>
> //totally untested//
>
> def search_whatever(people=[], items=[], clothings=[]):
>   q = db.people.name.belongs(people)
>   if items:
>   q = q & (db.item_person.person_id == db.person.id) #the 
> reference
>   q = q & (db.item.name.belongs(items))
>   if clothing:
>   q = q & (
>   (db.clothing.id == db.clothing_person.clothing_id) &  
>   (db.person.id == db.clothing_person.person_id)
>  ) #the reference
>q = q & (db.clothing.name.belongs(clothings))
>   
>   rows = db(q).select(db.person.ALL)
>   return rows
>
>
>
>
>
> On Wednesday, January 29, 2014 11:03:06 PM UTC+1, Apple Mason wrote:
>>
>> Is there a more lenient version of what_I_want that will give me based on 
>> what I put in? For example,
>>
>> If I just want all people named Bob, it would return all people named Bob.
>>
>> If I just want all people named Bob or nicknamed Bobcat, then I wlll get 
>> all people named Bob or nicknamed Bobcat.
>>
>> If I just want all people nicknamed Bobcat who also have item1, item2, 
>> then I get all people nicknamed Bobcat with item1,item2
>>
>> If I just want all people named Bob and nicknamed Bobcat and have item1, 
>> and clothing1, clothing2, then I get all people named Bob and nicknamed 
>> Bobcat with item1, clothing1, clothnig2
>>
>> Right now if I do:
>>
>> what_i_want = (
>>(db.person.name=='Bob') &
>>(db.item.name=='item1') &
>>(db.clothing.name=='clothing1')
>> )
>>
>> I get results. But if I do:
>>
>> what_I_want = (
>> (db.person.name=='Bob')
>> )
>>
>> It doesn't return any rows.
>>
>> On Wednesday, January 29, 2014 3:14:09 AM UTC-5, Niphlod wrote:
>>>
>>> why the hassle of using joins like those ones ?
>>> If you're not fond of searching through left joins, and you still want 
>>> your whole dataset "consistent", and a search "a-la-fulltext".better do 
>>> something like this
>>>
>>> whole_set = (
>>>  (db.person.id == db.clothing_person.person_id) &
>>>  (db.clothing.id == db.clothing_person.clothing_id) &
>>>  (db.item_person.person_id == db.person.id) &
>>>  (db.item_person.item_id == db.item.id)
>>> )
>>>
>>> then, you can search it as 
>>>
>>> what_I_want = (
>>> (db.person.name == 'Bob') &
>>> 
>>> (db.item.name == 'item1')
>>> )
>>>
>>> rows = db(whole_set)(what_I_want).select()
>>>
>>> On Wednesday, January 29, 2014 6:29:10 AM UTC+1, Apple Mason wrote:
>>>>
>>>> I want to search across some many to many tables, but with certain 
>>>> conditions.
>>>>
>>>>
>>>> db.define_table('person',
>>>> Field('name', 'string'),
>>>> Field('nickname', 'string'))
>>>>
>>>> db.define_table('clothing',
>>>> Field('name', 'string'))
>>>>
>>>> db.define_table('item',
>>>> Field('name', 'string'))
>>>>
>>>> db.define_table('item_person',
>>>> Field('person_id', 'reference person'),
>>>> Field('item_id', 'reference item'))
>>>>
>>>> db.define_table('clothing_person',
>>>> Field('person_id', 'reference person'),
>>>> Field('clothing_id', 'reference clothing'))
>>>>
>>>>
>>>>
>>>> How would I find all people who have the name 'Bob' or nickname 
>>>> 'Bobcat' AND have items called 'item1' and 'item2' AND have clothing 
>>>> 'clothing1' ?
>>>>
>>>> For example, these are valid results:
>>>>
>>>> Bob has item1, item2 and clothing1
>>>> Bobcat has item1, item2 and clothing1
>>>>
>>>> Would I use a join for this? Maybe something like:
>>>>
>>>> db( (db.person.name.like('Bob')) | 
>>>> (db.person.name.like('Bobcat')).select(db.person.ALL, join=[
>>>> db.item_person.on( 
>>>> (db.item.id==db.item_person.item_id) 
>>>> & ((db.item.name=='item1') & (db.item.name='item2'))),
>>>> db.clothing_person.on( 
>>>> (db.clothing.id==db.clothing_person.clothing_id) 
>>>> & (db.clothing.name=='clothing1'))
>>>> ])
>>>>
>>>> But that doesn't seem correct.
>>>>
>>>

-- 
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: Querying rows over several many-to-many tables.

2014-01-29 Thread Apple Mason
Is there a more lenient version of what_I_want that will give me based on 
what I put in? For example,

If I just want all people named Bob, it would return all people named Bob.

If I just want all people named Bob or nicknamed Bobcat, then I wlll get 
all people named Bob or nicknamed Bobcat.

If I just want all people nicknamed Bobcat who also have item1, item2, then 
I get all people nicknamed Bobcat with item1,item2

If I just want all people named Bob and nicknamed Bobcat and have item1, 
and clothing1, clothing2, then I get all people named Bob and nicknamed 
Bobcat with item1, clothing1, clothnig2

Right now if I do:

what_i_want = (
   (db.person.name=='Bob') &
   (db.item.name=='item1') &
   (db.clothing.name=='clothing1')
)

I get results. But if I do:

what_I_want = (
(db.person.name=='Bob')
)

It doesn't return any rows.

On Wednesday, January 29, 2014 3:14:09 AM UTC-5, Niphlod wrote:
>
> why the hassle of using joins like those ones ?
> If you're not fond of searching through left joins, and you still want 
> your whole dataset "consistent", and a search "a-la-fulltext".better do 
> something like this
>
> whole_set = (
>  (db.person.id == db.clothing_person.person_id) &
>  (db.clothing.id == db.clothing_person.clothing_id) &
>  (db.item_person.person_id == db.person.id) &
>  (db.item_person.item_id == db.item.id)
> )
>
> then, you can search it as 
>
> what_I_want = (
> (db.person.name == 'Bob') &
> 
> (db.item.name == 'item1')
> )
>
> rows = db(whole_set)(what_I_want).select()
>
> On Wednesday, January 29, 2014 6:29:10 AM UTC+1, Apple Mason wrote:
>>
>> I want to search across some many to many tables, but with certain 
>> conditions.
>>
>>
>> db.define_table('person',
>> Field('name', 'string'),
>> Field('nickname', 'string'))
>>
>> db.define_table('clothing',
>> Field('name', 'string'))
>>
>> db.define_table('item',
>> Field('name', 'string'))
>>
>> db.define_table('item_person',
>> Field('person_id', 'reference person'),
>> Field('item_id', 'reference item'))
>>
>> db.define_table('clothing_person',
>> Field('person_id', 'reference person'),
>> Field('clothing_id', 'reference clothing'))
>>
>>
>>
>> How would I find all people who have the name 'Bob' or nickname 'Bobcat' 
>> AND have items called 'item1' and 'item2' AND have clothing 'clothing1' ?
>>
>> For example, these are valid results:
>>
>> Bob has item1, item2 and clothing1
>> Bobcat has item1, item2 and clothing1
>>
>> Would I use a join for this? Maybe something like:
>>
>> db( (db.person.name.like('Bob')) | 
>> (db.person.name.like('Bobcat')).select(db.person.ALL, join=[
>> db.item_person.on( (db.item.id==db.item_person.item_id) 
>> & ((db.item.name=='item1') & (db.item.name='item2'))),
>> db.clothing_person.on( 
>> (db.clothing.id==db.clothing_person.clothing_id) 
>> & (db.clothing.name=='clothing1'))
>> ])
>>
>> But that doesn't seem correct.
>>
>

-- 
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] Querying rows over several many-to-many tables.

2014-01-28 Thread Apple Mason
I want to search across some many to many tables, but with certain 
conditions.


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

db.define_table('clothing',
Field('name', 'string'))

db.define_table('item',
Field('name', 'string'))

db.define_table('item_person',
Field('person_id', 'reference person'),
Field('item_id', 'reference item'))

db.define_table('clothing_person',
Field('person_id', 'reference person'),
Field('clothing_id', 'reference clothing'))



How would I find all people who have the name 'Bob' or nickname 'Bobcat' 
AND have items called 'item1' and 'item2' AND have clothing 'clothing1' ?

For example, these are valid results:

Bob has item1, item2 and clothing1
Bobcat has item1, item2 and clothing1

Would I use a join for this? Maybe something like:

db( (db.person.name.like('Bob')) | 
(db.person.name.like('Bobcat')).select(db.person.ALL, join=[
db.item_person.on( (db.item.id==db.item_person.item_id) 
& ((db.item.name=='item1') & (db.item.name='item2'))),
db.clothing_person.on( 
(db.clothing.id==db.clothing_person.clothing_id) & 
(db.clothing.name=='clothing1'))
])

But that doesn't seem correct.

-- 
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: Form on every page?

2014-01-27 Thread Apple Mason
Yeah, the search terms will be open to the public. But the search terms 
will be queried in the database using like() or contains() from the DAL. 
Will that be okay if those search terms are unsanitized?

On Monday, January 27, 2014 2:34:45 PM UTC-5, Anthony wrote:
>
> Is this just a search form making GET requests open to the public? In that 
> case, I don't think you need to worry about CSRF or input sanitizing.
>
> Anthony
>
> On Monday, January 27, 2014 2:16:04 PM UTC-5, Apple Mason wrote:
>>
>> If I manually create the raw html form and set the action attribute, how 
>> would I get csrf protection? SQLFORM would generate a token to handle this, 
>> but wouldn't I lack this protection is I write the html myself? Also, since 
>> there's no form.process().accepted, does this also mean I'm open to 
>> unsanitized input from the webuser?
>>
>> On Monday, January 27, 2014 1:11:27 PM UTC-5, Anthony wrote:
>>>
>>> You can set the "action" attribute of the form to the URL of your 
>>> searchbar() function (you might also change the method from post to get 
>>> since the form is for search). How you create the form itself in the view 
>>> depends on your needs. Do you just need a single text search field? What 
>>> does the search function do to return results?
>>>
>>> Anthony
>>>
>>> On Monday, January 27, 2014 1:02:03 PM UTC-5, Apple Mason wrote:
>>>>
>>>> I found this thread that has a similar problem:
>>>>
>>>> https://groups.google.com/forum/#!searchin/web2py/form$20in$20layout.html/web2py/JRxUYp_YpHk/4uVM7kg9Ja4J
>>>>
>>>> The example was:
>>>>
>>>> def contact(): 
>>>>  form=SQLFORM.factory() 
>>>>  if form.accepts() 
>>>>  return form # not dict(form=form) 
>>>>  
>>>> and in layout.html 
>>>>  
>>>> {{=LOAD('default','contact')}} 
>>>>
>>>> But in my case I would like to use {{=form.custom.begin}} and 
>>>> {{=form.custom.end}} to format the html in a certain way. How would this 
>>>> be 
>>>> possible?
>>>>
>>>> Also, is it possible to not use javascript to have a search form on 
>>>> every page?
>>>>
>>>> On Monday, January 27, 2014 12:20:50 AM UTC-5, Apple Mason wrote:
>>>>>
>>>>> Oh, it's probably because the url is /index.html and not 
>>>>> /searchform.html.
>>>>>
>>>>> In that case, how would I create a search form that is present 
>>>>> globally in the site?
>>>>>
>>>>> On Monday, January 27, 2014 12:04:43 AM UTC-5, Apple Mason wrote:
>>>>>>
>>>>>> My controller default.py:
>>>>>>
>>>>>> def searchbar:
>>>>>> form = SQLFORM()
>>>>>>
>>>>>> return (form=form)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Monday, January 27, 2014 12:03:37 AM UTC-5, Apple Mason wrote:
>>>>>>>
>>>>>>> I have a search bar that I want to display on every page, but 
>>>>>>> something is not working. Here is an example of what I have:
>>>>>>>
>>>>>>> layout.html:
>>>>>>>
>>>>>>> 
>>>>>>> 
>>>>>>>
>>>>>>> 
>>>>>>> {{include 'default/searchbar.html'}}
>>>>>>> 
>>>>>>>
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> In default/searchbar.html:
>>>>>>>
>>>>>>> {{=form}}
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> But web2py doesn't find the searchbar controller function. I get an 
>>>>>>> error: 
>>>>>>>
>>>>>>> "NameError: name 'form' is not defined"
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> because searchbar.html can't find {{=form}}.
>>>>>>>
>>>>>>> There have been some threads that use javascript for this, but I 
>>>>>>> don't want to use that. Is there a pure html solution 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: Form on every page?

2014-01-27 Thread Apple Mason
If I manually create the raw html form and set the action attribute, how 
would I get csrf protection? SQLFORM would generate a token to handle this, 
but wouldn't I lack this protection is I write the html myself? Also, since 
there's no form.process().accepted, does this also mean I'm open to 
unsanitized input from the webuser?

On Monday, January 27, 2014 1:11:27 PM UTC-5, Anthony wrote:
>
> You can set the "action" attribute of the form to the URL of your 
> searchbar() function (you might also change the method from post to get 
> since the form is for search). How you create the form itself in the view 
> depends on your needs. Do you just need a single text search field? What 
> does the search function do to return results?
>
> Anthony
>
> On Monday, January 27, 2014 1:02:03 PM UTC-5, Apple Mason wrote:
>>
>> I found this thread that has a similar problem:
>>
>> https://groups.google.com/forum/#!searchin/web2py/form$20in$20layout.html/web2py/JRxUYp_YpHk/4uVM7kg9Ja4J
>>
>> The example was:
>>
>> def contact(): 
>>  form=SQLFORM.factory() 
>>  if form.accepts() 
>>  return form # not dict(form=form) 
>>  
>> and in layout.html 
>>  
>> {{=LOAD('default','contact')}} 
>>
>> But in my case I would like to use {{=form.custom.begin}} and 
>> {{=form.custom.end}} to format the html in a certain way. How would this be 
>> possible?
>>
>> Also, is it possible to not use javascript to have a search form on every 
>> page?
>>
>> On Monday, January 27, 2014 12:20:50 AM UTC-5, Apple Mason wrote:
>>>
>>> Oh, it's probably because the url is /index.html and not 
>>> /searchform.html.
>>>
>>> In that case, how would I create a search form that is present globally 
>>> in the site?
>>>
>>> On Monday, January 27, 2014 12:04:43 AM UTC-5, Apple Mason wrote:
>>>>
>>>> My controller default.py:
>>>>
>>>> def searchbar:
>>>> form = SQLFORM()
>>>>
>>>> return (form=form)
>>>>
>>>>
>>>>
>>>>
>>>> On Monday, January 27, 2014 12:03:37 AM UTC-5, Apple Mason wrote:
>>>>>
>>>>> I have a search bar that I want to display on every page, but 
>>>>> something is not working. Here is an example of what I have:
>>>>>
>>>>> layout.html:
>>>>>
>>>>> 
>>>>> 
>>>>>
>>>>> 
>>>>> {{include 'default/searchbar.html'}}
>>>>> 
>>>>>
>>>>> 
>>>>> 
>>>>> 
>>>>>
>>>>>
>>>>>
>>>>> In default/searchbar.html:
>>>>>
>>>>> {{=form}}
>>>>>
>>>>>
>>>>>
>>>>> But web2py doesn't find the searchbar controller function. I get an 
>>>>> error: 
>>>>>
>>>>> "NameError: name 'form' is not defined"
>>>>>
>>>>>
>>>>>
>>>>> because searchbar.html can't find {{=form}}.
>>>>>
>>>>> There have been some threads that use javascript for this, but I don't 
>>>>> want to use that. Is there a pure html solution 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: Form on every page?

2014-01-27 Thread Apple Mason
I found this thread that has a similar problem:
https://groups.google.com/forum/#!searchin/web2py/form$20in$20layout.html/web2py/JRxUYp_YpHk/4uVM7kg9Ja4J

The example was:

def contact(): 
 form=SQLFORM.factory() 
 if form.accepts() 
 return form # not dict(form=form) 
 
and in layout.html 
 
{{=LOAD('default','contact')}} 

But in my case I would like to use {{=form.custom.begin}} and 
{{=form.custom.end}} to format the html in a certain way. How would this be 
possible?

Also, is it possible to not use javascript to have a search form on every 
page?

On Monday, January 27, 2014 12:20:50 AM UTC-5, Apple Mason wrote:
>
> Oh, it's probably because the url is /index.html and not /searchform.html.
>
> In that case, how would I create a search form that is present globally in 
> the site?
>
> On Monday, January 27, 2014 12:04:43 AM UTC-5, Apple Mason wrote:
>>
>> My controller default.py:
>>
>> def searchbar:
>> form = SQLFORM()
>>
>>     return (form=form)
>>
>>
>>
>>
>> On Monday, January 27, 2014 12:03:37 AM UTC-5, Apple Mason wrote:
>>>
>>> I have a search bar that I want to display on every page, but something 
>>> is not working. Here is an example of what I have:
>>>
>>> layout.html:
>>>
>>> 
>>> 
>>>
>>> 
>>> {{include 'default/searchbar.html'}}
>>> 
>>>
>>> 
>>> 
>>> 
>>>
>>>
>>>
>>> In default/searchbar.html:
>>>
>>> {{=form}}
>>>
>>>
>>>
>>> But web2py doesn't find the searchbar controller function. I get an 
>>> error: 
>>>
>>> "NameError: name 'form' is not defined"
>>>
>>>
>>>
>>> because searchbar.html can't find {{=form}}.
>>>
>>> There have been some threads that use javascript for this, but I don't 
>>> want to use that. Is there a pure html solution 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: Form on every page?

2014-01-26 Thread Apple Mason
Oh, it's probably because the url is /index.html and not /searchform.html.

In that case, how would I create a search form that is present globally in 
the site?

On Monday, January 27, 2014 12:04:43 AM UTC-5, Apple Mason wrote:
>
> My controller default.py:
>
> def searchbar:
> form = SQLFORM()
>
> return (form=form)
>
>
>
>
> On Monday, January 27, 2014 12:03:37 AM UTC-5, Apple Mason wrote:
>>
>> I have a search bar that I want to display on every page, but something 
>> is not working. Here is an example of what I have:
>>
>> layout.html:
>>
>> 
>> 
>>
>> 
>> {{include 'default/searchbar.html'}}
>> 
>>
>> 
>> 
>> 
>>
>>
>>
>> In default/searchbar.html:
>>
>> {{=form}}
>>
>>
>>
>> But web2py doesn't find the searchbar controller function. I get an 
>> error: 
>>
>> "NameError: name 'form' is not defined"
>>
>>
>>
>> because searchbar.html can't find {{=form}}.
>>
>> There have been some threads that use javascript for this, but I don't 
>> want to use that. Is there a pure html solution 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: Form on every page?

2014-01-26 Thread Apple Mason
My controller default.py:

def searchbar:
form = SQLFORM()

return (form=form)




On Monday, January 27, 2014 12:03:37 AM UTC-5, Apple Mason wrote:
>
> I have a search bar that I want to display on every page, but something is 
> not working. Here is an example of what I have:
>
> layout.html:
>
> 
> 
>
> 
> {{include 'default/searchbar.html'}}
> 
>
> 
> 
> 
>
>
>
> In default/searchbar.html:
>
> {{=form}}
>
>
>
> But web2py doesn't find the searchbar controller function. I get an error: 
>
> "NameError: name 'form' is not defined"
>
>
>
> because searchbar.html can't find {{=form}}.
>
> There have been some threads that use javascript for this, but I don't 
> want to use that. Is there a pure html solution 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] Form on every page?

2014-01-26 Thread Apple Mason
I have a search bar that I want to display on every page, but something is 
not working. Here is an example of what I have:

layout.html:





{{include 'default/searchbar.html'}}








In default/searchbar.html:

{{=form}}



But web2py doesn't find the searchbar controller function. I get an error: 

"NameError: name 'form' is not defined"



because searchbar.html can't find {{=form}}.

There have been some threads that use javascript for this, but I don't want 
to use that. Is there a pure html solution 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: Multiple one-to-many join query help.

2014-01-24 Thread Apple Mason
Is there a way to get all the information returned as one row, with the 
focus on a particular person? For example, 



... Or something similar? This would give me a single row that I can 
iterate through his things or pets if I need to. For example, to print out 
people's information:

for person in persons:
  things = .
  pets = ...

  print "%s %s" % (things, pets)



Right now the code I have is:

a = db( db.person.id==1).select(db.person.ALL, db.pet.ALL, db.thing.
ALL,
left=[db.pet.on(db.person.id==db.pet.person_id),
  db.thing.on(db.person.id==db.thing.person_id)])


When I print this out, I get a combination of the same thing, which is a 
mess:














On Wednesday, January 22, 2014 4:40:31 PM UTC-5, Niphlod wrote:
>
> I'm guessing you had it wrong
>
> db(main_table.filter == something).select(
> main_table, other_table, 
> left=[other_table.on(main_table.some_id == other_table.reference), 
> 
> ]
> )
>
>
>
> On Wednesday, January 22, 2014 10:24:14 PM UTC+1, Apple Mason wrote:
>>
>>
>> I have the following tables:
>>
>>
>> db.define_table('person',
>> Field('name', 'string'))
>>
>> db.define_table('pet',
>> Field('name', 'string'),
>> Field('person_id', 'reference person'))
>>
>> db.define_table('thing',
>> Field('name', 'string'),
>> Field('person_id', 'reference person'))
>>
>> I have a person_id given to me, so I want all information about that 
>> person (person's name, all pets, all things).
>>
>> I am trying left join, but I am not getting it quite right:
>>
>>  person = db(db.person.id==person_id).select(db.person.ALL, db.pet.ALL, 
>> db.thing.ALL, 
>>  
>> left=[db.person.on(db.person.id==db.pet.person_id),
>>  
>> db.person.on(db.person.id==db.thing.person_id)])
>>
>> I get an error:
>>
>> OperationalError: ambiguous column name: person.id
>>
>

-- 
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] Multiple one-to-many join query help.

2014-01-22 Thread Apple Mason

I have the following tables:


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

db.define_table('pet',
Field('name', 'string'),
Field('person_id', 'reference person'))

db.define_table('thing',
Field('name', 'string'),
Field('person_id', 'reference person'))

I have a person_id given to me, so I want all information about that person 
(person's name, all pets, all things).

I am trying left join, but I am not getting it quite right:

 person = db(db.person.id==person_id).select(db.person.ALL, db.pet.ALL, 
db.thing.ALL, 
 
left=[db.person.on(db.person.id==db.pet.person_id),
 
db.person.on(db.person.id==db.thing.person_id)])

I get an error:

OperationalError: ambiguous column name: person.id

-- 
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: Is there a way to have a field in one table be computed by a field in another table?

2014-01-14 Thread Apple Mason
Yeah, that thread says to use _before_delete, and it fits this use case.

Can you verify if what I'm seeing about the delete is correct? The 
_before_delete is causing the admin panel to not delete the record for some 
reason. Is it a bug?

I'm using web2py 2.7.4 stable

On Tuesday, January 14, 2014 9:20:27 PM UTC-5, 黄祥 wrote:
>
> for after delete callback, please check this discussion
> https://groups.google.com/forum/#!msg/web2py/M4_5THMHzH0/r9aXH-k8eJQJ
>
> best regards,
> stifan
>

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


[web2py] Re: Is there a way to have a field in one table be computed by a field in another table?

2014-01-14 Thread Apple Mason
I read through the link you show me. I'm using _before_delete now, since 
doing s.select() returns 0 rows since it's already been deleted. I'm not 
sure how to deal with sets in _after_delete.

Here is my updated models:

db.define_table('person',
Field('name'),
Field('total_items', 'integer'),
format='%(name)s')
db.define_table('thing',
Field('name'),
Field('owner_id', 'reference person'),
format='%(name)s')
## after defining tables, uncomment below to enable auditing
# auth.enable_record_versioning(db)

db.thing._after_insert.append(lambda f,id: 
db(db.person.id==f['owner_id']).update(total_items=len(db(db.thing.owner_id==f['owner_id']).select(
from pprint import pprint
db.thing._before_delete.append(lambda s: 
db(db.person.id==s.select().first()['owner_id']).update(total_items=db(db.thing.owner_id==s.select().first()['owner_id']).count()))

With this, deleting doesn't throw errors in the admin panel, but now for 
some reason deleting rows from the things table doesn't work anymore. The 
admin interface flashes the 'done!' message, but I still see the record. 

On Tuesday, January 14, 2014 6:58:37 PM UTC-5, 黄祥 wrote:
>
> another way around i think you can do it in web form using oncreate, 
> onupdate and ondelete. and for delete callback, please check this 
> discussion :
> https://groups.google.com/forum/#!topic/web2py/didLpxEKT38
> reference for oncreate, onupdate and ondelete, please check this 
> discussion :
> https://groups.google.com/forum/#!topic/web2py/ShebcblC9pM
>
> best regards,
> stifan
>

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


[web2py] Re: Is there a way to have a field in one table be computed by a field in another table?

2014-01-14 Thread Apple Mason
Thanks, I came up with this:

db.thing._after_insert.append(lambda f,id: 
db(db.person.id==f['owner_id']).update(total_items=len(db(db.thing.owner_id==f['owner_id']).select(

It works, but is there is a better way to do this? Also, can someone help 
me with _after_delete? _after_delete gives me a set of db.thing.id, and I'm 
not sure how to use this to update the db.persons.total_items field.

On Tuesday, January 14, 2014 8:50:38 AM UTC-5, Anthony wrote:
>
> If you want db.person to be updated upon changes to db.thing, instead of a 
> computed field in db.person, you probably want to create _after_insert and 
> _after_update callbacks for db.thing (see 
> http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#before-and-after-callbacks
> ).
>
> Anthony
>
> On Tuesday, January 14, 2014 12:48:59 AM UTC-5, Apple Mason wrote:
>>
>> In the online doc on computed field, the computed fields uses a field in 
>> the current table, and not in another table.
>>
>> I modified the one-to-many example by adding a 'total_items' field on 
>> person. If I want 'total_items' to be the sum of all items the person 
>> currently has, and this field should be updated when an inserted/deleted 
>> 'thing' for this person happens, what should computed be?
>>
>>
>> >>> db.define_table('person',
>> Field('name'),
>> Field('total_items', 'integer', compute=#lamdba r: 
>> r.??),  # what should go here?
>> format='%(name)s')
>> >>> db.define_table('thing',
>> Field('name'),
>> Field('owner_id', 'reference person'),
>> format='%(name)s')
>>
>>

-- 
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] Is there a way to have a field in one table be computed by a field in another table?

2014-01-13 Thread Apple Mason
In the online doc on computed field, the computed fields uses a field in 
the current table, and not in another table.

I modified the one-to-many example by adding a 'total_items' field on 
person. If I want 'total_items' to be the sum of all items the person 
currently has, and this field should be updated when an inserted/deleted 
'thing' for this person happens, what should computed be?


>>> db.define_table('person',
Field('name'),
Field('total_items', 'integer', compute=#lamdba r: r.??),  
# what should go here?
format='%(name)s')
>>> db.define_table('thing',
Field('name'),
Field('owner_id', 'reference person'),
format='%(name)s')

-- 
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: "incomplete format" error when trying to insert ids

2014-01-09 Thread Apple Mason
Nevermind, I figured it out. My format string was wrong. After fixing that, 
everything works.

On Thursday, January 9, 2014 4:42:01 PM UTC-5, Apple Mason wrote:
>
> My many-to-many table is throwing an error every time I access that table 
> in the admin page:
>
>  incomplete format
>
> Traceback (most recent call last):
>   File "/home/apl/Desktop/web2py/gluon/restricted.py", line 217, in 
> restricted
> exec ccode in environment
>   File 
> "/home/apl/Desktop/web2py/applications/testapp/views/appadmin.html", line 
> 189, in 
> 
>   File "/home/apl/Desktop/web2py/gluon/sqlhtml.py", line 2917, in __init__
> r = A(represent(field, r, record), _href=str(href))
>   File "/home/apl/Desktop/web2py/gluon/sqlhtml.py", line 56, in represent
> return f(value)
>   File "/home/apl/Desktop/web2py/gluon/dal.py", line 6966, in repr_ref
> def repr_ref(id, row=None, r=referenced, f=ff): return f(r, id)
>   File "/home/apl/Desktop/web2py/gluon/dal.py", line 6939, in ff
> return r._format % row
> ValueError: incomplete format
>
> Here is the gist of what I'm trying to do:
>
> db.category.bulk_insert([ {'title':'category1'} ])
> db.subcategory.bulk_insert([ {'title':'subcategory1'} ])
>
> # This part will throw an error when visiting the admin page for this table
> db.category_subcategory.bulk_insert([ {'category_id':1L, 
> 'subcategory_id':1L} ])
>
> My db has these fields:
>
> category: name Field
> subcategory: name Field
> category_subcategory: category_id Field, subcategory_id Field.
>
> Why am I getting this error?
>

-- 
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] "incomplete format" error when trying to insert ids

2014-01-09 Thread Apple Mason
My many-to-many table is throwing an error every time I access that table 
in the admin page:

 incomplete format

Traceback (most recent call last):
  File "/home/apl/Desktop/web2py/gluon/restricted.py", line 217, in 
restricted
exec ccode in environment
  File "/home/apl/Desktop/web2py/applications/testapp/views/appadmin.html", 
line 189, in 

  File "/home/apl/Desktop/web2py/gluon/sqlhtml.py", line 2917, in __init__
r = A(represent(field, r, record), _href=str(href))
  File "/home/apl/Desktop/web2py/gluon/sqlhtml.py", line 56, in represent
return f(value)
  File "/home/apl/Desktop/web2py/gluon/dal.py", line 6966, in repr_ref
def repr_ref(id, row=None, r=referenced, f=ff): return f(r, id)
  File "/home/apl/Desktop/web2py/gluon/dal.py", line 6939, in ff
return r._format % row
ValueError: incomplete format

Here is the gist of what I'm trying to do:

db.category.bulk_insert([ {'title':'category1'} ])
db.subcategory.bulk_insert([ {'title':'subcategory1'} ])

# This part will throw an error when visiting the admin page for this table
db.category_subcategory.bulk_insert([ {'category_id':1L, 
'subcategory_id':1L} ])

My db has these fields:

category: name Field
subcategory: name Field
category_subcategory: category_id Field, subcategory_id Field.

Why am I getting this error?

-- 
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] Sharing fields across different tables in models?

2014-01-08 Thread Apple Mason
If we have a table full of products, but some products use slightly 
different fields, how should this be represented?

For example, if I sell clothing and furniture:

clothing and furniture share these fields:
 - price
 - description
 - stock
 - name

clothing have these special fields:
 - material/fabric
 - size

furniture have these special fields:
 - weight

Then, would this be a good way to handle it:

db.define_tables('product_fields', 
Field('price', 'double'),
Field('description', 'string'),
Field('stock', 'integer),
Field('name', 'string'))

db.define_tables('clothing_product',
Field('material_fabric', 'string'),
Field('size', 'string'),
Field('product_field', 'reference product_fields'))

db.define_tables('furniture_product',
Field('weight', 'double'),
Field('product_field', 'reference product_fields'))

The other way I can think of would be to have only two tables; 
'clothing_product' and 'furniture_product' but have the shared fields be 
replicated in both tables.

If I use the first approach, how would I resolve these problems:

1) How do I query all products at once, both clothing and furniture(and 
more if I add different products in the future)?

2) Because the tables are split for the products (ie, a clothing product 
stores its data in 'clothing_product' and 'product_fields' tables), how do 
I build forms for both tables and save them in one html page? I looked 
here: http://www.web2py.com/book/default/chapter/07#Multiple-forms-per-page but 
that has two submit buttons that submit two independent forms.  The only 
solution I can think of is to build my forms manually and then grab the 
values to insert into the db.

3) if I want to associate a product with a category, how should this be 
linked? For example:

db.define_tables('categories',
   Field('category_name', 'string'))

db.define_tables('categories_and_products',# Many to many relationship
   Field('category_id', 'reference categories'),
   Field('product_id', 'reference ???'))  # what table should I 
reference here ???


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


[web2py] How to map custom code to specific user roles to determine the auth_user field?

2013-10-14 Thread Apple Mason
Suppose I have three different types of users: buyer, distributor, and 
reseller.

All buyers, distributors, and resellers have an email, password, and 
ratings. Since email and password are already part of auth_user, the 
ratings Field will be an extra field in auth_user.

To separate the user roles, we can user auth_membership and auth_group to 
designate an auth_user as a 'buyer', 'distributor', or 'reseller'. 

Although each user role uses the same backend code for storing email and 
password (through auth_user), how would one go about storing a custom 
rating mechanism for each user role?

For example, let's say:

A buyer is rated with some combination of # of product reviews written and 
credible purchase history.

A reseller is rated with some combination of buyer reviews and warranty 
service.

A distributor is rated with reseller reviews.

Assuming I have the following functions which returns on an integer with 
range 1 - 100 for ratings:

def buyer_calc_rating():  # Random calcluation for this example
 comment_num = len(db(db.comments.user == db.buyer.id).select())
 purchase_history = #... some calculation that returns int

 return comment_num + purchase_history

def reseller_calc_rating();   # Assume similar calculation returns int
def distributor_calc_rating();  # Assume similar calculation returns int

I have two questions:

- How would I go about assigning these functions to user's ratings Field in 
auth_user?

- How would the ratings be dynamically updated each time something changes 
pertaining to rating calculation (ie, when a buyer rates a seller, etc)?

   Would the preferred way be to stick the above functions in a module 
which is then called wherever some controller function changes ratings? I 
would always get an update-to-date rating on the user this way (simply by 
querying 'db.auth_user.rating'), but that would also be a code-maintanence 
nightmare since I would have to keep track of all the places in the code 
that manipulates ratings?

Thanks in advance.


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


Re: [web2py] missing 'index' in url with routes.py?

2013-10-10 Thread Apple Mason
Thanks Jonathan, I ended just pointing the default function to a main() and 
from there I redirected to my index() in my controller.


On Thursday, October 10, 2013 5:47:22 PM UTC-4, Jonathan Lundell wrote:
>
> On 9 Oct 2013, at 9:11 PM, Apple Mason > 
> wrote:
>
> I'm trying to shorten the url from something like:
>
> www.example.com/myapp/default/index?page=1
>
> to 
>
> www.example/com/index?page=1
>
> I'm using pagination on the index page, so that's why you see the ?page=1
>
> My routes.py is pretty standard:
>
> routers = dict(
> # base router
> BASE=dict(
> default_application='myapp',
> ),
> myapp = dict(
> default_controller='default',
> default_function='index',
> functions=['index', 'dostuff', 'download'],
> ),
> )
>
>
> Everything seems fine, except the index page is this:
>
> www.example.com/?page=1
>
> I'm missing the word 'index' in the url.
>
>
> The function listed as default will also be removed from URLs as they get 
> shortened. If you don't want that, specify something else. I don't recall 
> offhand the best way to do it, but you might try setting the default 
> function to None, or else to some non-existent function name.
>

-- 
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] missing 'index' in url with routes.py?

2013-10-09 Thread Apple Mason
I'm trying to shorten the url from something like:

www.example.com/myapp/default/index?page=1

to 

www.example/com/index?page=1

I'm using pagination on the index page, so that's why you see the ?page=1

My routes.py is pretty standard:

routers = dict(
# base router
BASE=dict(
default_application='myapp',
),
myapp = dict(
default_controller='default',
default_function='index',
functions=['index', 'dostuff', 'download'],
),
)


Everything seems fine, except the index page is this:

www.example.com/?page=1

I'm missing the word 'index' in the url.


-- 
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: Redirect to my own 404 page through a custom error handler?

2013-09-20 Thread Apple Mason
Nevermind, I think I've figured things out. Although I noticed that 
routes_onerror doesn't do anything if it's in the application-specific 
routes.py. It works if I place it in the web2py root routes.py.

Is this intentional?


On Friday, September 20, 2013 2:27:20 AM UTC-4, Apple Mason wrote:
>
> I would like to throw a 404 when a user tries to access something that 
> doesn't exist, like trying to access a non-existent comment by providing a 
> comment id that doesn't exist in the database. In these cases, web2py will 
> throw an exception and point to a ticket (ie, NoneType has no attribute 
> 'id' or something).
>
> Instead, I'd like to throw up a custom 404 page which I have created. This 
> seems possible with routes_onerror (taken from the docs):
>
>  ('*/404', '/init/static/cantfind.html')
>
>
>
> However, my understanding from other threads is that this would not preserve 
> the error code. I found a nice example that
> points routes_onerror to a custom error handler, which will then preserve the 
> error code:
> http://www.web2pyslices.com/slice/show/1529/custom-error-routing
>
> In that code slice, it just returns a string like "Not found" for the errors. 
> How would I have web2py redirect
> to my custom_404.html instead?
>
> Then, in my controller, would I still do something like:
>
> if not comment:
> raise HTTP(404, 'sorry, that post does not exist')
>
> Even though the message 'sorry, that post does not exist' doesn't matter 
> anymore? I would be displaying my custom_404.html instead of this message?
>
>
>

-- 
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] Redirect to my own 404 page through a custom error handler?

2013-09-19 Thread Apple Mason
I would like to throw a 404 when a user tries to access something that 
doesn't exist, like trying to access a non-existent comment by providing a 
comment id that doesn't exist in the database. In these cases, web2py will 
throw an exception and point to a ticket (ie, NoneType has no attribute 
'id' or something).

Instead, I'd like to throw up a custom 404 page which I have created. This 
seems possible with routes_onerror (taken from the docs):

 ('*/404', '/init/static/cantfind.html')



However, my understanding from other threads is that this would not preserve 
the error code. I found a nice example that
points routes_onerror to a custom error handler, which will then preserve the 
error code:
http://www.web2pyslices.com/slice/show/1529/custom-error-routing

In that code slice, it just returns a string like "Not found" for the errors. 
How would I have web2py redirect
to my custom_404.html instead?

Then, in my controller, would I still do something like:

if not comment:
raise HTTP(404, 'sorry, that post does not exist')

Even though the message 'sorry, that post does not exist' doesn't matter 
anymore? I would be displaying my custom_404.html instead of this message?


-- 
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: Updating the auth_user profile that also has a one-to-many field?

2013-09-09 Thread Apple Mason
Ah, okay. Thanks!

On Monday, September 9, 2013 3:57:38 PM UTC-4, Niphlod wrote:
>
> your user_image is a reference to the id of the images table: you're the 
> one choosing to have it instead of the image itself on the auth_user table. 
> You have to deal with your model and your requirements making your own 
> profile update/insert page, dealing with all the things you explained .
>
> On Monday, September 9, 2013 9:50:40 PM UTC+2, Apple Mason wrote:
>>
>> I created a custom profile view so that the user can create/update his 
>> profile. Currently I have something like:
>>
>> models/db.py:
>>
>> db.define_table('images',
>>Field('image', 'upload', requires = IS_EMPTY_OR(IS_IMAGE()))
>>
>> auth.settings.extra_fields['auth_user'] = [
>>Field('user_image', 'reference images', requires=IS_NULL_OR(IS_IN_DB(
>> db, db.images.id)))
>> ]
>>
>>
>>
>> controller/default.py:
>> def user():
>> return dict(form=auth())
>>
>>
>>
>> view (for editing):
>>
>> {{=form.custom.begin}}
>>...
>>
>> Your Image: 
>>{{=form.custom.widget.user_image}}
>> {{=form.custom.end}}
>>
>> The problem is {{=form.custom.widget.user_image}} will render a dropdown 
>> of all image ids that are in the images table. Instead, I want a file 
>> upload, so that the user can change the image and it will be reflected in 
>> the database. How would I change the form to do this?
>>
>> Also, since an image doesn't initially exist for a user, web2py will have 
>> to first do the insert into the image table, and then update/insert it to 
>> the auth_user table. The other problem is if a user decides to change his 
>> user picture, then web2py has to deal with deleting the old picture in the 
>> database *and *on the filesystem.
>>
>> How can I handle these problems in web2py?
>>
>>
>>

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


[web2py] Updating the auth_user profile that also has a one-to-many field?

2013-09-09 Thread Apple Mason
I created a custom profile view so that the user can create/update his 
profile. Currently I have something like:

models/db.py:

db.define_table('images',
   Field('image', 'upload', requires = IS_EMPTY_OR(IS_IMAGE()))

auth.settings.extra_fields['auth_user'] = [
   Field('user_image', 'reference images', requires=IS_NULL_OR(IS_IN_DB(db,db
.images.id)))
]



controller/default.py:
def user():
return dict(form=auth())



view (for editing):

{{=form.custom.begin}}
   ...
   
Your Image: 
   {{=form.custom.widget.user_image}}
{{=form.custom.end}}

The problem is {{=form.custom.widget.user_image}} will render a dropdown of 
all image ids that are in the images table. Instead, I want a file upload, 
so that the user can change the image and it will be reflected in the 
database. How would I change the form to do this?

Also, since an image doesn't initially exist for a user, web2py will have 
to first do the insert into the image table, and then update/insert it to 
the auth_user table. The other problem is if a user decides to change his 
user picture, then web2py has to deal with deleting the old picture in the 
database *and *on the filesystem.

How can I handle these problems in web2py?


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


[web2py] Re: How to process a custom register form?

2013-09-07 Thread Apple Mason
Thanks, I think I understand now. The last snippet looks very clean as 
opposed to defining the various auth actions in the controller.

Also, I think I figured out why the form isn't saving. It's because there 
are errors on the form, but the errors are hidden. Right now I only display 
three fields: username, email, and password. But because auth_user requires 
first_name and last_name not be empty(Error: "
Cannot be empty")
, the submission actually fails since they are empty. And since there's no 
html code for the extraneous fields, the error never shows.

>From your first post you suggest:

def user():
if request.args(0) == 'register':
for field in [list, of, fields]:
db.auth_user[field].readable = db.auth_user[field].writable = 
False

return dict(form=auth())

But won't that set the db.auth_user[field] readable and writable to False 
every time a user visits the register page?

Is there any difference doing it this way inside db.py (using the 
'last_name' field) instead of in the controller:

db.auth_user['last_name'].readable = db.auth_user['last_name'].writable = 
False





On Friday, September 6, 2013 8:55:13 PM UTC-4, Anthony wrote:
>
> On Friday, September 6, 2013 7:51:54 PM UTC-4, Apple Mason wrote:
>
>> Oops, I do have form.custom.begin and form.custom.end. I had forgotten to 
>> type it here.
>>
>> I also wanted a custom view for the registration, login, and whatever 
>> else, so my understanding is that I can do this by using 
>> form=auth.register() and form=auth.login(). Then in their respective views, 
>> I can format the html whatever way I want with form.custom.begin and 
>> form.custom.end.
>>
>
> You can also create a single view and include logic like this:
>
> {{if request.args(0) == 'login':}}
> [code to show login form]
> {{elif request.args(0) == 'register':}}
> [code to show register form]
> {{else:}}
> {{=form  # use defaults for other forms}}
> {{pass}}
>
> Is form=auth.register() supposed to handle inserting the new user to the 
>> database? I've only dealt with handling it in the controller with 'if 
>> form.process().accepted', so looking at 'return(form=auth.register()) is a 
>> bit confusing.
>>
>
> Don't call form.process() with an Auth form -- the Auth method already 
> calls .process(), and calling it twice will lead to errors. Yes, 
> auth.register() does handle inserting the user into the database.
>
> Anthony
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: How to process a custom register form?

2013-09-06 Thread Apple Mason
Oops, I do have form.custom.begin and form.custom.end. I had forgotten to 
type it here.

I also wanted a custom view for the registration, login, and whatever else, 
so my understanding is that I can do this by using form=auth.register() and 
form=auth.login(). Then in their respective views, I can format the html 
whatever way I want with form.custom.begin and form.custom.end.

Is form=auth.register() supposed to handle inserting the new user to the 
database? I've only dealt with handling it in the controller with 'if 
form.process().accepted', so looking at 'return(form=auth.register()) is a 
bit confusing.


On Friday, September 6, 2013 5:38:15 PM UTC-4, Anthony wrote:
>
> Did you also include form.custom.begin and form.custom.end (you need the 
> latter, or the _formkey check will fail silently)? Anyway, if you just want 
> to exclude some fields from the register form, you can set the readable and 
> writable attributes to False within the user function:
>
> def user():
> if request.args(0) == 'register':
> for field in [list, of, fields]:
> db.auth_user[field].readable = db.auth_user[field].writable = 
> False
> return dict(form=auth())
>
>
> Anthony
>
> On Friday, September 6, 2013 5:17:23 PM UTC-4, Apple Mason wrote:
>>
>> The default register form has too many fields, so I created a 
>> slimmed-down custom one:
>>
>> register.html:
>>
>> 
>> Username: {{=form.custom.widget.username}}
>> Email: {{=form.custom.widget.email}}
>> Password: {{=form.custom.widget.password}}
>>
>> {{=form.custom.submit}}
>> 
>>
>> default.py:
>>
>> def register():
>>   return dict(form=auth.register())
>>
>> def login():
>>   return dict(form=auth.login())
>>
>> The default validation works if you submit an invalid input (ie, an 
>> invalid email will error on the form). But if the information is correct, 
>> the information doesn't get saved into the database, so the user is never 
>> created.
>>
>> I thought maybe doing something like:
>>
>> form = auth.register()
>> if form.process().accepted:
>> # Then what??
>>
>> But that seems incorrect because it looks like it'll process the form 
>> twice.
>>
>> What's the proper way of handling user actions on custom forms? ie, 
>> login, registration, request_reset_password...
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] How to process a custom register form?

2013-09-06 Thread Apple Mason
The default register form has too many fields, so I created a slimmed-down 
custom one:

register.html:


Username: {{=form.custom.widget.username}}
Email: {{=form.custom.widget.email}}
Password: {{=form.custom.widget.password}}

{{=form.custom.submit}}


default.py:

def register():
  return dict(form=auth.register())

def login():
  return dict(form=auth.login())

The default validation works if you submit an invalid input (ie, an invalid 
email will error on the form). But if the information is correct, the 
information doesn't get saved into the database, so the user is never 
created.

I thought maybe doing something like:

form = auth.register()
if form.process().accepted:
# Then what??

But that seems incorrect because it looks like it'll process the form twice.

What's the proper way of handling user actions on custom forms? ie, login, 
registration, request_reset_password...

-- 

--- 
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: Help with deploying on nginx

2013-08-29 Thread Apple Mason
There's a lot of lines but here's a good portion of it:



*** Operational MODE: no-workers ***
spawned uWSGI master process (pid: 10483)
*** starting uWSGI Emperor ***
*** has_emperor mode detected (fd: 6) ***
[uWSGI] parsing config file web2py.xml
*** Starting uWSGI 1.2.3-debian (64bit) on [Thu Aug 29 18:25:59 2013] ***
compiled with version: 4.7.2 on 07 November 2012 03:49:52
detected number of CPU cores: 8
current working directory: /etc/uwsgi
detected binary path: /usr/bin/uwsgi-core
setgid() to 33
setuid() to 33
limiting address space of processes...
your process address space limit is 536870912 bytes (512 MB)
your memory page size is 4096 bytes
 *** WARNING: you have enabled harakiri without post buffering. Slow upload 
could be rejected on post-unbuffered webservers ***
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to UNIX address /tmp/web2py.socket fd 3
your server socket listen backlog is limited to 100 connections
*** Operational MODE: preforking ***
mounting wsgihandler:application on /
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 10485)
spawned uWSGI worker 1 (pid: 10486, cores: 1)
set cpu affinity for worker 1 to 0
spawned uWSGI worker 2 (pid: 10487, cores: 1)
spawned uWSGI worker 1 (pid: 10486, cores: 1)
set cpu affinity for worker 1 to 0
spawned uWSGI worker 2 (pid: 10487, cores: 1)
set cpu affinity for worker 2 to 1spawned uWSGI worker 3 (pid: 10488, cores: 
1)
set cpu affinity for worker 3 to 2
spawned uWSGI worker 4 (pid: 10489, cores: 1)
*** Stats server enabled on /tmp/stats.socket fd: 16 ***
set cpu affinity for worker 4 to 3
-- unavailable modifier requested: 0 --
announcing my loyalty to the Emperor...
*** vassal web2py.xml is now loyal ***
-- unavailable modifier requested: 0 --
announcing my loyalty to the Emperor...
*** vassal web2py.xml is now loyal ***
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
announcing my loyalty to the Emperor...
*** vassal web2py.xml is now loyal ***
-- unavailable modifier requested: 0 --
announcing my loyalty to the Emperor...
*** vassal web2py.xml is now loyal ***
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --





On Thursday, August 29, 2013 3:10:20 PM UTC-4, Niphlod wrote:
>
> what does uwsgi log show ?
>
> On Thursday, August 29, 2013 8:18:02 PM UTC+2, Apple Mason wrote:
>>
>> I keep getting 502 Bad Gateway, and I'm not sure why. I followed the 
>> Nginx deployment recipe on the website, with the following changes:
>>
>> /etc/uwsgi/web2py.xml: Used /var/www-data/web2py/ instead of 
>> /home/www-data/web2py/
>>
>> nginx conf: server_name is my server ip (I don't have a domain name) 
>> instead of $hostname. I also changed the location to /web2py instead of 
>> root.
>>
>> Here is my nginx conf:
>>
>> server {
>> listen 443 default_server ssl;
>> server_name xxx.xxx.xxx.xxx;
>> ssl_certificate /etc/nginx/ssl/server.crt;
>> ssl_certificate_key /etc/nginx/ssl/server.key;
>> ssl_prefer_server_ciphers on;
>> ssl_session_cache shared:SSL:10m;
>> ssl_session_timeout 10m;
>> ssl_ciphers ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-
>> AES256-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA;
>> ssl_protocols SSLv3 TLSv1;
>> keepalive_timeout70;
>> location /web2py {
>> #uwsgi_pass  127.0.0.1:9001;
>> uwsgi_pass  unix:///tmp/web2py.socket;
>> include uwsgi_params;
>> uwsgi_param UWSGI_SCHEME $scheme;
>> uwsgi_param SERVER_SOFTWAREnginx/$nginx_version;
>> }
>> }
>>
>>
>>
>> I omitted http since I only want to test over https for now.
>>
>> Restarted both uwsgi and nginx in that order. uwsgi seems to find web2py 
>> okay in their logs:
>>
>> announcing my loyalty to the Emperor...
>> *** vass

[web2py] Help with deploying on nginx

2013-08-29 Thread Apple Mason
I keep getting 502 Bad Gateway, and I'm not sure why. I followed the Nginx 
deployment recipe on the website, with the following changes:

/etc/uwsgi/web2py.xml: Used /var/www-data/web2py/ instead of 
/home/www-data/web2py/

nginx conf: server_name is my server ip (I don't have a domain name) 
instead of $hostname. I also changed the location to /web2py instead of 
root.

Here is my nginx conf:

server {
listen 443 default_server ssl;
server_name xxx.xxx.xxx.xxx;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_ciphers ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES256-
SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA;
ssl_protocols SSLv3 TLSv1;
keepalive_timeout70;
location /web2py {
#uwsgi_pass  127.0.0.1:9001;
uwsgi_pass  unix:///tmp/web2py.socket;
include uwsgi_params;
uwsgi_param UWSGI_SCHEME $scheme;
uwsgi_param SERVER_SOFTWAREnginx/$nginx_version;
}
}



I omitted http since I only want to test over https for now.

Restarted both uwsgi and nginx in that order. uwsgi seems to find web2py 
okay in their logs:

announcing my loyalty to the Emperor...
*** vassal web2py.xml is now loyal ***


When I access "https:///web2py", I get the 502 error.

Nginx error.log says:

2013/08/29 18:10:08 [error] 9793#0: *4 upstream prematurely closed 
connection while reading response header from upstream, client: 
xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /web2py HTTP/1.1", 
upstream: "uwsgi://unix:///tmp/web2py.socket:", host: "xxx.xxx.xxx.xxx.

I'm running ubuntu 13.04 server, if that's any use.


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: How to query many to many with three fields?

2013-08-27 Thread Apple Mason
Yup, that did it. Many thanks, Alex!

On Tuesday, August 27, 2013 5:34:03 PM UTC-4, Alex wrote:
>
> my mistake, the alias should be for table location.
>
> location_one = db.location.with_alias('location_one')
> location_two = db.location.with_alias('location_two')
>
>
> I hope this works.
>
> Am Dienstag, 27. August 2013 21:51:56 UTC+2 schrieb Apple Mason:
>>
>> Hey Alex, 
>>
>> Thanks for the suggestion. The problem with the query is that 
>> 'location_one.geom.st_equals(point_x_y)' won't work. That's because the 
>> table db.item_location doesn't have a field called 'geom'. This is the 
>> error:
>>
>> AttributeError: 'Table' object has no attribute 'geom'
>>
>>
>> Is there a way to implicitly reference the fields in another table so 
>> that it will work?
>>
>> On Tuesday, August 27, 2013 3:15:10 PM UTC-4, Alex wrote:
>>>
>>> try something like this:
>>>
>>>
>>> location_one = db.item_location.with_alias('location_one')
>>> location_two = db.item_location.with_alias('location_two')
>>> rows = db((db.item_location.item == db.item.id) & (db.item.id != itemid) 
>>> & (db.item_location.location_one == location_one.id) & (db.item_location
>>> .location_two == location_two.id) &
>>>  (location_one.geom.st_equals(point_x_y)) & (location_two.geom.
>>> st_equals(point_n_m))).select(db.item.ALL)
>>>
>>> Alex
>>>
>>> Am Dienstag, 27. August 2013 19:43:08 UTC+2 schrieb Apple Mason:
>>>>
>>>> I have this many to many relationship example:
>>>>
>>>> db.define_table('location',
>>>> Field('geom', 'geometry()'))
>>>>
>>>> db.define_table('item',
>>>> Field('name'))
>>>>
>>>> db.define_table('item_location',
>>>> Field('item', db.item),
>>>> Field('location_one', db.location),
>>>> Field('location_two', db.location))
>>>>
>>>>
>>>>
>>>> The goal is to find all items that are NOT the given item.id, but 
>>>> matches locations.
>>>>  An example query would be:
>>>>
>>>> Given: item.id==1 and two points POINT(x,y) and POINT(n,m), 
>>>> Result: "get all items that are not item.id==1, but has 
>>>> location_one==POINT(x,y) and location_two==POINT(n,m)"
>>>>
>>>> I am able to get it matching one of the points, but not the other with 
>>>> this:
>>>>
>>>>
>>>> point_x_y = "POINT(1,2)"
>>>> point_n_m = "POINT(3,4)"
>>>> itemid = 1
>>>>
>>>> t = db( (db.item.id==db.item_location.item) &  
>>>>( (db.location.id==db.item_location.location_one) & (db.
>>>> location.geom.st_equals(point_x_y
>>>>
>>>> result = t( db.item.id != itemid ).select()
>>>>
>>>>
>>>> This will successfully match all items that do not have an id=1, and 
>>>> has location_one as point_x_y.
>>>>
>>>> The problem is I do not know how to match location_two with point_n_m. 
>>>> I tried this, but it doesn't make sense (it also returns in nothing):
>>>>
>>>> t = db( (db.item.id==db.item_location.item) &  
>>>>( (db.location.id==db.item_location.location_one) & (db.
>>>> location.geom.st_equals(point_x_y)))
>>>>( (db.location.id==db.item_location.location_two) & (db.
>>>> location.geom.st_equals(point_n_m
>>>>
>>>> Any help would be great!
>>>>
>>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: How to query many to many with three fields?

2013-08-27 Thread Apple Mason
Hey Alex, 

Thanks for the suggestion. The problem with the query is that 
'location_one.geom.st_equals(point_x_y)' won't work. That's because the 
table db.item_location doesn't have a field called 'geom'. This is the 
error:

AttributeError: 'Table' object has no attribute 'geom'


Is there a way to implicitly reference the fields in another table so that 
it will work?

On Tuesday, August 27, 2013 3:15:10 PM UTC-4, Alex wrote:
>
> try something like this:
>
>
> location_one = db.item_location.with_alias('location_one')
> location_two = db.item_location.with_alias('location_two')
> rows = db((db.item_location.item == db.item.id) & (db.item.id != itemid) & 
> (db.item_location.location_one == location_one.id) & 
> (db.item_location.location_two 
> == location_two.id) &
>  (location_one.geom.st_equals(point_x_y)) & (location_two.geom.
> st_equals(point_n_m))).select(db.item.ALL)
>
> Alex
>
> Am Dienstag, 27. August 2013 19:43:08 UTC+2 schrieb Apple Mason:
>>
>> I have this many to many relationship example:
>>
>> db.define_table('location',
>> Field('geom', 'geometry()'))
>>
>> db.define_table('item',
>> Field('name'))
>>
>> db.define_table('item_location',
>> Field('item', db.item),
>> Field('location_one', db.location),
>> Field('location_two', db.location))
>>
>>
>>
>> The goal is to find all items that are NOT the given item.id, but 
>> matches locations.
>>  An example query would be:
>>
>> Given: item.id==1 and two points POINT(x,y) and POINT(n,m), 
>> Result: "get all items that are not item.id==1, but has 
>> location_one==POINT(x,y) and location_two==POINT(n,m)"
>>
>> I am able to get it matching one of the points, but not the other with 
>> this:
>>
>>
>> point_x_y = "POINT(1,2)"
>> point_n_m = "POINT(3,4)"
>> itemid = 1
>>
>> t = db( (db.item.id==db.item_location.item) &  
>>( (db.location.id==db.item_location.location_one) & (db.
>> location.geom.st_equals(point_x_y
>>
>> result = t( db.item.id != itemid ).select()
>>
>>
>> This will successfully match all items that do not have an id=1, and has 
>> location_one as point_x_y.
>>
>> The problem is I do not know how to match location_two with point_n_m. I 
>> tried this, but it doesn't make sense (it also returns in nothing):
>>
>> t = db( (db.item.id==db.item_location.item) &  
>>( (db.location.id==db.item_location.location_one) & (db.
>> location.geom.st_equals(point_x_y)))
>>( (db.location.id==db.item_location.location_two) & (db.
>> location.geom.st_equals(point_n_m
>>
>> Any help would be great!
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] How to query many to many with three fields?

2013-08-27 Thread Apple Mason
I have this many to many relationship example:

db.define_table('location',
Field('geom', 'geometry()'))

db.define_table('item',
Field('name'))

db.define_table('item_location',
Field('item', db.item),
Field('location_one', db.location),
Field('location_two', db.location))



The goal is to find all items that are NOT the given item.id, but matches 
locations.
 An example query would be:

Given: item.id==1 and two points POINT(x,y) and POINT(n,m), 
Result: "get all items that are not item.id==1, but has 
location_one==POINT(x,y) and location_two==POINT(n,m)"

I am able to get it matching one of the points, but not the other with this:


point_x_y = "POINT(1,2)"
point_n_m = "POINT(3,4)"
itemid = 1

t = db( (db.item.id==db.item_location.item) &  
   ( (db.location.id==db.item_location.location_one) & (db.location.
geom.st_equals(point_x_y

result = t( db.item.id != itemid ).select()


This will successfully match all items that do not have an id=1, and has 
location_one as point_x_y.

The problem is I do not know how to match location_two with point_n_m. I 
tried this, but it doesn't make sense (it also returns in nothing):

t = db( (db.item.id==db.item_location.item) &  
   ( (db.location.id==db.item_location.location_one) & (db.location.
geom.st_equals(point_x_y)))
   ( (db.location.id==db.item_location.location_two) & (db.location.
geom.st_equals(point_n_m

Any help would be great!

-- 

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