Re: [web2py] Re: one to many relationship

2015-08-10 Thread Dave S


On Monday, August 10, 2015 at 7:32:31 PM UTC-7, Yebach wrote:

 Thank you for detailed answer

 I am trying to implement this in SQLFORM? Looks like multiple option is 
 not avaliable, the field is presented as text field in the form

 BTW - why web2py does not add new field to a table. If I set migrate to 
 True I get an error table already exists if it is set to false new fields 
 were not created so I had to create them manually ??

 Thank you


Which database are you interfacing to?

/dps
 


 2015-08-07 19:10 GMT+08:00 Lisandro rostagno...@gmail.com javascript::

 Hi there.
 Web2py has some cool field types called list:string, list:integer and 
 list:reference table. Check them here:

 http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Field-types

 In your case, you could avoid the creation of the third table with 
 *list:reference 
 table*, for example, in your db.py:

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

 db.define_table('worker',\
 Field('name'),\
 Field('skills','list:reference skill'))


 Then you can do things like:

 skill_1 = db.skill.insert(name='coding in python')
 skill_2 = db.skill.insert(name='making a cake')
 skill_3 = db.skill.insert(name='writing a song')

 db.worker.insert(name='John', skills=[skill_1, skill_2])
 db.worker.insert(name='Paul', skills=[skill_3])
 db.worker.insert(name='Richard', skills=[skill_2, skill_3])

 # search which workers have skill_2:
 have_skill_3 = db(db.worker.skills.contains(skill_2)).select()


 The list:reference field will be rendered as a select with multiple=True.
 You can always write your own widget to use other stuff, like checkboxes.

 Look for list:reference in this group, you will lots of posts about it. 
 Hope it helps!



 El jueves, 6 de agosto de 2015, 22:51:53 (UTC-3), Yebach escribió:

 Hello

 How to solve the problem of one to many relationship:

 Lets say I have a worker that has multiple skills. How to set up SQLFORM 
 to add as many skills to the worker as possible.

 So skills in one table workers in another.I guess a third table will be 
 needed

 Thank you

 best regards

 -- 
 Resources:
 - http://web2py.com
 - http://web2py.com/book (Documentation)
 - http://github.com/web2py/web2py (Source code)
 - https://code.google.com/p/web2py/issues/list (Report Issues)
 --- 
 You received this message because you are subscribed to a topic in the 
 Google Groups web2py-users group.
 To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/web2py/HjhQdAZWFWY/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to 
 web2py+un...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/d/optout.




 -- 
 Lep pozdrav 

 Vid Ogris




-- 
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: one to many relationship

2015-08-10 Thread Vid Ogris
Postgres. The thimg is i have no table files. They somehow got deleted
On Aug 11, 2015 12:30 PM, Dave S snidely@gmail.com wrote:



 On Monday, August 10, 2015 at 7:32:31 PM UTC-7, Yebach wrote:

 Thank you for detailed answer

 I am trying to implement this in SQLFORM? Looks like multiple option is
 not avaliable, the field is presented as text field in the form

 BTW - why web2py does not add new field to a table. If I set migrate to
 True I get an error table already exists if it is set to false new fields
 were not created so I had to create them manually ??

 Thank you


 Which database are you interfacing to?

 /dps



 2015-08-07 19:10 GMT+08:00 Lisandro rostagno...@gmail.com:

 Hi there.
 Web2py has some cool field types called list:string, list:integer
 and list:reference table. Check them here:

 http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Field-types

 In your case, you could avoid the creation of the third table with 
 *list:reference
 table*, for example, in your db.py:

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

 db.define_table('worker',\
 Field('name'),\
 Field('skills','list:reference skill'))


 Then you can do things like:

 skill_1 = db.skill.insert(name='coding in python')
 skill_2 = db.skill.insert(name='making a cake')
 skill_3 = db.skill.insert(name='writing a song')

 db.worker.insert(name='John', skills=[skill_1, skill_2])
 db.worker.insert(name='Paul', skills=[skill_3])
 db.worker.insert(name='Richard', skills=[skill_2, skill_3])

 # search which workers have skill_2:
 have_skill_3 = db(db.worker.skills.contains(skill_2)).select()


 The list:reference field will be rendered as a select with multiple=True.
 You can always write your own widget to use other stuff, like checkboxes.

 Look for list:reference in this group, you will lots of posts about
 it.
 Hope it helps!



 El jueves, 6 de agosto de 2015, 22:51:53 (UTC-3), Yebach escribió:

 Hello

 How to solve the problem of one to many relationship:

 Lets say I have a worker that has multiple skills. How to set up
 SQLFORM to add as many skills to the worker as possible.

 So skills in one table workers in another.I guess a third table will be
 needed

 Thank you

 best regards

 --
 Resources:
 - http://web2py.com
 - http://web2py.com/book (Documentation)
 - http://github.com/web2py/web2py (Source code)
 - https://code.google.com/p/web2py/issues/list (Report Issues)
 ---
 You received this message because you are subscribed to a topic in the
 Google Groups web2py-users group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/web2py/HjhQdAZWFWY/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/d/optout.




 --
 Lep pozdrav

 Vid Ogris


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


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


[web2py] Scheduler - import models

2015-08-10 Thread Peter Gastinger
Hi, 

I was wondering whether it is possible to import models when using the 
scheduler? I have a couple of scheduler tasks, one of them is created a 
textfile which takes a couple of minutes. Scheduling this was pretty easy. 
After the file is created, I want to send a mail with it as attachment to a 
couple of recipients. I want to use the Mail-object, which is created in 
db.py. Unfortunately, this module is not available when the scheduler is 
executing my method. 

When running web2py from CLI, there is the parameter -M (which imports the 
models), how to you do that using the scheduler or what is the best way to 
solve this problem? (preferably without any other scripts, ...)

Thanks and best regards, 
Peter

-- 
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] SQLFORM.grid different classes for add and edit forms

2015-08-10 Thread Najtsirk
Hello,

is it possible to assign different classes for add and edit forms in 
SQLFORM.grid?

A this point there is no difference between them so I cannot use proper CSS 
selectors for JS.

Best,
Najtsirk

-- 
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] Hidden fields are not read from the database

2015-08-10 Thread icodk
I need to represent field_1 dynamically base on another field (field_2) 
that should not be visible to the user in a smartgrid.
However if I set 
db.table1.field_2.writable=db.table1.field_2.readable=False
in order to hide it, then my row parameter to the lambda function of the 
represent settings do not include field_2
so 
db.table1.field_1.represent= lambda val, row: val if row.field_2 else ''
Will generate an error :
Row' object has no attribute 'field_2'
 
Thanks for help

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


[web2py] Re: Appconfig cast boolean

2015-08-10 Thread Massimo Di Pierro
That that should be correct.

On Sunday, 9 August 2015 11:26:36 UTC-5, Mark Graves wrote:

 And, sanity check here, I can also do the following, correct:

 [db] 

 uri   = sqlite://storage.sqlite 
 migrate   = 

 myconf = AppConfig()

 mc = myconf.take('db.migrate',cast=bool)

 print mc
 print type(mc)

 Which should yield False, Boolean




 On Monday, August 3, 2015 at 9:09:37 AM UTC-5, Mark Graves wrote:

 Should've thought of that.

 Nice to confirm intended behavior.

 I guess I could have done bool(mc) = myconf.take('db.migrate',cast = int)

 On Monday, August 3, 2015 at 6:22:09 AM UTC-5, Anthony wrote:

 Therefore:

 mc = myconf.take('db.migrate',cast=lambda value: bool(int(value)))

 Anthony

 On Monday, August 3, 2015 at 7:08:00 AM UTC-4, Leonel Câmara wrote:

 Well you're casting a string so any non-empty string is True. You have 
 to cast to an int.



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


[web2py] Re: Scheduler - import models

2015-08-10 Thread Massimo Di Pierro
The scheduler always sees models. It is executed in the same context as a 
controller. Then you can use import to import anything else you need.

On Monday, 10 August 2015 10:39:37 UTC-5, Peter Gastinger wrote:

 Hi, 

 I was wondering whether it is possible to import models when using the 
 scheduler? I have a couple of scheduler tasks, one of them is created a 
 textfile which takes a couple of minutes. Scheduling this was pretty easy. 
 After the file is created, I want to send a mail with it as attachment to a 
 couple of recipients. I want to use the Mail-object, which is created in 
 db.py. Unfortunately, this module is not available when the scheduler is 
 executing my method. 

 When running web2py from CLI, there is the parameter -M (which imports the 
 models), how to you do that using the scheduler or what is the best way to 
 solve this problem? (preferably without any other scripts, ...)

 Thanks and best regards, 
 Peter


-- 
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] Software Testing

2015-08-10 Thread Richard Vézina
See web2py.test and welcome_augmented :

https://github.com/viniciusban/web2py.test

https://github.com/niphlod/welcome_augmented

Richard

On Sun, Aug 9, 2015 at 4:44 PM, alexielgr...@gmail.com wrote:

 I would like to know, if someone of you know something about Software
 Testing with web2py, how to test systems created with it.
 To test model / view / controller, the information in the database, test
 JavaScript, etc.
 In the reference manual of the  framework, I found some information to do
 functional tests with the WebClient and a little about doctests, but I did
 not quite understand.
 May be a link, a document, a book, something helps.
 Thank you,
 Alexiel

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


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


[web2py] Re: db query that returns a list of field values

2015-08-10 Thread Massimo Di Pierro
yes a Row (a record is a dictionary) but you can do:

def make_run():
siteList = []
rows = db(db.websites).select(db.websites.URL).as_list()
for row in rows:
siteList.append(row.URL)
return locals()

or

def make_run():
rows = db(db.websites).select(db.websites.URL).as_list()
siteList = [row.URL for row in rows]
return locals()

On Monday, 10 August 2015 10:39:51 UTC-5, Jose W wrote:

 Hello,

 I am new to Web2py and I am running into an issue with making a query to 
 the DB, and returning a list of the filed values.

 Relevant Info:
 DB db(db.websites).select(db.websites.URL):
   websites.URL
   http://www.example.com
   http://www.example.com
   http://www.example.com
   http://www.example.com
   http://www.example.com
   http://www.example.com
   http://www.example.com
   http://www.example.com

 Controller
 def make_run():
 siteList = []
 rows = db(db.websites).select(db.websites.URL).as_list()
 for url in rows:
 siteList.append(url)
 return locals()


 View:
   {{extend 'layout.html'}}


   {{=siteList}}
   p/p
   {{=rows}}



 The problem is that my query is returning a list of dictionaries.  What I 
 am looking to get is a list of the filed values.

 *What I am getting from both the *siteList *and* rows *in my view**:*
 [{'URL': 'http://www.example.com'}, {'URL': 'http://www.example.com'}, 
 {'URL': 'http://www.example.com'}, {'URL': 'http://www.example.com'}, 
 {'URL': 'http://www.example.com'}, {'URL': 'http://www.example.com'}, 
 {'URL': 'http://www.example.com'}, {'URL': 'http://www.example.com'}, 
 {'URL': 'http://www.example.com'}]

 *What I am looking for:*
 [http://www.example.com, http://www.example.com, http://www.example.com, 
 http://www.example.com, http://www.example.com, http://www.example.com, 
 http://www.example.com, http://www.example.com, http://www.example.com]

 I know the problem is in my query, I just have not been able to figure out 
 the correct one to return a clean list. I have tried a couple of other 
 things with no success, like not using the .as_list() and using the loop to 
 build the list, but I get the response below:
 [Row {'URL': 'http://www.example.com'}, Row {'URL': '
 http://www.example.com'}, Row {'URL': 'http://www.example.com'}]


 Thanks in advance!


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


[web2py] Software Testing

2015-08-10 Thread alexielgrace
I would like to know, if someone of you know something about Software 
Testing with web2py, how to test systems created with it.
To test model / view / controller, the information in the database, test 
JavaScript, etc.
In the reference manual of the  framework, I found some information to do 
functional tests with the WebClient and a little about doctests, but I did 
not quite understand.
May be a link, a document, a book, something helps.
Thank you,
Alexiel

-- 
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] db query that returns a list of field values

2015-08-10 Thread Jose W
Hello,

I am new to Web2py and I am running into an issue with making a query to 
the DB, and returning a list of the filed values.

Relevant Info:
DB db(db.websites).select(db.websites.URL):
  websites.URL
  http://www.example.com
  http://www.example.com
  http://www.example.com
  http://www.example.com
  http://www.example.com
  http://www.example.com
  http://www.example.com
  http://www.example.com

Controller
def make_run():
siteList = []
rows = db(db.websites).select(db.websites.URL).as_list()
for url in rows:
siteList.append(url)
return locals()


View:
  {{extend 'layout.html'}}


  {{=siteList}}
  p/p
  {{=rows}}



The problem is that my query is returning a list of dictionaries.  What I 
am looking to get is a list of the filed values.

*What I am getting from both the *siteList *and* rows *in my view**:*
[{'URL': 'http://www.example.com'}, {'URL': 'http://www.example.com'}, 
{'URL': 'http://www.example.com'}, {'URL': 'http://www.example.com'}, 
{'URL': 'http://www.example.com'}, {'URL': 'http://www.example.com'}, 
{'URL': 'http://www.example.com'}, {'URL': 'http://www.example.com'}, 
{'URL': 'http://www.example.com'}]

*What I am looking for:*
[http://www.example.com, http://www.example.com, http://www.example.com, 
http://www.example.com, http://www.example.com, http://www.example.com, 
http://www.example.com, http://www.example.com, http://www.example.com]

I know the problem is in my query, I just have not been able to figure out 
the correct one to return a clean list. I have tried a couple of other 
things with no success, like not using the .as_list() and using the loop to 
build the list, but I get the response below:
[Row {'URL': 'http://www.example.com'}, Row {'URL': 
'http://www.example.com'}, Row {'URL': 'http://www.example.com'}]


Thanks in advance!

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


[web2py] Re: SQLFORM.grid different classes for add and edit forms

2015-08-10 Thread Yoel Benitez Fonseca
you can tell when u are editing or creating by the args passed in 
request.args, for example in the view:

{{if 'edit' in request.args:}}
  // do something
{{elif 'new' in request.args:}}
  // do other thing
{{pass}}



El lunes, 10 de agosto de 2015, 12:13:53 (UTC-4), Najtsirk escribió:

 Hello,

 is it possible to assign different classes for add and edit forms in 
 SQLFORM.grid?

 A this point there is no difference between them so I cannot use proper 
 CSS selectors for JS.

 Best,
 Najtsirk


-- 
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] Software Testing

2015-08-10 Thread alexielgrace
Thanks Richard
Alexiel

Em segunda-feira, 10 de agosto de 2015 13:14:01 UTC-3, Richard escreveu:

 See web2py.test and welcome_augmented : 

 https://github.com/viniciusban/web2py.test

 https://github.com/niphlod/welcome_augmented

 Richard

 On Sun, Aug 9, 2015 at 4:44 PM, alexie...@gmail.com javascript: wrote:

 I would like to know, if someone of you know something about Software 
 Testing with web2py, how to test systems created with it.
 To test model / view / controller, the information in the database, test 
 JavaScript, etc.
 In the reference manual of the  framework, I found some information to do 
 functional tests with the WebClient and a little about doctests, but I did 
 not quite understand.
 May be a link, a document, a book, something helps.
 Thank you,
 Alexiel

 -- 
 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+un...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/d/optout.




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


[web2py] Problems with the shell

2015-08-10 Thread Martin Weissenboeck
On my testserver I made an update to 2.12.2 and tried the Shell


At first a test in 2.9.12:
print 1
print 2

The result (as expected):






*web2py Shell 2.9.12-stable+timestamp.2015.01.17.06.11.03In [1] : print
11In [2] : print 11*
--
Now in 2.12.2
print 1
print 2

The result always None


*web2py Shell 2.12.2-stable+timestamp.2015.08.09.14.29.44NoneNone*

My mistake oder went something wrong?

​R
​egards, Martin​

-- 
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] can a filename be suggested in a custom Exporter class for a SQLFORM.grid?

2015-08-10 Thread Yoel Benitez Fonseca
In sqlhtml.py:

class ExportClass(object):
label = None
file_ext = None
content_type = None

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

Is there a way to suggest a filename to the client ?

-- 
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: Code organization help

2015-08-10 Thread David Ripplinger
Here's an update after I learned some more:

It looks like I can have the best of both worlds, since web2py has routers 
that can translate between a public URL and a back-end URL (see the 
subsection titled URL Rewrite 
http://web2py.com/books/default/chapter/29/04/the-core#URL-rewrite in the 
book). My plan is to use URLs in my API such as /object_a, /object_a/1, 
/object_a/1/info, and /object_a?type=1 along with the various HTTP methods, 
then use the router to translate these to the appropriate controllers' URLs.

-- 
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: sessions piling up

2015-08-10 Thread Massimo Di Pierro
You seem to have an old version of session2strash.py. The new one only uses 
self.expiration and not expiration.

On Sunday, 9 August 2015 10:15:57 UTC-5, Bob St John wrote:

 Using 2.12.1

 I run a small site... about 200 members who login (some using the 
 'Remember me for 30 days') plus about 1500 public visitors per day. The 
 sessions are stored in the file system. I run the sessions2trash.py script 
 once a day. I have noticed the sessions are increasing by about 1000 per 
 day which did not seem right. I made the following changes to trash() and 
 now the sessions remaining after being 'trashed' is about 200-300, which 
 seems correct. I think the problem was when a large expiration was saved 
 (30 days) and the next expired public sessions were not trashed


 CURRENT TRASH:
 def trash(self):
 Trash expired sessions.
 now = datetime.datetime.now()
 for item in self.get():
 status = 'OK'
 last_visit = item.last_visit_default()

 try:
 session = item.get()
 if session.auth:
 if session.auth.expiration and not self.force:
 self.expiration = session.auth.expiration
 if session.auth.last_visit:
 last_visit = session.auth.last_visit
 except:
 pass

 age = 0
 if last_visit:
 age = total_seconds(now - last_visit)

 if age  self.expiration or not self.expiration:
 item.delete()
 status = 'trashed'

 if self.verbose  1:
 print 'key: %s' % str(item)
 print 'expiration: %s seconds' % self.expiration
 print 'last visit: %s' % str(last_visit)
 print 'age: %s seconds' % age
 print 'status: %s' % status
 print ''
 elif self.verbose  0:
 print('%s %s' % (str(item), status))

 MODIFIED TRASH:
 def trash(self):
 Trash expired sessions.
 now = datetime.datetime.now()
 for item in self.get():
 status = 'OK'
 last_visit = item.last_visit_default()
 expiration = self.expiration ### added this

 try:
 session = item.get()
 if session.auth:
 if session.auth.expiration and not self.force:
 ###self.expiration = session.auth.expiration
 expiration = session.auth.expiration
 if session.auth.last_visit:
 last_visit = session.auth.last_visit
 except:
 pass

 age = 0
 if last_visit:
 age = total_seconds(now - last_visit)

 ###if age  self.expiration or not self.expiration:
 if age  expiration or not expiration:
 item.delete()
 status = 'trashed'

 if self.verbose  1:
 print 'key: %s' % str(item)
 print 'expiration: %s seconds' % self.expiration
 print 'last visit: %s' % str(last_visit)
 print 'age: %s seconds' % age
 print 'status: %s' % status
 print ''
 elif self.verbose  0:
 print('%s %s' % (str(item), status))



-- 
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: The mobile device error

2015-08-10 Thread forumweb2py
The TicketFile:

S'Traceback (most recent call last):\n  File 
/.../Desktop/web2py/gluon/restricted.py, line 227, 
in restricted\nexec ccode in environment\n  File 
/.../Desktop/web2py/applications/Daten/views/default/index.html, line 73, 
in module\n  File /.../Desktop/web2py/gluon/globals.py, line 425, 
in write\nself.body.write(xmlescape(data))\n  File 
/.../Desktop/web2py/gluon/html.py, line 130, 
in xmlescape\nreturn data.xml()\n  File 
/.../Desktop/web2py/gluon/html.py, line 2580, 
in xml\nreturn self.serialize_mobile(self.data, 0).xml()\n  File 
/.../Desktop/web2py/gluon/html.py, line 2572, 
in serialize_mobile\nitem[3], select, prefix=CAT(prefix, item[0], 
\'/\'))\n  File /.../Desktop/web2py/gluon/html.py, line 2563,
 in serialize_mobile\nif len(item) = 3 and (not item[0]) or 
(isinstance(item[0], DIV) and not (item[2])):\n  File 
/.../Desktop/web2py/gluon/html.py, line 785, 
in __getitem__\nreturn self.components[i]\nIndexError: list index out 
of range\n'

Am Mittwoch, 5. August 2015 01:51:06 UTC+2 schrieb forum...@gmail.com:

 he Group,

 i creat different Projectts with we2py. But last time i see, that all 
 Project works fine only with DesktopPc.If i call the project from 
 a mobile device a get an error:
 exceptions.IndexError list index out of range

 I understand, that web2py will render the Project if a mobile device
 is dedected. Therefore i use the plugin Jqmoble but i can not
 solv the problem. 





-- 
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: When will we have a proper forum ?

2015-08-10 Thread Richard Vézina
+1 Limedrop

Do you think to something like the Mercurial book?
http://hgbook.red-bean.com/read/how-did-we-get-here.html

I saw side comments after...

Richard





On Thu, Aug 6, 2015 at 5:07 PM, Limedrop russ...@holtrd.com wrote:

 The first step would be to add it to the web2py roadmap :-)  I don't know
 enough about the code-base to comment on the implementation specifics.
 Would you see comment functionality being added to directly to the
 auth.wiki() code or developed as a separate app/plugin?



 On Thursday, 6 August 2015 18:12:00 UTC+12, Massimo Di Pierro wrote:

 I very much agree with this. How do you propose we do it?

 On Wednesday, 5 August 2015 17:37:19 UTC-5, Limedrop wrote:

 I hesitate to comment on this as it's one of those topics were there's
 not one obvious way to do it (obviously I'm not Dutch). Essentially, I
 think google groups does an okay job and the benefits of any change are
 likely to be outweighed by the heavy cost of that change.

 Having said that, I've always thought that we're missing a trick by not
 integrating forum questions with the web2py book. Imagine having
 medium.com-style side comments with the book, making it more of a living
 document. Questions and answers would be right next to the relevant section
 of the book, providing further explanation and reducing RTFM answers. I
 guess you'd also add a better search facility, a stack-overflow style
 'homepage' and possibly a slight re-structure of the book sections. Ask a
 question and it gets tagged to a book section.  The book is already built
 with auth.wiki() - so we would be adding to functionality/infrastructure
 that has to be maintained anyway.

 We can always dream ;-)

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


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


[web2py] Re: Routes.py - Remove Application prefix

2015-08-10 Thread Massimo Di Pierro
yes but after some though the jammer is a fun example but not a really 
useful one. Yes you would send lots of crap to the client but you will also 
keep your own sever busy doing so.

On Sunday, 9 August 2015 15:40:45 UTC-5, Jordan Ladora wrote:

 I was wondering how to also incorporate routing any asp/jsp/php requests 
 to the jammer app in this example?

 Can you add it to routes_in? eg-

 routes_in = (
   ('/admin/$anything', '/admin/$anything'),
   ('/$anything', '/init/$anything'),
  ('.*.(php|PHP|asp|ASP|jsp|JSP)','jammer/default/jam'),
 )

 Is this correct?



 On Monday, March 1, 2010 at 11:46:31 PM UTC-8, Elam Watkins wrote:

 Thanks all, it's working now.  I did what mdipierro suggested.

 On Mar 1, 6:20 am, mdipierro mdipie...@cs.depaul.edu wrote:
  oops. Try this
 
  routes_in = (
('/admin/$anything', '/admin/$anything'),
('/$anything', '/init/$anything'),
  )
  routes_out = (('/init/$anything', '/$anything'),)
 
  On Mar 1, 8:18 am, Mengu whalb...@gmail.com wrote:
 
 
 
   massimo, this breaks admin. :)
 
   On 1 Mart, 14:53, mdipierro mdipie...@cs.depaul.edu wrote:
 
or the new simpler way
 
routes_in = (('/$anything', '/init/$anything'),)
routes_out = (('/init/$anything', '/$anything'),)
 
On Mar 1, 5:51 am, Álvaro Justen [Turicas] alvarojus...@gmail.com
wrote:
 
 On Mon, Mar 1, 2010 at 03:47, Elam Watkins elamwatk...@gmail.com 
 wrote:
  I downloaded web2py version 1.75.5. I then renamed the welcome
  application to init.
 
  I want to remove the application prefix from the application's 
 URLs
  because I want to only expose one application.  I created a 
 routes.py
  in the web2py folder and tried the following:
 
  #-
  routes_in = (
   ('/testme', '/init/default/index'),
  )
  routes_out = (
   ('/init/default/index', '/testme'),
  )
  #-
 
  It worked fine.
 
  I then tried
 
  #-
  routes_in = (
   ('/(?Pany.*)', '/init/   any'),
  )
  routes_out = (
   ('/init/(?Pany.*)', '/   any'),
  )
  #-
 
 There is some typo in the online book. You should use \g. See 
 [1]
 for one example (/docs).
 
  and this:
 
  #-
  routes_in = (
   ('/$c/$f', '/init/$c/$f'),
  )
 
  routes_out = (
   ('/init/$c/$f', '/$c/$f'),
  )
  #-
 
 Try this:
 
 routes_in = (
   ('/', '/init'),
   ('/$c/?', '/init/$c'),
   ('/$c/$f', '/init/$c/$f'),
 )
 
 routes_out = (
   ('/init/$c/$f', '/$c/$f'),
 )
 
 [1]http://web2py.com/AlterEgo/default/show/67
 
  Neither worked.  This is straight from the book:
 http://web2py.com/book/default/section/4/15
 
  --
  You received this message because you are subscribed to the 
 Google Groups web2py-users group.
  To post to this group, send email to web...@googlegroups.com.
  To unsubscribe from this group, send email to 
 web2py+un...@googlegroups.com.
  For more options, visit this group athttp://
 groups.google.com/group/web2py?hl=en.
 
 --
 Álvaro Justen - Turicas
  http://blog.justen.eng.br/
  21 9898-0141- Hide quoted text -
 
  - Show quoted text -



-- 
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: can a filename be suggested in a custom Exporter class for a SQLFORM.grid?

2015-08-10 Thread Yoel Benitez Fonseca
i'm allways getting rows.EXT

El lunes, 10 de agosto de 2015, 14:49:23 (UTC-4), Yoel Benitez Fonseca 
escribió:

 In sqlhtml.py:

 class ExportClass(object):
 label = None
 file_ext = None
 content_type = None

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

 Is there a way to suggest a filename to the client ?


-- 
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: can a filename be suggested in a custom Exporter class for a SQLFORM.grid?

2015-08-10 Thread Yoel Benitez Fonseca
on sqlhtml.py line 2394:

...
oExp = clazz(rows)
export_filename = \
request.vars.get('_export_filename') or 'rows'
filename = '.'.join((export_filename, oExp.file_ext))
response.headers['Content-Type'] = oExp.content_type
response.headers['Content-Disposition'] = \
'attachment;filename=' + filename + ';'
...

seems to be the code responsible for the download filename, and it is 
trying to find a filename suggestion on *request.vars.get('_export_filename') 
*!?

El lunes, 10 de agosto de 2015, 14:49:23 (UTC-4), Yoel Benitez Fonseca 
escribió:

 In sqlhtml.py:

 class ExportClass(object):
 label = None
 file_ext = None
 content_type = None

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

 Is there a way to suggest a filename to the client ?


-- 
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: db query that returns a list of field values

2015-08-10 Thread Jose W
That was it, I needed to pull the content using row.URL.

Thank you for the prompt response.


On Monday, August 10, 2015 at 11:52:26 AM UTC-4, Massimo Di Pierro wrote:

 yes a Row (a record is a dictionary) but you can do:

 def make_run():
 siteList = []
 rows = db(db.websites).select(db.websites.URL).as_list()
 for row in rows:
 siteList.append(row.URL)
 return locals()

 or

 def make_run():
 rows = db(db.websites).select(db.websites.URL).as_list()
 siteList = [row.URL for row in rows]
 return locals()

 On Monday, 10 August 2015 10:39:51 UTC-5, Jose W wrote:

 Hello,

 I am new to Web2py and I am running into an issue with making a query to 
 the DB, and returning a list of the filed values.

 Relevant Info:
 DB db(db.websites).select(db.websites.URL):
   websites.URL
   http://www.example.com
   http://www.example.com
   http://www.example.com
   http://www.example.com
   http://www.example.com
   http://www.example.com
   http://www.example.com
   http://www.example.com

 Controller
 def make_run():
 siteList = []
 rows = db(db.websites).select(db.websites.URL).as_list()
 for url in rows:
 siteList.append(url)
 return locals()


 View:
   {{extend 'layout.html'}}


   {{=siteList}}
   p/p
   {{=rows}}



 The problem is that my query is returning a list of dictionaries.  What I 
 am looking to get is a list of the filed values.

 *What I am getting from both the *siteList *and* rows *in my view**:*
 [{'URL': 'http://www.example.com'}, {'URL': 'http://www.example.com'}, 
 {'URL': 'http://www.example.com'}, {'URL': 'http://www.example.com'}, 
 {'URL': 'http://www.example.com'}, {'URL': 'http://www.example.com'}, 
 {'URL': 'http://www.example.com'}, {'URL': 'http://www.example.com'}, 
 {'URL': 'http://www.example.com'}]

 *What I am looking for:*
 [http://www.example.com, http://www.example.com, http://www.example.com, 
 http://www.example.com, http://www.example.com, http://www.example.com, 
 http://www.example.com, http://www.example.com, http://www.example.com]

 I know the problem is in my query, I just have not been able to figure 
 out the correct one to return a clean list. I have tried a couple of other 
 things with no success, like not using the .as_list() and using the loop to 
 build the list, but I get the response below:
 [Row {'URL': 'http://www.example.com'}, Row {'URL': '
 http://www.example.com'}, Row {'URL': 'http://www.example.com'}]


 Thanks in advance!



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


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-08-10 Thread Val K
As I see, the problem is that ajax request (may be not ajax only) didn't 
wait for closing session file by another one and read/save data from/to it 
at any time! Lock did not work on my Win7 because , as I think, for Win 
it's one  process.
Request processing may be not pure parallel but fully asynchronous  - I 
placed some print statement in ajax controller and got full chaos - among 
print from one request were one from another.
Here is my littlle test. 3 ajax calls start at once but finish 
 asynchronously (time.sleep()).   By change time.sleep() it's possible to 
get any order (I did start first - finish last). At the end of all 
session contains only vars/changes of ajax which finish last.
   


import time

# it's a funny AJAX test
#just create new app and paste it in the default controller
# call   .../default/many_ajx_form

def ajx_bug():
if request.args(0)=='0':
time.sleep(10) # well, now wait until fish fall asleep in the pond
session.req_0='Only req_0 ... nothing else!!! Where are req_1, 
req_2 and other kids? It seems, that guys ignored my session lock?'
elif request.args(0)=='1':
time.sleep(5) 
session.req_1='I killed req_2 and created req_1 which will be 
killed by req_0 !'
else:
session.req_2='I created req_2'
response.flash=click 'Print Session' !
if request.args(0)=='0':
return dict(ret='Better late than never')
else:
return dict(ret='completed req_%s'%request.args(0))

def print_session():
lst=[]
for k,v in session.items():
lst.append(DIV(
DIV(k,_class='col-xs-2', _style=font-weight:bold; 
 text-align:right; min-height:50px),
DIV(':',_class='col-xs-1'),
DIV(v,_class='col-xs-9'),
_class='row'
   )
  )
return dict(r=DIV(*lst, _class=container, _style=max-width:800px))



# CALL THIS 
def many_ajx_form():
session.clear() #  - for clear test
session.dummy_data = 'dummy data'   # make some action for sure init 
session 
ret={}
for i in xrange(3):
ret['ajx_frm_%s'%i]= \
DIV(
LOAD('default','ajx_bug.load',
 args=[i],
 ajax=True,
 target='cont_%s'%i
 ),
_id='cont_%s'%i
   )

btn_prnt=DIV(BUTTON(Print Session, _type=button,_class=btn 
btn-default,
   _onclick=myLOAD_any(default,print_session, 
target=lst)),
 DIV(_id=lst) 
)

ret['z']=btn_prnt

return ret

#return string, no SCRIPT tag!
def myLOAD_any(contrl, fun, target, args=None, vars=None, ):

if vars:
vars_str='?'
for k,v  in vars.items():
vars_str+=('%s=%s'%(k,v))
vars_str= vars_str[:-1] # remove last ''
else:
vars_str=''
if args:
args_str='/'.join([str(it) for it  in args])
else:
args_str=''
data=dict(
   rmt= /%s/%s/%s.load/%s%s%(request.application, contrl, fun, 
args_str, vars_str ),
   trg=target
)
load_str=$.web2py.component(%(rmt)s, %(trg)s, 0, 1, 
$(#%(trg)s));
return load_str%data







On Monday, August 10, 2015 at 4:05:57 AM UTC+3, Anthony wrote:

 All responses within the same session are supposed to have the same 
 session_id. The fact that all three Ajax requests can access the session 
 doesn't necessarily mean they are being processed in parallel (the requests 
 might still be completing one after another).

 It would be helpful if you could attach a minimal app that demonstrates 
 the problem.

 Anthony

 On Sunday, August 9, 2015 at 12:30:01 PM UTC-4, Val K wrote:

 I realize your advice - no effect!
 I analyzed *session.connect* and found  strange  place at the biginig of 
 *connect *definition:
 ...
 self._unlock(response)   # -  *unconditional unlock *session file witch 
 have a name == response.session_id
 ...

 Then I  changed definition of ajx_bug(): form=SQLFORM.factory(Field('
 any', *comment=response.session_id* ), table_name=form_name)
 and here is I got:

 Many Ajx Form
 ajx_frm_0:
 Any
 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350
 ajx_frm_1:
 Any
 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350
 ajx_frm_2:
 Any
 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350






 All ajax responses have the same response_id! i.e. each ajax-process can 
 unlock session file locked by another!
 In other words, requests parallel processing works properly across 
 sessions, but  not within one session, because all responses within session 
 have the same response_id
 It seems, that file is not locked across parallel process (on my Win7 at 
 least), may because it is children of one parent or something else?



 On Sunday, August 9, 2015 at 3:28:04 PM UTC+3, Anthony wrote:

 Does the problem occur only on the first page load of the session? If 
 

[web2py] Re: can a filename be suggested in a custom Exporter class for a SQLFORM.grid?

2015-08-10 Thread Yoel Benitez Fonseca
Here is my solution, idk if this is corrent or not:

class CustomExporter(ExportClass):
label = ''
file_ext = ''
content_type = ''
file_name = ''

def __init__(self, rows):
super(CustomExporter, self).__init__(rows)
request = current.request
request.vars._export_filename = self.file_name or request.function

class ExporterPDF(CustomExporter):
label = 'PDF'
file_ext = pdf
content_type = application/pdf

def __init__(self, rows):
super(ExporterPDF, self).__init__(rows)

def export(self):
request = current.request
response = current.response
pdf = MyFPDF()
pdf.add_page()
pdf.add_font('dejavu','', 
'/agis/static/fonts/DejaVuSansCondensed.ttf')
pdf.add_font('dejavu','B', 
'/agis/static/fonts/DejaVuSansCondensed-Bold.ttf')
pdf.set_font('dejavu', '', 12)
filename = '%s/%s.pdf' % (request.controller,request.function)
if os.path.exists(os.path.join(request.folder,'views',filename)):
html=response.render(filename, dict(rows=self.rows))
else:
html=BODY(BEAUTIFY(response._vars)).xml()
pass
pdf.write_html(html)
return XML(pdf.output(dest='S'))

In this case is my own recipie for generic PDF exporting, using 
view_file.pdf as a template and request.function as the default filename 
for the exported file name.

El lunes, 10 de agosto de 2015, 14:49:23 (UTC-4), Yoel Benitez Fonseca 
escribió:

 In sqlhtml.py:

 class ExportClass(object):
 label = None
 file_ext = None
 content_type = None

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

 Is there a way to suggest a filename to the client ?


-- 
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: one to many relationship

2015-08-10 Thread Vid Ogris
Thank you for detailed answer

I am trying to implement this in SQLFORM? Looks like multiple option is not
avaliable, the field is presented as text field in the form

BTW - why web2py does not add new field to a table. If I set migrate to
True I get an error table already exists if it is set to false new fields
were not created so I had to create them manually ??

Thank you

2015-08-07 19:10 GMT+08:00 Lisandro rostagnolisan...@gmail.com:

 Hi there.
 Web2py has some cool field types called list:string, list:integer and
 list:reference table. Check them here:

 http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Field-types

 In your case, you could avoid the creation of the third table with 
 *list:reference
 table*, for example, in your db.py:

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

 db.define_table('worker',\
 Field('name'),\
 Field('skills','list:reference skill'))


 Then you can do things like:

 skill_1 = db.skill.insert(name='coding in python')
 skill_2 = db.skill.insert(name='making a cake')
 skill_3 = db.skill.insert(name='writing a song')

 db.worker.insert(name='John', skills=[skill_1, skill_2])
 db.worker.insert(name='Paul', skills=[skill_3])
 db.worker.insert(name='Richard', skills=[skill_2, skill_3])

 # search which workers have skill_2:
 have_skill_3 = db(db.worker.skills.contains(skill_2)).select()


 The list:reference field will be rendered as a select with multiple=True.
 You can always write your own widget to use other stuff, like checkboxes.

 Look for list:reference in this group, you will lots of posts about it.
 Hope it helps!



 El jueves, 6 de agosto de 2015, 22:51:53 (UTC-3), Yebach escribió:

 Hello

 How to solve the problem of one to many relationship:

 Lets say I have a worker that has multiple skills. How to set up SQLFORM
 to add as many skills to the worker as possible.

 So skills in one table workers in another.I guess a third table will be
 needed

 Thank you

 best regards

 --
 Resources:
 - http://web2py.com
 - http://web2py.com/book (Documentation)
 - http://github.com/web2py/web2py (Source code)
 - https://code.google.com/p/web2py/issues/list (Report Issues)
 ---
 You received this message because you are subscribed to a topic in the
 Google Groups web2py-users group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/web2py/HjhQdAZWFWY/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/d/optout.




-- 
Lep pozdrav

Vid Ogris

-- 
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: Code organization help

2015-08-10 Thread Dave S


On Monday, August 10, 2015 at 11:41:44 AM UTC-7, David Ripplinger wrote:

 Here's an update after I learned some more:

 It looks like I can have the best of both worlds, since web2py has routers 
 that can translate between a public URL and a back-end URL (see the 
 subsection titled URL Rewrite 
 http://web2py.com/books/default/chapter/29/04/the-core#URL-rewrite in 
 the book). My plan is to use URLs in my API such as /object_a, /object_a/1, 
 /object_a/1/info, and /object_a?type=1 along with the various HTTP methods, 
 then use the router to translate these to the appropriate controllers' URLs.


I'm exploring RESTfulness myself, slowly.  (I have some SOAP and JSONRPC 
services already, but I need to translate some things for external tools.)

Here's an example from RedHat.

POST /api/datacenters/d70d5e2d-b8ad-494a-a4d2-c7a5631073c4/storagedomains 
HTTP/1.1
POST 
/api/datacenters/d70d5e2d-b8ad-494a-a4d2-c7a5631073c4/storagedomains/fabe0451-701f-4235-8f7e-e20e458819ed/activate
 
HTTP/1.

In the book, api would be the action name, and GET, POST, etc would 
be function names (covers the first part of the example),
and the rest of the URL would be treated as arguments.  The second part of 
the example includes an extra verb (activate), but I guess that would be 
a subcase of the POST verb, based on processing the args.

(The book does use the router, but mainly to hide the controller name (in 
web2py, the file that holds the actions)

As I said, I'm still trying to absorb some of this myself.

/dps


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to 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: always https

2015-08-10 Thread Paolo Amboni
OK I'm waiting for a free certificate.

But what i can't understand is why all the site is https not only the admin 
interface.
I will study all the deployment chapter of the book to find some clues and 
how to use the new certificate.
Thanks.

Il giorno lunedì 10 agosto 2015 02:56:39 UTC+2, Anthony ha scritto:

 3) Gandi SSL certificates are simple to use, work just fine, and are not 
 expensive: gandi.net


 You can even get a free one from http://www.startssl.com/?app=1.


-- 
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: always https

2015-08-10 Thread Pablo Angulo

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

El 10/08/15 a las 10:11, Paolo Amboni escribió:
 OK I'm waiting for a free certificate.

 But what i can't understand is why all the site is https not only the
admin interface.

I told you, some web2py contributor it was best to do it that way in
2015, and everyone else thought it was a good idea, so the install
script was changed so that all http is redirected to https.
Specifically, this config tells apache redirect all http to https:


https://github.com/web2py/web2py/blob/master/scripts/setup-web2py-ubuntu.sh
VirtualHost *:80
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
  CustomLog /var/log/apache2/access.log common
  ErrorLog /var/log/apache2/error.log
/VirtualHost

while the one on the manual just configures http:

http://web2py.com/books/default/chapter/29/13/deployment-recipes#mod_wsgi

|VirtualHost *:80
  ServerName web2py.example.com
  WSGIDaemonProcess web2py user=www-data group=www-data
display-name=%{GROUP}
  WSGIProcessGroup web2py
  WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py

#This is Apache 2.2.x permission syntax. See Apache docs for 2.4 syntax
# http://httpd.apache.org/docs/2.4/upgrading.html#run-time

  Directory /home/www-data/web2py
AllowOverride None
Order Allow,Deny
Deny from all
Files wsgihandler.py
  Allow from all
/Files
  /Directory

  AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*)   
/users/www-data/web2py/applications/$1/static/$2
  Directory /users/www-data/web2py/applications/*/static/
Order Allow,Deny
Allow from all
  /Directory

  Location /admin
  Deny from all
  /Location

  LocationMatch ^/([^/]+)/appadmin
  Deny from all
  /LocationMatch

  CustomLog /private/var/log/apache2/access.log common
  ErrorLog /private/var/log/apache2/error.log
/VirtualHost|


 I will study all the deployment chapter of the book to find some clues and 
 how to use the new certificate.
 Thanks.

In the manual, or in the script, it configures a self-signed
certificate. You can use the script, or follow the book, but then you
must replace the self-signed certificates

|  SSLCertificateFile /etc/apache2/ssl/server.crt
  SSLCertificateKeyFile /etc/apache2/ssl/server.key
|

by certificated signed by startssl (only for non-commercial purposes),
or gandi.net, or any other authority. You must follow their particular
procedure to generate your server.key file and then get the correct
server.crt file.
-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iQIcBAEBCAAGBQJVyGMLAAoJEATsOw+FDrzILdIP+wfVshYU7F4teHsQZGfhCC5X
md2vA3SuNU6LE4Q+kNHaFAoY05ziUywetObgGpw36+qe59I4UePa7F3f9aNqhaQP
yFiBmdpNZZmBGUWzHABI9JbSXAjc5be/4ReNUDcAx7MKT7wpTEeXJDlsn62e4Xom
M6pXfOrLrtygsXGB0JF0DeJ3QL+EjcXPvTEQBC3x3C3bnKugDtzKfNzbxWmUhdaY
ybs5e4rmD1g+b6QG50j/imnnGm4Pqfo+iI9AmcxGfs4bjWp7vup6JV8Lr4W+CsAV
sccY0Jy6FDeqhQpdKPWcLe3YRrpY0p6wouzOZHlUfF8FeFPT7F6p9rOxEdw/2yJ6
uHfXG+9vFslM3y5lWfUp2ymp4dm0P31jfAc8eftLV+ZumiLDndO491EgJj8ewz9z
+4VMWryEW+uJF1yUjpxikeQlvIMrGz+CEj4Yj/1mB6T4g3NKgtUdyIPP3ptjrWbQ
ZMBTYPXhWETiNlf33N/YdSfz/9rzTjw+N1Vn1bc1k2WB9oyBGY7P2A/OqxrOD/G3
Mr/bFWwH0pD2UpvSWI+nUwIDoPtwgCx0SyiyItqBXnKBc5rQKSmdDBd1WSyTLWbG
zqesLbifwzfN+zK+x6oAozp2fUWLq4CgcPTOPp9RBPwdPSD7lDHrShzfoyqxYvDy
CMRh3KXHYMhdG4H2e3IU
=+WTS
-END PGP SIGNATURE-

-- 
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: always https

2015-08-10 Thread Paolo Amboni
OK now is much more clear.
If i replace the apache configuration file with the one that i find on the 
book i can have https  on admin interface only?
I got a certificate from startssl but i really can't find a way to export 
or generate the server.crt and server.key files.

My knowledge is not that advanced for the moment.
The server is only for educational purpose and to store some data from 
sensors.
Thanks.

Il giorno lunedì 10 agosto 2015 10:39:16 UTC+2, Pablo Angulo ha scritto:


 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA256

 El 10/08/15 a las 10:11, Paolo Amboni escribió:
  OK I'm waiting for a free certificate.
 
  But what i can't understand is why all the site is https not only the 
 admin interface.

 I told you, some web2py contributor it was best to do it that way in 2015, 
 and everyone else thought it was a good idea, so the install script was 
 changed so that all http is redirected to https. Specifically, this config 
 tells apache redirect all http to https:


 https://github.com/web2py/web2py/blob/master/scripts/setup-web2py-ubuntu.sh
 VirtualHost *:80
   RewriteEngine On
   RewriteCond %{HTTPS} !=on
   RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
   CustomLog /var/log/apache2/access.log common
   ErrorLog /var/log/apache2/error.log
 /VirtualHost

 while the one on the manual just configures http:

 http://web2py.com/books/default/chapter/29/13/deployment-recipes#mod_wsgi

 |VirtualHost *:80
   ServerName web2py.example.com
   WSGIDaemonProcess web2py user=www-data group=www-data 
 display-name=%{GROUP}
   WSGIProcessGroup web2py
   WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py

 #This is Apache 2.2.x permission syntax. See Apache docs for 2.4 syntax
 # http://httpd.apache.org/docs/2.4/upgrading.html#run-time

   Directory /home/www-data/web2py
 AllowOverride None
 Order Allow,Deny
 Deny from all
 Files wsgihandler.py
   Allow from all 
 /Files
   /Directory

   AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*)
 /users/www-data/web2py/applications/$1/static/$2
   Directory /users/www-data/web2py/applications/*/static/
 Order Allow,Deny
 Allow from all
   /Directory

   Location /admin
   Deny from all
   /Location

   LocationMatch ^/([^/]+)/appadmin
   Deny from all
   /LocationMatch

   CustomLog /private/var/log/apache2/access.log common
   ErrorLog /private/var/log/apache2/error.log
 /VirtualHost|


  I will study all the deployment chapter of the book to find some clues 
 and how to use the new certificate.
  Thanks.

 In the manual, or in the script, it configures a self-signed certificate. 
 You can use the script, or follow the book, but then you must replace the 
 self-signed certificates

 |  SSLCertificateFile /etc/apache2/ssl/server.crt
   SSLCertificateKeyFile /etc/apache2/ssl/server.key
 |

 by certificated signed by startssl (only for non-commercial purposes), or 
 gandi.net, or any other authority. You must follow their particular 
 procedure to generate your server.key file and then get the correct 
 server.crt file.
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v2

 iQIcBAEBCAAGBQJVyGMLAAoJEATsOw+FDrzILdIP+wfVshYU7F4teHsQZGfhCC5X
 md2vA3SuNU6LE4Q+kNHaFAoY05ziUywetObgGpw36+qe59I4UePa7F3f9aNqhaQP
 yFiBmdpNZZmBGUWzHABI9JbSXAjc5be/4ReNUDcAx7MKT7wpTEeXJDlsn62e4Xom
 M6pXfOrLrtygsXGB0JF0DeJ3QL+EjcXPvTEQBC3x3C3bnKugDtzKfNzbxWmUhdaY
 ybs5e4rmD1g+b6QG50j/imnnGm4Pqfo+iI9AmcxGfs4bjWp7vup6JV8Lr4W+CsAV
 sccY0Jy6FDeqhQpdKPWcLe3YRrpY0p6wouzOZHlUfF8FeFPT7F6p9rOxEdw/2yJ6
 uHfXG+9vFslM3y5lWfUp2ymp4dm0P31jfAc8eftLV+ZumiLDndO491EgJj8ewz9z
 +4VMWryEW+uJF1yUjpxikeQlvIMrGz+CEj4Yj/1mB6T4g3NKgtUdyIPP3ptjrWbQ
 ZMBTYPXhWETiNlf33N/YdSfz/9rzTjw+N1Vn1bc1k2WB9oyBGY7P2A/OqxrOD/G3
 Mr/bFWwH0pD2UpvSWI+nUwIDoPtwgCx0SyiyItqBXnKBc5rQKSmdDBd1WSyTLWbG
 zqesLbifwzfN+zK+x6oAozp2fUWLq4CgcPTOPp9RBPwdPSD7lDHrShzfoyqxYvDy
 CMRh3KXHYMhdG4H2e3IU
 =+WTS
 -END PGP SIGNATURE-



-- 
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: always https

2015-08-10 Thread Pablo Angulo

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

El 10/08/15 a las 10:57, Paolo Amboni escribió:
 OK now is much more clear.
 If i replace the apache configuration file with the one that i find on
the book i can have https  on admin interface only?

Yes, apache will forward both http and https to web2py, without any
redirection. Then web2py will display admin disabled because of
insecure channel if you try to enter throught http. Not a problem, I
hope, since admin interface is not for regular users.

 I got a certificate from startssl but i really can't find a way to export or 
 generate the
server.crt and server.key files.

You have to follow their instructions. The procedure varies with the
registrar. One thing is for sure:
you generate server.key: it's your private key that you do not share
with anyone, not even with the registrar.
you probably generate a csr file alongside the key file.
Then you give the csr to the registrar, the registrar verifies in some
way that you are the owner of the domain, and then they give you the crt.
You must look for details searching for apache2, openssl, and/or
startssl (you're using apache2, are you?)
-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iQIcBAEBCAAGBQJVyHD2AAoJEATsOw+FDrzIMEQP/iZgK2bdfJr+dQKFYinUncbf
BxDZY8nPb35LE0vaiyYodRaszMkJna7tQMGXNi17mOa49s4Wrw8obtz1fh8ieYo2
2CLnp0rWLLX9Gu1CcWsCCzgxEZqDQcvJXtJSUNwOrA+xYBmBHifVYGXygawS2Avw
kCn0cjQv7Z/LWm2U3ezrjVuVOM12ihIJpVazsgov36WbdcphHQ4lIEOLwmO/F4Kq
Kwy/CqhbQZaM9+scsp3pTE+s1DIhHyYRPU/K8oIZGH3d8h5D/TfS2uKqc42EDMSV
pgYq9jFwDADS6q7Km8Bx8rcn6OBez/6rCpD69MAZE3EPHePysCpN/YTENIbh9TUh
hnPPCZYEkcPFyLdCfZaOyinM0Hi9tKxjqby1sfnol3dEjurqDrL45Ja8TBwgwpBu
qRJBaZve0OLZeF7ld+Ugh+P61IolfEGp1DMEeCPZIac193y4Wou0b/WnKYVBeG9j
o1qLLARAqZcjOtTxQXLdrBnrOLsLwtQRGpzJcm6HZXv4OvB4iudqyRpuDP871Nbo
72PSwodKBBBjywrml49zyeElk7jzdhytPWEonLG3dtfSznnezj7A2GC4gaX/voej
z0bIuKMQNiJDGKwChnZn8bRuXODcODKH8sWmX8qTrLCfGpWRn7OGA9Vw1g1z6x64
Je12wGEqWxoa/1ga+mej
=pVQl
-END PGP SIGNATURE-

-- 
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] SQLFORM with external references

2015-08-10 Thread Massimiliano
You have to use requires in field definition.

Something like:

db.define_table('yourtable',
Field('title','string'),
Field('scheda', 'reference db.scheda',
requires=IS_IN_DB(db, db.scheda.scheda, zero='Select...')
)

Take a look here:
http://www.web2py.com/books/default/chapter/29/07/forms-and-validators?#Database-validators
http://www.web2py.com/books/default/chapter/29/07/forms-and-validators?search=IS_IN_DB#Links-to-referencing-records


On Sun, Aug 9, 2015 at 4:03 PM, Alessio Varalta varalt...@gmail.com wrote:

 Hi, I have a table with external references my main table is person and
 this has a field called scheda that is a external references to a table
 scheda. If i create a sqlform the field scheda is a input string and the
 user must insert the id of the external references for the form submit
 accept. There is the possibility to create sqlform where the field scheda
 is a list of schede and the user can choose one field that is translate
 like a id, because is not natural for the user insert a id. Now i simulate
 the operation with javascript but is not the solution

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




-- 
Massimiliano

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