[web2py] Import CSV in appadmin to update database

2012-07-17 Thread Mark Li
Is there a way I can add an import excel (saved as csv) option in the 
appadmin that can update multiple data tables (one of them an 
intermediate/relational table)? 

for example the excel file (saved as csv):

*ID   |  title  |category|*
1 | one   |   cat1, cat2   |
2 | two|   cat2, cat3  |
3 | three |cat2   |

Uploading this would update table1 with the ID and title, and also update 
the intermediate/relational table with the relation between the title and 
category (as described here 
http://web2py.com/books/default/chapter/29/6#Many-to-many)

I'm relatively new to web2py and could not find anything in the book, while 
other questions relating to importing CSV files already had a strong 
understanding of what to do. I'd appreciate any info that could set me on 
the right path, thanks!

-- 





[web2py] Import CSV in appadmin to update database

2012-07-17 Thread Mark Li
I would like to know how I would add an import csv (from excel) option to 
appadmin that would update multiple database tables (one of them a 
relational/intermediate table).

For example, the CSV file would look like this (in excel)

ID |  posttitle |category  |
1   |  title1 | cat1, cat2|
2   |  title2 | cat2, cat3|
3   |  title3 | cat1, cat3|

Uploading this would update table 1 with the ID and posttitle, and also the 
intermediate/relational table with the relationship between posttitle and 
category (as described here: 
http://web2py.com/books/default/chapter/29/6#Many-to-many).

I'm new to web2py and couldn't find anything in the book, also the 
questions previously asked already had a good grasp of what to do add a CSV 
upload feature. I'd appreciate any help as I'm not really sure where to 
start with this, thanks!

-- 





[web2py] Re: Import CSV in appadmin to update database

2012-07-17 Thread Mark Li
I am also unable to import a CSV file using the list:reference format 
(exporting then importing with no changes still doesn't work). I get the 
error message :

Unable to parse CSV file

'nonetype'object has no attribute '__getitem__'






On Tuesday, July 17, 2012 2:44:58 PM UTC-7, Mark Li wrote:
>
> I would like to know how I would add an import csv (from excel) option to 
> appadmin that would update multiple database tables (one of them a 
> relational/intermediate table).
>
> For example, the CSV file would look like this (in excel)
>
> ID |  posttitle |category  |
> 1   |  title1 | cat1, cat2|
> 2   |  title2 | cat2, cat3|
> 3   |  title3 | cat1, cat3|
>
> Uploading this would update table 1 with the ID and posttitle, and also 
> the intermediate/relational table with the relationship between posttitle 
> and category (as described here: 
> http://web2py.com/books/default/chapter/29/6#Many-to-many).
>
> I'm new to web2py and couldn't find anything in the book, also the 
> questions previously asked already had a good grasp of what to do add a CSV 
> upload feature. I'd appreciate any help as I'm not really sure where to 
> start with this, thanks!
>

-- 





[web2py] Unit Testing Database Best Practices

2012-07-23 Thread Mark Li
I'm fairly new to test-driven development and have decided it is the best 
way to go for my new webapp. While functional tests with selenium seem to 
be more straightforward (as far as what the tests want to accomplish), I'm 
lost on what unit tests for the database should test for.

For example, if I have a database table with columns id, 'dogowner', and 
'dogname', and have a controller returning a dict with 'dogowners', what 
should I be testing in the unit tests for the database and controller? 

The database table will be fixed with a limited number of 'dogowner' 
entries, about 10, so should I be testing whether the database has 10 
entries, and if the len of the dict returned by the controller is 10? This 
datatable may not be fixed in the future, so what functionality of the 
database would I be testing for?



I'm following http://www.web2py.com/AlterEgo/default/show/260 , but while 
that page explains HOW to go about unit testing, it doesn't explain what I 
should be testing for. Anyone experienced with TDD in web2py want to point 
me in the right direction? Thanks in advance!

-- 





Re: [web2py] Unit Testing Database Best Practices

2012-07-23 Thread Mark Li
Thanks Richard, for now I am going to create a special database table that 
will follow the structure of the actual data tables, but with a fixed data 
set like you suggested (controls for count very well).

I'm still interested in any real examples people use for unit testing 
databases and controller functions, I'm sure i'm glossing over something!

On Monday, July 23, 2012 7:40:51 AM UTC-7, Richard wrote:
>
> I am interesting in what will come out of this thread...
>
> But, to me I think your last question on fact that database will have 
> undertermined set of data mean that you maybe not validate your app base on 
> the entries of the database but on a testing database with a set of known 
> data, that you can even charge on need for the test. Also, you will just 
> test the limit with data that will for example help to demonstrate that a 
> field type is appropriately defined to get all type of data you intend to 
> put in in. Count, if variable get creates, etc., is more in the basic thing 
> you can always check for every function...
>
> I am also pretty new to unit test in general and have most the same 
> questions.
>
> Cheers!
>
> Richard
>
>
> On Sun, Jul 22, 2012 at 9:41 PM, Mark Li  wrote:
>
>> I'm fairly new to test-driven development and have decided it is the best 
>> way to go for my new webapp. While functional tests with selenium seem to 
>> be more straightforward (as far as what the tests want to accomplish), I'm 
>> lost on what unit tests for the database should test for.
>>
>> For example, if I have a database table with columns id, 'dogowner', and 
>> 'dogname', and have a controller returning a dict with 'dogowners', what 
>> should I be testing in the unit tests for the database and controller? 
>>
>> The database table will be fixed with a limited number of 'dogowner' 
>> entries, about 10, so should I be testing whether the database has 10 
>> entries, and if the len of the dict returned by the controller is 10? This 
>> datatable may not be fixed in the future, so what functionality of the 
>> database would I be testing for?
>>
>>
>>
>> I'm following http://www.web2py.com/AlterEgo/default/show/260 , but 
>> while that page explains HOW to go about unit testing, it doesn't explain 
>> what I should be testing for. Anyone experienced with TDD in web2py want to 
>> point me in the right direction? Thanks in advance!
>>
>> -- 
>>  
>>  
>>  
>>
>
>

-- 





[web2py] Empty Database value is not None, but an empty string

2012-07-23 Thread Mark Li
I have a table defined in the following manner:

db.define_table('songinfo',
Field('songtitle'),
Field('artist'))

When I add an empty entry, or upload a CSV with empty values, I can only 
access those values with a database call like

songs = db(db.songinfo.artist=="").select()

as opposed to db(db.songinfo.artist==None).select()


The web2py book states that fields default=None, but I'm getting an empty 
string. Is there an appropriate way to have None instead of an empty string 
in the database?


-- 





[web2py] Re: Empty Database value is not None, but an empty string

2012-07-23 Thread Mark Li
Unfortunately the lambda method didn't work, Anthony. Any other ideas for 
having a None default for empty entries?


On a side note, if the 'integer' field type is used, then a blank entry 
results in a None. Don't know if that helps but it's something I've noticed.

On Monday, July 23, 2012 2:07:51 PM UTC-7, Anthony wrote:
>
> To enter a value of None, this might work:
>
> default=lambda: None
>
> Anthony
>
> On Monday, July 23, 2012 5:04:44 PM UTC-4, Anthony wrote:
>>
>> default=None means that no default is specified, not that a default value 
>> of None will be inserted.
>>
>> Anthony
>>
>> On Monday, July 23, 2012 5:02:33 PM UTC-4, Mark Li wrote:
>>>
>>> I have a table defined in the following manner:
>>>
>>> db.define_table('songinfo',
>>> Field('songtitle'),
>>> Field('artist'))
>>>
>>> When I add an empty entry, or upload a CSV with empty values, I can only 
>>> access those values with a database call like
>>>
>>> songs = db(db.songinfo.artist=="").select()
>>>
>>> as opposed to db(db.songinfo.artist==None).select()
>>>
>>>
>>> The web2py book states that fields default=None, but I'm getting an 
>>> empty string. Is there an appropriate way to have None instead of an empty 
>>> string in the database?
>>>
>>>
>>>

-- 





Re: [web2py] Re: Empty Database value is not None, but an empty string

2012-07-23 Thread Mark Li
Aren't those the default values for a Field Contructor? I tried explicitly 
adding "notnull=False" and "required=False", and didn't set the default 
property, but empty values still come out as an empty string instead of 
None.

On Monday, July 23, 2012 2:48:56 PM UTC-7, viniciusban wrote:
>
> As far as I know, let "notnull=False" and "required=False" for your 
> fields and don't set "default" property. 
>
>
>
> On 07/23/2012 06:32 PM, Mark Li wrote: 
> > Unfortunately the lambda method didn't work, Anthony. Any other ideas 
> > for having a None default for empty entries? 
> > 
> > 
> > On a side note, if the 'integer' field type is used, then a blank entry 
> > results in a None. Don't know if that helps but it's something I've 
> noticed. 
> > 
> > On Monday, July 23, 2012 2:07:51 PM UTC-7, Anthony wrote: 
> > 
> > To enter a value of None, this might work: 
> > 
> > | 
> > default=lambda:None 
> > | 
> > 
> > Anthony 
> > 
> > On Monday, July 23, 2012 5:04:44 PM UTC-4, Anthony wrote: 
> > 
> > default=None means that no default is specified, not that a 
> > default value of None will be inserted. 
> > 
> > Anthony 
> > 
> > On Monday, July 23, 2012 5:02:33 PM UTC-4, Mark Li wrote: 
> > 
> > I have a table defined in the following manner: 
> > 
> > db.define_table('songinfo', 
> > Field('songtitle'), 
> > Field('artist')) 
> > 
> > When I add an empty entry, or upload a CSV with empty 
> > values, I can only access those values with a database call 
> like 
> > 
> > songs = db(db.songinfo.artist=="").select() 
> > 
> > as opposed to db(db.songinfo.artist==None).select() 
> > 
> > 
> > The web2py book states that fields default=None, but I'm 
> > getting an empty string. Is there an appropriate way to have 
> > None instead of an empty string in the database? 
> > 
> > 
> > -- 
> > 
> > 
> > 
>
>

-- 





[web2py] Select Distinct for more than 1 distinct value

2012-07-23 Thread Mark Li
I have a database setup with id and 'dogname.' I would like to retrieve 
distinct values of dogname, but allow for 2 of each dogname. So instead of 
limiting it to one distinct value, there could be 2 identical dognames that 
are retrieved, but no more than that.

Is there a way to set this kind of limit for distinct?

-- 





[web2py] Re: Select Distinct for more than 1 distinct value

2012-07-23 Thread Mark Li
I'll be looping over them for now, is there anyway to use a query or 
select() to return a set with no more than 2 of each name?

On Monday, July 23, 2012 3:43:38 PM UTC-7, villas wrote:
>
> I can't see how distinct would help there because it only returns unique 
> rows.
>
> I would say that the main question is how much data you have.  I mean,  it 
> is probably easier to grab all the data and then discard (or simply loop 
> over) the data you do not need.  However,  if you have a huge number of 
> records that may not be practical.
>
>
> On Monday, July 23, 2012 11:15:14 PM UTC+1, Mark Li wrote:
>>
>> I have a database setup with id and 'dogname.' I would like to retrieve 
>> distinct values of dogname, but allow for 2 of each dogname. So instead of 
>> limiting it to one distinct value, there could be 2 identical dognames that 
>> are retrieved, but no more than that.
>>
>> Is there a way to set this kind of limit for distinct?
>>
>

-- 





Re: [web2py] Unit Testing Database Best Practices

2012-07-23 Thread Mark Li
Regarding Martin's response for anyone who is learning the ropes like me, I 
removed the execfile() line and placed my unit_test.py script in the module 
folder.

On Monday, July 23, 2012 12:13:07 PM UTC-7, Martin.Mulone wrote:
>
> I'm following http://www.web2py.com/AlterEgo/default/show/260 
>>
>
> that guide is too old, have execfile() :S. Search in the group on how to 
> use modules in your app.
>
> 2012/7/22 Mark Li 
>
>> I'm fairly new to test-driven development and have decided it is the best 
>> way to go for my new webapp. While functional tests with selenium seem to 
>> be more straightforward (as far as what the tests want to accomplish), I'm 
>> lost on what unit tests for the database should test for.
>>
>> For example, if I have a database table with columns id, 'dogowner', and 
>> 'dogname', and have a controller returning a dict with 'dogowners', what 
>> should I be testing in the unit tests for the database and controller? 
>>
>> The database table will be fixed with a limited number of 'dogowner' 
>> entries, about 10, so should I be testing whether the database has 10 
>> entries, and if the len of the dict returned by the controller is 10? This 
>> datatable may not be fixed in the future, so what functionality of the 
>> database would I be testing for?
>>
>>
>>
>> I'm following http://www.web2py.com/AlterEgo/default/show/260 , but 
>> while that page explains HOW to go about unit testing, it doesn't explain 
>> what I should be testing for. Anyone experienced with TDD in web2py want to 
>> point me in the right direction? Thanks in advance!
>>
>> -- 
>>  
>>  
>>  
>>
>
>
>
> -- 
>  http://www.tecnodoc.com.ar
>
>

-- 





Re: [web2py] Re: Empty Database value is not None, but an empty string

2012-07-24 Thread Mark Li
Anthony, I tried

db.mytable.import_from_csv_file([file object], null='')

from the web2py shell, but it gave me an error:

OperationalError: near ")": syntax error


In fact, trying to import from csv using the book's method does not work at 
all, although exporting works fine.


Viniciusban, I'm inserting data through the database administation 
interface (filling out the form). I've also tried importing the CSV file 
through the administrative interface as well, where all blank spaces in the 
csv some out to empty strings (unless the field type is 'integer').



On Monday, July 23, 2012 10:47:24 PM UTC-7, viniciusban wrote:
>
> Yes, they are default settings. 
>
> It's quite strange you get empty strings instead null (None, in Python). 
>
> How are you inserting data into db? Are you using a SQLFORM or 
> my_table.validate_and_insert() or simply mytable.insert()? 
>
> Do you get same results (blank values) inserting it from web2py shell 
> using simply mytable.insert()? 
>
> -- 
> Vinicius Assef 
>
>
> > On Monday, July 23, 2012 5:58:19 PM UTC-4, Mark Li wrote: 
> > 
> > Aren't those the default values for a Field Contructor? I tried 
> > explicitly adding "notnull=False" and "required=False", and didn't 
> > set the default property, but empty values still come out as an 
> > empty string instead of None. 
> > 
> > On Monday, July 23, 2012 2:48:56 PM UTC-7, viniciusban wrote: 
> > 
> >     As far as I know, let "notnull=False" and "required=False" for 
> your 
> > fields and don't set "default" property. 
> > 
> > 
> > 
> > On 07/23/2012 06:32 PM, Mark Li wrote: 
> > > Unfortunately the lambda method didn't work, Anthony. Any 
> other ideas 
> > > for having a None default for empty entries? 
> > > 
> > > 
> > > On a side note, if the 'integer' field type is used, then a 
> blank entry 
> > > results in a None. Don't know if that helps but it's something 
> I've noticed. 
> > > 
> > > On Monday, July 23, 2012 2:07:51 PM UTC-7, Anthony wrote: 
> > > 
> > > To enter a value of None, this might work: 
> > > 
> > > | 
> > > default=lambda:None 
> > > | 
> >     > 
> > > Anthony 
> > > 
> > > On Monday, July 23, 2012 5:04:44 PM UTC-4, Anthony wrote: 
> > > 
> > > default=None means that no default is specified, not 
> that a 
> > > default value of None will be inserted. 
> > > 
> > > Anthony 
> > > 
> > > On Monday, July 23, 2012 5:02:33 PM UTC-4, Mark Li 
> wrote: 
> > > 
> > > I have a table defined in the following manner: 
> > > 
> > > db.define_table('songinfo', 
> > > Field('songtitle'), 
> > > Field('artist')) 
> > > 
> > > When I add an empty entry, or upload a CSV with 
> empty 
> > > values, I can only access those values with a 
> database call like 
> > > 
> > > songs = db(db.songinfo.artist=="").select() 
> > > 
> > > as opposed to 
> db(db.songinfo.artist==None).select() 
> > > 
> > > 
> > > The web2py book states that fields default=None, 
> but I'm 
> > > getting an empty string. Is there an appropriate 
> way to have 
> > > None instead of an empty string in the database? 
> > > 
> > > 
> > > -- 
> > > 
> > > 
> > > 
> > 
> > -- 
> > 
> > 
> > 
>
>

-- 





Re: [web2py] Re: Empty Database value is not None, but an empty string

2012-07-25 Thread Mark Li
I'm using SQLite3 on Windows (running from source). I didn't install 
anything extra, just been using SQLite that came with web2py

I attempted 

 
try: 
   db.testtable.import_from_csv_file('example.csv', null='')
 
except: 
   print db._lastsql 
   db.rollback()




However, print db._lastsql doesn't print anything.

I made a new app and the problem still exists (can't import CSV from shell 
and importing from database administration still gives empty string instead 
of None).


Here is my db.py code:


db = DAL('sqlite://storage.sqlite')
 
db.define_table('testtable',
Field('column1'),
Field('column2'),
Field('column3','string'))

>From the web2py shell, I use:

db.testtable.import_from_csv_file('example.csv', null='')

which gives me the following error

Traceback (most recent call last):
  File "c:\Users\Mark\Documents\dubliners\web2py\gluon\contrib\shell.py",line 
233, in run
exec compiled in statement_module.__dict__
  File "", line 1, in 
  File "c:\Users\Mark\Documents\dubliners\web2py\gluon\dal.py", line 6955, 
in import_from_csv_file
new_id = self.insert(**dict(items))
  File "c:\Users\Mark\Documents\dubliners\web2py\gluon\dal.py", line 6829, 
in insert
return self._db._adapter.insert(self,self._listify(fields))
  File "c:\Users\Mark\Documents\dubliners\web2py\gluon\dal.py", line 928, 
ininsert
raise e
OperationalError: near ")": syntax error

The 'example.csv' file is located in my web2py folder.





On Wednesday, July 25, 2012 6:23:56 AM UTC-7, Anthony wrote:
>
> Can you attach a sample CSV file that fails, and show your table model 
> code as well as any code used to do the import?
>
> Anthony
>
> On Tuesday, July 24, 2012 11:31:27 PM UTC-4, Mark Li wrote:
>>
>> Anthony, I tried
>>
>> db.mytable.import_from_csv_file([file object], null='')
>>
>> from the web2py shell, but it gave me an error:
>>
>> OperationalError: near ")": syntax error
>>
>>
>> In fact, trying to import from csv using the book's method does not work 
>> at all, although exporting works fine.
>>
>>
>> Viniciusban, I'm inserting data through the database administation 
>> interface (filling out the form). I've also tried importing the CSV file 
>> through the administrative interface as well, where all blank spaces in the 
>> csv some out to empty strings (unless the field type is 'integer').
>>
>>
>>
>> On Monday, July 23, 2012 10:47:24 PM UTC-7, viniciusban wrote:
>>>
>>> Yes, they are default settings. 
>>>
>>> It's quite strange you get empty strings instead null (None, in Python). 
>>>
>>> How are you inserting data into db? Are you using a SQLFORM or 
>>> my_table.validate_and_insert() or simply mytable.insert()? 
>>>
>>> Do you get same results (blank values) inserting it from web2py shell 
>>> using simply mytable.insert()? 
>>>
>>> -- 
>>> Vinicius Assef 
>>>
>>>
>>> > On Monday, July 23, 2012 5:58:19 PM UTC-4, Mark Li wrote: 
>>> > 
>>> > Aren't those the default values for a Field Contructor? I tried 
>>> > explicitly adding "notnull=False" and "required=False", and didn't 
>>> > set the default property, but empty values still come out as an 
>>> > empty string instead of None. 
>>> > 
>>> > On Monday, July 23, 2012 2:48:56 PM UTC-7, viniciusban wrote: 
>>> > 
>>> > As far as I know, let "notnull=False" and "required=False" for 
>>> your 
>>> > fields and don't set "default" property. 
>>> > 
>>> > 
>>> > 
>>> > On 07/23/2012 06:32 PM, Mark Li wrote: 
>>> > > Unfortunately the lambda method didn't work, Anthony. Any 
>>> other ideas 
>>> > > for having a None default for empty entries? 
>>> > > 
>>> > > 
>>> > > On a side note, if the 'integer' field type is used, then a 
>>> blank entry 
>>> > > results in a None. Don't know if that helps but it's 
>>> something I've noticed. 
>>> > > 
>>> > > On Monday, July 23, 2012 2:07:51 PM UTC-7, Anthony wrote: 
>>> > > 
>>> > > 

Re: [web2py] Re: Empty Database value is not None, but an empty string

2012-07-25 Thread Mark Li
Massimo I tried your example and it worked! I was using the web2py web 
shell from the admin interface before, but using the interactive console 
shell through cygwin worked. 

Thanks to you, Anthony, and viniciusban for helping out. 


On Wednesday, July 25, 2012 2:51:01 PM UTC-7, Massimo Di Pierro wrote:
>
> I cannot reproduce the problem:
>
> $ python web2py.py -S welcome -N
> >>> db=DAL()
> >>> db.define_table('testtable',
> ... Field('column1'),
> ... Field('column2'),
> ... Field('column3','string'))
> >>> 
> db.testtable.import_from_csv_file(open('/Users/massimodipierro/Downloads/example.csv'),null='')
> >>> print db(db.testtable).select()
> testtable.id,testtable.column1,testtable.column2,testtable.column3
> 1,record1,,
> 2,record2,text,text
> 3,record3,text,
>
>
> I tested with trunk. Can you try the same example from the shell, as I did?
>
> On Wednesday, 25 July 2012 16:27:44 UTC-5, Mark Li wrote:
>>
>> I'm using SQLite3 on Windows (running from source). I didn't install 
>> anything extra, just been using SQLite that came with web2py
>>
>> I attempted 
>>
>>  
>> try: 
>>db.testtable.import_from_csv_file('example.csv', null='')
>>  
>> except: 
>>print db._lastsql 
>>db.rollback()
>>
>>
>>
>>
>> However, print db._lastsql doesn't print anything.
>>
>> I made a new app and the problem still exists (can't import CSV from 
>> shell and importing from database administration still gives empty string 
>> instead of None).
>>
>>
>> Here is my db.py code:
>>
>>
>> db = DAL('sqlite://storage.sqlite')
>>  
>> db.define_table('testtable',
>> Field('column1'),
>> Field('column2'),
>> Field('column3','string'))
>>
>> From the web2py shell, I use:
>>
>> db.testtable.import_from_csv_file('example.csv', null='')
>>
>> which gives me the following error
>>
>> Traceback (most recent call last):
>>   File 
>> "c:\Users\Mark\Documents\dubliners\web2py\gluon\contrib\shell.py",line 
>> 233, in run
>> exec compiled in statement_module.__dict__
>>   File "", line 1, in 
>>   File "c:\Users\Mark\Documents\dubliners\web2py\gluon\dal.py", line 6955
>> , in import_from_csv_file
>> new_id = self.insert(**dict(items))
>>   File "c:\Users\Mark\Documents\dubliners\web2py\gluon\dal.py", line 6829
>> , in insert
>> return self._db._adapter.insert(self,self._listify(fields))
>>   File "c:\Users\Mark\Documents\dubliners\web2py\gluon\dal.py", line 928, 
>> in insert
>> raise e
>> OperationalError: near ")": syntax error
>>
>> The 'example.csv' file is located in my web2py folder.
>>
>>
>>
>>
>>
>> On Wednesday, July 25, 2012 6:23:56 AM UTC-7, Anthony wrote:
>>>
>>> Can you attach a sample CSV file that fails, and show your table model 
>>> code as well as any code used to do the import?
>>>
>>> Anthony
>>>
>>> On Tuesday, July 24, 2012 11:31:27 PM UTC-4, Mark Li wrote:
>>>>
>>>> Anthony, I tried
>>>>
>>>> db.mytable.import_from_csv_file([file object], null='')
>>>>
>>>> from the web2py shell, but it gave me an error:
>>>>
>>>> OperationalError: near ")": syntax error
>>>>
>>>>
>>>> In fact, trying to import from csv using the book's method does not 
>>>> work at all, although exporting works fine.
>>>>
>>>>
>>>> Viniciusban, I'm inserting data through the database administation 
>>>> interface (filling out the form). I've also tried importing the CSV file 
>>>> through the administrative interface as well, where all blank spaces in 
>>>> the 
>>>> csv some out to empty strings (unless the field type is 'integer').
>>>>
>>>>
>>>>
>>>> On Monday, July 23, 2012 10:47:24 PM UTC-7, viniciusban wrote:
>>>>>
>>>>> Yes, they are default settings. 
>>>>>
>>>>> It's quite strange you get empty strings instead null (None, in 
>>>>> Python). 
>>>>>
>>>>> How are you inserting data into db? Are you 

Re: [web2py] Re: Import CSV in appadmin to update database

2012-07-25 Thread Mark Li
My question title is misleading, what I want to accomplish is using a CSV 
file, formatted in the manner below, to update both the 'owner' data table 
and the 'owner-food' relational table. Assuming here I have 3 tables, 
'person', 'fav food', and 'owner-food' which is a relational table (many to 
many).


person.ID |  person.name | fav food 
|
1  |  name1   | 
food1, food2  |
2  |  name2   | 
food2, food3  |
3  |  name3   | 
food1, food3  |


I'm unfamiliar with the use of UUID, as it's not really documented in the 
book. If I was to define a table using UUID, would it look something like 
this:

db.define_table('table1',
Field('title'),
Field('age'),
Field('uuid'))



On Wednesday, July 18, 2012 3:35:22 AM UTC-7, Johann Spies wrote:
>
> On 18 July 2012 03:41, Mark Li  wrote:
>
>> I am also unable to import a CSV file using the list:reference format 
>> (exporting then importing with no changes still doesn't work). I get the 
>> error message :
>>
>> Unable to parse CSV file
>>
>> 'nonetype'object has no attribute '__getitem__'
>>
>>
>>
> I am not sure exactly what you want to achieve.  Compare the headings of 
> the csv-file with the table definition and make sure they correspond.
>
> If your exported tables are referenced or are referencing other tables, 
> that reference will be broken unless you export and import the whole 
> database as described in the web2py book.
>
> Also see this thread:
>
>
> https://groups.google.com/forum/?fromgroups#!topicsearchin/web2py/group:web2py$20AND$20subject:uuid/web2py/0X3ykXLmcEQ
>  
>
> especially Massimo's remark near the end of the thread.
>
> Regards
> Johann
> -- 
> Because experiencing your loyal love is better than life itself, 
> my lips will praise you.  (Psalm 63:3)
>
>

-- 





[web2py] import_from_csv_file with validation

2012-07-26 Thread Mark Li
Is there something like validate_and_insert()  for import_from_csv_file()? 
I would like to update my database with csv files, but have the form 
validators fired to ensure that the data inserted is of the correct type.

-- 





[web2py] Accessing static file with consecutive hypens in filename.

2012-07-26 Thread Mark Li
I have a static file named 

person---dog-3.jpg

When I try to access the file through 
http://127.0.0.1:8000/myapp/static/pets/person---dog-3.jpg
I get an "invalid request" error.

However, if I rename the file to person-dog-3.jpg, it works fine.
I have a very large number of files named this way (with consecutive 
hyphens), and it worked fine on other sites, just not working for web2py. 
Any idea how I can make this work without renaming all the files?

-- 





[web2py] Using UUID in a many to many database

2012-07-27 Thread Mark Li
I currently have 3 data tables setup, one is an intermediate table linking 
a many to many relationship. I would like to use UUID as the reference ID, 
so I insert the uuid into the intermediate table instead of the normal ID.

However this doesn't work as expected, all the fields in the relational 
data table are 0 after inserting the UUID.

My db.py code below:




db = DAL('sqlite://storage.sqlite')

import uuid

db.define_table('people',
Field('uuid', length=64, default=uuid.uuid4(), 
notnull=True,writable=False,unique
=True),
Field('person'),
Field('age'), format='%(person)s')

db.define_table('foods',
Field('uuid', length=64, default=uuid.uuid4(), 
notnull=True,writable=False,unique
=True),
Field('food'),
Field('foodtype'), format='%(food)s')

db.define_table('people_food',
Field('person',db.people),
Field('foods',db.foods))


db.people_food.person.requires = IS_IN_DB(db,db.people.uuid,)
db.people_food.foods.requires = IS_IN_DB(db,db.foods.uuid,)


I am doing this so my references won't break, as the regular ID may change 
if the database isn't empty. Any idea what I'm doing wrong here?

-- 





[web2py] Invalid File Format when importing from CSV to db

2012-07-28 Thread Mark Li
I used 

db.export_to_csv_file(open('somefile.csv', 'wb'))

to export my database, but when I try to import it with

db.import_from_csv_file(open('somefile.csv', 'rb'))

I get the following error

Traceback (most recent call last):
  File "", line 1, in 
  File "C:\users\mark\documents\dubliners\web2py\gluon\dal.py", line 6446, in im
port_from_csv_file
raise SyntaxError, 'invalid file format'
SyntaxError: invalid file format


I've tried emptying the database and re-creating the datatables, but nothing is 
working so far.

-- 





[web2py] Re: Using UUID in a many to many database

2012-07-28 Thread Mark Li
Thanks for the tip Anthony

On Saturday, July 28, 2012 12:28:15 PM UTC-7, Anthony wrote:
>
> db.define_table('people',
>> Field('uuid', length=64, default=uuid.uuid4()
>>
>
> Note, you may not want to set default=uuid.uuid4() -- that will set the 
> default to a single fixed uuid value for the entire request, so if multiple 
> records are inserted during the request, they will all get the same uuid. 
> Instead, you can do default=uuid.uuid4 or default=lambda: uuid.uuid4() -- 
> in those cases, the default is a callable rather than a fixed value, and 
> the callable will be called separately for each record inserted, thereby 
> generating a new value for each record.
>
> Anthony
>

-- 





[web2py] Re: Invalid File Format when importing from CSV to db

2012-07-28 Thread Mark Li
I found my problem. Turns out saving a CSV file in excel will add trailing 
commas for empty cells, so after "END" in the original CSV file, there 
would be "" for each empty cell (based on the number of column fields). 

On Saturday, July 28, 2012 12:23:20 PM UTC-7, Mark Li wrote:
>
> I used 
>
> db.export_to_csv_file(open('somefile.csv', 'wb'))
>
> to export my database, but when I try to import it with
>
> db.import_from_csv_file(open('somefile.csv', 'rb'))
>
> I get the following error
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "C:\users\mark\documents\dubliners\web2py\gluon\dal.py", line 6446, in 
> im
> port_from_csv_file
> raise SyntaxError, 'invalid file format'
> SyntaxError: invalid file format
>
>
> I've tried emptying the database and re-creating the datatables, but nothing 
> is working so far.
>
>

-- 





[web2py] Re: Unit test and request object

2012-08-06 Thread Mark Li
Was having trouble with this too, thanks for find this!

On Friday, April 8, 2011 7:03:21 AM UTC-7, Jérémie wrote:
>
> Some more points. 
>
> I finally succeeded to reset request thanks to matclab's comments and 
> code on the slice (http://www.web2pyslices.com/main/slices/take_slice/ 
> 67) : 
> >> "note that without pickling at init and unpickling at setup, the 
> session and request was not cleaned up before each test." 
>
> class DefaultController(unittest.TestCase): 
> def __init__(self, p): 
> global auth, session, request 
> unittest.TestCase.__init__(self, p) 
> self.session = pickle.dumps(session) 
> request.application = 'appname' 
> request.controller = 'default' 
> self.request = pickle.dumps(request) 
>
>
> def setUp(self): 
> global response, session, request, auth 
> session = pickle.loads(self.session) 
> request = pickle.loads(self.request) 
> auth = Auth(globals(), db) 
> auth.define_tables() 
>
>
> In case anybody would need it. 
>
> Jérémie

-- 





[web2py] Option to visit Non-mobile site with @mobilize

2012-08-25 Thread Mark Li
I would like to add the option to visit the regular version of the site on 
the mobile-view.

However, from my understanding of @mobilize, it automatically redirects to 
the mobile version of the page if a mobile device is detected. Is there a 
way to override this behavior if a visitor on a mobile-device chooses the 
Non-mobile option for the site?

-- 





[web2py] Re: Option to visit Non-mobile site with @mobilize

2012-08-26 Thread Mark Li
Thanks Anthony!

Is it possible to set a request variable without URL args (to store in the 
session)? I don't want the URL on the redirected desktop page to have a 
'?mobile=false' attached. Is it bad practice to use a form with a fixed 
value to send request variables, as opposed to a link with URL args?

On Saturday, August 25, 2012 5:20:25 PM UTC-7, Anthony wrote:
>
> I don't think you can control that using the @mobilize decorator, but 
> instead of using the decorator, you can use request.user_agent().is_mobile 
> to detect mobile clients and make changes accordingly. The @mobilize 
> decorator just does this:
>
> user_agent = request.user_agent()
> if user_agent.is_mobile:
> items = response.view.split('.')
> items.insert(-1,'mobile')
> response.view = '.'.join(items)
>
> You could add that logic yourself to a model file, but make it conditional 
> so it isn't executed if the user has selected the desktop version (that 
> choice can be stored in the session).
>
> Anthony
>
> On Saturday, August 25, 2012 8:04:57 PM UTC-4, Mark Li wrote:
>>
>> I would like to add the option to visit the regular version of the site 
>> on the mobile-view.
>>
>> However, from my understanding of @mobilize, it automatically redirects 
>> to the mobile version of the page if a mobile device is detected. Is there 
>> a way to override this behavior if a visitor on a mobile-device chooses the 
>> Non-mobile option for the site?
>>
>

-- 





[web2py] Setting request.vars without URL args

2012-08-26 Thread Mark Li
I want a link that will redirect users to the desktop view of my page (from 
the mobile view), where I will store a session variable to remember that 
the user wants to stay in desktop view.

However, I would rather not use URL args because I don't want the args, 
like '?mobile=false', attached to the redirected URL. I was thinking about 
a form with a fixed value, where the 'submit' button would set the request 
variable mobile=false and redirect to the desktop view. Is there a more 
elegant way to do this, rather than using a form to avoid URL args?

-- 





[web2py] Using request.user_agent to check if Android device

2012-08-30 Thread Mark Li
I would like to use request.user_agent to check if a device is an Android.

I'm currently using is_mobile() to check and load the mobile view, but I 
would like to break it down one more step and add some code only for 
Android devices. Is there any way to go about this? 

And would this be more efficient than using Javascript device sniffer?

-- 





[web2py] Best Method to implement a "like" button

2012-09-10 Thread Mark Li
I have 3 datatables as follows:


db.define_table('songs',
Field('songname'),
format='%(songname)s')

db.define_table('likes',
Field('username', 'reference auth_user'),
Field('songname', 'reference songs'))

with the 3rd table being db.auth_user

I would like to implement a "like" button, where clicking it adds an entry 
to the intermediate table 'likes'. For example, if User1 likes Song1, it 
would perform the following:
db.likes.insert(username=auth.user.id, songname=1)



Right now I have the like button as the following in the view: 
{{=A('like me', callback=URL('add_like'))}}

and the function as:
def add_like():
db.likes.insert(username=auth.user.id, songname=1)

The problem I'm having is that a user should only be allowed to 'like' a 
song once; if the user has already liked the song, clicking on 'like' again 
should remove that like. Basically a toggle functionality for the 'like' 
button.

I'm not sure how to implement the last part, as it seems checking the 
entire database for the existence of that record on every 'like' click is 
overkill. Is there an eloquent way (minimal database calls) to go about 
implementing this toggle functionality for a 'like' button?





-- 





[web2py] Re: Best Method to implement a "like" button

2012-09-11 Thread Mark Li
I went with the unique composite field index method (unique across 3 
fields, not just 2), with my database as follows:

db.define_table('likes',
Field('username', 'reference auth_user'),
Field('songname', 'reference songs'),
Field('playlist_name', 'reference playlist'))

if auth.is_logged_in():
already_liked = db((db.likes.username==auth.user.id) & (db.likes.
playlist_name==request.vars.playlist_name)) 

db.likes.songname.requires=IS_NOT_IN_DB(already_liked, 'likes.songname')


I also changed my add_like() controller function to the following:


def add_like():


ret = db.likes.validate_and_insert(username=auth.user.id, playlist_name 
= request.vars.playlist_name, songname = request.vars.songname)

if ret.errors:

already_liked = (db.likes.username==auth.user.id) & (db.likes.
playlist_name==request.vars.playlist_name) & (db.likes.songname==request.
vars.songname)
db(already_liked).delete()

return "like removed"

else:
return "like added"

I used the web2py ajax function to call the add_like action. The whole 
process seems somewhat sluggish, are there any unnecessary database calls 
I'm making?

On Tuesday, September 11, 2012 4:53:44 AM UTC-7, villas wrote:
>
> How about:  in 'likes' make a unique composite index of both fields 
> (created at DB level).  Try to insert a record.  If it fails (because of 
> the index) then delete instead.
>
>
> On Monday, September 10, 2012 11:58:03 PM UTC+1, Mark Li wrote:
>>
>> I have 3 datatables as follows:
>>
>>
>> db.define_table('songs',
>> Field('songname'),
>> format='%(songname)s')
>>
>> db.define_table('likes',
>> Field('username', 'reference auth_user'),
>> Field('songname', 'reference songs'))
>>
>> with the 3rd table being db.auth_user
>>
>> I would like to implement a "like" button, where clicking it adds an 
>> entry to the intermediate table 'likes'. For example, if User1 likes Song1, 
>> it would perform the following:
>> db.likes.insert(username=auth.user.id, songname=1)
>>
>>
>>
>> Right now I have the like button as the following in the view: 
>> {{=A('like me', callback=URL('add_like'))}}
>>
>> and the function as:
>> def add_like():
>> db.likes.insert(username=auth.user.id, songname=1)
>>
>> The problem I'm having is that a user should only be allowed to 'like' a 
>> song once; if the user has already liked the song, clicking on 'like' again 
>> should remove that like. Basically a toggle functionality for the 'like' 
>> button.
>>
>> I'm not sure how to implement the last part, as it seems checking the 
>> entire database for the existence of that record on every 'like' click is 
>> overkill. Is there an eloquent way (minimal database calls) to go about 
>> implementing this toggle functionality for a 'like' button?
>>
>>
>>
>>
>>
>>

-- 





[web2py] Plain Text and HTML Email with auth.messages.verify_email

2012-09-14 Thread Mark Li
Is it possible to send both Plain Text and HTML Emails with 
auth.messages.verify_email? From the book, it seems 
auth.messages.verify_email only accepts a single string.


-- 





[web2py] Re: Plain Text and HTML Email with auth.messages.verify_email

2012-09-14 Thread Mark Li
Sorry I should've been more specific in my question.

I wanted to know if you could combine plain text and html emails with 
auth.messages.verify_email like you can with the following:

mail.send('y...@example.com',
  'Message subject',
  ('Plain text body', 'html body'))




On Friday, September 14, 2012 2:25:04 PM UTC-7, Massimo Di Pierro wrote:
>
> If the email text looks like '' it should be send as html.
>
> On Friday, 14 September 2012 12:12:21 UTC-5, Mark Li wrote:
>>
>> Is it possible to send both Plain Text and HTML Emails with 
>> auth.messages.verify_email? From the book, it seems 
>> auth.messages.verify_email only accepts a single string.
>>
>>
>>

-- 





[web2py] Resend email_verify like request_reset_password

2012-09-14 Thread Mark Li
I would like to know how I should go about adding a 'resend_email_verify' 
action to utilize the 'request_reset_password' action, but instead of 
sending a link to the reset_password view, it simply resends 
auth.message.verify_email   .

-- 





[web2py] Changing auth validator error messages

2012-09-16 Thread Mark Li
Is it possible to change the validator error messages in for auth fields 
like "value already in database or empty," without having to redefine all 
the validators for that field? For example, I wanted to change the 
validator error message for IS_NOT_IN_DB for auth_user.email, and I wrote:

db.auth_user.email.requires=IS_NOT_IN_DB(db, auth_user.email, error_message=
T("Email already in use"))


Would I have to define all the validators for auth_user.email now? Is there 
a less intrusive way of changing the error message without overriding the 
default validators for auth?

-- 





[web2py] Re: Changing auth validator error messages

2012-09-17 Thread Mark Li
Ok that answers my question; I would still have to define all the 
validators for auth_user.email (assuming there is more than one).

Also just for claficiation, using the following:
db.auth_user.email.requires.error_message = T("")


gives me the following error message: 
 'list' object has no attribute 
'error_message'





On Sunday, September 16, 2012 7:37:52 PM UTC-7, Massimo Di Pierro wrote:
>
> I think you can do:
>
> db.auth_user.email.requires.error_message = T()
>
> Unless they have more then one validator.
>
> On Sunday, 16 September 2012 21:21:00 UTC-5, Mark Li wrote:
>>
>> Is it possible to change the validator error messages in for auth fields 
>> like "value already in database or empty," without having to redefine all 
>> the validators for that field? For example, I wanted to change the 
>> validator error message for IS_NOT_IN_DB for auth_user.email, and I wrote:
>>
>> db.auth_user.email.requires=IS_NOT_IN_DB(db, auth_user.email,error_message
>> =T("Email already in use"))
>>
>>
>> Would I have to define all the validators for auth_user.email now? Is 
>> there a less intrusive way of changing the error message without overriding 
>> the default validators for auth?
>>
>

-- 





[web2py] Specify sender name in auth.settings.mailer

2012-09-17 Thread Mark Li
I am using 'mycomp...@gmail.com' as my email address for 
auth.settings.mailer.settings.sender

and the sender name shows up as 'mycompany' in the received email. However, 
I would like to edit the sender name so it is different from 'mycompany'. 
Is there any way to accomplish this using the mailer from Auth?

-- 





[web2py] Re: Specify sender name in auth.settings.mailer

2012-09-17 Thread Mark Li
Yep here it is: http://code.google.com/p/web2py/issues/detail?id=1017

On Monday, September 17, 2012 12:05:40 PM UTC-7, Massimo Di Pierro wrote:
>
> Looks like there is not but there should be. Can you please open a ticket 
> about this?
>
> On Monday, 17 September 2012 12:57:10 UTC-5, Mark Li wrote:
>>
>> I am using 'myco...@gmail.com' as my email address for 
>> auth.settings.mailer.settings.sender
>>
>> and the sender name shows up as 'mycompany' in the received email. 
>> However, I would like to edit the sender name so it is different from 
>> 'mycompany'. Is there any way to accomplish this using the mailer from Auth?
>>
>

-- 





[web2py] Re: Changing auth validator error messages

2012-09-17 Thread Mark Li
Awesome, that worked and I didn't have to redefine the other validators for 
auth_user.email

On Monday, September 17, 2012 11:52:38 AM UTC-7, Massimo Di Pierro wrote:
>
> sorry. Try:
>
> db.auth_user.email.requires[0].error_message = T("")
>
> On Monday, 17 September 2012 11:40:24 UTC-5, Mark Li wrote:
>>
>> Ok that answers my question; I would still have to define all the 
>> validators for auth_user.email (assuming there is more than one).
>>
>> Also just for claficiation, using the following:
>> db.auth_user.email.requires.error_message = T("")
>>
>>
>> gives me the following error message: 
>>  'list' object has no attribute 
>> 'error_message'
>>
>>
>>
>>
>>
>> On Sunday, September 16, 2012 7:37:52 PM UTC-7, Massimo Di Pierro wrote:
>>>
>>> I think you can do:
>>>
>>> db.auth_user.email.requires.error_message = T()
>>>
>>> Unless they have more then one validator.
>>>
>>> On Sunday, 16 September 2012 21:21:00 UTC-5, Mark Li wrote:
>>>>
>>>> Is it possible to change the validator error messages in for auth 
>>>> fields like "value already in database or empty," without having to 
>>>> redefine all the validators for that field? For example, I wanted to 
>>>> change 
>>>> the validator error message for IS_NOT_IN_DB for auth_user.email, and I 
>>>> wrote:
>>>>
>>>> db.auth_user.email.requires=IS_NOT_IN_DB(db, auth_user.email,error_message
>>>> =T("Email already in use"))
>>>>
>>>>
>>>> Would I have to define all the validators for auth_user.email now? Is 
>>>> there a less intrusive way of changing the error message without 
>>>> overriding 
>>>> the default validators for auth?
>>>>
>>>

-- 





Re: [web2py] Re: Best Method to implement a "like" button

2012-09-18 Thread Mark Li
Thanks for the response guys! I'm going with rochabruno's method as it is 
the most straightfoward, I hadn't really looked into the compute 
capabilities.

On Tuesday, September 11, 2012 3:55:21 PM UTC-7, rochacbruno wrote:
>
> The computation should be
>
> compute= lambda row: "%(username)s-%(songname)s-%(playlist_name)s" % row
>

-- 





[web2py] Httponly for cookies/sessions

2013-01-14 Thread Mark Li
I haven't found anything in the web2py documentation about setting the 
httponly attribute for cookies and sessions.

For sessions, there is session.secure() to set the session cookies to 
secure, is there a similiar method to setting the httponly option for 
session cookies?


Also for regular cookies, the following would make the cookie secure

response.cookies['mycookie']['secure'] = True


So is there something similar you can do to set HttpOnly to true?

-- 





[web2py] Re: Httponly for cookies/sessions

2013-01-14 Thread Mark Li


On Monday, January 14, 2013 2:45:21 PM UTC-8, Mark Li wrote:
>
> I haven't found anything in the web2py documentation about setting the 
> httponly attribute for cookies and sessions.
>
> For sessions, there is session.secure() to set the session cookies to 
> secure, is there a similiar method to setting the httponly option for 
> session cookies?
>
>
> Also for regular cookies, the following would make the cookie secure
>
> response.cookies['mycookie']['secure'] = True
>
>
> So is there something similar you can do to set HttpOnly to true?
>

-- 





[web2py] Re: Httponly for cookies/sessions

2013-01-14 Thread Mark Li
Yep that did the trick, thanks Anthony!

On Monday, January 14, 2013 2:45:21 PM UTC-8, Mark Li wrote:
>
> I haven't found anything in the web2py documentation about setting the 
> httponly attribute for cookies and sessions.
>
> For sessions, there is session.secure() to set the session cookies to 
> secure, is there a similiar method to setting the httponly option for 
> session cookies?
>
>
> Also for regular cookies, the following would make the cookie secure
>
> response.cookies['mycookie']['secure'] = True
>
>
> So is there something similar you can do to set HttpOnly to true?
>

-- 





[web2py] Register action using info from POST

2013-01-22 Thread Mark Li
I am currently using web2py's auth to return a registration form.

However, I would also like users to be able to register RESTfully, with the 
email and password information in a POST call. How would I write a register 
action that mimics auth.register(), except the information is from a POST, 
not a form.

-- 





[web2py] Re: Register action using info from POST

2013-01-23 Thread Mark Li
I have decided to use validate_and_insert with web2py's REST methods

db.auth_user.validate_and_insert(**fields)

Testing so far, I was able to add a user even though the email and password 
fields were empty in the POST call. I altered my api action so that it 
checks whether or not the email and password fields in the request are 
empty. All other validators seem to be working fine.

If anyone has previous experience with validate_and_insert with the 
auth_user table, and knows of any registration holes this way, please let 
me know!


On Tuesday, January 22, 2013 6:50:06 PM UTC-8, Mark Li wrote:
>
> I am currently using web2py's auth to return a registration form.
>
> However, I would also like users to be able to register RESTfully, with 
> the email and password information in a POST call. How would I write a 
> register action that mimics auth.register(), except the information is from 
> a POST, not a form.
>

-- 





[web2py] Re: Register action using info from POST

2013-01-29 Thread Mark Li
Thanks for the tips Anthony! I'm going to look more into the first method 
you suggested. 

Do you know if enabling Captcha would affect the custom register action if 
I used auth.register()? Right now, the 
db.auth_user.validate_and_insert(**fields)
works fine. I would be unable to implement Captcha on the clientside 
(android app), so would auth.register() not work in that case if I have 
Captchas enabled?



On Thursday, January 24, 2013 4:57:51 AM UTC, Anthony wrote:
>
> Or an easier option is to use the 
> auth.get_or_create_user()<http://code.google.com/p/web2py/source/browse/gluon/tools.py#1704>method,
>  though that doesn't provide the password verification 
> field/validation that the auth.register() function includes (which you may 
> not want anyway). It also won't provide the CSRF protection that the 
> auth.register() formkey provides.
>
> Anthony
>
> On Wednesday, January 23, 2013 11:45:15 PM UTC-5, Anthony wrote:
>>
>> You might consider looking at the auth.register() code: 
>> http://code.google.com/p/web2py/source/browse/gluon/tools.py#2168
>>
>> Another option might be to generate an auth.register() form and send the 
>> formkey to the client to be passed back as a hidden field in the POST call. 
>> You can then let the web2py auth.register() function handle the 
>> registration as usual.
>>
>> If you use a web2py view to create the register form, you can do:
>>
>> > />
>> 
>>
>> Otherwise, you can make an Ajax request to get a formkey:
>>
>> def get_formkey():
>> return auth.register().formkey
>>
>> That will put the formkey in the session, and when the form is submitted, 
>> the submitted formkey value will be compared to the value in the session. 
>> Note, you also need to send a "_formname" field with the value "register".
>>
>> Your register function could then be:
>>
>> def register():
>> auth.register()
>> return 'An error occurred'
>>
>> Note, by default, if the registration is accepted, that will do a 
>> client-side redirect to auth.settings.register_next (assuming web2py.js is 
>> loaded in the client). If you don't want a redirect, you can define an 
>> onaccept function that raises an HTTP 
>> exception<http://web2py.com/books/default/chapter/29/04#HTTP-and-redirect>in 
>> order to return a string:
>>
>> def register():
>> def success(form):
>> raise HTTP(200, 'Success')
>> auth.register(onaccept=success)
>> return 'An error occurred'
>>
>> This is untested, so I may have missed something.
>>
>> Anthony
>>
>> On Wednesday, January 23, 2013 6:11:26 PM UTC-5, Mark Li wrote:
>>>
>>> I have decided to use validate_and_insert with web2py's REST methods
>>>
>>> db.auth_user.validate_and_insert(**fields)
>>>
>>> Testing so far, I was able to add a user even though the email and 
>>> password fields were empty in the POST call. I altered my api action so 
>>> that it checks whether or not the email and password fields in the request 
>>> are empty. All other validators seem to be working fine.
>>>
>>> If anyone has previous experience with validate_and_insert with the 
>>> auth_user table, and knows of any registration holes this way, please let 
>>> me know!
>>>
>>>
>>> On Tuesday, January 22, 2013 6:50:06 PM UTC-8, Mark Li wrote:
>>>>
>>>> I am currently using web2py's auth to return a registration form.
>>>>
>>>> However, I would also like users to be able to register RESTfully, with 
>>>> the email and password information in a POST call. How would I write a 
>>>> register action that mimics auth.register(), except the information is 
>>>> from 
>>>> a POST, not a form.
>>>>
>>>

-- 

--- 
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] DAL and MySQL indexing

2013-01-31 Thread Mark Li
Simple question. My web2py app just received a heavy amount of traffic, and 
I was looking for ways I could optimize performance.

I am currently using MySQL, and using a database query like
rows = db(db.tablename.category=="category_name").select()

I am aware that web2py does not automatically create indexes for the 
database table. After I've created indexes for the table, is it necessary 
to use Raw SQL through db.executesql() to take advantage of MySQL indexing, 
or can I still use the same DAL query?

-- 

--- 
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] DAL and MySQL indexing

2013-01-31 Thread Mark Li
Awesome, thanks for that!

On Thursday, January 31, 2013 4:43:24 PM UTC-8, rochacbruno wrote:
>
> Since you have the indexes created on DB backend, The DAL will use this 
> for any query on that table, because the output of .select() is in fact a 
> pure SQL statement.
>
>
>

-- 

--- 
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] Append to list:reference or list:string with update_record

2012-10-25 Thread Mark Li
Is it possible to append to a database list (like list:reference or 
list:string) with update_record, as opposed to explicitly stating the whole 
list for update_record?

-- 





[web2py] Re: autodelete image computed field

2012-11-09 Thread Mark Li
Any success on getting the computed thumbnail image to autodelete? I'm 
having trouble with this too, where an update of a new thumbnail will not 
delete the old file.

On Saturday, April 28, 2012 5:06:25 PM UTC-7, ctrlSoft wrote:
>
>
> hi i have a resize function wich creates image thumbanils...
> def THUMB(image, nx=120, ny=120):
> from PIL import Image 
> import os  
> try:
> img = Image.open(request.folder + 'static/img_folder/' + image)
> img.thumbnail((nx,ny), Image.ANTIALIAS) 
> root,ext = os.path.splitext(image)
> thumb='%s_thumb%s' %(root, ext)
> img.save(request.folder + 'static/img_folder/' + thumb)
> return thumb
> except: 
> return None  
>  
> and this :
> db.define_table("news",
> Field('image', 'upload', requires=IS_EMPTY_OR(IS_IMAGE()), 
> uploadfolder=request.folder+'static/img_folder', autodelete=True), 
> Field('image_thumb', 'upload', compute=lambda r: THUMB(r['image']), 
> autodelete=True), 
> Field("title",label=T('Title'),requires=IS_NOT_EMPTY()),
> Field("content" 
> ,type='text',label=T('Content'),requires=IS_NOT_EMPTY()))
>
> the problem is when i delete a row, image("big image") is deleteing from 
> disk but the image_thumb stil remains on disk. 
> any solutions are welcome :), thx
>
> ___
> Alex
>
>

-- 





[web2py] Updating profile does not update auth.user for computed field

2012-11-12 Thread Mark Li
I am currently using auth.profile() for a form where users can update their 
information. I have an 'upload' field for images, and a computed field that 
creates a thumbnail of the previous field.

When the user hits 'save profile', auth.user is updated only for the 
original 'upload' field, not the computed field. Is there anyway to update 
the computed field for auth.user as well (while still using the form 
created by auth.profile)?

-- 





[web2py] Re: Updating profile does not update auth.user for computed field

2012-11-14 Thread Mark Li
Here's the link to the ticket: 
http://code.google.com/p/web2py/issues/detail?id=1164&thanks=1164&ts=1352926016

On Wednesday, November 14, 2012 6:21:03 AM UTC-8, Massimo Di Pierro wrote:
>
> Please open a ticket and well' fix this asap. Probably today at the web2py 
> sprint at PyCon Ar.
>
> On Monday, 12 November 2012 22:40:14 UTC-6, Mark Li wrote:
>>
>> I am currently using auth.profile() for a form where users can update 
>> their information. I have an 'upload' field for images, and a computed 
>> field that creates a thumbnail of the previous field.
>>
>> When the user hits 'save profile', auth.user is updated only for the 
>> original 'upload' field, not the computed field. Is there anyway to update 
>> the computed field for auth.user as well (while still using the form 
>> created by auth.profile)?
>>
>

-- 





[web2py] Orderby does not work field type 'double', sorts as if floats were strings

2012-11-21 Thread Mark Li
I currently have a table with 'scores' as one of the fields, with the field 
type 'double'. 

When I go to fetch a row (ordered by scores) and print the scores, they 
come back sorted as if they were strings.
I use the following:

rows = db(db.song_table).select(orderby = db.song_table.scores)
for x in rows:
print x.scores

this prints out the following:

-15.0
-16.0
-17.0
-2.0
-20.0
-34.0
0.0
0.0
15.0
2.0
20.0


The scores are ordered as if they were strings, not numbers. However, when 
you fetch a score, it is still a float, not a string. 

Is this intended behavior, or a bug with field type 'double'? 


I am aware that for field type 'integer', the scores are sorted properly, 
but I will have decimals in my scores.



-- 





[web2py] Re: Orderby does not work field type 'double', sorts as if floats were strings

2012-11-22 Thread Mark Li
Yes this is on SQLite, is this a problem unique to SQLite?

On Thursday, November 22, 2012 1:58:41 AM UTC-8, Niphlod wrote:
>
> is this on SQLite ?
>
> On Thursday, November 22, 2012 3:44:38 AM UTC+1, Mark Li wrote:
>>
>> I currently have a table with 'scores' as one of the fields, with the 
>> field type 'double'. 
>>
>> When I go to fetch a row (ordered by scores) and print the scores, they 
>> come back sorted as if they were strings.
>> I use the following:
>>
>> rows = db(db.song_table).select(orderby = db.song_table.scores)
>> for x in rows:
>> print x.scores
>>
>> this prints out the following:
>>
>> -15.0
>> -16.0
>> -17.0
>> -2.0
>> -20.0
>> -34.0
>> 0.0
>> 0.0
>> 15.0
>> 2.0
>> 20.0
>>
>>
>> The scores are ordered as if they were strings, not numbers. However, 
>> when you fetch a score, it is still a float, not a string. 
>>
>> Is this intended behavior, or a bug with field type 'double'? 
>>
>>
>> I am aware that for field type 'integer', the scores are sorted properly, 
>> but I will have decimals in my scores.
>>
>>
>>
>>

-- 





[web2py] Re: Orderby does not work field type 'double', sorts as if floats were strings

2012-11-22 Thread Mark Li
Ahh thanks Niphlod!

On Thursday, November 22, 2012 2:49:28 PM UTC-8, Niphlod wrote:
>
> yep, support for decimal is kinda absent so it's treated "like a string".
>
> On Thursday, November 22, 2012 10:10:23 PM UTC+1, Mark Li wrote:
>>
>> Yes this is on SQLite, is this a problem unique to SQLite?
>>
>> On Thursday, November 22, 2012 1:58:41 AM UTC-8, Niphlod wrote:
>>>
>>> is this on SQLite ?
>>>
>>> On Thursday, November 22, 2012 3:44:38 AM UTC+1, Mark Li wrote:
>>>>
>>>> I currently have a table with 'scores' as one of the fields, with the 
>>>> field type 'double'. 
>>>>
>>>> When I go to fetch a row (ordered by scores) and print the scores, they 
>>>> come back sorted as if they were strings.
>>>> I use the following:
>>>>
>>>> rows = db(db.song_table).select(orderby = db.song_table.scores)
>>>> for x in rows:
>>>> print x.scores
>>>>
>>>> this prints out the following:
>>>>
>>>> -15.0
>>>> -16.0
>>>> -17.0
>>>> -2.0
>>>> -20.0
>>>> -34.0
>>>> 0.0
>>>> 0.0
>>>> 15.0
>>>> 2.0
>>>> 20.0
>>>>
>>>>
>>>> The scores are ordered as if they were strings, not numbers. However, 
>>>> when you fetch a score, it is still a float, not a string. 
>>>>
>>>> Is this intended behavior, or a bug with field type 'double'? 
>>>>
>>>>
>>>> I am aware that for field type 'integer', the scores are sorted 
>>>> properly, but I will have decimals in my scores.
>>>>
>>>>
>>>>
>>>>

-- 





[web2py] Re: Changing auth validator error messages

2012-11-28 Thread Mark Li
db.auth_user.email.requires[1].error_message = T("The email you have 
entered has already been registered.")

Try using the index of 1, not 0.


On Wednesday, November 28, 2012 4:55:54 PM UTC, Daniele wrote:
>
> I'd also like to change that error message "value already in database or 
> empty" as I find it a pointless message.
> But I tried with db.auth_user.email.requires[0].error_message = T("The 
> email you have entered has already been registered.")
> and it doesn't seem to change anything. Am I misplacing this? I put it in 
> the db.py file after the 
> auth.define_tables(username=False, signature=False)
>
> Thanks
>
> On Monday, September 17, 2012 3:21:00 AM UTC+1, Mark Li wrote:
>>
>> Is it possible to change the validator error messages in for auth fields 
>> like "value already in database or empty," without having to redefine all 
>> the validators for that field? For example, I wanted to change the 
>> validator error message for IS_NOT_IN_DB for auth_user.email, and I wrote:
>>
>> db.auth_user.email.requires=IS_NOT_IN_DB(db, auth_user.email,error_message
>> =T("Email already in use"))
>>
>>
>> Would I have to define all the validators for auth_user.email now? Is 
>> there a less intrusive way of changing the error message without overriding 
>> the default validators for auth?
>>
>

-- 





[web2py] Standalone DAL fetching old/obsolete data (mysql)

2012-11-28 Thread Mark Li
For some functional tests I'm running, I am fetching a row, clicking on a 
button, and then fetching the same row to see if the button action worked.

I have the following to establish a database connection (using DAL outside 
of web2py environment):
path_to_database = path.join(path.curdir, "databases")
db = DAL('mysql://username:password@localhost/test')
db.import_table_definitions(path_to_database)

I then run the following to fetch a row:

row = db(db.likes.id>0).select().first() 
print row.like_score

which prints "1" as expected

Then I click a button (through Selenium webdriver), which sets the score 
back to "0"
button.click() 
time.sleep(2)

#checking the db, the score is already 0 before the row is fetched
row2 = db(db.likes.id>0).select().first() 
print row2.like_score

However, the printed score is still "1".

This was not a problem using SQLite, and the score in the database is 0, 
which I confirmed by only fetching the row AFTER the button is clicked. The 
problem arises when fetching the same row more than once.

When fetching the row a 2nd time, I am getting old/obsolete data, instead 
of getting the same row with new data. Any ideas as to how I can fix this?

-- 





Re: [web2py] Standalone DAL fetching old/obsolete data (mysql)

2012-11-28 Thread Mark Li
Ah so simple! I assumed that since the button called a controller action in 
the web2py environment, that I would not need an explicit db.commit() (as I 
don't need it with the webapp). But yes, for a script outside of web2py 
using DAL, the db.commit() updated the value for the new fetched row.

On Wednesday, November 28, 2012 10:02:57 PM UTC-8, rochacbruno wrote:
>
> You need to use
>
> *db.commit()* just after you update any value.
>
> db.table.update(field=0)
> db.commit()
>
> *Bruno Cezar Rocha** - @rochacbruno*
> rocha...@gmail.com  | Mobile: +55 (11) 99210-8821
> www.CursoDePython.com.br | www.rochacbruno.com.br
> Blog: Search form with 
> web2py<http://rochacbruno.com.br/search-form-with-web2py/>
>   Get a signature like this. 
> <http://r1.wisestamp.com/r/landing?promo=18&dest=http%3A%2F%2Fwww.wisestamp.com%2Femail-install%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_campaign%3Dpromo_18>
>  Click 
> here.<http://r1.wisestamp.com/r/landing?promo=18&dest=http%3A%2F%2Fwww.wisestamp.com%2Femail-install%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_campaign%3Dpromo_18>
>
>
>
>
> On Thu, Nov 29, 2012 at 2:36 AM, Mark Li 
> > wrote:
>
>> For some functional tests I'm running, I am fetching a row, clicking on a 
>> button, and then fetching the same row to see if the button action worked.
>>
>> I have the following to establish a database connection (using DAL 
>> outside of web2py environment):
>> path_to_database = path.join(path.curdir, "databases")
>> db = DAL('mysql://username:password@localhost/test')
>> db.import_table_definitions(path_to_database)
>>
>> I then run the following to fetch a row:
>>
>> row = db(db.likes.id>0).select().first() 
>> print row.like_score
>>
>> which prints "1" as expected
>>
>> Then I click a button (through Selenium webdriver), which sets the score 
>> back to "0"
>> button.click() 
>> time.sleep(2)
>>
>> #checking the db, the score is already 0 before the row is fetched
>> row2 = db(db.likes.id>0).select().first() 
>> print row2.like_score
>>
>> However, the printed score is still "1".
>>
>> This was not a problem using SQLite, and the score in the database is 0, 
>> which I confirmed by only fetching the row AFTER the button is clicked. The 
>> problem arises when fetching the same row more than once.
>>
>> When fetching the row a 2nd time, I am getting old/obsolete data, instead 
>> of getting the same row with new data. Any ideas as to how I can fix this?
>>
>>  -- 
>>  
>>  
>>  
>>
>
>
>

-- 





[web2py] Returning a token for Android app authentication

2012-12-31 Thread Mark Li
I am currently trying to authenticate users on an Android app to my Web2py 
application. I am not comfortable implementing this on my own without some 
guidance/advice, as I'm worried about the security of the login information 
becoming jeopardized.


I am following the guideline for authentication outlined by Google here: 
https://developers.google.com/accounts/docs/MobileApps

Another outline of what how I'm trying to accomplish Authentication 
outlined here: 
http://stackoverflow.com/questions/7358715/authentication-model-for-android-application


The first step, and my question, is how I would generate a token to return 
to the Android app after the user has successfully logged in. It is 
suggested that this token be in the same format to what Web2py uses for 
session login cookies, except with a 'mobile' flag indicating the token can 
only be used for API calls, and doesn't have the short lifespan of a 
browser session.

Any help would be greatly appreciated, as I haven't read too much about 
authentication to web2py from an Android app.

-- 





[web2py] Re: Returning a token for Android app authentication

2013-01-01 Thread Mark Li
Thanks for the responses, and Happy New Years to you guys too!

dlypka, for your cookieless solution, it assumes that the client app can't 
store/extract tokens? In the Google Android link above, it says that both 
Android and iOS can read and extract the tokens/cookies. So when the 
Android app calls the Web2py app, wouldn't it just pass in the cookie/token 
and have Web2py verify it as it Web2py normally verifies session login 
cookies?



On Tuesday, January 1, 2013 9:07:16 AM UTC-8, Massimo Di Pierro wrote:
>
> :-)
>
>
>
> On Tuesday, 1 January 2013 10:45:47 UTC-6, dlypka wrote:
>>
>> Yes it is my New Year's Resolution to make time to put it in a Slice.
>>
>> On Tuesday, January 1, 2013 10:35:49 AM UTC-6, Massimo Di Pierro wrote:
>>>
>>> Perhaps this should go in a web2pyslice?
>>>
>>> On Monday, 31 December 2012 21:28:04 UTC-6, dlypka wrote:
>>>>
>>>> I developed a solution for this.
>>>> I posted it here:
>>>> https://groups.google.com/forum/?fromgroups=#!topic/web2py/YVYQHRJmcos
>>>>
>>>> Happy New Year!
>>>>
>>>>
>>>> On Monday, December 31, 2012 4:38:40 PM UTC-6, Mark Li wrote:
>>>>>
>>>>> I am currently trying to authenticate users on an Android app to my 
>>>>> Web2py application. I am not comfortable implementing this on my own 
>>>>> without some guidance/advice, as I'm worried about the security of the 
>>>>> login information becoming jeopardized.
>>>>>
>>>>>
>>>>> I am following the guideline for authentication outlined by Google 
>>>>> here: https://developers.google.com/accounts/docs/MobileApps
>>>>>
>>>>> Another outline of what how I'm trying to accomplish Authentication 
>>>>> outlined here: 
>>>>> http://stackoverflow.com/questions/7358715/authentication-model-for-android-application
>>>>>
>>>>>
>>>>> The first step, and my question, is how I would generate a token to 
>>>>> return to the Android app after the user has successfully logged in. It 
>>>>> is 
>>>>> suggested that this token be in the same format to what Web2py uses for 
>>>>> session login cookies, except with a 'mobile' flag indicating the token 
>>>>> can 
>>>>> only be used for API calls, and doesn't have the short lifespan of a 
>>>>> browser session.
>>>>>
>>>>> Any help would be greatly appreciated, as I haven't read too much 
>>>>> about authentication to web2py from an Android app.
>>>>>
>>>>

-- 





[web2py] Re: Returning a token for Android app authentication

2013-01-03 Thread Mark Li
I reviewed your code again and looked into the source code for web2py to 
see how web2py deals with session login cookies.

For what I want to accomplish, I believe I have found a method which does 
not involved changing web2py source code. It's simpler and more straight 
forward for me to wrap my head around (also not having to worry about 
storing cookies in the app). Please let me know if there's anything 
important I am missing or security flaws that I should consider.


1. Embed webview into native Android app, using auth.login_bare to 
authenticate.
2. On login success, return a token of similar format to web2py's session 
cookies.
3. Store this token in the database (in a table named 'tokens'), and send 
back to Android app as a cookie
4. For every request to my web service that requires authentication, send 
the token as a cookie and have the receiving API controller function 
extract the cookie/token. If the token is currently in the db.tokens, then 
the user has been authenticated and the request returns the appropriate 
data.
5. On logout/password change, delete the issued tokens for this user from 
db.tokens, so the same token can't be used to authenticate for future api 
calls.

On Tuesday, January 1, 2013 10:33:26 PM UTC-8, dlypka wrote:
>
> I was not precisely calling from a native Android or native IOS app.
> I was using a PhoneGap client, which is different. It is looks like a web 
> browser but is not a browser client.
> PhoneGap can only use HTML5 storage unless you write a native Android / 
> IOS PhoneGap extension/plugin.
> So my technique will work from almost any client platform, even from a 
> Windows native client app for example
> as long as it uses HTTP.
>
> Also, in my tracing of how web2py handles the client connection, I believe 
> I found a few wrinkles in the sequence of events
> which needed to be handled specially in this case where the client is not 
> a web browser.
>
> In your particular case, if you have cookies in the native client, then 
> that is one less problem to solve,
> You probably just have to mimic the HTTP messages that a browser would 
> send.
>
> On Tuesday, January 1, 2013 5:19:50 PM UTC-6, Mark Li wrote:
>>
>> Thanks for the responses, and Happy New Years to you guys too!
>>
>> dlypka, for your cookieless solution, it assumes that the client app 
>> can't store/extract tokens? In the Google Android link above, it says that 
>> both Android and iOS can read and extract the tokens/cookies. So when the 
>> Android app calls the Web2py app, wouldn't it just pass in the cookie/token 
>> and have Web2py verify it as it Web2py normally verifies session login 
>> cookies?
>>
>>
>>
>> On Tuesday, January 1, 2013 9:07:16 AM UTC-8, Massimo Di Pierro wrote:
>>>
>>> :-)
>>>
>>>
>>>
>>> On Tuesday, 1 January 2013 10:45:47 UTC-6, dlypka wrote:
>>>>
>>>> Yes it is my New Year's Resolution to make time to put it in a Slice.
>>>>
>>>> On Tuesday, January 1, 2013 10:35:49 AM UTC-6, Massimo Di Pierro wrote:
>>>>>
>>>>> Perhaps this should go in a web2pyslice?
>>>>>
>>>>> On Monday, 31 December 2012 21:28:04 UTC-6, dlypka wrote:
>>>>>>
>>>>>> I developed a solution for this.
>>>>>> I posted it here:
>>>>>> https://groups.google.com/forum/?fromgroups=#!topic/web2py/YVYQHRJmcos
>>>>>>
>>>>>> Happy New Year!
>>>>>>
>>>>>>
>>>>>> On Monday, December 31, 2012 4:38:40 PM UTC-6, Mark Li wrote:
>>>>>>>
>>>>>>> I am currently trying to authenticate users on an Android app to my 
>>>>>>> Web2py application. I am not comfortable implementing this on my own 
>>>>>>> without some guidance/advice, as I'm worried about the security of the 
>>>>>>> login information becoming jeopardized.
>>>>>>>
>>>>>>>
>>>>>>> I am following the guideline for authentication outlined by Google 
>>>>>>> here: https://developers.google.com/accounts/docs/MobileApps
>>>>>>>
>>>>>>> Another outline of what how I'm trying to accomplish Authentication 
>>>>>>> outlined here: 
>>>>>>> http://stackoverflow.com/questions/7358715/authentication-model-for-android-application
>>>>>>>
>>>>>>>
>>>>>>> The first step, and my question, is how I would generate a token to 
>>>>>>> return to the Android app after the user has successfully logged in. It 
>>>>>>> is 
>>>>>>> suggested that this token be in the same format to what Web2py uses for 
>>>>>>> session login cookies, except with a 'mobile' flag indicating the token 
>>>>>>> can 
>>>>>>> only be used for API calls, and doesn't have the short lifespan of a 
>>>>>>> browser session.
>>>>>>>
>>>>>>> Any help would be greatly appreciated, as I haven't read too much 
>>>>>>> about authentication to web2py from an Android app.
>>>>>>>
>>>>>>

-- 





[web2py] Re: Returning a token for Android app authentication

2013-01-04 Thread Mark Li
Would it be necessary to connect to the same web2py session?

To my understanding, connecting to the same session would be necessary if 
the session contained Auth information indicating whether or not a user was 
logged in. However, using auth.login_bare(), I only return a token on login 
success, and the Auth information is never stored in session. Only the 
token would be used to check whether or not a user was authenticated, as 
this info is not stored in session.

The login/authentication from Android would only be used for API calls, and 
not for browsing the site. In the 'tokens' table, there would be 
information about the user that would be similar to the Auth info stored in 
session. When the token is passed to web2py, it would return the same 
information that would normally be stored in session about the user.

Thanks again for your help and checking my logic, I'm still pretty new to 
this!

On Thursday, January 3, 2013 7:57:45 PM UTC-8, dlypka wrote:
>
> But are you reconnecting to the same web2py session on each request?
>
> On Thursday, January 3, 2013 3:20:01 PM UTC-6, Mark Li wrote:
>>
>> I reviewed your code again and looked into the source code for web2py to 
>> see how web2py deals with session login cookies.
>>
>> For what I want to accomplish, I believe I have found a method which does 
>> not involved changing web2py source code. It's simpler and more straight 
>> forward for me to wrap my head around (also not having to worry about 
>> storing cookies in the app). Please let me know if there's anything 
>> important I am missing or security flaws that I should consider.
>>
>>
>> 1. Embed webview into native Android app, using auth.login_bare to 
>> authenticate.
>> 2. On login success, return a token of similar format to web2py's session 
>> cookies.
>> 3. Store this token in the database (in a table named 'tokens'), and send 
>> back to Android app as a cookie
>> 4. For every request to my web service that requires authentication, send 
>> the token as a cookie and have the receiving API controller function 
>> extract the cookie/token. If the token is currently in the db.tokens, then 
>> the user has been authenticated and the request returns the appropriate 
>> data.
>> 5. On logout/password change, delete the issued tokens for this user from 
>> db.tokens, so the same token can't be used to authenticate for future api 
>> calls.
>>
>> On Tuesday, January 1, 2013 10:33:26 PM UTC-8, dlypka wrote:
>>>
>>> I was not precisely calling from a native Android or native IOS app.
>>> I was using a PhoneGap client, which is different. It is looks like a 
>>> web browser but is not a browser client.
>>> PhoneGap can only use HTML5 storage unless you write a native Android / 
>>> IOS PhoneGap extension/plugin.
>>> So my technique will work from almost any client platform, even from a 
>>> Windows native client app for example
>>> as long as it uses HTTP.
>>>
>>> Also, in my tracing of how web2py handles the client connection, I 
>>> believe I found a few wrinkles in the sequence of events
>>> which needed to be handled specially in this case where the client is 
>>> not a web browser.
>>>
>>> In your particular case, if you have cookies in the native client, then 
>>> that is one less problem to solve,
>>> You probably just have to mimic the HTTP messages that a browser would 
>>> send.
>>>
>>> On Tuesday, January 1, 2013 5:19:50 PM UTC-6, Mark Li wrote:
>>>>
>>>> Thanks for the responses, and Happy New Years to you guys too!
>>>>
>>>> dlypka, for your cookieless solution, it assumes that the client app 
>>>> can't store/extract tokens? In the Google Android link above, it says that 
>>>> both Android and iOS can read and extract the tokens/cookies. So when the 
>>>> Android app calls the Web2py app, wouldn't it just pass in the 
>>>> cookie/token 
>>>> and have Web2py verify it as it Web2py normally verifies session login 
>>>> cookies?
>>>>
>>>>
>>>>
>>>> On Tuesday, January 1, 2013 9:07:16 AM UTC-8, Massimo Di Pierro wrote:
>>>>>
>>>>> :-)
>>>>>
>>>>>
>>>>>
>>>>> On Tuesday, 1 January 2013 10:45:47 UTC-6, dlypka wrote:
>>>>>>
>>>>>> Yes it is my New Year's Resolution to make time to put it in a Slice.
>>>>>>
>>>>>> On Tuesday, January

[web2py] Re: Remember me with custom or alternate login?

2013-06-05 Thread Mark Li
Does anyone know why the session.auth.remember and session.auth.expiration 
are only saved after a new page load?

Currently, I am making an ajax call that sets session.auth.remember and 
session.auth.expiration (after auth.login_bare()). If I close the browser 
after the ajax call without a new page load, then the session.auth.remember 
is not saved and the user is not logged in.

However, if I make the ajax call, then load a new page/refresh the page, 
and then close the browser, session.auth.remember is saved.

Is there any reason why a page refresh/load does this, and why the ajax 
call alone will not save session.auth.remember and session.auth.expiration 
(and thus keep the user logged in)?

-- 

--- 
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: Remember me with custom or alternate login?

2013-06-06 Thread Mark Li
Here's the relevant part of the code I'm using. I make an ajax call to the 
function below

def ajax_login():
email = request.vars.email
password = request.vars.password
remember_me = request.vars.remember_me

user = auth.login_bare(email, password)
if user:
if remember_me:
session.auth.expiration = auth.settings.long_expiration
session.auth.remember = True



-- 

--- 
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: Remember me with custom or alternate login?

2013-06-06 Thread Mark Li
Ahh yep that did the trick, thanks for the help Anthony!

On Thursday, June 6, 2013 3:07:31 PM UTC-7, Anthony wrote:
>
> Yes, sorry, there's one more thing you have to do -- you have to convert 
> the session cookie to a non-session cookie:
>
> response.cookies[response.session_id_name]["expires"] = session.auth.
> expiration
>
> That will happen the next time Auth is initialized (which would happen on 
> the next request), but it won't happen if you simply close the browser.
>
> Anthony
>
> On Thursday, June 6, 2013 5:33:37 PM UTC-4, Mark Li wrote:
>>
>> Here's the relevant part of the code I'm using. I make an ajax call to 
>> the function below
>>
>> def ajax_login():
>> email = request.vars.email
>> password = request.vars.password
>> remember_me = request.vars.remember_me
>>
>> user = auth.login_bare(email, password)
>> if user:
>> if remember_me:
>> session.auth.expiration = auth.settings.long_expiration
>> session.auth.remember = True
>>
>>
>>
>>

-- 

--- 
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] Inner join and left join in a many to many relationship

2013-07-17 Thread Mark Li
I have an intermediate table representing a many to many relationship 
between users and songs. Users can like/dislike many songs, and songs can 
be liked/disliked by many users. I am trying to retrieve a list of 30 
songs, that can be any songs except for songs that have been disliked by 
the user.

Here's a simplified version of the 3 tables:

#Table 1: 
db.define_table('auth_user',
Field('id')
)

#Table 2:
db.define_table('songs',
Field('id')
)

#Table 3 (intermediate)
db.define_table('likes_and_dislikes',
Field('username', 'reference auth_user'),
Field('songname','reference songs'),
Field('like_score', 'integer')
)



Originally I had made 2 database selects to accomplish this, first finding 
all the songs that have been disliked by the user (this can be a very high 
number), and then querying songs to avoid the disliked songs:

disliked_ids = []
dislike_query = (db.likes.username==auth.user.id) & (db.likes.like_score==-1
) #score of -1 represents a dislike
disliked_songs = db(dislike_query).select().as_list()
for row in disliked_songs:
disliked_ids.append(row['songname'])

query = (~db.songinfo.id.belongs(disliked_ids))
song_rows = db(pre_query).select(orderby='', limitby=(0,30))


I'm sure there's a more efficient way to do this, and I have been looking 
into left joins and inner joins to accomplish everything in one database 
select. My understanding of joins get a little hazy once there needs to be 
more than join performed, any help is appreciated!



-- 

--- 
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: Inner join and left join in a many to many relationship

2013-07-18 Thread Mark Li
I think I've figured it out. I just needed one left join, but with the two 
arguments in the ON clause:


query = ((db.likes.like_score!=-1) | (db.likes.like_score==None))
rows = db(query).select(db.songs.ALL, db.auth_user.id, db.likes.like_score,
left=db.likes.on((db.likes.songname == db.songs.id) & (db.likes.username 
== auth.user.id)) 
, orderby='', limitby=(0,30))


If there are any mistakes please let me know!

On Wednesday, July 17, 2013 8:05:18 PM UTC-7, Mark Li wrote:
>
> I have an intermediate table representing a many to many relationship 
> between users and songs. Users can like/dislike many songs, and songs can 
> be liked/disliked by many users. I am trying to retrieve a list of 30 
> songs, that can be any songs except for songs that have been disliked by 
> the user.
>
> Here's a simplified version of the 3 tables:
>
> #Table 1: 
> db.define_table('auth_user',
> Field('id')
> )
>
> #Table 2:
> db.define_table('songs',
> Field('id')
> )
>
> #Table 3 (intermediate)
> db.define_table('likes_and_dislikes',
> Field('username', 'reference auth_user'),
> Field('songname','reference songs'),
> Field('like_score', 'integer')
> )
>
>
>
> Originally I had made 2 database selects to accomplish this, first finding 
> all the songs that have been disliked by the user (this can be a very high 
> number), and then querying songs to avoid the disliked songs:
>
> disliked_ids = []
> dislike_query = (db.likes.username==auth.user.id) & (db.likes.like_score
> ==-1) #score of -1 represents a dislike
> disliked_songs = db(dislike_query).select().as_list()
> for row in disliked_songs:
> disliked_ids.append(row['songname'])
>
> query = (~db.songinfo.id.belongs(disliked_ids))
> song_rows = db(pre_query).select(orderby='', limitby=(0,30))
>
>
> I'm sure there's a more efficient way to do this, and I have been looking 
> into left joins and inner joins to accomplish everything in one database 
> select. My understanding of joins get a little hazy once there needs to be 
> more than join performed, any help is appreciated!
>
>
>
>

-- 

--- 
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] Force user to reenter password to save auth.profile() changes

2013-08-07 Thread Mark Li
I currently have a "settings" page, where a form created by auth.profile() 
is displayed. I want to force the user to re-enter his/her password in 
order to save any changes they make to their profile (such as email, 
username, etc).

Not really sure the best way to go about this, all the authentication stuff 
I've dealt with involves logging the user in with both email and pw. In 
this case, the user is already logged in, but I just want them to reenter 
their password before changing important profile information.

-- 

--- 
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: Force user to reenter password to save auth.profile() changes

2013-08-09 Thread Mark Li
For anyone else wondering how to do this, I decided to add a "password" 
field and have onvalidation check the password.

This link gave me the idea for checking the text password against the 
encrypted pw: 
https://groups.google.com/forum/#!msg/web2py/eqbXmseZ6XA/abnGIMevI6wJ

On Wednesday, August 7, 2013 10:18:17 PM UTC-7, Mark Li wrote:
>
> I currently have a "settings" page, where a form created by auth.profile() 
> is displayed. I want to force the user to re-enter his/her password in 
> order to save any changes they make to their profile (such as email, 
> username, etc).
>
> Not really sure the best way to go about this, all the authentication 
> stuff I've dealt with involves logging the user in with both email and pw. 
> In this case, the user is already logged in, but I just want them to 
> reenter their password before changing important profile information.
>

-- 

--- 
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] Specifying onvalidation with auth.profile() prevents default onaccepts method

2013-09-05 Thread Mark Li
Currently I am creating a form with auth.profile()

I have an onvalidation method to perform some extra checks.

form = auth.profile()
if form.process(onvalidation=reauthenticate_user).accepted:

response.flash = "Changes Saved"
elif form.errors:

response.flash = "Errors found



This prevented auth.user object from being updated, which auth.profile() 
usually takes care of.

I also tried it with the following:

form = auth.profile()
form.process(onvalidation=reauthenticate_user)



but the default accepts method that usually updates auth.user doesn't work 
either

For now, I've just added the following to the accepted method:
auth.user.update(db.auth_user._filter_fields(form.vars)) 

But I'm interested in knowing if it's possible to specify an onvalidation 
method for auth.profile(), while still using the built-in accepts method.

-- 

--- 
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: Specifying onvalidation with auth.profile() prevents default onaccepts method

2013-09-05 Thread Mark Li
Thanks Massimo. However, using 
auth.settings.profile_onvalidation.append(reauthenticate_user)

has presented a problem of its own.

I insert an extra field ("confirm_password"), to recheck in the 
onvalidation method. However, the form.vars does not contain 
form.vars.confirm_password, which worked before when I was using form.
process(onvalidation=reauthenticate_user)


Here is the relevant code:

auth.settings.profile_onvalidation.append(reauthenticate_user)
form=auth.profile()
my_extra_element = TR(LABEL('Confirm Password'),INPUT(_type="password",_name
="confirm_password", _class="string"))
form[0].insert(-1,my_extra_element)


def reauthenticate_user(form):
#recheck the user password
plain_password = form.vars.confirm_password
if db.auth_user.password.validate(plain_password) != (db(db.auth_user.id
==auth.user.id).select().first().password, None):
form.errors.confirm_password = "Must enter correct password"


The form passed into reauthenticate_user does not contain 
form.vars.confirm_password variable. Any ideas on why this happens now, but 
not before?


On Thursday, September 5, 2013 4:46:11 PM UTC-7, Massimo Di Pierro wrote:
>
> This
>
> form = auth.profile()
> form.process(onvalidation=reauthenticate_user)
>
> is wrong because auth.profile() already calls process inside. Instead you 
> should do:
>
> auth.settings.profile_onvalidation.append(reauthenticate_user)
> form = auth.profile()
>
> On Thursday, 5 September 2013 17:42:18 UTC-5, Mark Li wrote:
>>
>> Currently I am creating a form with auth.profile()
>>
>> I have an onvalidation method to perform some extra checks.
>>
>> form = auth.profile()
>> if form.process(onvalidation=reauthenticate_user).accepted:
>>
>> response.flash = "Changes Saved"
>> elif form.errors:
>>
>> response.flash = "Errors found
>>
>>
>>
>> This prevented auth.user object from being updated, which auth.profile() 
>> usually takes care of.
>>
>> I also tried it with the following:
>>
>> form = auth.profile()
>> form.process(onvalidation=reauthenticate_user)
>>
>>
>>
>> but the default accepts method that usually updates auth.user doesn't 
>> work either
>>
>> For now, I've just added the following to the accepted method:
>> auth.user.update(db.auth_user._filter_fields(form.vars)) 
>>
>> But I'm interested in knowing if it's possible to specify an onvalidation 
>> method for auth.profile(), while still using the built-in accepts method.
>>
>

-- 

--- 
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: Specifying onvalidation with auth.profile() prevents default onaccepts method

2013-09-06 Thread Mark Li
Ahh ok, thanks Anthony. If the form is being processed before adding the 
extra element to the DOM, then is it possible to add an error like 

form.errors.confirm_password = "Must enter correct password"

This would usually cause the error message to appear below the input row, 
but the confirm_password field does not display the error in this case. 
Would I have to manually check for an error and add an error div, or is 
there still a way to use the builtin error messages?

On Friday, September 6, 2013 6:42:40 AM UTC-7, Anthony wrote:
>
> You are adding an element to the form DOM after the form has been 
> processed, so the new field will not get added to form.vars. However, in 
> your onvalidation function, you should be able to replace 
> form.vars.confirm_password with request.vars.confirm_password.
>
> Anthony
>
> On Friday, September 6, 2013 2:17:49 AM UTC-4, Mark Li wrote:
>>
>> Thanks Massimo. However, using 
>> auth.settings.profile_onvalidation.append(reauthenticate_user)
>>
>> has presented a problem of its own.
>>
>> I insert an extra field ("confirm_password"), to recheck in the 
>> onvalidation method. However, the form.vars does not contain 
>> form.vars.confirm_password, which worked before when I was using form.
>> process(onvalidation=reauthenticate_user)
>>
>>
>> Here is the relevant code:
>>
>> auth.settings.profile_onvalidation.append(reauthenticate_user)
>> form=auth.profile()
>> my_extra_element = TR(LABEL('Confirm Password'),INPUT(_type="password",
>> _name="confirm_password", _class="string"))
>> form[0].insert(-1,my_extra_element)
>>
>>
>> def reauthenticate_user(form):
>> #recheck the user password
>> plain_password = form.vars.confirm_password
>> if db.auth_user.password.validate(plain_password) != (db(db.auth_user
>> .id==auth.user.id).select().first().password, None):
>> form.errors.confirm_password = "Must enter correct password"
>>
>>
>> The form passed into reauthenticate_user does not contain 
>> form.vars.confirm_password variable. Any ideas on why this happens now, but 
>> not before?
>>
>>
>> On Thursday, September 5, 2013 4:46:11 PM UTC-7, Massimo Di Pierro wrote:
>>>
>>> This
>>>
>>> form = auth.profile()
>>> form.process(onvalidation=reauthenticate_user)
>>>
>>> is wrong because auth.profile() already calls process inside. Instead 
>>> you should do:
>>>
>>> auth.settings.profile_onvalidation.append(reauthenticate_user)
>>> form = auth.profile()
>>>
>>> On Thursday, 5 September 2013 17:42:18 UTC-5, Mark Li wrote:
>>>>
>>>> Currently I am creating a form with auth.profile()
>>>>
>>>> I have an onvalidation method to perform some extra checks.
>>>>
>>>> form = auth.profile()
>>>> if form.process(onvalidation=reauthenticate_user).accepted:
>>>>
>>>> response.flash = "Changes Saved"
>>>> elif form.errors:
>>>>
>>>> response.flash = "Errors found
>>>>
>>>>
>>>>
>>>> This prevented auth.user object from being updated, which 
>>>> auth.profile() usually takes care of.
>>>>
>>>> I also tried it with the following:
>>>>
>>>> form = auth.profile()
>>>> form.process(onvalidation=reauthenticate_user)
>>>>
>>>>
>>>>
>>>> but the default accepts method that usually updates auth.user doesn't 
>>>> work either
>>>>
>>>> For now, I've just added the following to the accepted method:
>>>> auth.user.update(db.auth_user._filter_fields(form.vars)) 
>>>>
>>>> But I'm interested in knowing if it's possible to specify an 
>>>> onvalidation method for auth.profile(), while still using the built-in 
>>>> accepts method.
>>>>
>>>

-- 

--- 
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] 1071, 'Specified key was too long; max key length is 767 bytes'

2013-10-09 Thread Mark Li
Just wanted to chime in on this.

For me, I had to add a "length=255" to all my "unique=True" fields, even 
after adding length=255 for the "string" fields.

On Wednesday, October 9, 2013 11:46:48 AM UTC-7, Niphlod wrote:
>
> sorry for being late. This is from web2py's 2.6.0 changelog.
>
> Attention MySQL users: The length of string fields changed from 255 to 512 
> bytes. If you have migrations enabled this will trigger a large migration. 
> To prevent it, first set migrate_enabled=False, upgrade, check everything 
> is ok, then add length=255 to your string Fields, then re-enable migrations 
> with migrate_enabled=True if needed.
>
> tl;dr: remember to ALWAYS set length= for strings.
>
> tl;dr n.2 : Mysql has huge issues. One of them is that you can't index a 
> too large column. 
>
>
> On Wednesday, October 9, 2013 9:25:51 AM UTC+2, Gwayne aka Mike Veltman 
> wrote:
>>
>>   
>>
>> I found it. 
>>
>>  
>>
>> It was in db.py
>>
>>  
>>
>> db.define_table('frame',
>>
>>  
>>
>> Field('framename', type='string',
>>
>> # #unique=True, < 
>> the problem. Is it a bug ?
>>
>> label=T('Framename')),
>>
>> Field('description', type='string',
>>
>> label=T('Description')),
>>
>> Field('netboot', type='string',default="None",
>>
>> label=T('Netboot information')),
>>
>> Field('ip', type='string',
>>
>> #unique=True,
>>
>> label=T('IP Address')),
>>
>> Field('servermodel', type='string',default="p6",
>>
>> label=T('Server model')),
>>
>> Field('serial', type='string',default="None",
>>
>> label=T('Serial Number')),
>>
>> Field('lvname', type='string',default="FRAMEx",
>>
>> label=T('Frame extension for storage logical volumes')),
>>
>> Field('framestaterecord_ID', type='integer',
>>
>> label=T('Frame State record ID')),
>>
>> Field('created_on','datetime',default=request.now,
>>
>> label=T('Created On'),writable=False,readable=False),
>>
>> Field('modified_on','datetime',default=request.now,
>>
>> label=T('Modified On'),writable=False,readable=False,
>>
>> update=request.now),
>>
>> format='%(framename)s',
>>
>> migrate=True)
>>
>>  
>>
>>  
>>
>>  
>>
>> On Tuesday 08 October 2013 13:41:31 Mike Veltman wrote:
>>
>> Ok, I am now fighting with it for two days and it drives me crazy.
>>
>> My gut feeling says mysql 5.1 --> mysql 5.5 upgrade is the cause. Am I 
>> right ? And how do I solve it. :-)
>>
>>  
>>
>> Error ticket for "adeploy"
>>
>> Ticket ID
>>
>> 192.168.2.106.2013-10-08.12-46-19.24f3f1a5-d637-4522-965b-fed4958115ed
>>
>>  (1071, 'Specified key was 
>> too long; max key length is 767 bytes')
>>
>> Version
>>   
>> web2py™
>>  
>> Version 2.7.2-stable+timestamp.2013.10.07.13.52.24
>>
>> Traceback
>>
>>  
>>   
>> 1.
>> 2.
>> 3.
>> 4.
>> 5.
>> 6.
>> 7.
>> 8.
>> 9.
>> 10.
>> 11.
>> 12.
>> 13.
>> 14.
>> 15.
>> 16.
>> 17.
>> 18.
>> 19.
>> 20.
>> 21.
>> 22.
>>  
>> Traceback (most recent call last):
>> File "/srv/web-apps/web2py/gluon/restricted.py", line 217, in restricted
>> exec ccode in environment
>> File "/srv/web-apps/web2py/applications/adeploy/compiled/models/db.py", line 
>> 178, in 
>> File "/srv/web-apps/web2py/gluon/dal.py", line 7911, in define_table
>> table = self.lazy_define_table(tablename,*fields,**args)
>> File "/srv/web-apps/web2py/gluon/dal.py", line 7948, in lazy_define_table
>> polymodel=polymodel)
>> File "/srv/web-apps/web2py/gluon/dal.py", line 1029, in create_table
>> fake_migrate=fake_migrate)
>> File "/srv/web-apps/web2py/gluon/dal.py", line 1136, in migrate_table
>> self.execute(sub_query)
>> File "/srv/web-apps/web2py/gluon/dal.py", line 1836, in execute
>> return self.log_execute(*a, **b)
>> File "/srv/web-apps/web2py/gluon/dal.py", line 1830, in log_execute
>> ret = self.cursor.execute(command, *a[1:], **b)
>> File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 173, in 
>> execute
>> self.errorhandler(self, exc, value)
>> File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 36, 
>> in defaulterrorhandler
>> raise errorclass, errorvalue
>> OperationalError: (1071, 'Specified key was too long; max key length is 
>> 767 bytes')
>>
>> In file: /srv/web-apps/web2py/applications/adeploy/compiled/models/db.pyc
>>   
>> 1.
>>  
>>  at 0x168c468, file 
>> "/srv/web-apps/web2py/applications/adeploy/compiled/models/db.py", line 
>> 28>
>>
>>  
>>
>>  
>>
>>
>>
>>

-- 
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] Database models don't import when using IPython 1.0.0 with web2py 2.7 (interactive shell)

2013-10-10 Thread Mark Li
I recently upgraded to the new version of web2py from 2.5 (on 
Pythonanywhere); everything seems to work fine except for the interactive 
shell.

Using the command "python web2py.py -M -S appname" worked fine with 2.5, 
but now it doesn't seem to import the database models. I get the error 
"name 'db' is not defined" when trying to query the database. This runs 
web2py in IPython 1.0.0

When I run Web2py in a plain python shell using "python web2py.py -M -P -S 
appname", then querying the database works fine. 

Not the biggest problem, but I do enjoy using IPython and wanted to see if 
others were having problems with the database models not importing (even 
with the -M option). I'm doing this on Pythonanywhere; the problem arose 
immediately after the web2py upgrade and not any Pythonanywhere changes.

-- 
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] Retrieving user id for auth.settings.reset_password_onaccept

2013-10-19 Thread Mark Li
I'm trying to retrieve the user id for 
auth.settings.reset_password_onaccept.append( code needing user id here). 
The user is not logged in when they reset their password.

The auth.reset_password function contains the user object, but I'm not sure 
how I can obtain that user id to use in onaccept.append, because the user 
id is not one of the form variables. Any help is appreciated!

-- 
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: 2.4.7 problems

2013-10-20 Thread Mark Li
I've just encountered this problem myself, and I opened a ticket about this 
since I couldn't find one already posted.

http://code.google.com/p/web2py/issues/detail?id=1736&thanks=1736&ts=1382314136

-- 
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] cache.action questions (views with db selects, and different views for logged-in users)

2013-10-20 Thread Mark Li
I have 2 questions about cache.action

Firstly, I am looking into cache.action to cache several static pages 
(about, contact, etc), that rarely change content.

For users who aren't logged in, the pages would be the same. However, if a 
user is logged in, then there are links to the users' profile, as well as a 
logout link; thus making the page different for every user, and different 
for logged-in vs. non-logged-in users. Is there any way to effectively 
cache these pages, or only cache the non-logged in page for non-logged in 
viewers?


Secondly, cache.action can't be used to cache views with database selects. 
However, if the database select was converted to a list/dict, with 
as_list() or as_dict(), would caching the page with cache.action be 
possible (this would make it pickleable as a regular dictionary)?

Would there be a significant improvement of using cache.action to cache the 
view that has a database select, over simply caching the select?

-- 
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: cache.action questions (views with db selects, and different views for logged-in users)

2013-10-21 Thread Mark Li
Thanks Niphlod and Anthony! That answered my question about caching views 
with database selects. However, my problem with client-side caching 
differently for logged-in and non-logged in users is still a problem.

Niphlod, I'm not sure what you're referring to by the "user" parameter. The 
closet parameters to "user" would be "session" and "public". But I don't 
see these options helping to differentiate between logged in and non-logged 
for caching. Doesn't "session" only add a session id key for server-side 
caching, and "public" only determine whether a cache is useable on a single 
user's machine, or the user's network?

Anthony, my problem still persists with your code; the "public" parameter 
does not seem to be the proper parameter for this problem.

For example, when a user first hits the page (not logged-in), the public 
parameter will be set to True. This will cache the page in it's non-logged 
in state. If the user then logs in, and hits the page again, the browser 
will serve the non-logged-in version of the page from cache.

No matter what the value of "public" is (unless the browser doesn't cache 
at all for public=false), if the user hits the page in either 
logged-in/non-logged in state, and goes to the same page later in the 
opposite state, the browser will serve the previously cached version of 
that page (which will be in the wrong logged-in/non-logged in state).

The "public" parameter, if set to False, is helpful in preventing cached 
logged-in versions of the site from being the same across users. However, 
for each user, it does not help differentiate between logged in and 
non-logged cache pages.


I've done some more research, and there doesn't seem to be any 
straightforward or practical ways of doing this. The main problem is that 
the browser can't tell whether a cached page is logged-in/not-logged in 
(since it's the same URL). Let me know if I'm missing something here, I'd 
like to take advantage of cache.action.



On Monday, October 21, 2013 6:07:56 AM UTC-7, Anthony wrote:
>
>
> For users who aren't logged in, the pages would be the same. However, if a 
>> user is logged in, then there are links to the users' profile, as well as a 
>> logout link; thus making the page different for every user, and different 
>> for logged-in vs. non-logged-in users. Is there any way to effectively 
>> cache these pages, or only cache the non-logged in page for non-logged in 
>> viewers?
>>
>
> cache.action does two things -- it sends appropriate response headers to 
> the browser to enable client-side caching, and it (optionally) does 
> server-side caching via the web2py cache mechanism. You might want to avoid 
> doing per-user server-side caching, as that will start to fill up server 
> memory, and you'd have to make sure you manually clear cached values 
> periodically. Maybe consider something like:
>
> @cache.client(cache_model=cache.ram if not auth.is_logged_in() else None,
>   public=not auth.is_logged_in(), ...)
>
> That will do server-side caching of the non-logged-in page only, and it 
> will set public client-side caching to False for logged in users.
>  
>
>> Secondly, cache.action can't be used to cache views with database 
>> selects. However, if the database select was converted to a list/dict, with 
>> as_list() or as_dict(), would caching the page with cache.action be 
>> possible (this would make it pickleable as a regular dictionary)?
>>
>
> Not sure what you mean -- can you show some code? cache.action caches only 
> the output of the decorated function (and only if cache_model is specified 
> -- otherwise, all it does is send headers to the browser to enable 
> client-side caching).
>
> 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/groups/opt_out.


[web2py] After reset password, delete rows from table associated with user

2013-11-05 Thread Mark Li
I currently have a table of tokens

db.define_table('mobile_tokens',
Field ('username', 'reference auth_user'),
Field ('token')
)

After a user resets their password, all the mobile tokens for that user 
should also be deleted.


After a user resets their password, is it possible to user 
auth.settings.reset_password_onvalidation to get the id of the user (who 
just changed their password), in order to delete the mobile_tokens 
associated with that user? The user is not yet logged in, so auth.user.id 
doesn't work.

So far, I have been resorting to the auth.settings.reset_password_next to 
delete the mobile_tokens once the user is on the redirect page. However, 
the purpose of the redirect page is just to show confirmation that the 
password has changed, not to clear the mobile_tokens on every visit. It 
seems more logical to have the mobile_token deletion be attached to the 
reset_password function.


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


[web2py] Re: After reset password, delete rows from table associated with user

2013-11-06 Thread Mark Li
Thanks for pointing me in the right direction, Stifan.

I added this line to the model file:
db.auth_user._after_update.append(lambda s: remove_mobile_token(s, db))

and this function in a module

def remove_mobile_token(set, db):
request = current.request

#delete mobile tokens if the change IS NOT from reset_password
if request.function == "user" and request.args>0 and request.args(0)==
"reset_password" :
user_id = set.select().first().id
db(db.mobile_tokens.username==user_id).delete()
db.commit()

I tried using the f variable from the after_update callback (containing 
dictionary of fields to be updated) to check for existence of "password" in 
f, but changes to the auth_user table using auth.profile() form contains 
all the fields for auth_user, thus any changes using the auth.profile() 
form would trigger a mobile_token deletion.

To make sure only changes to the password field would trigger mobile_token 
deletion, I check that the request is coming from the user/reset_password.

On Wednesday, November 6, 2013 4:51:33 AM UTC-8, 黄祥 wrote:
>
> i think you can achieve it using after_update callback. define 
> after_update function for auth_user to delete the mobile_tokens row that 
> associated with user.
>
> ref:
>
> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#before-and-after-callbacks
>
> 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] Saving incomplete form with required fields (to prevent dynamically added form inputs from disappear

2013-11-23 Thread Mark Li

I currently have 2 tables as follows, with a form containing values both 
tables

db.define_table('playlist',
 Field('title', notnull=True),
 Field('description'),
 Field('tags'),
 Field('genre', 'reference genre')
 Field('finished', 'boolean')
)

db.define_table('playlist_tracks',
Field('playlist', 'reference playlist'),
Field('songname')
)



The form to add playlist_tracks is dynamic; a user enters a songname, which 
appends an input element with value=songname. When the user submits the 
form, if the form does not pass validation, then the playlist_tracks will 
all disappear when the page reloads, since they were added dynamically.

I want to prevent this from happening, as it can be very time consuming to 
add all the playlist tracks. I want to save the playlist_tracks in the 
reference table so they don't disappear, but it's not possible because 
there is no 'playlist' reference (the playlist didn't pass validation). I 
also want to give the user the option of "saving" an incomplete form to 
work on later, which has the same problem because the incomplete form might 
not pass validation, and thus there is no 'playlist' reference.

What would be the best method of saving this incomplete form, so the 
dynamically added playlist tracks will have a playlist reference?

I was thinking about inserting the record with dummy default values, after 
validation fails, but that has the disadvantage of automatically filling a 
required field that the user didn't choose. For example, if a user doesn't 
enter a title and doesn't select a genre from the select drop-down, then 
after validation fails, I'll insert the record with "Untitled Playlist" and 
genre==1 (and all other fields that passed validation would remain 
unchanged) but still show the form errors. 


-- 
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: Saving incomplete form with required fields (to prevent dynamically added form inputs from disappear

2013-11-23 Thread Mark Li
I think I've found an optimal solution for this.

Since the validators for my table are only enforced at the form-level, I 
first insert a blank playlists record, and then use a SQLFORM or CRUD to 
update the newly inserted record. I can't submit an incomplete form, but I 
can insert an incomplete record and mark the "finished" column as false.

This way, the playlist id already exists and I can save the playlist_tracks 
to the reference table. The validators will still apply when the user 
submits the form.

On Saturday, November 23, 2013 6:50:19 PM UTC-8, Mark Li wrote:
>
>
> I currently have 2 tables as follows, with a form containing values both 
> tables
>
> db.define_table('playlist',
>  Field('title', notnull=True),
>  Field('description'),
>  Field('tags'),
>  Field('genre', 'reference genre')
>  Field('finished', 'boolean')
> )
>
> db.define_table('playlist_tracks',
> Field('playlist', 'reference playlist'),
> Field('songname')
> )
>
>
>
> The form to add playlist_tracks is dynamic; a user enters a songname, 
> which appends an input element with value=songname. When the user submits 
> the form, if the form does not pass validation, then the playlist_tracks 
> will all disappear when the page reloads, since they were added dynamically.
>
> I want to prevent this from happening, as it can be very time consuming to 
> add all the playlist tracks. I want to save the playlist_tracks in the 
> reference table so they don't disappear, but it's not possible because 
> there is no 'playlist' reference (the playlist didn't pass validation). I 
> also want to give the user the option of "saving" an incomplete form to 
> work on later, which has the same problem because the incomplete form might 
> not pass validation, and thus there is no 'playlist' reference.
>
> What would be the best method of saving this incomplete form, so the 
> dynamically added playlist tracks will have a playlist reference?
>
> I was thinking about inserting the record with dummy default values, after 
> validation fails, but that has the disadvantage of automatically filling a 
> required field that the user didn't choose. For example, if a user doesn't 
> enter a title and doesn't select a genre from the select drop-down, then 
> after validation fails, I'll insert the record with "Untitled Playlist" and 
> genre==1 (and all other fields that passed validation would remain 
> unchanged) but still show the form errors. 
>
>
>

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


Re: [web2py] Re: Saving incomplete form with required fields (to prevent dynamically added form inputs from disappear

2013-11-26 Thread Mark Li
Yep, the "finished" field will prevent the unfinished records from being
exposed where they shouldn't be.



On Mon, Nov 25, 2013 at 11:15 AM, Dave S  wrote:

> On Saturday, November 23, 2013 11:44:05 PM UTC-8, Mark Li wrote:
>>
>> I think I've found an optimal solution for this.
>>
>> Since the validators for my table are only enforced at the form-level, I
>> first insert a blank playlists record, and then use a SQLFORM or CRUD to
>> update the newly inserted record. I can't submit an incomplete form, but I
>> can insert an incomplete record and mark the "finished" column as false.
>>
>> This way, the playlist id already exists and I can save the
>> playlist_tracks to the reference table. The validators will still apply
>> when the user submits the form.
>>
>>
> As long as the "finished" field is adequate protection from having an
> incomplete or invalid entry messing up some of your db table processing at
> a later time if the user doesn't correct the form.  I think I would have
> done something with storing partials in the session, but maybe one the
> Respected Regulars has some alternative advice.
>
> /dps
>
>
>
>> On Saturday, November 23, 2013 6:50:19 PM UTC-8, Mark Li wrote:
>>>
>>>
>>> I currently have 2 tables as follows, with a form containing values both
>>> tables
>>>
>>> db.define_table('playlist',
>>>  Field('title', notnull=True),
>>>  Field('description'),
>>>  Field('tags'),
>>>  Field('genre', 'reference genre')
>>>  Field('finished', 'boolean')
>>> )
>>>
>>> db.define_table('playlist_tracks',
>>> Field('playlist', 'reference playlist'),
>>> Field('songname')
>>> )
>>>
>>>
>>>
>>> The form to add playlist_tracks is dynamic; a user enters a songname,
>>> which appends an input element with value=songname. When the user submits
>>> the form, if the form does not pass validation, then the playlist_tracks
>>> will all disappear when the page reloads, since they were added dynamically.
>>>
>>> I want to prevent this from happening, as it can be very time consuming
>>> to add all the playlist tracks. I want to save the playlist_tracks in the
>>> reference table so they don't disappear, but it's not possible because
>>> there is no 'playlist' reference (the playlist didn't pass validation). I
>>> also want to give the user the option of "saving" an incomplete form to
>>> work on later, which has the same problem because the incomplete form might
>>> not pass validation, and thus there is no 'playlist' reference.
>>>
>>> What would be the best method of saving this incomplete form, so the
>>> dynamically added playlist tracks will have a playlist reference?
>>>
>>> I was thinking about inserting the record with dummy default values,
>>> after validation fails, but that has the disadvantage of automatically
>>> filling a required field that the user didn't choose. For example, if a
>>> user doesn't enter a title and doesn't select a genre from the select
>>> drop-down, then after validation fails, I'll insert the record with
>>> "Untitled Playlist" and genre==1 (and all other fields that passed
>>> validation would remain unchanged) but still show the form errors.
>>>
>>>
>>>  --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/GG0oaBNSthE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


[web2py] Prevent multiple submit buttons from showing "Working..." on submit

2013-12-04 Thread Mark Li
I currently have 2 submit buttons in a form. When a user clicks on one of 
them, it changes both submit input values to "Working..."

I looked into web2py.js and tried applying the suggestion there for 
preventing "Working.." from showing up on the buttons


/*if you don't want to see "working..." on buttons, replace the following
  * two lines with this one
  * el.data('w2p_disable_with', el[method]());
  */

This would be fine with 1 submit button. However, with 2 submit buttons, 
the value of the 2nd submit button is changed to the value of the 1st.

For example, button 1 text is "Save", and button 2 text is "Post", clicking 
on either will change button 2 text to "Save" (after applying the 
suggestions from web2py.js


Is there any way to disable the changing of the value/text of the submit 
input on submission (for multiple submit buttons in 1 form)?

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


[web2py] Re: Prevent multiple submit buttons from showing "Working..." on submit

2013-12-05 Thread Mark Li
Hey Niphlod,

The 2 submit buttons have different names, here's the resulting HTML.










However, clicking on either results in both having the "working..." 
message. Is this not intended behavior?

One of the form submit buttons is from the SQLFORM (i add a _name attribute 
later), and the other one I insert into the form.

On Thursday, December 5, 2013 12:50:00 PM UTC-8, Niphlod wrote:
>
> uhm, you're right. However, usually with different submit buttons you'd 
> likely have one of them having a "name" attribute (and those are "excluded" 
> from being put in the "working..." state) is this your case ?
>
> How are you handling different "posts" based on the fact that the user 
> clicks on one instead of the other ?
>
> BTW2: if any "clickable-something" has a data-w2p_disable_with attribute, 
> that one is used instead of the default "Working..." 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.


Re: [web2py] Re: Prevent multiple submit buttons from showing "Working..." on submit

2013-12-07 Thread Mark Li
My web2py.js is the same as the one shipped with the latest web2py.

I also tried adding a "data-w2p_disable_with" attribute to the input, but
it didn't change to the attribute value:




On Fri, Dec 6, 2013 at 11:55 AM, Niphlod  wrote:

> can you please check that your web2py.js is the same one shipped with the
> latest web2py ?
> You can fetch it here
>
> https://raw.github.com/web2py/web2py/master/applications/welcome/static/js/web2py.js
>
>
> On Friday, December 6, 2013 12:31:17 AM UTC+1, Mark Li wrote:
>>
>> Hey Niphlod,
>>
>> The 2 submit buttons have different names, here's the resulting HTML.
>>
>> 
>> 
>> 
>> > />
>> 
>> 
>> 
>> 
>>
>> However, clicking on either results in both having the "working..."
>> message. Is this not intended behavior?
>>
>> One of the form submit buttons is from the SQLFORM (i add a _name
>> attribute later), and the other one I insert into the form.
>>
>> On Thursday, December 5, 2013 12:50:00 PM UTC-8, Niphlod wrote:
>>>
>>> uhm, you're right. However, usually with different submit buttons you'd
>>> likely have one of them having a "name" attribute (and those are "excluded"
>>> from being put in the "working..." state) is this your case ?
>>>
>>> How are you handling different "posts" based on the fact that the user
>>> clicks on one instead of the other ?
>>>
>>> BTW2: if any "clickable-something" has a data-w2p_disable_with
>>> attribute, that one is used instead of the default "Working..." 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/aT_YWu0Ublo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: [web2py] Re: Prevent multiple submit buttons from showing "Working..." on submit

2013-12-11 Thread Mark Li
I looked into the code and my web2py.js was not the same as the github
link, which I noticed because my forminputclickselector did not contain

:not([name])

. When I diff-ed the original link for the newest web2py.js, with my
current web2py.js, it showed no difference. Very odd, maybe I had an old
web2py.js in browser cache. Sorry for the confusion.


On Mon, Dec 9, 2013 at 2:54 AM, Martin Weissenboeck wrote:

> Interesting. My minimal app does not show any "Working..." message.
> I have to make more tests.
>
>
> 2013/12/9 Martin Weissenboeck 
>
>> ok, maybe during the next two hours.
>>
>>
>> 2013/12/9 Niphlod 
>>
>>> this is really unexpected.
>>> this line
>>>
>>> https://github.com/web2py/web2py/blob/master/applications/welcome/static/js/web2py.js#L462
>>> "selects" all the inputs in the form ... that syntax **should** leave
>>> out all inputs with a name attribute....
>>> Can you pack a minimal app to reproduce the issue ?
>>>
>>>
>>>
>>> On Sunday, December 8, 2013 3:28:06 AM UTC+1, Mark Li wrote:
>>>
>>>> My web2py.js is the same as the one shipped with the latest web2py.
>>>>
>>>> I also tried adding a "data-w2p_disable_with" attribute to the input,
>>>> but it didn't change to the attribute value:
>>>>
>>>> 
>>>>
>>>>
>>>> On Fri, Dec 6, 2013 at 11:55 AM, Niphlod  wrote:
>>>>
>>>>> can you please check that your web2py.js is the same one shipped with
>>>>> the latest web2py ?
>>>>> You can fetch it here
>>>>> https://raw.github.com/web2py/web2py/master/applications/
>>>>> welcome/static/js/web2py.js
>>>>>
>>>>>
>>>>> On Friday, December 6, 2013 12:31:17 AM UTC+1, Mark Li wrote:
>>>>>>
>>>>>> Hey Niphlod,
>>>>>>
>>>>>> The 2 submit buttons have different names, here's the resulting HTML.
>>>>>>
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>>
>>>>>> However, clicking on either results in both having the "working..."
>>>>>> message. Is this not intended behavior?
>>>>>>
>>>>>> One of the form submit buttons is from the SQLFORM (i add a _name
>>>>>> attribute later), and the other one I insert into the form.
>>>>>>
>>>>>> On Thursday, December 5, 2013 12:50:00 PM UTC-8, Niphlod wrote:
>>>>>>>
>>>>>>> uhm, you're right. However, usually with different submit buttons
>>>>>>> you'd likely have one of them having a "name" attribute (and those are
>>>>>>> "excluded" from being put in the "working..." state) is this your 
>>>>>>> case ?
>>>>>>>
>>>>>>> How are you handling different "posts" based on the fact that the
>>>>>>> user clicks on one instead of the other ?
>>>>>>>
>>>>>>> BTW2: if any "clickable-something" has a data-w2p_disable_with
>>>>>>> attribute, that one is used instead of the default "Working..." 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 a topic in the
>>>>> Google Groups "web2py-users" group.
>>>>> To unsubscribe from this topic, visit https://groups.google.com/d/
>>>>> topic/web2py/aT_YWu0Ublo/unsubscribe.
>>>>>  To unsubscribe from this group and all its topics, send an email to
>>>>> web2py+un...@googlegroups.com.
>>>>>
>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>
>>>>
>>>>  --
>>> Resources:
>>> - http://web2py.com
>>> - http://web2py.

[web2py] Re: 1054, "Unknown column in 'field list'... Help me

2014-06-05 Thread Mark Li
I've had this happen several times, and the solution provided in this link 
have worked for me.

http://comments.gmane.org/gmane.comp.python.web2py/42344

On Sunday, March 9, 2014 11:58:29 PM UTC-7, sujin...@gmail.com wrote:
>
> I had made MXPDEVICE table, and I added MXPPCPLATFORM table yesterday.
> Then definition of MXPDEVICE changed as below (Red color part).
>
> -
> db.define_table('MXPDEVICE',
> Field('NAME','string', notnull=True, label='Device'),
> Field('MODEL_NO','string', required=True),
> Field('PLATFORM_ID', db.MXPPLATFORM, ondelete='NO ACTION', 
> required=True, label='Platform'),
> Field('PLATFORM_VERSION',required=True),
> Field('PC_PLATFORM_ID', db.MXPPCPLATFORM, ondelete='NO ACTION', 
> required=True, label='PC Platform'),
> Field('PC_PLATFORM_VERSION',required=True),
> Field('DEVICE_INFO', 'text', required=True),
> Field('DEFAULT_TESTER_ID', db.MXPTESTER, required=True, ondelete='NO 
> ACTION', label = 'Tester'),
> Field('DEFAULT_TEST_DEVICE_YN', 'boolean', default=True),
> Field('USE_YN', 'boolean', default=True, writable=False, readable = 
> False ),
> Field('CREATED_ON',  'datetime', default=request.now,  writable=False 
> ),
> Field('UPDATED_ON',  'datetime', update=request.now,  writable=False 
>  ))
>
> -
>
> and then I got Error..
> ===
> Database db select
> Traceback
> Traceback (most recent call last):
>   File 
> "/home/mxptest/web2py/applications/mxpTest/controllers/appadmin.py", line 
> 270, in select
> *fields, limitby=(start, stop))
>   File "/home/mxptest/web2py/gluon/dal.py", line 10335, in select
> return adapter.select(self.query,fields,attributes)
>   File "/home/mxptest/web2py/gluon/dal.py", line 1831, in select
> return self._select_aux(sql,fields,attributes)
>   File "/home/mxptest/web2py/gluon/dal.py", line 1796, in _select_aux
> self.execute(sql)
>   File "/home/mxptest/web2py/gluon/dal.py", line 1916, in execute
> return self.log_execute(*a, **b)
>   File "/home/mxptest/web2py/gluon/dal.py", line 1910, in log_execute
> ret = self.cursor.execute(command, *a[1:], **b)
>   File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py", line 166, in 
> execute
> self.errorhandler(self, exc, value)
>   File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 35, in 
> defaulterrorhandler
> raise errorclass, errorvalue
> OperationalError: (1054, "Unknown column 'MXPDEVICE.PC_PLATFORM_ID' in 
> 'field list'")
> ===
> I thought it's because of migration.
> but even though I changed the option, It wasn't solved.
>
> Thank you for your answer!!
>
>
> -
>
>
> Hi.
> I tried adding new columns, but I got that error 1054, "Unknown column in 
> 'field list'.
> As web2py document
> (set fake_migrate=True and after the metadata has been rebuilt, set
> fake_migrate=False and migrate the table again).--- I'm using MySQL), I 
> did it but the problem was not solved.
> I searched and tried many things... change migration option, delete .table 
> file etc...  But It didn't work.
>
> Is anybody who knows solution? Help m
>
> Thank you so much!!! :)
>

-- 
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] Display registration error for auth.register_bare()

2014-07-21 Thread Mark Li
Is it possible to return the registration error msg from 
auth.register_bare(), similar to how auth.register() would display the 
error msg after submit? From what I can gather in the source, seems like it 
only returns False on fail, and the user object on success. I would like to 
display more information to the user (password too short, username already 
taken, etc.), if registration fails.

I am implementing an ajax registration, where I do not want the page to 
reload on submit unless registration is successful. 

-- 
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: Display registration error for auth.register_bare()

2014-07-21 Thread Mark Li
Maybe I'm not going about this in the right way. I basically want 
auth.register() functionality, but without a page reload on registration 
fail; just a flash msg of the error.

On Monday, July 21, 2014 12:07:05 PM UTC-7, Mark Li wrote:
>
> Is it possible to return the registration error msg from 
> auth.register_bare(), similar to how auth.register() would display the 
> error msg after submit? From what I can gather in the source, seems like it 
> only returns False on fail, and the user object on success. I would like to 
> display more information to the user (password too short, username already 
> taken, etc.), if registration fails.
>
> I am implementing an ajax registration, where I do not want the page to 
> reload on submit unless registration is successful. 
>

-- 
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: Display registration error for auth.register_bare()

2014-07-22 Thread Mark Li
Hey Massimo! Just for clarification, are you referring to opening a ticket 
for:

1. auth.register() only showing a flash msg on registration error, without 
a page reload

OR

2. auth.register_bare() returning error msg on registration fail, instead 
of just False


In my case I would like functionality for #1, but I just wanted to know to 
which of my suggestions you were referring to.


On Monday, July 21, 2014 11:32:13 PM UTC-7, Massimo Di Pierro wrote:
>
> Please open a ticket. Perhaps this should be the default behavior. Easy to 
> change.
>
> On Monday, 21 July 2014 14:59:34 UTC-5, Mark Li wrote:
>>
>> Maybe I'm not going about this in the right way. I basically want 
>> auth.register() functionality, but without a page reload on registration 
>> fail; just a flash msg of the error.
>>
>> On Monday, July 21, 2014 12:07:05 PM UTC-7, Mark Li wrote:
>>>
>>> Is it possible to return the registration error msg from 
>>> auth.register_bare(), similar to how auth.register() would display the 
>>> error msg after submit? From what I can gather in the source, seems like it 
>>> only returns False on fail, and the user object on success. I would like to 
>>> display more information to the user (password too short, username already 
>>> taken, etc.), if registration fails.
>>>
>>> I am implementing an ajax registration, where I do not want the page to 
>>> reload on submit unless registration is successful. 
>>>
>>

-- 
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: Display registration error for auth.register_bare()

2014-07-23 Thread Mark Li
Posted up a ticket for both suggestions:

https://code.google.com/p/web2py/issues/detail?id=1955
https://code.google.com/p/web2py/issues/detail?id=1956

On Wednesday, July 23, 2014 12:49:01 AM UTC-7, Massimo Di Pierro wrote:
>
> Both are good suggestions.
>
> On Tuesday, 22 July 2014 11:55:33 UTC-5, Mark Li wrote:
>>
>> Hey Massimo! Just for clarification, are you referring to opening a 
>> ticket for:
>>
>> 1. auth.register() only showing a flash msg on registration error, 
>> without a page reload
>>
>> OR
>>
>> 2. auth.register_bare() returning error msg on registration fail, instead 
>> of just False
>>
>>
>> In my case I would like functionality for #1, but I just wanted to know 
>> to which of my suggestions you were referring to.
>>
>>
>> On Monday, July 21, 2014 11:32:13 PM UTC-7, Massimo Di Pierro wrote:
>>>
>>> Please open a ticket. Perhaps this should be the default behavior. Easy 
>>> to change.
>>>
>>> On Monday, 21 July 2014 14:59:34 UTC-5, Mark Li wrote:
>>>>
>>>> Maybe I'm not going about this in the right way. I basically want 
>>>> auth.register() functionality, but without a page reload on registration 
>>>> fail; just a flash msg of the error.
>>>>
>>>> On Monday, July 21, 2014 12:07:05 PM UTC-7, Mark Li wrote:
>>>>>
>>>>> Is it possible to return the registration error msg from 
>>>>> auth.register_bare(), similar to how auth.register() would display the 
>>>>> error msg after submit? From what I can gather in the source, seems like 
>>>>> it 
>>>>> only returns False on fail, and the user object on success. I would like 
>>>>> to 
>>>>> display more information to the user (password too short, username 
>>>>> already 
>>>>> taken, etc.), if registration fails.
>>>>>
>>>>> I am implementing an ajax registration, where I do not want the page 
>>>>> to reload on submit unless registration is successful. 
>>>>>
>>>>

-- 
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] How to prevent interactive shell from 303 error with redirect in model file.

2014-07-26 Thread Mark Li
I am currently redirecting my "index" page to another page (the "splash" 
page). The index page is the default function in my routes.py. The idea, is 
that if a user visits the "index" page, they will get redirected to the 
"splash" page, which works fine. At it's core, my redirect code looks like 
this (inside a models file):


if request.function=="index":
redirect(URL('splash'))


However, upon using the interactive shell:
python web2py.py -M -S appname

I get a 303 error and can't start the interactive shell, because the index 
function is requested at the start of the interactive shell (causing a 
redirect). I still want the index page to redirect to the splash page, but 
the interactive shell does not work with the redirect code. Not quite sure 
what the best way to go about this is. I have several background scripts 
that run using the interactive shell; I would still like these to work, 
while maintaining the redirect code for users visiting the front-end of the 
site.

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


[web2py] Re: How to prevent interactive shell from 303 error with redirect in model file.

2014-07-27 Thread Mark Li
Thanks a lot, Anthony! I was not aware of 
request.global_settings.cmd_options, and yes it works in differentiating 
between the http request and shell.

I've posted up a ticket for this as well: 
https://code.google.com/p/web2py/issues/detail?id=1957


On Saturday, July 26, 2014 8:27:48 PM UTC-7, Anthony wrote:
>
> Try:
>
> cmd_opts = request.global_settings.cmd_options
> if request.function=="index" and not (cmd_opts and (cmd_opts.shell or 
> cmd_opts.scheduler)):
> redirect(URL('splash'))
>
> We should probably provide a more convenient method to check whether we 
> have an http request vs. a shell or scheduler run (maybe a flag such as 
> request.is_http_request). Feel free to submit a Google Code issue about 
> this.
>
> Anthony
>
> On Saturday, July 26, 2014 9:38:54 PM UTC-4, Mark Li wrote:
>>
>> I am currently redirecting my "index" page to another page (the "splash" 
>> page). The index page is the default function in my routes.py. The idea, is 
>> that if a user visits the "index" page, they will get redirected to the 
>> "splash" page, which works fine. At it's core, my redirect code looks like 
>> this (inside a models file):
>>
>>
>> if request.function=="index":
>> redirect(URL('splash'))
>>
>>
>> However, upon using the interactive shell:
>> python web2py.py -M -S appname
>>
>> I get a 303 error and can't start the interactive shell, because the 
>> index function is requested at the start of the interactive shell (causing 
>> a redirect). I still want the index page to redirect to the splash page, 
>> but the interactive shell does not work with the redirect code. Not quite 
>> sure what the best way to go about this is. I have several background 
>> scripts that run using the interactive shell; I would still like these to 
>> work, while maintaining the redirect code for users visiting the front-end 
>> of the site.
>>
>

-- 
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: Display registration error for auth.register_bare()

2014-07-30 Thread Mark Li
I'd like to give a shot at AJAX-ifying the auth.register() form, but I'm 
not quite sure where to start. Looks quite daunting (for me). I'm looking 
at auth.register() source and web2py.js; would I simply want to add code to 
web2py.js to force the auth.register() forms to submit via AJAX (and return 
errors via ajax as well)?

Or would this involve adding changes to auth.register() as well, such as 
providing an option auth.register(ajax=False)?

On Wednesday, July 23, 2014 4:42:05 PM UTC-7, Mark Li wrote:
>
> Posted up a ticket for both suggestions:
>
> https://code.google.com/p/web2py/issues/detail?id=1955
> https://code.google.com/p/web2py/issues/detail?id=1956
>
> On Wednesday, July 23, 2014 12:49:01 AM UTC-7, Massimo Di Pierro wrote:
>>
>> Both are good suggestions.
>>
>> On Tuesday, 22 July 2014 11:55:33 UTC-5, Mark Li wrote:
>>>
>>> Hey Massimo! Just for clarification, are you referring to opening a 
>>> ticket for:
>>>
>>> 1. auth.register() only showing a flash msg on registration error, 
>>> without a page reload
>>>
>>> OR
>>>
>>> 2. auth.register_bare() returning error msg on registration fail, 
>>> instead of just False
>>>
>>>
>>> In my case I would like functionality for #1, but I just wanted to know 
>>> to which of my suggestions you were referring to.
>>>
>>>
>>> On Monday, July 21, 2014 11:32:13 PM UTC-7, Massimo Di Pierro wrote:
>>>>
>>>> Please open a ticket. Perhaps this should be the default behavior. Easy 
>>>> to change.
>>>>
>>>> On Monday, 21 July 2014 14:59:34 UTC-5, Mark Li wrote:
>>>>>
>>>>> Maybe I'm not going about this in the right way. I basically want 
>>>>> auth.register() functionality, but without a page reload on registration 
>>>>> fail; just a flash msg of the error.
>>>>>
>>>>> On Monday, July 21, 2014 12:07:05 PM UTC-7, Mark Li wrote:
>>>>>>
>>>>>> Is it possible to return the registration error msg from 
>>>>>> auth.register_bare(), similar to how auth.register() would display the 
>>>>>> error msg after submit? From what I can gather in the source, seems like 
>>>>>> it 
>>>>>> only returns False on fail, and the user object on success. I would like 
>>>>>> to 
>>>>>> display more information to the user (password too short, username 
>>>>>> already 
>>>>>> taken, etc.), if registration fails.
>>>>>>
>>>>>> I am implementing an ajax registration, where I do not want the page 
>>>>>> to reload on submit unless registration is successful. 
>>>>>>
>>>>>

-- 
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: duplicate ids on using auth.login and auth.register forms on same page

2014-08-14 Thread Mark Li
Was this problem addressed, or is there are workaround for this?

I am currently trying to implement something very similar, where both 
auth.login() and auth.register() forms are on the same page. Currently, 
they produce duplicate ID's (ex. both login and register password inputs 
have the id of "auth_user_password").

On Tuesday, May 18, 2010 6:28:56 AM UTC-7, mdipierro wrote:
>
> I am on the case... 
>
> On May 18, 1:15 am, Tarun  wrote: 
> > We are also facing same issue forhttp://radbox.me/for this. The code 
> > used is 
> > 
> >  
> > {{=auth.login()}} 
> > {{=A('Forgot password?', 
> > _href=URL(request.application,'account','user/retrieve_password'))}} > p> 
> >  
> > 
> >  
> > {{=auth.register()}} 
> > By registering, you confirm that you accept our  > href="{{=URL(request.application, 'support', 'tos')}}">Terms of 
> > service. 
> >  
> > I can only see class for auth_user_password_two__row, for all other 
> > fields ids are used. 
> > 
> > Thanks 
> > Tarun 
> > 
> > On May 13, 6:36 pm, mdipierro  wrote: 
> > 
> > > please post an example of the controller and view. If I understand the 
> > > problem, this should work. 
> > 
> > > On May 13, 1:54 am, Rohan  wrote: 
> > 
> > > > i am using  latest version 1.77.3 (2010-04-20 02:48:54) 
> > 
> > > > On May 12, 8:29 pm, mdipierro  wrote: 
> > 
> > > > > This was fixed. What version of web2py are you using? 
> > 
> > > > > On May 12, 5:51 am, Rohan  wrote: 
> > 
> > > > > >  I am using auth.login and auth.register forms on a single page 
> and it 
> > > > > > is resulting in duplicate ids for email and password rows. 
> > > > > > similar discussions were going on this threadhttp://
> groups.google.com/group/web2py/browse_frm/thread/e43c1203d8749630 
> > > > > > Is there any update on 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/d/optout.


[web2py] How to differentiate logic for auth.login() and auth.register() forms on the same page?

2014-08-14 Thread Mark Li
I am currently using auth.login() and auth.register() forms on the same page

I would like to use the following code for the login (to allow users to 
sign up with either username or email)

auth.settings.login_userfield = 'email'
if request.vars.email and IS_EMAIL()(request.vars.email)[1]:
auth.settings.login_userfield = 'username'
request.vars.username = request.vars.email
request.post_vars.username = request.vars.username
request.vars.email = None
request.post_vars.email = None
return dict(form=auth.login())

So the whole function looks like this (including the registration form):

def mypage():
auth.settings.login_userfield = 'email'
 
#to allow user to login with either username or email
if request.vars.email and IS_EMAIL()(request.vars.email)[1]:
auth.settings.login_userfield = 'username'
request.vars.username = request.vars.email
request.post_vars.username = request.vars.username
request.vars.email = None
request.post_vars.email = None

return dict(login_form=auth.login(), register_form=auth.register())

Because the auth.login() and auth.register() forms both have inputs with 
the same name (password, email, username), how can I differentiate between 
whether a form was submitted by the login or the register form (both have 
request.vars.email). I only want the above logic to affect the auth.login() 
form, and may also want certain logic to only affect the register form.

I was considering a check for request.vars.username (which is not present 
in the login form), but if the registration form username input is empty, 
then request.vars.username is still None (thus can't differentiate b/t 
login and register).

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


[web2py] Re: How to differentiate logic for auth.login() and auth.register() forms on the same page?

2014-08-14 Thread Mark Li
Yep that did it, thanks Leonel!

On Thursday, August 14, 2014 4:55:45 PM UTC-7, Leonel Câmara wrote:
>
> You need to differentiate them using the form name. 
>
> Something like:
>
> if request.post_vars._formname == 'login':
># do my login stuff
>

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


Re: [web2py] Re: SQLFORM generating duplicate ids in HTML

2014-08-15 Thread Mark Li
Was the duplicate ID's bug ever fixed or addressed with an optional prefix 
field? It currently looks like I would have to manually alter all the ID's 
of my auth.login() form, because auth.register() form is on the same page.

On Wednesday, January 27, 2010 5:17:14 PM UTC-8, Jonathan Lundell wrote:
>
> On Jan 27, 2010, at 5:07 PM, Thadeus Burgess wrote:
>
> > Doesn't javascript input serialization expect to look the field up by id?
>
> There's nothing *wrong* with having an id; it just needs to be unique on 
> the page.
>
> > 
> > it should be
> > 
> > form = id = formname class=formname:
> >   input:
> >  class = formname
> >  id = formname_field
> > 
> > #formname input { ... }
> > #formname #formname_users_email { ... }
> > #formname .formname { ... }
> > 
> > This would give a lot more flexibility from both a CSS design and a UI
> > design using jquery selection.
> > 
> > -Thadeus
> > 
> > 
> > 
> > 
> > 
> > On Wed, Jan 27, 2010 at 5:12 PM, Jonathan Lundell  > wrote:
> >> On Jan 27, 2010, at 2:30 PM, Thadeus Burgess wrote:
> >> 
> >>> if it was defaulted to None we could go
> >>> 
> >>> if _id == None then id = tablename else id = _id
> >>> 
> >>> Id accept that, just set a unique id for each of my forms and nothing
> >>> will conflict and it will still keep good with old apps.
> >> 
> >> And _id = False for no id at all.
> >> 
> >> It's not that it isn't useful to put all of them into the same class; 
> it's that class is the right way to do it, rather than id.
> >> 
> >> 
> >>> 
> >>> -Thadeus
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> On Wed, Jan 27, 2010 at 4:27 PM, Wes James  > wrote:
>  Why not:
>  
>   form1=SQLFORM(..., _id="what_you_want")
>  
>  -wes
>  
>  On Wed, Jan 27, 2010 at 7:31 AM, mdipierro  > wrote:
> > The ids are only used for CSS. you can do
> > 
> > form1=SQLFORM(...,_class='form1')
> > form1.accepts(request.post_vars,formname=None)
> > form2=SQLFORM(...,_class='form2')
> > form2.accepts(request.post_vars,formname=None)
> > return dict(form1=form1,form2=form2)
> > 
> > and you can use the class to refer to the id of the first or the
> > second in CSS. There should be no ambiguity.
> > 
> > Massimo
> > 
> > 
>  
>  
>
>
>

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


[web2py] How to alter attributes of multiple elements with the same prefix, in a form

2014-08-18 Thread Mark Li
I am currently trying to alter all the ID's of the elements in the 
auth.login() form. Basically, I want to add a prefix or suffix to all the 
elements that have an ID.

All of the id's (except for the submit button row), are prefixed with 
"auth_user_". Is it possible to use form.elements() to select all those 
elements at once?

I tried using a css3 substring selector, like 

login_form.elements('[id*="auth_user"]')

but this selected a few extra elements that did not have the auth_user ID 
prefix. Is there an efficient way to accomplish this? 

As a last resort, I can change the ID's of each element individually

-- 
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] Registration passworld field security risk on form failure?

2014-08-25 Thread Mark Li
I am currently looking into whether or not password fields should be 
cleared on registration error after the form fails server-side validation. 
At the moment, web2py shows the password after a registration error, 
instead of leaving it blank. While this may make editing the password 
easier (in case there are pw errors), it seems to pose a security risk 
because you are sending the password back to the client in plain text. To 
my understanding, this would allow the page to be cached with the 
password's value in plain text.

I tested this on a variety of browsers and systems, so to the best of my 
knowledge this is behavior is not unique to a browser.

Does this pose a reasonable security risk?

Some reference links:
http://ux.stackexchange.com/questions/3/why-do-most-create-account-forms-clear-the-password-fields-upon-wrong-validation
http://ux.stackexchange.com/questions/20418/when-form-submission-fails-password-field-gets-blanked-why-is-that-the-case

-- 
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: Registration passworld field security risk on form failure?

2014-08-26 Thread Mark Li
Looking at the password input through Firebug/developer tools, and the 
value of the password input is the plaintext of the password I entered.

I have a test site here: 
http://tedlee.pythonanywhere.com/welcome/default/user/register

Typing in a password and failing registration will return that password. Is 
this just the behavior of a modern browser (to remember failed inputs), or 
is it web2py form handling?

In the case that web2py did only return asterisks, wouldn't that be very 
misleading to the user? Because the password input is masked, they would 
assume that the returned password value (after registration failure) was 
what they previously had typed, not a password replaced with asterisks. 
Thus on re-submitting the form, they would not think to alter the password 
and would just submit a password with asterisks.

On Monday, August 25, 2014 3:25:44 PM UTC-7, Derek wrote:
>
> Have you actually looked at it? I believe it just returns asterisks.
>
> On Monday, August 25, 2014 3:02:49 PM UTC-7, Mark Li wrote:
>>
>> I am currently looking into whether or not password fields should be 
>> cleared on registration error after the form fails server-side validation. 
>> At the moment, web2py shows the password after a registration error, 
>> instead of leaving it blank. While this may make editing the password 
>> easier (in case there are pw errors), it seems to pose a security risk 
>> because you are sending the password back to the client in plain text. To 
>> my understanding, this would allow the page to be cached with the 
>> password's value in plain text.
>>
>> I tested this on a variety of browsers and systems, so to the best of my 
>> knowledge this is behavior is not unique to a browser.
>>
>> Does this pose a reasonable security risk?
>>
>> Some reference links:
>>
>> http://ux.stackexchange.com/questions/3/why-do-most-create-account-forms-clear-the-password-fields-upon-wrong-validation
>>
>> http://ux.stackexchange.com/questions/20418/when-form-submission-fails-password-field-gets-blanked-why-is-that-the-case
>>
>

-- 
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: Registration passworld field security risk on form failure?

2014-08-27 Thread Mark Li
Under the Net tab in Firebug, the Post contains the submitted variables, 
and the response tab is the HTML of the returned page. This response 
contains the password input value in plain text.

If I submitted the password as "asdf" and submitted the registration form 
with failures, the response will contain this (as shown in the net tab):


Does no one else experience this behavior?

On Tuesday, August 26, 2014 11:08:14 AM UTC-7, Willoughby wrote:
>
> Using the same Firebug, look at the Net tab - look at your post and the 
> response.
>
>
> On Tuesday, August 26, 2014 1:32:14 PM UTC-4, Mark Li wrote:
>>
>> Looking at the password input through Firebug/developer tools, and the 
>> value of the password input is the plaintext of the password I entered.
>>
>> I have a test site here: 
>> http://tedlee.pythonanywhere.com/welcome/default/user/register
>>
>> Typing in a password and failing registration will return that password. 
>> Is this just the behavior of a modern browser (to remember failed inputs), 
>> or is it web2py form handling?
>>
>> In the case that web2py did only return asterisks, wouldn't that be very 
>> misleading to the user? Because the password input is masked, they would 
>> assume that the returned password value (after registration failure) was 
>> what they previously had typed, not a password replaced with asterisks. 
>> Thus on re-submitting the form, they would not think to alter the password 
>> and would just submit a password with asterisks.
>>
>> On Monday, August 25, 2014 3:25:44 PM UTC-7, Derek wrote:
>>>
>>> Have you actually looked at it? I believe it just returns asterisks.
>>>
>>> On Monday, August 25, 2014 3:02:49 PM UTC-7, Mark Li wrote:
>>>>
>>>> I am currently looking into whether or not password fields should be 
>>>> cleared on registration error after the form fails server-side validation. 
>>>> At the moment, web2py shows the password after a registration error, 
>>>> instead of leaving it blank. While this may make editing the password 
>>>> easier (in case there are pw errors), it seems to pose a security risk 
>>>> because you are sending the password back to the client in plain text. To 
>>>> my understanding, this would allow the page to be cached with the 
>>>> password's value in plain text.
>>>>
>>>> I tested this on a variety of browsers and systems, so to the best of 
>>>> my knowledge this is behavior is not unique to a browser.
>>>>
>>>> Does this pose a reasonable security risk?
>>>>
>>>> Some reference links:
>>>>
>>>> http://ux.stackexchange.com/questions/3/why-do-most-create-account-forms-clear-the-password-fields-upon-wrong-validation
>>>>
>>>> http://ux.stackexchange.com/questions/20418/when-form-submission-fails-password-field-gets-blanked-why-is-that-the-case
>>>>
>>>

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


  1   2   >