[web2py] Re: postgres beginner questions: passwords, peer authentication, dev/production

2014-02-17 Thread Niphlod
a simple fabric file that pulls git and renames private/models/0_prod.py to 
models/0_db.py

On Sunday, February 16, 2014 10:20:05 PM UTC+1, Tim Richardson wrote:

 postgres has peer authentication. 
 If I have mapped OS user www-data to a postgres role, and if apache runs 
 as www-data, can I use peer authentication in web2py and therefore not code 
 a password in?
 It seems that the connection string is parsed for user and password.

 The main reason I want to avoid a password is that it having a different 
 password in development and production becomes a nuisance. 
 However, everyone must have this inconvenience; what's the solution that 
 I'm missing? (I use git between development and production)




-- 
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: View does not display datetime in format chosen in database.

2014-02-17 Thread Niphlod
how is it called in the view ?

On Sunday, February 16, 2014 8:23:53 PM UTC+1, HittingSmoke wrote:

 I have the following in my model:

Field('date', 'date', default=datetime.date.today(), requires = IS_DATE
 (format=('%B %-d, %Y')), writable=False,readable=False),


 ...and in the appadmin database entry form the date displays in the format 
 I've chosen. However when db.mytable.date is called in a view it displays 
 in the default -MM-DD format. According to all the search results I've 
 found setting the requires=IS_DATE format should fix this.

 How do I get the view to render the date in the format I want?


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


[web2py] Re: How to fix DAL, datetime error

2014-02-17 Thread Niphlod
all gotchas with databases are largely and explicitely documented in the 
book.
SQLite is cool because it doesn't need any setup.
That being said, I work with Postgresql wherever I can .

On Sunday, February 16, 2014 5:07:21 PM UTC+1, A36_Marty wrote:

 Thanks Niphlod.  Deleting the database fixed it.

 I had encountered a few similar errors in the past where deleting the 
 database fixed it.  However, this is the first one I've come across where 
 the app would still partially work and not fail immediately at startup.

 Sounds like SQLite may not even be a good choice for development 
 considering the bug, chasing fantom errors due to how it handles altered 
 tables/columns.   Is there a dbms you suggest that works most nicely with 
 web2py for small applications?   From my very minor experience and only 
 reading on the web, I see few negatives with Postgres.

 Thanks again.


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


[web2py] Running a web2py command after sleep

2014-02-17 Thread Robin Manoli
Hey, I would like to create a background timer, and when it finishes I 
would like web2py to do something.

I have tried numerous ways to do this, without succeeding. The closest one 
to success looked like this:
1. import urllib; urllib.urlopen(url).read() # read url which is a php 
script that calls a python script that sleeps
2. url is a php script that calls a python script that sleeps inside thread
3. the php script uses exec(/path/to/script.py ) which goes in the 
background
4. when I access the php url from my browser the web server answers 
instantly, which is why I thought it would succeed
5. when I access the php url from python/web2py however, as in the code 
above, it waits until after the sleep, which causes a timeout

Note that web2py is using apache webserver in my case.

I have also tried to sleep inside a thread in web2py, calling the script 
through a subprocess from web2py, but nothing has worked.

Is there any way to run a web2py command after a customly chosen time?

-- 
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: logout error

2014-02-17 Thread LightDot
 Keep in mind that redirect() is an equivalent to raising an HTTP(303) 
exception. In other words, an intentional exception is raised to create a 
redirect.

Looks like it's your own code doing a traceback and creating an error page 
on every exception, including the cases of the intentional redirect(), 
which is not what you want.

Regards


On Monday, February 17, 2014 8:23:57 AM UTC+1, ajith c t wrote:

 Hi Massimo, there is one more thing, it seems that the redirect problem is 
 not only with my login function. Every function where I use a redirect call 
 from my controller results in a error page with a log as 303 error.

 File /srv/trustvouch-fe/applications/app/controllers/default.py, line 
 480, in mrtusrMgr
 form = crud.update(db.tv_auth_users, request.args(1), 
 next=URL('mrtusrMgr'))
   File /srv/trustvouch-fe/gluon/tools.py, line 3906, in update
 redirect(next)
   File /srv/trustvouch-fe/gluon/http.py, line 147, in redirect
 Location=loc)
 HTTP: 303 SEE OTHER


 File /srv/trustvouch-fe/applications/app/controllers/reportmgr.py, line 
 85, in options
 redirect(URL('reportmgr', 'list'))
   File /srv/trustvouch-fe/gluon/http.py, line 147, in redirect
 Location=loc)
 HTTP: 303 SEE OTHER



 On Monday, 17 February 2014 11:57:29 UTC+5:30, ajith c t wrote:

 Sorry Massimo,  I commented both the requires_login() and 
 requires_permission() for both dashboard() and my index() functions, still 
 the error is same.

 2014-02-17 06:12:42,411 - ERROR - app - Traceback (most recent call last):
   File /srv/trustvouch-fe/applications/app/controllers/default.py, line 
 25, in login
 form = auth.login()
   File /srv/trustvouch-fe/gluon/tools.py, line 2393, in login
 redirect(next, client_side=settings.client_side)
   File /srv/trustvouch-fe/gluon/http.py, line 147, in redirect
 Location=loc)
 HTTP: 303 SEE OTHER

 got no idea on this. 

 On Sunday, 16 February 2014 13:35:20 UTC+5:30, Massimo Di Pierro wrote:

 Sorry I mean here:

 @auth.requires_login()
 @auth.requires_permission(request.function)
 def dashboard():

 you should NOT have both. Perhaps this was causing the problem?

 On Saturday, 15 February 2014 09:15:18 UTC-6, ajith c t wrote:

 Hi Massimo, 

  Thanks for the reply, but sorry to say this, but I didn't 
 understand what you meant there, which function should have both. I wanted 
 every user to have login and logout functions, thats why I didn't add 
 auth.permission for them.   And can you explain why it is giving 303 
 error. 
 Is it something with the redirect(next).

 On Thursday, 13 February 2014 18:16:27 UTC+5:30, ajith c t wrote:


 Hi ,
   I am using web2py 2.5.1-stable+timestamp.2013.06.06.15.39.19 in my 
 production environment. I know it is old but thinking about the mysql and 
 other folders and files structure changes I am little hesitant to update 
 it. My problem is this.

 My logout function doesn't work properly.  

 # Login function
 def login():
   
   try:  
 logger.debug(login page)
 form = auth.login()
 return dict(form = form)

   except Exception,e:
 logger.error(traceback.format_exc())
 redirect(URL(errorpage))

 @auth.requires_login()
 def index():

 try:
 if auth.has_membership('root'):
 logger.debug(auth.user.first_name + : logged in)
 redirect(URL('default', 'usrMgr')) 
 else:
 logger.debug(auth.user.first_name +: logged in)   

 redirect(URL('dashboard'))
 
 except Exception,e:
 logger.error(traceback.format_exc())
 redirect(URL(errorpage))

 @auth.requires_login()
 @auth.requires_permission(request.function)
 def dashboard():

   try:
 logger.info(dashboard)
 ###Some Code###
   except Exception,e:
 logger.error(traceback.format_exc())
 redirect(URL(errorpage))

  def logout():
  
try:
  logger.debug(logout)
  auth.logout(next=URL(r=request, c='default', f='login'))
  return dict()
except Exception,e:
  logger.error(traceback.format_exc())
  redirect(URL(errorpage))


 The behavior is different in different browsers. In Chrome when I 
 select logout from the dashboard page, it remains in the same page. When 
 I 
 select the developer tools and check the network the urls are logout, 
 login, dashboard in order and its loaded from cache. But there is no 
 problem in firefox.

 My problem is the logut function doesnt redirect to login page. When I 
 clear the browser cache or delete all the sessions in the sessions 
 folder, 
 it works neatly. But when the session file or the cache gets filled up, 
 everything goes wrong.  Let me know if I wasn't specific, so I can clear 
 this problem.

 Thanks and Regards,

 Ajith



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list 

[web2py] A query too far? Inner join with group by...

2014-02-17 Thread Joe Barnhart
So I'm trying to use the DAL to create all of my queries, but I may have 
just exceeded its capability.

My task is to create a view of best times for a particular sport.  The 
sport has multiple events and the user is interested in collecting their 
best times over the entire database, organized by event.  The SQL looks 
something like this:

select * from times as t
inner join (
  select course, event_code, min(finals) as min_time from times
where id_competitor= and finals0
group by course, event_code
  ) as tt
on t.event_code=tt.event_code
  and t.course=tt.course
  and t.finals=tt.min_time
  and t.id_competitor=
order by t.course, t.event_code

The  represents a specific literal ID number for the competitor.  This 
query is to be run for each competitor when they choose to see the view, so 
limiting it to a single person is the desired approach.  

The inner join choose the best (minimum) time for each course and 
event_code.  

Disqualifications are stored as negative times, so the clause to restrict 
finals0 is to exclude any of these outliers.

I've been studying up on the alternate join syntax for the DAL but I don't 
see a way to handle the conditions such as finals0 in the new syntax. 
 If the on method could be attached to a Set object instead of only a 
Table, maybe I could approach this query.

But I thought I'd ask the real SQL experts before I give up.  Also, what is 
my fallback if I need to do this query outside of DAL?

-- Joe B.

-- 
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: logout error

2014-02-17 Thread ajith c t
Thank you LightDot, saved my day and work at the right time. Read in forums 
that redirect() is internally calling a 303 exception, but didn't realise 
that I was catching that too and redirecting to errorpage. Thanks for the 
support.

On Monday, 17 February 2014 17:02:41 UTC+5:30, LightDot wrote:

 Keep in mind that redirect() is an equivalent to raising an HTTP(303) 
 exception. In other words, an intentional exception is raised to create a 
 redirect.

 Looks like it's your own code doing a traceback and creating an error page 
 on every exception, including the cases of the intentional redirect(), 
 which is not what you want.

 Regards


 On Monday, February 17, 2014 8:23:57 AM UTC+1, ajith c t wrote:

 Hi Massimo, there is one more thing, it seems that the redirect problem 
 is not only with my login function. Every function where I use a redirect 
 call from my controller results in a error page with a log as 303 error.

 File /srv/trustvouch-fe/applications/app/controllers/default.py, line 
 480, in mrtusrMgr
 form = crud.update(db.tv_auth_users, request.args(1), 
 next=URL('mrtusrMgr'))
   File /srv/trustvouch-fe/gluon/tools.py, line 3906, in update
 redirect(next)
   File /srv/trustvouch-fe/gluon/http.py, line 147, in redirect
 Location=loc)
 HTTP: 303 SEE OTHER


 File /srv/trustvouch-fe/applications/app/controllers/reportmgr.py, line 
 85, in options
 redirect(URL('reportmgr', 'list'))
   File /srv/trustvouch-fe/gluon/http.py, line 147, in redirect
 Location=loc)
 HTTP: 303 SEE OTHER



 On Monday, 17 February 2014 11:57:29 UTC+5:30, ajith c t wrote:

 Sorry Massimo,  I commented both the requires_login() and 
 requires_permission() for both dashboard() and my index() functions, still 
 the error is same.

 2014-02-17 06:12:42,411 - ERROR - app - Traceback (most recent call 
 last):
   File /srv/trustvouch-fe/applications/app/controllers/default.py, 
 line 25, in login
 form = auth.login()
   File /srv/trustvouch-fe/gluon/tools.py, line 2393, in login
 redirect(next, client_side=settings.client_side)
   File /srv/trustvouch-fe/gluon/http.py, line 147, in redirect
 Location=loc)
 HTTP: 303 SEE OTHER

 got no idea on this. 

 On Sunday, 16 February 2014 13:35:20 UTC+5:30, Massimo Di Pierro wrote:

 Sorry I mean here:

 @auth.requires_login()
 @auth.requires_permission(request.function)
 def dashboard():

 you should NOT have both. Perhaps this was causing the problem?

 On Saturday, 15 February 2014 09:15:18 UTC-6, ajith c t wrote:

 Hi Massimo, 

  Thanks for the reply, but sorry to say this, but I didn't 
 understand what you meant there, which function should have both. I 
 wanted 
 every user to have login and logout functions, thats why I didn't add 
 auth.permission for them.   And can you explain why it is giving 303 
 error. 
 Is it something with the redirect(next).

 On Thursday, 13 February 2014 18:16:27 UTC+5:30, ajith c t wrote:


 Hi ,
   I am using web2py 2.5.1-stable+timestamp.2013.06.06.15.39.19 in my 
 production environment. I know it is old but thinking about the mysql 
 and 
 other folders and files structure changes I am little hesitant to update 
 it. My problem is this.

 My logout function doesn't work properly.  

 # Login function
 def login():
   
   try:  
 logger.debug(login page)
 form = auth.login()
 return dict(form = form)

   except Exception,e:
 logger.error(traceback.format_exc())
 redirect(URL(errorpage))

 @auth.requires_login()
 def index():

 try:
 if auth.has_membership('root'):
 logger.debug(auth.user.first_name + : logged in)
 redirect(URL('default', 'usrMgr')) 
 else:
 logger.debug(auth.user.first_name +: logged in)   

 redirect(URL('dashboard'))
 
 except Exception,e:
 logger.error(traceback.format_exc())
 redirect(URL(errorpage))

 @auth.requires_login()
 @auth.requires_permission(request.function)
 def dashboard():

   try:
 logger.info(dashboard)
 ###Some Code###
   except Exception,e:
 logger.error(traceback.format_exc())
 redirect(URL(errorpage))

  def logout():
  
try:
  logger.debug(logout)
  auth.logout(next=URL(r=request, c='default', f='login'))
  return dict()
except Exception,e:
  logger.error(traceback.format_exc())
  redirect(URL(errorpage))


 The behavior is different in different browsers. In Chrome when I 
 select logout from the dashboard page, it remains in the same page. When 
 I 
 select the developer tools and check the network the urls are logout, 
 login, dashboard in order and its loaded from cache. But there is no 
 problem in firefox.

 My problem is the logut function doesnt redirect to login page. When 
 I clear the browser cache or delete all the sessions in the sessions 
 folder, it works neatly. But when the session file or the 

[web2py] Re: Running a web2py command after sleep

2014-02-17 Thread LightDot
Err... don't do this like you did :) There are some do's and don'ts in 
the programming books and you've touched most of the don'ts with your 
code.

Use the scheduler:
http://web2py.com/books/default/chapter/29/04#Scheduler

You'll also most likely be using ajax to poll the database and check if the 
task has finished in order to make your front-end perform something. Once 
you have some code in place, don't hesitate to ask more questions if you 
get stuck. Sheduler has also been discussed a lot in the past, so the 
group's search will help you too.

Regards


On Monday, February 17, 2014 12:28:59 PM UTC+1, Robin Manoli wrote:

 Hey, I would like to create a background timer, and when it finishes I 
 would like web2py to do something.

 I have tried numerous ways to do this, without succeeding. The closest one 
 to success looked like this:
 1. import urllib; urllib.urlopen(url).read() # read url which is a php 
 script that calls a python script that sleeps
 2. url is a php script that calls a python script that sleeps inside thread
 3. the php script uses exec(/path/to/script.py ) which goes in the 
 background
 4. when I access the php url from my browser the web server answers 
 instantly, which is why I thought it would succeed
 5. when I access the php url from python/web2py however, as in the code 
 above, it waits until after the sleep, which causes a timeout

 Note that web2py is using apache webserver in my case.

 I have also tried to sleep inside a thread in web2py, calling the script 
 through a subprocess from web2py, but nothing has worked.

 Is there any way to run a web2py command after a customly chosen time?


-- 
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] Can't delete records in appadmin any more after enabling auth.enable_record_versioning

2014-02-17 Thread Horst Horst
I understand that enable_record_versioning() simply makes delete set the 
records' is_active flags to False, but I'm surprised that this also affects 
addadmin. This means I can't delete records any more for real.

As a web2py newbie, this, together with my other record versioning problem 
(https://groups.google.com/forum/#!topic/web2py/XqNkiPQq8v4), makes me 
scratch my head: I would naively expect record versioning to work 
transparently, but it seems to be implemented within the same layer of 
abstraction as the API which I'm using for my app.

-- 
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: del db.my_table[id] shortcut not working any more after enabling record versioning

2014-02-17 Thread Horst Horst
I don't understand the rationale behind the way record versioning is 
implemented: If you delete a record, it is marked as is_active=False in the 
original table, but it is also copied to the my_table_archive table.

Why this doubling of data? And /if/ data is doubled, why then not 
immediately when records are inserted (into both, the regular table and the 
archive), so that deletion could indeed delete from the original table?

Wouldn't this avoid our problem here, and also this other one: 
https://groups.google.com/forum/#!topic/web2py/9UwH5uR4uew ?


Am Samstag, 15. Februar 2014 20:05:19 UTC+1 schrieb Anthony:

 Looks like for now the del db.mytable[id] syntax is incompatible with 
 enable_record_versioning. By default, enable_record_versioning shortcuts 
 the delete process via a _before_delete callback -- rather than deleting 
 the record, it simply sets the is_active field to False. This causes the 
 .delete() method to return 0, which makes the Table.__delitem__ method 
 think the delete failed, leading to the exception.

 Not sure of a good way around this. The .delete() method returns a 0 if 
 either the delete fails or if any of the _before_delete callbacks returns a 
 non-falsey value. There also does not appear to be a way to verify for 
 certain that a particular table is being archived via 
 enable_record_versioning.

 Anthony

 On Saturday, February 15, 2014 11:35:02 AM UTC-5, Horst Horst wrote:

 Hi Massimo,

 del db.piece[int(id)]

 doesn't work either. But I can definitely confirm that it depends on the

 auth.enable_record_versioning(db)

 being enabled in the model file. If I comment out the line, the error 
 does not occur, if I put it in, the error comes back.



 Am Samstag, 15. Februar 2014 05:09:54 UTC+1 schrieb Massimo Di Pierro:

 del table[id]

 is more picky. Raises an exception if id is not int and if the record 
 does not exist.

 On Friday, 14 February 2014 16:23:04 UTC-6, Horst Horst wrote:

 I have a controller function for record deletion which worked reliably 
 for quite some time.

 Today I've added

   added auth.enable_record_versioning(db)

 to my model file for the first time (my tables had auth.signature 
 fields already).

 Since then, I get 

   type 'exceptions.SyntaxError' No such record: 230

 tickets whenever I call 

   del db.piece[id]

 However,

   db(db.piece.id == id).delete()

 works fine.

 (And yes, the records *do* exist.)

 I've found this thread here 
 https://groups.google.com/forum/#!topic/web2py/rNv8oARIttI where 
 someone appears to have a similar problem. (There's no conclusion though.)



-- 
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: Can't delete records in appadmin any more after enabling auth.enable_record_versioning

2014-02-17 Thread Horst Horst
(Please excuse the self follow-up.)

Perhaps appadmin could simply get an additional checkbox to toggle 
ignore_common_filters for each query/action? It'd be actually quite useful 
to be able to work on both levels of abstractions, database-as-seen-by-app 
and database-as-is.

What's weird currently is that a query shows the latter, but delete works 
on the former.

 
Am Montag, 17. Februar 2014 13:09:36 UTC+1 schrieb Horst Horst:

 I understand that enable_record_versioning() simply makes delete set the 
 records' is_active flags to False, but I'm surprised that this also affects 
 addadmin. This means I can't delete records any more for real.

 As a web2py newbie, this, together with my other record versioning problem 
 (https://groups.google.com/forum/#!topic/web2py/XqNkiPQq8v4), makes me 
 scratch my head: I would naively expect record versioning to work 
 transparently, but it seems to be implemented within the same layer of 
 abstraction as the API which I'm using for my app.



-- 
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: del db.my_table[id] shortcut not working any more after enabling record versioning

2014-02-17 Thread Anthony
On Monday, February 17, 2014 7:24:24 AM UTC-5, Horst Horst wrote:

 I don't understand the rationale behind the way record versioning is 
 implemented: If you delete a record, it is marked as is_active=False in the 
 original table, but it is also copied to the my_table_archive table.

 Why this doubling of data? And /if/ data is doubled, why then not 
 immediately when records are inserted (into both, the regular table and the 
 archive), so that deletion could indeed delete from the original table?


As mentioned 
herehttp://web2py.com/books/default/chapter/29/09/access-control#Record-versioning,
 
deletion is only prevented if the table in question includes an is_active 
field. So, if you don't include an is_active field, you will get a 
complete record deletion after the archiving.

You can also prevent the is_active behavior by using the 
Table._enable_record_versioning method rather than 
auth.enable_record_versioning. The former takes an is_active argument, 
which is used to specify the name of the is_active field (in case you 
want to name it something else) -- if you pass in any falsey value for that 
argument, you don't get the is_active behavior (even if the table does in 
fact include an is_active field).

This could probably be clarified in the book (particularly since record 
versioning is discussed in two different places).

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] Re: Can't delete records in appadmin any more after enabling auth.enable_record_versioning

2014-02-17 Thread Anthony
See https://groups.google.com/d/msg/web2py/XqNkiPQq8v4/XwoluXJruToJ.

On Monday, February 17, 2014 7:09:36 AM UTC-5, Horst Horst wrote:

 I understand that enable_record_versioning() simply makes delete set the 
 records' is_active flags to False, but I'm surprised that this also affects 
 addadmin. This means I can't delete records any more for real.

 As a web2py newbie, this, together with my other record versioning problem 
 (https://groups.google.com/forum/#!topic/web2py/XqNkiPQq8v4), makes me 
 scratch my head: I would naively expect record versioning to work 
 transparently, but it seems to be implemented within the same layer of 
 abstraction as the API which I'm using for my app.



-- 
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: Can't delete records in appadmin any more after enabling auth.enable_record_versioning

2014-02-17 Thread Anthony


 Perhaps appadmin could simply get an additional checkbox to toggle 
 ignore_common_filters for each query/action? It'd be actually quite 
 useful to be able to work on both levels of abstractions, 
 database-as-seen-by-app and database-as-is.


I believe appadmin does ignore_common_filters, but that's not what prevents 
the deletion.

I don't think appadmin should do a complete deletion by default (just 
because you're in appadmin doesn't mean you want deletion behavior 
different from the normal app operation), but it would be nice to have that 
as an option (maybe open a Google Code issue requesting this).

For now, you could include some conditional code in a model file to change 
the behavior in appadmin:

if not request.controller == 'appadmin':
auth.enable_record_versioning(db)

Of course, that completely disables record versioning while in appadmin. 
You could instead get more sophisticated and just change the is_active 
behavior by iterating over the tables and calling _enable_record_versioning 
with the appropriate arguments.

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] Re: logout error

2014-02-17 Thread Anthony
To avoid catching the HTTP exceptions, you can do something like this:

except Exception as e:
if isinstance(e, HTTP):
raise e

Anyway, why are you wrapping all of you code in try/except statements -- 
web2py already catches all exceptions?

Anthony

On Monday, February 17, 2014 6:44:16 AM UTC-5, ajith c t wrote:

 Thank you LightDot, saved my day and work at the right time. Read in 
 forums that redirect() is internally calling a 303 exception, but didn't 
 realise that I was catching that too and redirecting to errorpage. Thanks 
 for the support.

 On Monday, 17 February 2014 17:02:41 UTC+5:30, LightDot wrote:

 Keep in mind that redirect() is an equivalent to raising an HTTP(303) 
 exception. In other words, an intentional exception is raised to create a 
 redirect.

 Looks like it's your own code doing a traceback and creating an error 
 page on every exception, including the cases of the intentional redirect(), 
 which is not what you want.

 Regards


 On Monday, February 17, 2014 8:23:57 AM UTC+1, ajith c t wrote:

 Hi Massimo, there is one more thing, it seems that the redirect problem 
 is not only with my login function. Every function where I use a redirect 
 call from my controller results in a error page with a log as 303 error.

 File /srv/trustvouch-fe/applications/app/controllers/default.py, line 
 480, in mrtusrMgr
 form = crud.update(db.tv_auth_users, request.args(1), 
 next=URL('mrtusrMgr'))
   File /srv/trustvouch-fe/gluon/tools.py, line 3906, in update
 redirect(next)
   File /srv/trustvouch-fe/gluon/http.py, line 147, in redirect
 Location=loc)
 HTTP: 303 SEE OTHER


 File /srv/trustvouch-fe/applications/app/controllers/reportmgr.py, 
 line 85, in options
 redirect(URL('reportmgr', 'list'))
   File /srv/trustvouch-fe/gluon/http.py, line 147, in redirect
 Location=loc)
 HTTP: 303 SEE OTHER



 On Monday, 17 February 2014 11:57:29 UTC+5:30, ajith c t wrote:

 Sorry Massimo,  I commented both the requires_login() and 
 requires_permission() for both dashboard() and my index() functions, still 
 the error is same.

 2014-02-17 06:12:42,411 - ERROR - app - Traceback (most recent call 
 last):
   File /srv/trustvouch-fe/applications/app/controllers/default.py, 
 line 25, in login
 form = auth.login()
   File /srv/trustvouch-fe/gluon/tools.py, line 2393, in login
 redirect(next, client_side=settings.client_side)
   File /srv/trustvouch-fe/gluon/http.py, line 147, in redirect
 Location=loc)
 HTTP: 303 SEE OTHER

 got no idea on this. 

 On Sunday, 16 February 2014 13:35:20 UTC+5:30, Massimo Di Pierro wrote:

 Sorry I mean here:

 @auth.requires_login()
 @auth.requires_permission(request.function)
 def dashboard():

 you should NOT have both. Perhaps this was causing the problem?

 On Saturday, 15 February 2014 09:15:18 UTC-6, ajith c t wrote:

 Hi Massimo, 

  Thanks for the reply, but sorry to say this, but I didn't 
 understand what you meant there, which function should have both. I 
 wanted 
 every user to have login and logout functions, thats why I didn't add 
 auth.permission for them.   And can you explain why it is giving 303 
 error. 
 Is it something with the redirect(next).

 On Thursday, 13 February 2014 18:16:27 UTC+5:30, ajith c t wrote:


 Hi ,
   I am using web2py 2.5.1-stable+timestamp.2013.06.06.15.39.19 in my 
 production environment. I know it is old but thinking about the mysql 
 and 
 other folders and files structure changes I am little hesitant to 
 update 
 it. My problem is this.

 My logout function doesn't work properly.  

 # Login function
 def login():
   
   try:  
 logger.debug(login page)
 form = auth.login()
 return dict(form = form)

   except Exception,e:
 logger.error(traceback.format_exc())
 redirect(URL(errorpage))

 @auth.requires_login()
 def index():

 try:
 if auth.has_membership('root'):
 logger.debug(auth.user.first_name + : logged in)
 redirect(URL('default', 'usrMgr')) 
 else:
 logger.debug(auth.user.first_name +: logged in)   

 redirect(URL('dashboard'))
 
 except Exception,e:
 logger.error(traceback.format_exc())
 redirect(URL(errorpage))

 @auth.requires_login()
 @auth.requires_permission(request.function)
 def dashboard():

   try:
 logger.info(dashboard)
 ###Some Code###
   except Exception,e:
 logger.error(traceback.format_exc())
 redirect(URL(errorpage))

  def logout():
  
try:
  logger.debug(logout)
  auth.logout(next=URL(r=request, c='default', f='login'))
  return dict()
except Exception,e:
  logger.error(traceback.format_exc())
  redirect(URL(errorpage))


 The behavior is different in different browsers. In Chrome when I 
 select logout from the dashboard page, it remains in the same page. 
 When I 
 select the developer tools 

[web2py] Re: Web2py instead of MS Access?

2014-02-17 Thread Anthony
Good advice. Sounded like this was going to be used on a local network by a 
couple people sitting in a room together, so didn't want to complicate 
things with Auth and logins, but yes this is the way to go if you need to 
control access and permissions.

Anthony

On Monday, February 17, 2014 2:33:17 AM UTC-5, Massimo Di Pierro wrote:

 Anthony's example is great. Anyway, I would recommend replacing this:

 def index():
 return dict(grid=SQLFORM.grid(db.person, user_signature=False))

 with this:

 @auth.requires_login()
 def index():
 return dict(grid=SQLFORM.smartgrid(db.person))

 user_signature=False will expose all data to users of the system without 
 requiring a registration/password. Apart for security implications, that 
 will prevent versioning and auditing database changes.

 On Sunday, 16 February 2014 15:24:55 UTC-6, jimbo wrote:

 Anthony that is really good, very impressive and just what I want! From 
 memory that so far actually seems to be both simpler and better than what 
 MS Access would offer.

 A lot of people and companies could make good use of web2py as a 
 database, Especially small businesses and charities etc. I need to do a bit 
 more delving and get myself up to speed hopefully. However those precise 
 instructions are a base for progress, thanks to both yourself and Neo for 
 your time.

 I will leave this open for a few more days in case anybody else has 
 something to add. Many thanks. Jimmy.

 On Saturday, 15 February 2014 14:35:49 UTC, jimbo wrote:

 Hi I am thinking of using web2py for a small database instead of MS 
 Access. It is for a charity and would have only several hundred records of 
 employees and a table for clients. It would run on a local network with 
 probably only two computers using it. The usual name, address , tel no. and 
 some certificate and photo. It would avoid licence fees for a start and I 
 think easier to use via a browser

 I know a little about Access but very basic. Are there any simple 
 examples of where I could start, or some web2py appliance available?

 If any you can help or have something I can look at I would be very 
 grateful. It's as much a learing thing for myself  as I know virtually 
 nothing aobut DB's.


 Thanks, Jim



-- 
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: Insert on related tables by code

2014-02-17 Thread Anthony
Hard to say without seeing your code and the error. Please provide more 
detail.

On Monday, February 17, 2014 1:37:32 AM UTC-5, Luca Guerrieri wrote:

 Goodmorning,
 i:m trying to fill a table record by code. All the basic test went 
 good,but now i'm trying to fill a table that has a field wich is a foreign 
 key of another.
 luca
 field ('name', db.person)
 whrn i try to fill i catch an error .
 . in which way i can compose my instruction 
 for do it? 
 thank you in advance x you patience
 luca

-- 
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] can't access admin interface when using nginx deployment script

2014-02-17 Thread Tobias Locsei
Hi, 

I'm new to web2py and I really like how easy it is to use and how excellent 
the documentation is. 

However, I'm having some trouble deploying my hello world app on a vps 
(digital ocean droplet). I used the script 
scripts/setup-web2py-nginx-uwsgi-ubuntu.sh from 
http://web2py.com/book/default/chapter/13#Nginx. The welcome app works fine 
but I can't access admin. When I try to access it I get the message Admin 
is disabled because insecure channel. If I try the same link prefixed with 
https (i.e. https://mydomain.com/admin/default/index) then I get a blank 
screen and after a couple of minutes the server is taking too long to 
respond. 

Here are the things I've checked
- changed listen 80 to listen 8080 in the configuration file because 
I'm using port forwarding
- checked that web2py.crt and web2py.key are in the /etc/nginx/ssl/ 
directory

Any ideas what I might be doing wrong? Thanks in advance for any help,

Tobias 

P.S. Not sure if it's relevant, but before I used the nginx setup script I 
used the apache one step setup script, but I couldn't get even the welcome 
app to display.

-- 
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] Web2py Separating Controller and View Layer

2014-02-17 Thread Juslin Guo
Hi All,

I making the switch from cakephp to web2py, one of the things i struggle 
with is the form module... Is there a way i could override it without 
having to touch the controller.

This requires the controller to know the css class..
form = SQLFORM(db.post,_class=form-horizontal bucket-form, 
formstyle='bootstrap')

Another method of course is using the custom.widget... but it is kind of 
cumbersome, when you fields come up to 20-30 fields

div class=form-group
label class=col-sm-3 
control-labelName/label
div class=col-sm-6
   {{form.custom.widget.author['_class'] = 
'form-control'}}
   {{=form.custom.widget.author}}
/div
/div

Is there a more elegant way to do this?

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


[web2py] Re: GAE localhost mysql instance

2014-02-17 Thread Juslin Guo
Thanks, finally i understand. Need to set my local sql with the option 
parameter when starting GAE.

On Sunday, 16 February 2014 05:06:51 UTC+8, Christian Foster Howes wrote:

 did you invoke dev_appserver.py with the options to enable mysql?  there's 
 a couple of options that you must pass to dev_appserver to tell it to load 
 and connect to mysql for local emulation of google cloud sql.  i haven't 
 done it for a while so i don't remember the exact magic incantations

 cfh

 On Wednesday, February 12, 2014 3:53:56 AM UTC-8, Juslin Guo wrote:

 Hi,

 Can anyone point me to any resource that show me how to use CloudSQL+GAE 
 together with a local mysql development environment on mac..It can't seem 
 to connect to the local mysql for development purposes.

 I did this: 

 if not request.env.web2py_runtime_gae:
 db = DAL(mysql://root:123@localhost/testing) 
 else:
 db = DAL(google:sql://juslintest:data/testgae)
 session.connect(request, response, db=db)


 Error:

 RuntimeError(Failure to connect, tried %d times:\n%s % (attempts, tb))
 RuntimeError: Failure to connect, tried 5 times:

 RuntimeError: no driver available ('MySQLdb', 'pymysql', 'mysqlconnector')



-- 
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: Web2py Separating Controller and View Layer

2014-02-17 Thread Anthony
Well, SQLFORM doesn't really provide a complete separation between 
controller and view (i.e., you typically end up specifying some display 
related parameters in the controller). You can do some manipulation of the 
form object in the view via the server side DOM. For example:

{{form['_class'] = 'form-horizontal bucket-form'}}
{{=form}}

Anthony

On Monday, February 17, 2014 3:39:00 AM UTC-5, Juslin Guo wrote:

 Hi All,

 I making the switch from cakephp to web2py, one of the things i struggle 
 with is the form module... Is there a way i could override it without 
 having to touch the controller.

 This requires the controller to know the css class..
 form = SQLFORM(db.post,_class=form-horizontal bucket-form, 
 formstyle='bootstrap')

 Another method of course is using the custom.widget... but it is kind of 
 cumbersome, when you fields come up to 20-30 fields

 div class=form-group
 label class=col-sm-3 
 control-labelName/label
 div class=col-sm-6
{{form.custom.widget.author['_class'] = 
 'form-control'}}
{{=form.custom.widget.author}}
 /div
 /div

 Is there a more elegant way to do this?



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


[web2py] Re: logout error

2014-02-17 Thread ajith c t
I too raised the HTTP class and its working fine now, thank you to all for 
your continued support. 

I wrapped the code in try/ except so that I could log everything and save 
it in a file, and in case of an error redirect to another page. If there is 
a better workaround please let me know.

On Monday, 17 February 2014 19:16:07 UTC+5:30, Anthony wrote:

 To avoid catching the HTTP exceptions, you can do something like this:

 except Exception as e:
 if isinstance(e, HTTP):
 raise e

 Anyway, why are you wrapping all of your code in try/except statements -- 
 web2py already catches all exceptions?

 Anthony

 On Monday, February 17, 2014 6:44:16 AM UTC-5, ajith c t wrote:

 Thank you LightDot, saved my day and work at the right time. Read in 
 forums that redirect() is internally calling a 303 exception, but didn't 
 realise that I was catching that too and redirecting to errorpage. Thanks 
 for the support.

 On Monday, 17 February 2014 17:02:41 UTC+5:30, LightDot wrote:

 Keep in mind that redirect() is an equivalent to raising an HTTP(303) 
 exception. In other words, an intentional exception is raised to create a 
 redirect.

 Looks like it's your own code doing a traceback and creating an error 
 page on every exception, including the cases of the intentional redirect(), 
 which is not what you want.

 Regards


 On Monday, February 17, 2014 8:23:57 AM UTC+1, ajith c t wrote:

 Hi Massimo, there is one more thing, it seems that the redirect problem 
 is not only with my login function. Every function where I use a redirect 
 call from my controller results in a error page with a log as 303 error.

 File /srv/trustvouch-fe/applications/app/controllers/default.py, line 
 480, in mrtusrMgr
 form = crud.update(db.tv_auth_users, request.args(1), 
 next=URL('mrtusrMgr'))
   File /srv/trustvouch-fe/gluon/tools.py, line 3906, in update
 redirect(next)
   File /srv/trustvouch-fe/gluon/http.py, line 147, in redirect
 Location=loc)
 HTTP: 303 SEE OTHER


 File /srv/trustvouch-fe/applications/app/controllers/reportmgr.py, 
 line 85, in options
 redirect(URL('reportmgr', 'list'))
   File /srv/trustvouch-fe/gluon/http.py, line 147, in redirect
 Location=loc)
 HTTP: 303 SEE OTHER



 On Monday, 17 February 2014 11:57:29 UTC+5:30, ajith c t wrote:

 Sorry Massimo,  I commented both the requires_login() and 
 requires_permission() for both dashboard() and my index() functions, 
 still 
 the error is same.

 2014-02-17 06:12:42,411 - ERROR - app - Traceback (most recent call 
 last):
   File /srv/trustvouch-fe/applications/app/controllers/default.py, 
 line 25, in login
 form = auth.login()
   File /srv/trustvouch-fe/gluon/tools.py, line 2393, in login
 redirect(next, client_side=settings.client_side)
   File /srv/trustvouch-fe/gluon/http.py, line 147, in redirect
 Location=loc)
 HTTP: 303 SEE OTHER

 got no idea on this. 

 On Sunday, 16 February 2014 13:35:20 UTC+5:30, Massimo Di Pierro wrote:

 Sorry I mean here:

 @auth.requires_login()
 @auth.requires_permission(request.function)
 def dashboard():

 you should NOT have both. Perhaps this was causing the problem?

 On Saturday, 15 February 2014 09:15:18 UTC-6, ajith c t wrote:

 Hi Massimo, 

  Thanks for the reply, but sorry to say this, but I didn't 
 understand what you meant there, which function should have both. I 
 wanted 
 every user to have login and logout functions, thats why I didn't add 
 auth.permission for them.   And can you explain why it is giving 303 
 error. 
 Is it something with the redirect(next).

 On Thursday, 13 February 2014 18:16:27 UTC+5:30, ajith c t wrote:


 Hi ,
   I am using web2py 2.5.1-stable+timestamp.2013.06.06.15.39.19 in 
 my production environment. I know it is old but thinking about the 
 mysql 
 and other folders and files structure changes I am little hesitant to 
 update it. My problem is this.

 My logout function doesn't work properly.  

 # Login function
 def login():
   
   try:  
 logger.debug(login page)
 form = auth.login()
 return dict(form = form)

   except Exception,e:
 logger.error(traceback.format_exc())
 redirect(URL(errorpage))

 @auth.requires_login()
 def index():

 try:
 if auth.has_membership('root'):
 logger.debug(auth.user.first_name + : logged in)
 redirect(URL('default', 'usrMgr')) 
 else:
 logger.debug(auth.user.first_name +: logged in)   

 redirect(URL('dashboard'))
 
 except Exception,e:
 logger.error(traceback.format_exc())
 redirect(URL(errorpage))

 @auth.requires_login()
 @auth.requires_permission(request.function)
 def dashboard():

   try:
 logger.info(dashboard)
 ###Some Code###
   except Exception,e:
 logger.error(traceback.format_exc())
 redirect(URL(errorpage))

  def logout():
  
try:
  logger.debug(logout)
   

Re: [web2py] My db wont allow to enter decimals lower than 1.0

2014-02-17 Thread Richard Vézina
But your field is decimal type right?

So I guess you should use decimal in your SIZES calculation...

Something like this :

from deciaml import *

[v*Decimal('0.05') for v in range(0,int(50/Decimal('0.05')))]

Richard


On Fri, Feb 14, 2014 at 3:43 PM, greenpoise danel.sega...@gmail.com wrote:

 requires=IS_IN_SET(SIZES)

 is what I am using but fails to accept values under 1.0. So, 0.1 to 0.99
 prompt the error





 On Thursday, February 13, 2014 6:48:01 PM UTC-8, Richard wrote:

 So why not use IS_FLOAT_IN_RANGE()??

 requires = IS_FLOAT_IN_RANGE(0, 100, dot=.,
  error_message='too small or too large!')


 Do you really need to specify the value in a dropbox dynamically?

 If so,

 requires=IS_IN_SET(SIZES) don't work?

 Richard






 On Thu, Feb 13, 2014 at 5:07 PM, greenpoise danel@gmail.com wrote:

 A list of decimal values from 0.1 to 50.0



 On Thursday, February 13, 2014 1:47:53 PM UTC-8, Richard wrote:

 What is SIZES?

 Is it a validators?

 Richard



 On Thu, Feb 13, 2014 at 4:24 PM, greenpoise danel@gmail.comwrote:

 could it be
 SIZES = [v*0.05 for v in range(0,int(50/0.05))]

 which I use to populate a select box?




 On Thursday, February 13, 2014 1:06:14 PM UTC-8, Richard wrote:

 Hmm, the message says Foreign Key constraint...

 Not decimal issue...

 Richard


 On Thu, Feb 13, 2014 at 4:02 PM, greenpoise danel@gmail.comwrote:

 For the first time I had to enter a value that was 0.25, for some
 reason, it comes back with this error  class
 'sqlite3.IntegrityError' FOREIGN KEY constraint failed

 I have the field as a float type. It works with any value except
 from 0.1 to 0.99. I tried decimal (10,3) still nothing.

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

 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+un...@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+un...@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.


-- 
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] Bunch/Batch/Bulk insert Re-use db.define_table field definition in SQLFORM.factory() ?

2014-02-17 Thread Richard Vézina
That an option... The other option is to wrap IS_IN_DB() into
IS_EMPTY_OR()... But it is not garanti that the concerning field will be
filled...

Richard


On Sat, Feb 15, 2014 at 3:48 PM, ksotiris sotiris.kaza...@gmail.com wrote:

 Hello web2py-users,  I am new to web2py framework. I have a question about
 the followings:


 @Steve it exactly what I have in mind, except in my case the form has to
 be generic for many differents tables, but if you only one table to bunch
 insert, that way it works fine...

 Notice, if you create more inputs then the number your users will need
 (not 3 records for instance) you get in trouble if you have not null
 requires or IS_IN_DB or other validators)... So I use an other form to
 catch the number of input the user is needing and I pass it buy the URL as
 a vars something like that :

 URL(c='controller', f='bunch_func', vars=dict(nb_inputs=3))

 Then I use it in range function :

 for i in range(0, int(request.vars.nb_inputs))


 Is there another more easy way to do this ?

 For example why not to have an option before validate the posted data to
 delete emtpy row - fields of the form and post only row - fields with no
 empty values ???
 I have already try a lot of things but nothing is working.
 The batch input form is usefull and i think must be an easy way for this.
 The above is working but is not so practical for the end user of the batch
 input 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.


-- 
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: queries from tables

2014-02-17 Thread Richard Vézina
Maybe db.executeslq(''' Plain SQL Query Here ''')

Richard


On Sun, Feb 16, 2014 at 9:24 AM, 黄祥 steve.van.chris...@gmail.com wrote:

 tried to simplyfied test the query in the shell but got no result (no
 error occured).
 e.g.
 In [4] : sum = db.purchase_detail.quantity.sum()
 print db().select(sum).first()[sum]

 In [5] : for row in db(db.product).select():
 print row.name
 product0
 product1
 product2

 In [6] : for row in db(db.purchase_detail).select():
 print row.quantity
 1
 1

 any idea how to achieve it? or perhaps i define it on the views, not in
 the controllers, is it affect the query result?

 thanks and best regards,
 stifan

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


-- 
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] A query too far? Inner join with group by...

2014-02-17 Thread Richard Vézina
Hello Joe,

Found your plain sql query already convoluted, there is not simpler way to
express it in SQL first? You seem to use join as if it was a where, join
not intent for this, using it like that will make thing slower...

Could this work :

subquery = db.executesql('''select course, event_code, min(finals) as
min_time from times
where id_competitor= and finals0
group by course, event_code''')

rows = db((db.times.event_code.belongs(subquery[1])) 
(db.times.course.belongs(subquery[0])
 (db.times.min_time.belongs(subquery[2]))  (db.times.
competitor=='').select(db.times.ALL)

I can't try

:(

Richard


On Mon, Feb 17, 2014 at 6:38 AM, Joe Barnhart joe.barnh...@gmail.comwrote:

 So I'm trying to use the DAL to create all of my queries, but I may have
 just exceeded its capability.

 My task is to create a view of best times for a particular sport.  The
 sport has multiple events and the user is interested in collecting their
 best times over the entire database, organized by event.  The SQL looks
 something like this:

 select * from times as t
 inner join (
   select course, event_code, min(finals) as min_time from times
 where id_competitor= and finals0
 group by course, event_code
   ) as tt
 on t.event_code=tt.event_code
   and t.course=tt.course
   and t.finals=tt.min_time
   and t.id_competitor=
 order by t.course, t.event_code

 The  represents a specific literal ID number for the competitor.  This
 query is to be run for each competitor when they choose to see the view, so
 limiting it to a single person is the desired approach.

 The inner join choose the best (minimum) time for each course and
 event_code.

 Disqualifications are stored as negative times, so the clause to restrict
 finals0 is to exclude any of these outliers.

 I've been studying up on the alternate join syntax for the DAL but I don't
 see a way to handle the conditions such as finals0 in the new syntax.
  If the on method could be attached to a Set object instead of only a
 Table, maybe I could approach this query.

 But I thought I'd ask the real SQL experts before I give up.  Also, what
 is my fallback if I need to do this query outside of DAL?

 -- Joe B.

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


-- 
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] Making a complete backup of an app

2014-02-17 Thread BlueShadow
Hi,
I got several problems with my current web2py version: I can't disable 
apps, I can't use the package all command, or the update command and a few 
other minor things.
So I wanted to delete web2py completly and reinstall it. But I'm not sure 
how I get all things from my app (database (sqlite)). The main App has 
become pretty big over the time (about 400mb in pictures alone)
Anyone who can tell me how I can back up my App completly without the 
package system of w2p?

-- 
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] Making a complete backup of an app

2014-02-17 Thread Richard Vézina
tar -pczvf web2py/

That way you get web2py and applications folder...

w2p package is just a kind of tar.gz compression...

If you want to be sure you don't lost anything shut down your webserver
(apache, nginx, uwsgi) before making your tar ball. So there is not request
that pop up during the compression process.

Taking web2py at the same time as your app allow you to restore the whole
thing in case things go wrong.

You can also make a tar ball of your single app

tar -pczvf appname/

Hope it helps.

Richard



On Mon, Feb 17, 2014 at 10:34 AM, BlueShadow kevin.bet...@gmail.com wrote:

 Hi,
 I got several problems with my current web2py version: I can't disable
 apps, I can't use the package all command, or the update command and a few
 other minor things.
 So I wanted to delete web2py completly and reinstall it. But I'm not sure
 how I get all things from my app (database (sqlite)). The main App has
 become pretty big over the time (about 400mb in pictures alone)
 Anyone who can tell me how I can back up my App completly without the
 package system of w2p?

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


-- 
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: logout error

2014-02-17 Thread Anthony


 I wrapped the code in try/ except so that I could log everything and save 
 it in a file, and in case of an error redirect to another page. If there is 
 a better workaround please let me know.


See http://web2py.com/books/default/chapter/29/04/the-core#Routes-on-error 
for more sophisticated error handling options. web2py already saves all 
tracebacks along with other error related details in the error tickets. 
Anyway, you might at least consider creating a decorator rather than 
repeating the exact same try/except code in every single controller 
function.

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] Re: logout error

2014-02-17 Thread ajith c t
Thanks for the help , I will look into it. Anything that helps improve my 
code is always welcome.  

On Monday, 17 February 2014 22:26:42 UTC+5:30, Anthony wrote:

 I wrapped the code in try/ except so that I could log everything and save 
 it in a file, and in case of an error redirect to another page. If there is 
 a better workaround please let me know.


 See http://web2py.com/books/default/chapter/29/04/the-core#Routes-on-errorfor 
 more sophisticated error handling options. web2py already saves all 
 tracebacks along with other error related details in the error tickets. 
 Anyway, you might at least consider creating a decorator rather than 
 repeating the exact same try/except code in every single controller 
 function.

 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] Re: Custom login form - How to detect login failure?

2014-02-17 Thread desta
I am just reporting back to say that using

if response.flash == auth.messages.invalid_login:

as Anthony suggested worked.

I don't find it very elegant but hey it works!

Thanks again!

On Sunday, February 16, 2014 6:20:00 PM UTC+2, Anthony wrote:

 On Sunday, February 16, 2014 11:07:21 AM UTC-5, André Kablu wrote:

 Or you could automatically check for auth.user_id right after the 
 validation.


 The problem is the auth.login() function does a redirect after failed 
 login, so there's no opportunity to do anything after the auth.login() 
 function completes. You would have to use the auth.settings.login_onfail 
 callback. Also, note that checking for auth.user_id after the redirect 
 doesn't help because at that point, there is no way to distinguish between 
 a failed login and a normal arrival at the login page.

 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] Re: View does not display datetime in format chosen in database.

2014-02-17 Thread HittingSmoke
It was {{=P(post.date)}} but I've since changed it to prettydate. I'm still 
curious what the solution is though.

On Monday, February 17, 2014 3:13:33 AM UTC-8, Niphlod wrote:

 how is it called in the view ?

 On Sunday, February 16, 2014 8:23:53 PM UTC+1, HittingSmoke wrote:

 I have the following in my model:

Field('date', 'date', default=datetime.date.today(), requires =IS_DATE
 (format=('%B %-d, %Y')), writable=False,readable=False),


 ...and in the appadmin database entry form the date displays in the 
 format I've chosen. However when db.mytable.date is called in a view it 
 displays in the default -MM-DD format. According to all the search 
 results I've found setting the requires=IS_DATE format should fix this.

 How do I get the view to render the date in the format I want?



-- 
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] can't access admin interface when using nginx deployment script

2014-02-17 Thread Tim Richardson
What OS? I've used ubuntu 12.04 a few times and the apache script works 
perfectly.

-- 
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] If session cookie exists /user/register redirects to /user/profile even if user has been deleted.

2014-02-17 Thread HittingSmoke
This appears to be a bug.

You can recreate it by creating a user with auth then logging in with the 
remember me box checked.

Then empty the user table in the database. Go to /user/register and you 
will be redirected to /user/profile with an Object not found error.

Clearing cookies fixes the issue.

I imagine that auth should be checking the session cookie against the user 
table then deleting the session cookie if the user no longer exists.

-- 
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] Accessing views in Legacy tables

2014-02-17 Thread pythonic . jonathan
Hi List,
So, I have a sqlite database which has some views in that I want to access. 
The database isn't a web2py one (and can't be made so). I use the web2py 
extract_sqlite_models.py script to create the models. This creates a long 
file looking something like this:

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


legacy_db.define_table('table1',
migrate=False)



#
legacy_db.define_table('table1',
migrate=False)

But I can't see any Views referenced in there. Can I use web2py to access 
views in a legacy database?

Thanks

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


[web2py] Re: can't access admin interface when using nginx deployment script

2014-02-17 Thread Tobias Locsei
Hi Tim,

I'm using ubuntu 13.10. Is there an error log or something I can post here 
to help figure out what went wrong?

Tobias

On Monday, February 17, 2014 6:41:32 PM UTC, Tim Richardson wrote:

 What OS? I've used ubuntu 12.04 a few times and the apache script works 
 perfectly.

-- 
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: can't access admin interface when using nginx deployment script

2014-02-17 Thread Anthony
Why are you port forwarding? Is SSL still on port 443?

Anthony

On Monday, February 17, 2014 5:48:02 AM UTC-5, Tobias Locsei wrote:

 Hi, 

 I'm new to web2py and I really like how easy it is to use and how 
 excellent the documentation is. 

 However, I'm having some trouble deploying my hello world app on a vps 
 (digital ocean droplet). I used the script 
 scripts/setup-web2py-nginx-uwsgi-ubuntu.sh from 
 http://web2py.com/book/default/chapter/13#Nginx. The welcome app works 
 fine but I can't access admin. When I try to access it I get the message 
 Admin is disabled because insecure channel. If I try the same link 
 prefixed with https (i.e. https://mydomain.com/admin/default/index) then 
 I get a blank screen and after a couple of minutes the server is taking 
 too long to respond. 

 Here are the things I've checked
 - changed listen 80 to listen 8080 in the configuration file because 
 I'm using port forwarding
 - checked that web2py.crt and web2py.key are in the /etc/nginx/ssl/ 
 directory

 Any ideas what I might be doing wrong? Thanks in advance for any help,

 Tobias 

 P.S. Not sure if it's relevant, but before I used the nginx setup script I 
 used the apache one step setup script, but I couldn't get even the welcome 
 app to display.


-- 
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: A few suggestions for fixes to the web2py book

2014-02-17 Thread Horst Horst
That's what I'd indeed do if if was my book.

Am Sonntag, 16. Februar 2014 05:49:23 UTC+1 schrieb Tim Richardson:

 Perhaps we just delete the entire reference to pyjamas  and see if a 0.9 
 release ever happens? 


-- 
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: If session cookie exists /user/register redirects to /user/profile even if user has been deleted.

2014-02-17 Thread Anthony
Yes, we should probably have a friendlier error in that case. You can 
submit a Google Code issue about it.

For now, you can include logic in the /default/user function to check the 
db for a valid record whenever the profile action is called.

Anthony

On Monday, February 17, 2014 1:45:42 PM UTC-5, HittingSmoke wrote:

 This appears to be a bug.

 You can recreate it by creating a user with auth then logging in with the 
 remember me box checked.

 Then empty the user table in the database. Go to /user/register and you 
 will be redirected to /user/profile with an Object not found error.

 Clearing cookies fixes the issue.

 I imagine that auth should be checking the session cookie against the user 
 table then deleting the session cookie if the user no longer exists.


-- 
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: Reusing a prefilled, readonly SQLFORM.factory form?

2014-02-17 Thread mjm
I observed the same behavior for SQLFORM.factory generated read-only forms. 
I ran into this when I had a table with lots of fields for which I wanted 
to create forms that displayed/edited only a selection of the 
fields. SQLFORM.factory is the way to go. 
Having the readonly form ignore the prepopulated form.vars looks like a bug 
to me. 



On Friday, November 4, 2011 5:21:50 PM UTC+1, pepper_bg wrote:

 This got solved by using the fact that Field.default could be 
 manipulated *after* the Field has been created (following the above 
 line of examples): 

 def build_form(readonly=False): 
 #create fields or get from 
 db 
 field1=Field('test') 
 field2=db.my_table.best 
 #set 
 defaults 
 field1.default='abc' 
 field2.default='123' 
 #give it to the 
 form 
 form = SQLFORM.factory( *[field1, field2], readonly=readonly ) 

 def frm(): 
 form = build_form( readonly=True ) 
 return dict(form=form) 

 So readonly=True and no need of form.accepts. The lesson (if I am 
 still not missing something) - if you want to reuse a SQLFORM.factory 
 form and make it readonly set the defaults using Field.default and not 
 Form.vars. Very particular... 


-- 
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] A query too far? Inner join with group by...

2014-02-17 Thread Joe Barnhart
Hi Richard --

I thought about a subquery...  But I've never seen or heard of the trick of 
using subquery[0] to pick out one column of the subquery.  

I see your approach is to materialize the subquery as a Rows object and 
then pick out elements.  I don't think this will work as expected tho 
because the belongs logic will choose incorrect values.  For example say 
the time is 10 seconds, but there are 20 different rows (NOT best times) 
with the same time.  Your approach will choose the 10 sec. time for ALL 
combinations of event code and course -- not just the SPECIFIC combination 
in the row that matches the best time..  

That's why I chose a join -- it forces the elements to match perfectly. 
 But thanks for the technique.  The idea of materializing the Rows and 
using it in another query bears thinking about.

-- Joe

On Monday, February 17, 2014 7:32:57 AM UTC-8, Richard wrote:

 Hello Joe,

 Found your plain sql query already convoluted, there is not simpler way to 
 express it in SQL first? You seem to use join as if it was a where, join 
 not intent for this, using it like that will make thing slower...

 Could this work :

 subquery = db.executesql('''select course, event_code, min(finals) as 
 min_time from times
 where id_competitor= and finals0
 group by course, event_code''')

 rows = db((db.times.event_code.belongs(subquery[1]))  
 (db.times.course.belongs(subquery[0]) 
  (db.times.min_time.belongs(subquery[2]))  (db.times.
 competitor=='').select(db.times.ALL)

 I can't try 

 :(

 Richard


 On Mon, Feb 17, 2014 at 6:38 AM, Joe Barnhart 
 joe.ba...@gmail.comjavascript:
  wrote:

 So I'm trying to use the DAL to create all of my queries, but I may have 
 just exceeded its capability.

 My task is to create a view of best times for a particular sport.  The 
 sport has multiple events and the user is interested in collecting their 
 best times over the entire database, organized by event.  The SQL looks 
 something like this:

 select * from times as t
 inner join (
   select course, event_code, min(finals) as min_time from times
 where id_competitor= and finals0
 group by course, event_code
   ) as tt
 on t.event_code=tt.event_code
   and t.course=tt.course
   and t.finals=tt.min_time
   and t.id_competitor=
 order by t.course, t.event_code

 The  represents a specific literal ID number for the competitor. 
  This query is to be run for each competitor when they choose to see the 
 view, so limiting it to a single person is the desired approach.  

 The inner join choose the best (minimum) time for each course and 
 event_code.  

 Disqualifications are stored as negative times, so the clause to restrict 
 finals0 is to exclude any of these outliers.

 I've been studying up on the alternate join syntax for the DAL but I 
 don't see a way to handle the conditions such as finals0 in the new 
 syntax.  If the on method could be attached to a Set object instead of 
 only a Table, maybe I could approach this query.

 But I thought I'd ask the real SQL experts before I give up.  Also, what 
 is my fallback if I need to do this query outside of DAL?

 -- Joe B.

  -- 
 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/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] cache issue

2014-02-17 Thread Richard
Hello,

I have an issue with app design and global variable cached python dict...

I use web2py 2.4.7

I use to create cached python dict in models like so :

update_cached_dict_if_elapsed_time = 900
cached_dict = cache.ram('cached_dict',
  lambda: {r[0]: r[1] for r in 
db.executesql(...)},
  
time_expire=update_cached_dict_if_elapsed_time)

cached_dict is a for representation of a given table ids... It intent to 
reduce the number of requests that hit the database by using python dict as 
much as possible...

But I got in trouble trying to update this dict with 
update_cached_dictt_if_elapsed_time... First as cached_dict this variable 
is in globals, so I use to add more logic around the 
update_cached_dict_if_elapsed_time var like so :


update_cached_dict_if_elapsed_time = None
if update_cached_dict_if_elapsed_time == 0:
pass
elif request.args(0) == 'table_name' and request.function == 'create' and 
request.post_vars:
update_cached_dict_if_elapsed_time = 0

I find this cumbersome and prone to error because if I have other thing 
that should trigger a dict update, I have to add more logic...

So, I though I could make factory dict function like so :

def factory_cached_dict(update_cached_dict_if_elapsed_time=900):
global
cached_dict
cached_dict = cache.ram('cached_dict',
  lambda: {r[0]: r[1] for r in 
db.executesql(...)},
  
time_expire=update_cached_dict_if_elapsed_time)

factory_cached_dict(900)

Above is in models...

Then I though I could just update my global cached_dict var from any 
controller like so :

if form.process().accepts:
factory_cached_dict(0)  # Because in this form I just add a value to 
the table use to create the python dict

But I am really desapointed it not seems to work because I still experiment 
issue with not up to date cached_dict because there is missing key value 
pairs for id and it representation.

I think the issue is that even if I call the factory after form submit the 
dict get recreated at each request by the factory call in models or there 
is something else going on that I don't understand (maybe issue with cache 
in web2py in web2py 2.4.7??)

Thanks for any help.

Richard

-- 
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: Question on linking fields

2014-02-17 Thread Jim S
Not tested, but something like this maybe??

def calls():
form = SQLFORM(db.calls)
if form.process().accepted:
id = form.vars.id
redirect(URL('leads',vars={'id':id}))

def leads():
call_id = request.get_vars.id
db.leads.business.default = call_id
 form = SQLFORM(db.leads)
 if form.process().accepted:
redirect(...to the next place you're going)


On Sunday, February 16, 2014 12:34:46 PM UTC-6, Greg Vaughan wrote:

 Hi everyone...

 Linked tables like...

 db.define_table('calls',
 Field('business', 'string'),
 ...

 and

 db.define_table('leads',
 Field('business', 'reference calls'),
 ...

 with controller containing

 def calls():
 form = SQLFORM(db.calls)
 if form.process().accepted:
 redirect(URL('leads'))

 and form

 {{extend 'layout.html'}}
 {{=form}}

 create a drop down linking list for the Business field...

 How can I make this default to the record that has just been created in 
 'calls' instead?


-- 
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] A query too far? Inner join with group by...

2014-02-17 Thread Richard Vézina
But what you do in the join should be reproducible in a where clause... I
start rewriting your join into a where clause at first and realize that I
would need to rewrite 3-4 for time the same subquery in sql or I had to
write a recursive query that would not help in translation into web2py
query...

I don't see how the multiples belongs would not lead to the samething as
you query did you try it?

You still have the option of just using db.executesql(''' your actual sql
query ''')

Richard


On Mon, Feb 17, 2014 at 3:24 PM, Joe Barnhart joe.barnh...@gmail.comwrote:

 Hi Richard --

 I thought about a subquery...  But I've never seen or heard of the trick
 of using subquery[0] to pick out one column of the subquery.

 I see your approach is to materialize the subquery as a Rows object and
 then pick out elements.  I don't think this will work as expected tho
 because the belongs logic will choose incorrect values.  For example say
 the time is 10 seconds, but there are 20 different rows (NOT best times)
 with the same time.  Your approach will choose the 10 sec. time for ALL
 combinations of event code and course -- not just the SPECIFIC combination
 in the row that matches the best time..

 That's why I chose a join -- it forces the elements to match perfectly.
  But thanks for the technique.  The idea of materializing the Rows and
 using it in another query bears thinking about.

 -- Joe


 On Monday, February 17, 2014 7:32:57 AM UTC-8, Richard wrote:

 Hello Joe,

 Found your plain sql query already convoluted, there is not simpler way
 to express it in SQL first? You seem to use join as if it was a where, join
 not intent for this, using it like that will make thing slower...

 Could this work :

 subquery = db.executesql('''select course, event_code, min(finals) as 
 min_time from times
 where id_competitor= and finals0
 group by course, event_code''')

 rows = db((db.times.event_code.belongs(subquery[1]))  (db.times.
 course.belongs(subquery[0])  (db.times.min_time.belongs(subquery[2])) 
 (db.times.competitor=='').select(db.times.ALL)

 I can't try

 :(

 Richard


 On Mon, Feb 17, 2014 at 6:38 AM, Joe Barnhart joe.ba...@gmail.comwrote:

 So I'm trying to use the DAL to create all of my queries, but I may have
 just exceeded its capability.

 My task is to create a view of best times for a particular sport.  The
 sport has multiple events and the user is interested in collecting their
 best times over the entire database, organized by event.  The SQL looks
 something like this:

 select * from times as t
 inner join (
   select course, event_code, min(finals) as min_time from times
 where id_competitor= and finals0
 group by course, event_code
   ) as tt
 on t.event_code=tt.event_code
   and t.course=tt.course
   and t.finals=tt.min_time
   and t.id_competitor=
 order by t.course, t.event_code

 The  represents a specific literal ID number for the competitor.
  This query is to be run for each competitor when they choose to see the
 view, so limiting it to a single person is the desired approach.

 The inner join choose the best (minimum) time for each course and
 event_code.

 Disqualifications are stored as negative times, so the clause to
 restrict finals0 is to exclude any of these outliers.

 I've been studying up on the alternate join syntax for the DAL but I
 don't see a way to handle the conditions such as finals0 in the new
 syntax.  If the on method could be attached to a Set object instead of
 only a Table, maybe I could approach this query.

 But I thought I'd ask the real SQL experts before I give up.  Also, what
 is my fallback if I need to do this query outside of DAL?

 -- Joe B.

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

 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.


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

Re: [web2py] cache issue

2014-02-17 Thread Richard Vézina
Hmm, I think I find my issue...

if form.process().accepts:
db.commit()
factory_cached_dict(0)  # Because in this form I just add a value to
the table use to create the python dict


On Mon, Feb 17, 2014 at 3:41 PM, Richard ml.richard.vez...@gmail.comwrote:

 Hello,

 I have an issue with app design and global variable cached python dict...

 I use web2py 2.4.7

 I use to create cached python dict in models like so :

 update_cached_dict_if_elapsed_time = 900
 cached_dict = cache.ram('cached_dict',
   lambda: {r[0]: r[1] for r in
 db.executesql(...)},

 time_expire=update_cached_dict_if_elapsed_time)

 cached_dict is a for representation of a given table ids... It intent to
 reduce the number of requests that hit the database by using python dict as
 much as possible...

 But I got in trouble trying to update this dict with
 update_cached_dictt_if_elapsed_time... First as cached_dict this variable
 is in globals, so I use to add more logic around the
 update_cached_dict_if_elapsed_time var like so :


 update_cached_dict_if_elapsed_time = None
 if update_cached_dict_if_elapsed_time == 0:
 pass
 elif request.args(0) == 'table_name' and request.function == 'create' and
 request.post_vars:
 update_cached_dict_if_elapsed_time = 0

 I find this cumbersome and prone to error because if I have other thing
 that should trigger a dict update, I have to add more logic...

 So, I though I could make factory dict function like so :

 def factory_cached_dict(update_cached_dict_if_elapsed_time=900):
 global
 cached_dict
 cached_dict = cache.ram('cached_dict',
   lambda: {r[0]: r[1] for r in
 db.executesql(...)},

 time_expire=update_cached_dict_if_elapsed_time)

 factory_cached_dict(900)

 Above is in models...

 Then I though I could just update my global cached_dict var from any
 controller like so :

 if form.process().accepts:
 factory_cached_dict(0)  # Because in this form I just add a value to
 the table use to create the python dict

 But I am really desapointed it not seems to work because I still
 experiment issue with not up to date cached_dict because there is missing
 key value pairs for id and it representation.

 I think the issue is that even if I call the factory after form submit the
 dict get recreated at each request by the factory call in models or there
 is something else going on that I don't understand (maybe issue with cache
 in web2py in web2py 2.4.7??)

 Thanks for any help.

 Richard

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


-- 
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: View does not display datetime in format chosen in database.

2014-02-17 Thread Niphlod
the rows are rendered without calling explicitely the formatter because you 
**could** want to do something with a pure python date object (e.g. 
operations, etc).
Serializing using the grid instead calls the represent routine, so it gets 
serialized according to the formatting.

BTW: beware (only for forms)... there's not a perfect match between python 
datetime formatting to the widget in js: some combinations aren't paired 
perfectly

On Monday, February 17, 2014 7:41:06 PM UTC+1, HittingSmoke wrote:

 It was {{=P(post.date)}} but I've since changed it to prettydate. I'm 
 still curious what the solution is though.

 On Monday, February 17, 2014 3:13:33 AM UTC-8, Niphlod wrote:

 how is it called in the view ?

 On Sunday, February 16, 2014 8:23:53 PM UTC+1, HittingSmoke wrote:

 I have the following in my model:

Field('date', 'date', default=datetime.date.today(), requires =IS_DATE
 (format=('%B %-d, %Y')), writable=False,readable=False),


 ...and in the appadmin database entry form the date displays in the 
 format I've chosen. However when db.mytable.date is called in a view it 
 displays in the default -MM-DD format. According to all the search 
 results I've found setting the requires=IS_DATE format should fix this.

 How do I get the view to render the date in the format I want?



-- 
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: del db.my_table[id] shortcut not working any more after enabling record versioning

2014-02-17 Thread Niphlod
the is_active = 0 is actually a good rationale because of relational 
integrity. 
Dropping a row with dependants record on it would mean dropping also the 
dependant record(s), that can't be then archived properly.

On Monday, February 17, 2014 2:02:36 PM UTC+1, Anthony wrote:

 On Monday, February 17, 2014 7:24:24 AM UTC-5, Horst Horst wrote:

 I don't understand the rationale behind the way record versioning is 
 implemented: If you delete a record, it is marked as is_active=False in the 
 original table, but it is also copied to the my_table_archive table.

 Why this doubling of data? And /if/ data is doubled, why then not 
 immediately when records are inserted (into both, the regular table and the 
 archive), so that deletion could indeed delete from the original table?


 As mentioned 
 herehttp://web2py.com/books/default/chapter/29/09/access-control#Record-versioning,
  
 deletion is only prevented if the table in question includes an is_active 
 field. So, if you don't include an is_active field, you will get a 
 complete record deletion after the archiving.

 You can also prevent the is_active behavior by using the 
 Table._enable_record_versioning method rather than 
 auth.enable_record_versioning. The former takes an is_active argument, 
 which is used to specify the name of the is_active field (in case you 
 want to name it something else) -- if you pass in any falsey value for that 
 argument, you don't get the is_active behavior (even if the table does in 
 fact include an is_active field).

 This could probably be clarified in the book (particularly since record 
 versioning is discussed in two different places).

 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.


Re: [web2py] cache issue

2014-02-17 Thread Richard Vézina
Nop!

:(

Richard


On Mon, Feb 17, 2014 at 3:54 PM, Richard Vézina ml.richard.vez...@gmail.com
 wrote:

 Hmm, I think I find my issue...

 if form.process().accepts:
 db.commit()
 factory_cached_dict(0)  # Because in this form I just add a value to
 the table use to create the python dict


 On Mon, Feb 17, 2014 at 3:41 PM, Richard ml.richard.vez...@gmail.comwrote:

 Hello,

 I have an issue with app design and global variable cached python dict...

 I use web2py 2.4.7

 I use to create cached python dict in models like so :

 update_cached_dict_if_elapsed_time = 900
 cached_dict = cache.ram('cached_dict',
   lambda: {r[0]: r[1] for r in
 db.executesql(...)},

 time_expire=update_cached_dict_if_elapsed_time)

 cached_dict is a for representation of a given table ids... It intent to
 reduce the number of requests that hit the database by using python dict as
 much as possible...

 But I got in trouble trying to update this dict with
 update_cached_dictt_if_elapsed_time... First as cached_dict this variable
 is in globals, so I use to add more logic around the
 update_cached_dict_if_elapsed_time var like so :


 update_cached_dict_if_elapsed_time = None
 if update_cached_dict_if_elapsed_time == 0:
 pass
 elif request.args(0) == 'table_name' and request.function == 'create' and
 request.post_vars:
 update_cached_dict_if_elapsed_time = 0

 I find this cumbersome and prone to error because if I have other thing
 that should trigger a dict update, I have to add more logic...

 So, I though I could make factory dict function like so :

 def factory_cached_dict(update_cached_dict_if_elapsed_time=900):
 global
 cached_dict
 cached_dict = cache.ram('cached_dict',
   lambda: {r[0]: r[1] for r in
 db.executesql(...)},

 time_expire=update_cached_dict_if_elapsed_time)

 factory_cached_dict(900)

 Above is in models...

 Then I though I could just update my global cached_dict var from any
 controller like so :

 if form.process().accepts:
 factory_cached_dict(0)  # Because in this form I just add a value to
 the table use to create the python dict

 But I am really desapointed it not seems to work because I still
 experiment issue with not up to date cached_dict because there is missing
 key value pairs for id and it representation.

 I think the issue is that even if I call the factory after form submit
 the dict get recreated at each request by the factory call in models or
 there is something else going on that I don't understand (maybe issue with
 cache in web2py in web2py 2.4.7??)

 Thanks for any help.

 Richard

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




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


Re: [web2py] Re: how to get globals like request available in my own modules ?

2014-02-17 Thread Stef Mientki

thanks guys,
current works perfect,
I missed it in the huge amount of information
cheers,
Stef

On 17-02-14 1:40, Anthony wrote:

Note, instead of this method, you can now use gluon.current.

Anthony

On Sunday, February 16, 2014 6:32:13 PM UTC-5, Julio F. Schwarzbeck 
wrote:





I assume that if you will use modules they'll probably be
implemented in
some kind of class, I'd personally do something similar to this..

# mymodule.py
class ModuleHelper(object):
  Sample Helper for common methods.

 

 def __init__(self, environment):
 self.request = environment['request']
 self.response = environment['response']
 self.session = environment['session']
 self.cache = environment['cache']
 self.db = environment['db']
 self.auth = environment['auth']

 def method(self):
 self.request.get('variable', )

...

And when instantiating the module say from a model:

# mymodel.py
from mymodule import ModuleHelper
...
And Later in the same mymodel.py
...
# Make the module class/methods available:
my_module_helper = ModuleHelper(globals())

Now you can use my_module_helper.my_method(params) from within any
view
or controller..

Hope it helps.

Julio

On 02/16/2014 01:55 PM, Stef Mientki wrote:
 hello,

 how to get globals like request available in my own modules ?

 thanks,
 Stef




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


--
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] Can I globally set readable = False for all 'id' fields in my database?

2014-02-17 Thread Jim S
Title pretty much says it all.  By default, I don't ever want to display id 
fields in any of my SQLFORMs.  Is there a setting to globally turn this off?

-Jim

-- 
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: del db.my_table[id] shortcut not working any more after enabling record versioning

2014-02-17 Thread Horst Horst
Thanks, Anthony. In fact, I was completely missing the other 
enable_record_versioning section in the DAL chapter.  

Am Montag, 17. Februar 2014 14:02:36 UTC+1 schrieb Anthony:

 On Monday, February 17, 2014 7:24:24 AM UTC-5, Horst Horst wrote:

 I don't understand the rationale behind the way record versioning is 
 implemented: If you delete a record, it is marked as is_active=False in the 
 original table, but it is also copied to the my_table_archive table.

 Why this doubling of data? And /if/ data is doubled, why then not 
 immediately when records are inserted (into both, the regular table and the 
 archive), so that deletion could indeed delete from the original table?


 As mentioned 
 herehttp://web2py.com/books/default/chapter/29/09/access-control#Record-versioning,
  
 deletion is only prevented if the table in question includes an is_active 
 field. So, if you don't include an is_active field, you will get a 
 complete record deletion after the archiving.

 You can also prevent the is_active behavior by using the 
 Table._enable_record_versioning method rather than 
 auth.enable_record_versioning. The former takes an is_active argument, 
 which is used to specify the name of the is_active field (in case you 
 want to name it something else) -- if you pass in any falsey value for that 
 argument, you don't get the is_active behavior (even if the table does in 
 fact include an is_active field).

 This could probably be clarified in the book (particularly since record 
 versioning is discussed in two different places).

 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.


Re: [web2py] Can I globally set readable = False for all 'id' fields in my database?

2014-02-17 Thread Richard Vézina
showid=False

Or

# top contoller
showid = False

and

form = SQLFORM(..., showid=showid)

Just once per controller file...

Richard



On Mon, Feb 17, 2014 at 4:21 PM, Jim S j...@qlf.com wrote:

 Title pretty much says it all.  By default, I don't ever want to display
 id fields in any of my SQLFORMs.  Is there a setting to globally turn this
 off?

 -Jim

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


-- 
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: del db.my_table[id] shortcut not working any more after enabling record versioning

2014-02-17 Thread Horst Horst
I guess I'm too dumb, but if there's a transaction before and after which 
referential integrity of the DB if given, and the records of all tables 
involved are backed up on their respective updates, why are inactive 
records in the original tables needed? I understand that the backup records 
need to refer to the former IDs in the original tables, but why do the 
inactive records themselves need to exist?


Am Montag, 17. Februar 2014 22:08:17 UTC+1 schrieb Niphlod:

 the is_active = 0 is actually a good rationale because of relational 
 integrity. 
 Dropping a row with dependants record on it would mean dropping also the 
 dependant record(s), that can't be then archived properly.

 On Monday, February 17, 2014 2:02:36 PM UTC+1, Anthony wrote:

 On Monday, February 17, 2014 7:24:24 AM UTC-5, Horst Horst wrote:

 I don't understand the rationale behind the way record versioning is 
 implemented: If you delete a record, it is marked as is_active=False in the 
 original table, but it is also copied to the my_table_archive table.

 Why this doubling of data? And /if/ data is doubled, why then not 
 immediately when records are inserted (into both, the regular table and the 
 archive), so that deletion could indeed delete from the original table?


 As mentioned 
 herehttp://web2py.com/books/default/chapter/29/09/access-control#Record-versioning,
  
 deletion is only prevented if the table in question includes an is_active 
 field. So, if you don't include an is_active field, you will get a 
 complete record deletion after the archiving.

 You can also prevent the is_active behavior by using the 
 Table._enable_record_versioning method rather than 
 auth.enable_record_versioning. The former takes an is_active argument, 
 which is used to specify the name of the is_active field (in case you 
 want to name it something else) -- if you pass in any falsey value for that 
 argument, you don't get the is_active behavior (even if the table does in 
 fact include an is_active field).

 This could probably be clarified in the book (particularly since record 
 versioning is discussed in two different places).

 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.


Re: [web2py] Re: can't access admin interface when using nginx deployment script

2014-02-17 Thread Janos Tobias Locsei
Thanks Anthony, that's the problem - I hadn't opened port 443 in my
iptables. I knew it would be something silly. It works now.

I also had to change a couple of other things to make it work. Would either
of the below compromise the security of my setup?

1. I removed the -u www-data option in the line of the script that sets
the admin password, because I don't have a user called www-data. So, my
script says something like:
sudo python -c from gluon.main import save_password;
save_password(raw_input('admin password: '),443)
Should I create a user called www-data, and if so what privileges should I
give them? Sorry if this is a naive question.

2. I had to add sudo for the following commands in the script, otherwise
they wouldn't run
sudo start uwsgi-emperor
sudo /etc/init.d/nginx restart
I'm guessing that once again this is because I don't have a user called
www-data, and I haven't updated the uid and gid lines of the uwsgi config
file to reflect the user that I'm running as.

Tobias

P.S. For completeness, here's the whole script I'm using to launch the
server now:

# Set the password for the administrative interface
cd /home/www-data/web2py
sudo python -c from gluon.main import save_password;
save_password(raw_input('admin password: '),443)
# Stop server if it was already running
sudo stop uwsgi-emperor
sudo /etc/init.d/nginx stop
# Start the server
sudo start uwsgi-emperor
sudo /etc/init.d/nginx restart







On 17 February 2014 20:09, Anthony abasta...@gmail.com wrote:

 Why are you port forwarding? Is SSL still on port 443?

 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] Re: Can I globally set readable = False for all 'id' fields in my database?

2014-02-17 Thread Jim S
Thanks Richard.  I'm looking for something a bit more global, where I don't 
have to specify it on each SQLFORM.grid call that I make.

Something on the lines of crud.settings.showid = False

I thought that might work for SQLFORM.grid as well, but my testing is 
showing that it doesn't.

-Jim


On Monday, February 17, 2014 3:21:36 PM UTC-6, Jim S wrote:

 Title pretty much says it all.  By default, I don't ever want to display 
 id fields in any of my SQLFORMs.  Is there a setting to globally turn this 
 off?

 -Jim


-- 
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: Can I globally set readable = False for all 'id' fields in my database?

2014-02-17 Thread Richard Vézina
So as you suggested db.table.id_field.readable=False or better in table
model directly readable=False so lazy_table works better...

Though, I am not sure it even works with SQLFORM.grid(), because I think it
needs you tell it specifically...

Richard


On Mon, Feb 17, 2014 at 4:39 PM, Jim S j...@qlf.com wrote:

 Thanks Richard.  I'm looking for something a bit more global, where I
 don't have to specify it on each SQLFORM.grid call that I make.

 Something on the lines of crud.settings.showid = False

 I thought that might work for SQLFORM.grid as well, but my testing is
 showing that it doesn't.

 -Jim


 On Monday, February 17, 2014 3:21:36 PM UTC-6, Jim S wrote:

 Title pretty much says it all.  By default, I don't ever want to display
 id fields in any of my SQLFORMs.  Is there a setting to globally turn this
 off?

 -Jim

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


-- 
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: Can I globally set readable = False for all 'id' fields in my database?

2014-02-17 Thread Jim S
Thanks again Richard

Right now I'm just setting it after the table def but will take your advice 
and add it directly.

-Jim

On Monday, February 17, 2014 3:45:14 PM UTC-6, Richard wrote:

 So as you suggested db.table.id_field.readable=False or better in table 
 model directly readable=False so lazy_table works better...

 Though, I am not sure it even works with SQLFORM.grid(), because I think 
 it needs you tell it specifically...

 Richard


 On Mon, Feb 17, 2014 at 4:39 PM, Jim S j...@qlf.com javascript: wrote:

 Thanks Richard.  I'm looking for something a bit more global, where I 
 don't have to specify it on each SQLFORM.grid call that I make.

 Something on the lines of crud.settings.showid = False

 I thought that might work for SQLFORM.grid as well, but my testing is 
 showing that it doesn't.

 -Jim


 On Monday, February 17, 2014 3:21:36 PM UTC-6, Jim S wrote:

 Title pretty much says it all.  By default, I don't ever want to display 
 id fields in any of my SQLFORMs.  Is there a setting to globally turn this 
 off?

 -Jim

  -- 
 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/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] A query too far? Inner join with group by...

2014-02-17 Thread Joe Barnhart
Hi Richard --

Don't need to try it...  Do a thought experiment...  The belongs matches 
the entire set of all affected times, event_codes and courses.  It becomes 
the cartesian product of all combinations of time, event_code, and course. 
 It matches N*M*K entries in the times table, where N, M, and K are the 
counts of the members of the set.  By contrast, the number of rows in the 
minimum times query is a tiny fraction of that.

Let's say I have a competitor with a minimum time of 10 sec. in event 1, 
course A.  He may also have that exact time (on a bad day) for event 2, 
course B.  In this scenario, event 2 course B would normally be a much 
faster time -- in fact his best times has such a faster time.  But when 
you do the overall query with belongs on ALL members of times, 
event_code, and course, you will match BOTH 10 sec. times -- event 1 on 
course A and event 2 on course B, so both times will appear in the final 
result.  (Along with the true best time for event 2, course B, which was 
faster than 10 sec.)

I could probably do a correlated subquery to solve this problem, but those 
are famously inefficient.  The join, convoluted as it is (and I agree 
there) is still the best way.

What I really wish I could do is use a select to return the min(time) and 
the ID of the row it occurred on.  But GROUP BY won't allow that.  One of 
the limitations of the set theory underpinning SQL.  That's where the 
correlated subquery comes it -- do a select with ORDER BY on time, then 
choose LIMIT BY 0,1 to get only one row.  But that query has to be repeated 
for every combination of course and event_code.  I have about 20 rows to 
search for a typical competitor and each query above takes around 700 ms. 
so that's not a good option!

-- Joe B.

On Monday, February 17, 2014 12:51:07 PM UTC-8, Richard wrote:

 But what you do in the join should be reproducible in a where clause... I 
 start rewriting your join into a where clause at first and realize that I 
 would need to rewrite 3-4 for time the same subquery in sql or I had to 
 write a recursive query that would not help in translation into web2py 
 query...

 I don't see how the multiples belongs would not lead to the samething as 
 you query did you try it?

 You still have the option of just using db.executesql(''' your actual sql 
 query ''')

 Richard


 On Mon, Feb 17, 2014 at 3:24 PM, Joe Barnhart 
 joe.ba...@gmail.comjavascript:
  wrote:

 Hi Richard --

 I thought about a subquery...  But I've never seen or heard of the trick 
 of using subquery[0] to pick out one column of the subquery.  

 I see your approach is to materialize the subquery as a Rows object and 
 then pick out elements.  I don't think this will work as expected tho 
 because the belongs logic will choose incorrect values.  For example say 
 the time is 10 seconds, but there are 20 different rows (NOT best times) 
 with the same time.  Your approach will choose the 10 sec. time for ALL 
 combinations of event code and course -- not just the SPECIFIC combination 
 in the row that matches the best time..  

 That's why I chose a join -- it forces the elements to match perfectly. 
  But thanks for the technique.  The idea of materializing the Rows and 
 using it in another query bears thinking about.

 -- Joe


 On Monday, February 17, 2014 7:32:57 AM UTC-8, Richard wrote:

 Hello Joe,

 Found your plain sql query already convoluted, there is not simpler way 
 to express it in SQL first? You seem to use join as if it was a where, join 
 not intent for this, using it like that will make thing slower...

 Could this work :

 subquery = db.executesql('''select course, event_code, min(finals) as 
 min_time from times
 where id_competitor= and finals0
 group by course, event_code''')

 rows = db((db.times.event_code.belongs(subquery[1]))  (db.times.
 course.belongs(subquery[0])  (db.times.min_time.belongs(subquery[2])) 
  (db.times.competitor=='').select(db.times.ALL)

 I can't try 

 :(

 Richard


 On Mon, Feb 17, 2014 at 6:38 AM, Joe Barnhart joe.ba...@gmail.comwrote:

 So I'm trying to use the DAL to create all of my queries, but I may 
 have just exceeded its capability.

 My task is to create a view of best times for a particular sport. 
  The sport has multiple events and the user is interested in collecting 
 their best times over the entire database, organized by event.  The SQL 
 looks something like this:

 select * from times as t
 inner join (
   select course, event_code, min(finals) as min_time from times
 where id_competitor= and finals0
 group by course, event_code
   ) as tt
 on t.event_code=tt.event_code
   and t.course=tt.course
   and t.finals=tt.min_time
   and t.id_competitor=
 order by t.course, t.event_code

 The  represents a specific literal ID number for the competitor. 
  This query is to be run for each competitor when they choose to see the 
 view, so limiting it to a single person is the desired approach.  

 The 

Re: [web2py] Re: Free opensource Janrain alternative - Python Social auth

2014-02-17 Thread Tito Garrido
Do we have any update about this integration?

Thanks!

Tito


On Wed, Jul 31, 2013 at 4:27 PM, Massimo Di Pierro 
massimo.dipie...@gmail.com wrote:

 Thank you. Will look at it asap.


 On Wednesday, 31 July 2013 09:45:39 UTC-5, Quint wrote:

 I made an attempt to do this myself but i need some expert opinions about
 it.

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



 On Friday, June 21, 2013 11:34:26 AM UTC+2, Leonel Câmara wrote:

 +1 on this one.

 Social login support is a huge pain on the ass. The social network
 histrionics change their APIs every month.

  --

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






-- 

Linux User #387870
.
 _/_õ|__|
..º[ .-.___.-._| . . . .
.__( o)__( o).:___

-- 
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: can't access admin interface when using nginx deployment script

2014-02-17 Thread Janos Tobias Locsei
Update: actually I do have a user called www-data, and things are working
as expected now.

What tripped me up was that using sudo -u www-data command gave an
error No such file or directory, and it turned out it was because I had
an alias for sudo. So, using /usr/bin/sudo -u www-data command works as
expected. I'm posting this here in case another linux newbie gets tripped
up by the same thing in the future.

Tobias

---

For completeness, my script for restarting the server is now:

# Check if user has root privileges
if [[ $EUID -ne 0 ]]; then
   echo You must run the script as root or using sudo
   exit 1
fi
# Set ownership of web2py directory recursively (-R)
cd /home/www-data
chown -R www-data:www-data web2py
# Set the password for the administrative interface
cd /home/www-data/web2py
/usr/bin/sudo -u www-data python -c from gluon.main import save_password;
save_password(raw_input('admin password: '),443)
# Stop server if it was already running
stop uwsgi-emperor
/etc/init.d/nginx stop
# Start the server
start uwsgi-emperor
/etc/init.d/nginx restart



On 17 February 2014 21:37, Janos Tobias Locsei jtloc...@cantab.net wrote:

 Thanks Anthony, that's the problem - I hadn't opened port 443 in my
 iptables. I knew it would be something silly. It works now.

 I also had to change a couple of other things to make it work. Would
 either of the below compromise the security of my setup?

 1. I removed the -u www-data option in the line of the script that sets
 the admin password, because I don't have a user called www-data. So, my
 script says something like:
 sudo python -c from gluon.main import save_password;
 save_password(raw_input('admin password: '),443)
 Should I create a user called www-data, and if so what privileges should I
 give them? Sorry if this is a naive question.

 2. I had to add sudo for the following commands in the script, otherwise
 they wouldn't run
 sudo start uwsgi-emperor
 sudo /etc/init.d/nginx restart
 I'm guessing that once again this is because I don't have a user called
 www-data, and I haven't updated the uid and gid lines of the uwsgi config
 file to reflect the user that I'm running as.

 Tobias

 P.S. For completeness, here's the whole script I'm using to launch the
 server now:

 # Set the password for the administrative interface
 cd /home/www-data/web2py
 sudo python -c from gluon.main import save_password;
 save_password(raw_input('admin password: '),443)
 # Stop server if it was already running
 sudo stop uwsgi-emperor
 sudo /etc/init.d/nginx stop
 # Start the server
 sudo start uwsgi-emperor
 sudo /etc/init.d/nginx restart







 On 17 February 2014 20:09, Anthony abasta...@gmail.com wrote:

 Why are you port forwarding? Is SSL still on port 443?

 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.


Re: [web2py] Re: Social Login - Twitter logs out plus some other issues- web2py 2.8.2 / Mac OS X 10.9.1

2014-02-17 Thread Tito Garrido
Hi Luciano,

Did you find a way to use auth.settings.login_form in the controllers? I am
facing the same issue.

Regards,

Tito


On Mon, Dec 23, 2013 at 2:06 PM, Luciano Laporta Podazza 
lucianopoda...@gmail.com wrote:

 Thanks for the advice Leonel!,

 You're totally right, I should change the workflow, for instance, register
 the user using web2py auth and then asking for Facebook/Twitter permissions
 to access their API.

 On the other hand, I'm still having some issues if I change the workflow:
 Web2py stores Facebook user's data only if I set *auth.settings.login_form
 *in *db.py *and I trigger /user/login. Otherwise it does not work as
 expected.

 This is the code I'm currently using:
 *db.py:*


 auth_table = db.define_table(
 auth.settings.table_user_name,
 Field('name', length=128, default=),
 Field('first_name', length=128, default=),
 Field('last_name', length=128, default=),
 Field('username', length=128, default=, unique=True),
 Field('password', 'password', length=256, readable=False, label='Password'
 ),
 Field('registration_id', length=128, default= , writable=False, readable
 =False),
 Field('registration_key', length=128, default= , writable=False,readable
 =False))


 auth_table.username.requires = IS_NOT_IN_DB(db, auth_table.username)
 auth.define_tables(username=False, signature=False)


 ## configure email
 mail = auth.settings.mailer
 mail.settings.server = 'logging' or 'smtp.gmail.com:587'
 mail.settings.sender = 'y...@gmail.com'
 mail.settings.login = 'username:password'


 ## configure auth policy
 auth.settings.registration_requires_verification = False
 auth.settings.registration_requires_approval = False
 auth.settings.reset_password_requires_verification = True


 ## Define oauth application id and secret.
 FB_CLIENT_ID='my_id'
 FB_CLIENT_SECRET=my_secret


 # import required modules
 try:
 import json
 except ImportError:
 from gluon.contrib import simplejson as json
 from facebook import GraphAPI, GraphAPIError
 from gluon.contrib.login_methods.oauth20_account import OAuthAccount




 ## extend the OAUthAccount class
 class FaceBookAccount(OAuthAccount):
 OAuth impl for FaceBook
 AUTH_URL=https://graph.facebook.com/oauth/authorize;
 TOKEN_URL=https://graph.facebook.com/oauth/access_token;


 def __init__(self):
 OAuthAccount.__init__(self, None, FB_CLIENT_ID, FB_CLIENT_SECRET,
   self.AUTH_URL, self.TOKEN_URL,
   scope='email,user_about_me,user_activities,
 user_birthday, user_education_history, user_groups, user_hometown,
 user_interests, user_likes, user_location, user_relationships,
 user_relationship_details, user_religion_politics, user_subscriptions,
 user_work_history, user_photos, user_status, user_videos, publish_actions,
 friends_hometown, friends_location,friends_photos',
   state=auth_provider=facebook,
   display='popup')
 self.graph = None


 def get_user(self):
 '''Returns the user using the Graph API.
 '''
 if not self.accessToken():
 return None


 if not self.graph:
 self.graph = GraphAPI((self.accessToken()))


 user = None
 try:
 user = self.graph.get_object(me)
 except GraphAPIError, e:
 session.token = None
 self.graph = None


 if user:
 if not user.has_key('username'):
 username = user['id']
 else:
 username = user['username']

 if not user.has_key('email'):
 email = '%s.fakemail' %(user['id'])
 else:
 email = user['email']


 return dict(first_name = user['first_name'],
 last_name = user['last_name'],
 username = username,
 email = '%s' %(email) )


 # auth.settings.login_form=FaceBookAccount()
 crud.settings.auth = None


 import oauth2 as oauth
 from gluon.contrib.login_methods.oauth10a_account import OAuthAccount as
 OAuthAccount10a


 consumer_key = my_key
 consumer_secret =  my_secret


 class TwitterAccount(OAuthAccount10a):
 AUTH_URL = http://twitter.com/oauth/authorize;
 TOKEN_URL = https://twitter.com/oauth/request_token;
 ACCESS_TOKEN_URL = http://twitter.com/oauth/access_token;
 def __init__(self, g=globals()):
 OAuthAccount10a.__init__(self, g,
   consumer_key,
   consumer_secret,
   self.AUTH_URL,
   self.TOKEN_URL,
   self.ACCESS_TOKEN_URL)

 def get_user(self):
 if self.accessToken() is not None:
 client = oauth.Client(self.consumer, self.accessToken())
 resp, content = client.request('
 http://api.twitter.com/1.1/account/verify_credentials.json')
 if 

[web2py] Re: Can I globally set readable = False for all 'id' fields in my database?

2014-02-17 Thread Anthony
After all tables have been defined, maybe something like:

[setattr(t._id, 'readable', False) for t in db]

Anthony

On Monday, February 17, 2014 4:21:36 PM UTC-5, Jim S wrote:

 Title pretty much says it all.  By default, I don't ever want to display 
 id fields in any of my SQLFORMs.  Is there a setting to globally turn this 
 off?

 -Jim


-- 
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] View performance. Helpers vs raw HTML?

2014-02-17 Thread HittingSmoke
I'm curious if there's any notable performance overhead with using helpers. 
I have the following to list database entries on my home page:

ul class=thumbnails
{{for i,post in enumerate(posts):}}
{{if i==items_per_page: break}}
{{=LI(
DIV(
A(IMG(_src=URL('static', 'content', 'thumbs', args=post.image), 
_class=img-polaroid), _href=URL(view, args=post.id)),
DIV(
H2(A(post.title, _href=URL(view, args=post.id))),
SPAN(XML(post.caption), _class=muted),
_class=caption),
_class=thumbnail),
_class=span6)}}
{{pass}}
/ul

I mostly nested all the helpers so I could better learn web2py's helper 
syntax. Now that I think I have a decent grasp of it I'm wondering if I 
should convert what I can of this to raw HTML in the view so there is less 
server-side code parsing.

Would representing this view in raw HTML instead of building it with 
helpers provide any performance benefit since the server wouldn't have to 
convert it to HTML?

-- 
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: can't access admin interface when using nginx deployment script

2014-02-17 Thread Janos Tobias Locsei
Lol, please bear with me...

I still have a question about what read/write privileges the www-data user
and group should have. I changed them along the way as I was trying to get
things to work, and I suspect I've given too strong permissions. The
permissions as they stand now for the web2py folder are (as reported by ls
-l):

drwxrwsr-x 11 www-data www-data 4096 Feb 17 21:07 web2py

Are these permissions OK?

Thanks!

Tobias




On 17 February 2014 22:06, Janos Tobias Locsei jtloc...@cantab.net wrote:

 Update: actually I do have a user called www-data, and things are working
 as expected now.

 What tripped me up was that using sudo -u www-data command gave an
 error No such file or directory, and it turned out it was because I had
 an alias for sudo. So, using /usr/bin/sudo -u www-data command works as
 expected. I'm posting this here in case another linux newbie gets tripped
 up by the same thing in the future.

 Tobias

 ---

 For completeness, my script for restarting the server is now:

 # Check if user has root privileges
 if [[ $EUID -ne 0 ]]; then
echo You must run the script as root or using sudo
exit 1
 fi
 # Set ownership of web2py directory recursively (-R)
 cd /home/www-data
 chown -R www-data:www-data web2py

 # Set the password for the administrative interface
 cd /home/www-data/web2py
 /usr/bin/sudo -u www-data python -c from gluon.main import save_password;
 save_password(raw_input('admin password: '),443)

 # Stop server if it was already running
 stop uwsgi-emperor

 /etc/init.d/nginx stop
 # Start the server
 start uwsgi-emperor
 /etc/init.d/nginx restart



 On 17 February 2014 21:37, Janos Tobias Locsei jtloc...@cantab.netwrote:

 Thanks Anthony, that's the problem - I hadn't opened port 443 in my
 iptables. I knew it would be something silly. It works now.

 I also had to change a couple of other things to make it work. Would
 either of the below compromise the security of my setup?

 1. I removed the -u www-data option in the line of the script that sets
 the admin password, because I don't have a user called www-data. So, my
 script says something like:
 sudo python -c from gluon.main import save_password;
 save_password(raw_input('admin password: '),443)
 Should I create a user called www-data, and if so what privileges should
 I give them? Sorry if this is a naive question.

 2. I had to add sudo for the following commands in the script, otherwise
 they wouldn't run
 sudo start uwsgi-emperor
 sudo /etc/init.d/nginx restart
 I'm guessing that once again this is because I don't have a user called
 www-data, and I haven't updated the uid and gid lines of the uwsgi config
 file to reflect the user that I'm running as.

 Tobias

 P.S. For completeness, here's the whole script I'm using to launch the
 server now:

 # Set the password for the administrative interface
 cd /home/www-data/web2py
 sudo python -c from gluon.main import save_password;
 save_password(raw_input('admin password: '),443)
 # Stop server if it was already running
 sudo stop uwsgi-emperor
 sudo /etc/init.d/nginx stop
 # Start the server
 sudo start uwsgi-emperor
 sudo /etc/init.d/nginx restart







 On 17 February 2014 20:09, Anthony abasta...@gmail.com wrote:

 Why are you port forwarding? Is SSL still on port 443?

 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] Re: del db.my_table[id] shortcut not working any more after enabling record versioning

2014-02-17 Thread Horst Horst
I've just tried db.piece._enable_record_versioning(is_active = None), but 
this gives me yet another behavior: Backup records appear in the archive 
database on updates, but deleting records does not create backups but the 
opposite: It deletes the record from the original table as well as all 
backups referring to it.


Am Montag, 17. Februar 2014 14:02:36 UTC+1 schrieb Anthony:

 On Monday, February 17, 2014 7:24:24 AM UTC-5, Horst Horst wrote:

 I don't understand the rationale behind the way record versioning is 
 implemented: If you delete a record, it is marked as is_active=False in the 
 original table, but it is also copied to the my_table_archive table.

 Why this doubling of data? And /if/ data is doubled, why then not 
 immediately when records are inserted (into both, the regular table and the 
 archive), so that deletion could indeed delete from the original table?


 As mentioned 
 herehttp://web2py.com/books/default/chapter/29/09/access-control#Record-versioning,
  
 deletion is only prevented if the table in question includes an is_active 
 field. So, if you don't include an is_active field, you will get a 
 complete record deletion after the archiving.

 You can also prevent the is_active behavior by using the 
 Table._enable_record_versioning method rather than 
 auth.enable_record_versioning. The former takes an is_active argument, 
 which is used to specify the name of the is_active field (in case you 
 want to name it something else) -- if you pass in any falsey value for that 
 argument, you don't get the is_active behavior (even if the table does in 
 fact include an is_active field).

 This could probably be clarified in the book (particularly since record 
 versioning is discussed in two different places).

 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] Re: del db.my_table[id] shortcut not working any more after enabling record versioning

2014-02-17 Thread Anthony
The problem is that the archive table includes a current_record field 
that references the original table, and because ondelete defaults to 
CASCADE, when the original record is deleted, so are all the records that 
point to it.

It appears the current system is designed to store previous versions of 
records that still exist, not to archive records that no longer exist. If 
we want to enable archiving of deleted records, we would have to think 
about how it should work. In that case, all previous versions would have 
invalid references, so there would be no way to know they are related to 
each other. Probably the thing to do would be to archive the final version 
of the record and then change all previous versions to reference the 
archived final version. Maybe open a Google Code issue to request this 
feature.

Anthony

On Monday, February 17, 2014 5:20:49 PM UTC-5, Horst Horst wrote:

 I've just tried db.piece._enable_record_versioning(is_active = None), but 
 this gives me yet another behavior: Backup records appear in the archive 
 database on updates, but deleting records does not create backups but the 
 opposite: It deletes the record from the original table as well as all 
 backups referring to it.


 Am Montag, 17. Februar 2014 14:02:36 UTC+1 schrieb Anthony:

 On Monday, February 17, 2014 7:24:24 AM UTC-5, Horst Horst wrote:

 I don't understand the rationale behind the way record versioning is 
 implemented: If you delete a record, it is marked as is_active=False in the 
 original table, but it is also copied to the my_table_archive table.

 Why this doubling of data? And /if/ data is doubled, why then not 
 immediately when records are inserted (into both, the regular table and the 
 archive), so that deletion could indeed delete from the original table?


 As mentioned 
 herehttp://web2py.com/books/default/chapter/29/09/access-control#Record-versioning,
  
 deletion is only prevented if the table in question includes an is_active 
 field. So, if you don't include an is_active field, you will get a 
 complete record deletion after the archiving.

 You can also prevent the is_active behavior by using the 
 Table._enable_record_versioning method rather than 
 auth.enable_record_versioning. The former takes an is_active argument, 
 which is used to specify the name of the is_active field (in case you 
 want to name it something else) -- if you pass in any falsey value for that 
 argument, you don't get the is_active behavior (even if the table does in 
 fact include an is_active field).

 This could probably be clarified in the book (particularly since record 
 versioning is discussed in two different places).

 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] Re: View performance. Helpers vs raw HTML?

2014-02-17 Thread Anthony
Yes, there should be some performance benefit to raw HTML. Also, in terms 
of style, I think raw HTML is preferred in views, unless you are making use 
of some of the special functionality of the helpers 
(see http://stackoverflow.com/a/8095585/440323).

Anthony

On Monday, February 17, 2014 5:19:19 PM UTC-5, HittingSmoke wrote:

 I'm curious if there's any notable performance overhead with using 
 helpers. I have the following to list database entries on my home page:

 ul class=thumbnails
 {{for i,post in enumerate(posts):}}
 {{if i==items_per_page: break}}
 {{=LI(
 DIV(
 A(IMG(_src=URL('static', 'content', 'thumbs', args=post.image), 
 _class=img-polaroid), _href=URL(view, args=post.id)),
 DIV(
 H2(A(post.title, _href=URL(view, args=post.id))),
 SPAN(XML(post.caption), _class=muted),
 _class=caption),
 _class=thumbnail),
 _class=span6)}}
 {{pass}}
 /ul

 I mostly nested all the helpers so I could better learn web2py's helper 
 syntax. Now that I think I have a decent grasp of it I'm wondering if I 
 should convert what I can of this to raw HTML in the view so there is less 
 server-side code parsing.

 Would representing this view in raw HTML instead of building it with 
 helpers provide any performance benefit since the server wouldn't have to 
 convert it to HTML?


-- 
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] Email password on clear text?

2014-02-17 Thread sw2band
Good day:

I am developing my first web application with web2py, so I follow the 
Setting up mail section of the reference manual:

http://web2py.com/books/default/chapter/29/08/emails-and-sms#Setting-up-email

I have a concern with the *mail.settings.login*, because this expose my 
password on clear text (if the application is successful, more developers 
will have access to the code).

Is possible to get this credentials from the auth_user table?. So this would 
be encrypted and *synchronized* with my LDAP directory.

Thank You.

-- 
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: Can I globally set readable = False for all 'id' fields in my database?

2014-02-17 Thread Jim S
yes, something like that.  Thanks!

On Monday, February 17, 2014 4:09:33 PM UTC-6, Anthony wrote:

 After all tables have been defined, maybe something like:

 [setattr(t._id, 'readable', False) for t in db]

 Anthony

 On Monday, February 17, 2014 4:21:36 PM UTC-5, Jim S wrote:

 Title pretty much says it all.  By default, I don't ever want to display 
 id fields in any of my SQLFORMs.  Is there a setting to globally turn this 
 off?

 -Jim



-- 
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] Allow NULL in form validator with reference Field

2014-02-17 Thread brahama von
Hi,

dunno why my previous post didn't make it. Here it goes.

part of my model

legacy_db.define_table('courses',
Field('awc_name','string'),
Field('awc_version','string'),
Field('awc_link','string'),
Field('awc_pro_id',legacy_db.project, required=False, default=None),
Field('awc_cli_id',legacy_db.client),
format='%(awc_name)s',
migrate=False)

While creating a form for insert new courses i get the validator error; 
value not in database

While this is true, i allow that value to be NULL in DB. How can i allow 
that in the form and insert the record?


controller

form=SQLFORM(legacy_db.courses)
if form.process().accepted:
response.flash = 'Course was added Correctly'
return dict(form=form,message=T('Edition for Courses'))


Thanks!

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


[web2py] Re: intermittent edit

2014-02-17 Thread Bruce Burkholder
I used the instructables procedure and used the following for setup:


*wget http://web2py.googlecode.com/hg/scripts/setup-web2py-ubuntu.sh chmod 
+x setup-web2py-ubuntu.sh sudo ./setup-web2py-ubuntu.sh*
I did get an error when running the chmod line but ran the next line and 
web2py setup fine. (The instructable said there may be some errors but 
web2py will still setup fine.) I can edit files fine if I use the RPI file 
manager. Like I said I can do some editing in web2py after rebooting the 
RPI but ability to edit stops probably after maybe 5 minutes. I can click 
on a file in the file toggle on the left of the screen and the file will 
highlight but will not open for edit. Menu items work fine because I can 
use the  and get back to the main file list and all the upper buttons 
work. I just seem to be locked out of edit mode.
On Sunday, February 16, 2014 11:17:05 AM UTC-5, Bruce Burkholder wrote:

 I downloaded the latest web2py and I get intermittent ability to edit 
 files. I am using a Raspberry Pi model B. I tried editing today and no can 
 do. I can view the file but can not edit it. I tried Firefox, Google Chrome 
 and IE but am not able to edit. Seems if I reboot my RPI and reconnect to 
 my HTTPS, I will get one edit and the second time I try to edit, I am no 
 longer able to.
 Thanks


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


[web2py] Re: queries from tables

2014-02-17 Thread 黄祥
i'm so sorry my bad, it can work now, the problem is :
 sum = db.purchase_detail.quantity.sum()
print db().select(sum).first()[sum]

should be :
 sum = db.purchase_detail.quantity.sum()
 print db().select(sum).first()[sum]

the problem is occured because i create the query on the text editor and 
then copy whole code (2 lines) and paste in the web2py shell, it should be 
copy just one line and then paste it on the web2py shell.

and for the query above is i made a mistook for the select and _select, all 
works now.
*views/report/report_product.html*
{{=DIV('%s - %s' % (from_date, to_date) ) }}

table class = table
tr
th{{=SPAN(B(T('Code') ) ) }} 
/th
th{{=SPAN(B(T('Name') ) ) }} 
/th
th{{=SPAN(B(T('Base Unit') ) ) }}
/th
th{{=SPAN(B(T('Beginning') ) ) }}
/th
th{{=SPAN(B(T('In') ) ) }}
/th
th{{=SPAN(B(T('Out') ) ) }}
/th
th{{=SPAN(B(T('Balance') ) ) }}
/th
/tr

{{for row_product in db(db.product).select():}}
{{sum_quantity_purchase = db.purchase_detail.quantity.sum()}}
{{sum_quantity_sale = db.sale_detail.quantity.sum()}}

{{query_purchase_detail = (row_product.id == db.purchase_detail.product)  
(db.purchase_detail.purchase_no == db.purchase_header.id)  
(db.purchase_header.purchase_date = from_date)  
(db.purchase_header.purchase_date = to_date)}}
{{query_sale_detail = (row_product.id == db.sale_detail.product)  
(db.sale_detail.sale_no == db.sale_header.id)  (db.sale_header.sale_date 
= from_date)  (db.sale_header.sale_date = to_date) }}

{{purchase_result = 
db(query_purchase_detail).select(sum_quantity_purchase).first()[sum_quantity_purchase]
 
if db(query_purchase_detail).select() else 0}}
{{sale_result = 
db(query_sale_detail).select(sum_quantity_sale).first()[sum_quantity_sale] 
if db(query_sale_detail).select() else 0}}

tr
td{{=DIV(row_product.code)}}
/td
td{{=DIV(row_product.name)}}
/td
td{{=DIV(row_product.base_unit)}}
/td
td{{=DIV(row_product.quantity + sale_result - purchase_result)}}
/td
td{{=DIV(purchase_result)}}
/td
td{{=DIV(sale_result)}}
/td
td{{=DIV(row_product.quantity)}}
/td
/tr
{{pass}}

/table

thanks and best regards,
stifan

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


Re: [web2py] Making a complete backup of an app

2014-02-17 Thread 黄祥
another way is to be specific just copy your web2py app path from the 
system :
e.g.
rsync -avuzp web2py/app1 /backup/

or if you know exactly which path is belongs to your application, you can 
delete unnecessary folders on it.
e.g. you can delete folders : cache, errors, sessions, etc.

best regards,
stifan

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


[web2py] Re: View performance. Helpers vs raw HTML?

2014-02-17 Thread HittingSmoke
Wow, that is thorough and answers almost all of my other questions on 
helpers as well. Thanks.

New view is:

ul class=thumbnails
{{for i,post in enumerate(posts):}}
{{if i==items_per_page: break}}
li class=span6
div class=thumbnail
a href={{=URL(view, args=post.id)}}
img src={{=URL('static', 'content', 'thumbs', 
args=post.image)}} class=img-polaroid
/a
div class=caption
h2
a href={{=URL(view, args=post.id)}}{{=post.title}}/a
/h2
span class=muted{{=XML(post.caption)}}/span
/div
/div
/li
/ul



On Monday, February 17, 2014 3:03:49 PM UTC-8, Anthony wrote:

 Yes, there should be some performance benefit to raw HTML. Also, in terms 
 of style, I think raw HTML is preferred in views, unless you are making use 
 of some of the special functionality of the helpers (see 
 http://stackoverflow.com/a/8095585/440323).

 Anthony

 On Monday, February 17, 2014 5:19:19 PM UTC-5, HittingSmoke wrote:

 I'm curious if there's any notable performance overhead with using 
 helpers. I have the following to list database entries on my home page:

 ul class=thumbnails
 {{for i,post in enumerate(posts):}}
 {{if i==items_per_page: break}}
 {{=LI(
 DIV(
 A(IMG(_src=URL('static', 'content', 'thumbs', args=post.image), 
 _class=img-polaroid), _href=URL(view, args=post.id)),
 DIV(
 H2(A(post.title, _href=URL(view, args=post.id))),
 SPAN(XML(post.caption), _class=muted),
 _class=caption),
 _class=thumbnail),
 _class=span6)}}
 {{pass}}
 /ul

 I mostly nested all the helpers so I could better learn web2py's helper 
 syntax. Now that I think I have a decent grasp of it I'm wondering if I 
 should convert what I can of this to raw HTML in the view so there is less 
 server-side code parsing.

 Would representing this view in raw HTML instead of building it with 
 helpers provide any performance benefit since the server wouldn't have to 
 convert it to HTML?



-- 
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: Proper jQuery syntax in a component.load to refer an element in the containing HTML file?

2014-02-17 Thread A36_Marty
Found the answer through playing around with a sample html file - in case 
future novice users find this useful.

To hit a select list on an html page called id=account_select from a 
script in a component.load file, normal jQuery syntax works with the .val() 
function.   

e.g. From the component script: $(#account_select).val() gets the value 
of the list, while $(#account_select).value
does not.

In my novice state of jQuery and web2py, I had gotten confused due to using 
this.value successfully on another function and thought just selecting 
another element with $(...).value would work just as well.   It didn't.

In hopes of simplifying the problem, I confused it:  I created a simple 
html file, double clicked on it in Finder and would view it in Safari.   
Using an editor, I'd change the script in the html file, save it, and 
reload the file in Safair to trial-and-error jQuery syntax until I got 
something working.   I was using jQuery's alert() to pop-up debug/see 
responses from the $() code.   I found that even though the page source 
changed and was save with the correct code shown in the show source 
option of Safari, sometimes the alert() would fire and sometime it 
wouldn't.   I loaded my html in PyCharm and used View  Preview File In... 
[Safari] - and the alert() function worked every time...   So I probably 
had the script working much sooner than realized, but didn't see any 
alert() responses and assumed it was jQuery erroring out (when it 
wasn't)...   

I've got to be by-far the most novice web2py / jQuery user here -- and am 
simply hoping to pay-it-forward for other novices climbing the learning 
curve in the future...

On Sunday, February 16, 2014 11:24:20 PM UTC-6, A36_Marty wrote:

 I have an index.html page that loads two elements:
 1) A select list, id='account_select'
 2) A component (open_positions.load)

 In the component (open_positions.load), I have a script that needs to 
 get the value the select list (id='account_select') in the parent document.

 The following code does not work:
 $('#account_select).value

 Nor does this work:
 $(#account_select, parent.document).value

 What is the proper jQuery syntax to refer to the select list in the parent 
 html file from a script within the component.load file?




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


[web2py] How can I run postgresql VACUUM from web2py?

2014-02-17 Thread User
I'm trying to run postgresql vacuum from web2py (ultimately to be run by a 
scheduled task) and I get the following error:

db.executesql('VACUUM sometable;')
*** ProgrammingError: ('ERROR', '25001', 'VACUUM cannot run inside a 
transaction
 block')

How can I run VACUUM from web2py?

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


[web2py] SQLFORM.grid Search

2014-02-17 Thread horridohobbyist
I'm using SQLFORM.grid for my application. It's very powerful and saves me 
a lot of work. However, I would like to alter/customize the search function 
in the grid. Is there a way for me to do this?

Thanks.

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


[web2py] Making a phone call from within Web2Py

2014-02-17 Thread NeoToren
Maybe I am pushing the limits here...but I wonder, if we have an address 
book, with phone numbers ...and today most apps (W2P included)  run quite 
well in browsers (NOT as native app but HTML)then can user just click 
on the number and the smart phone will make the call ?
Like a ...native app ?
;-))
Did anyone have an idea if the above is doable in W2P ?
I know W2P can send emails and SMS - but what about making a phone call ?

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


[web2py] Re: SQLFORM.grid Search

2014-02-17 Thread Anthony
Yes. The searchable argument can be a callable that builds a query based 
on the keywords, and there is a search_widget argument you can use to 
generate a custom search widget. I suggest you check out the SQLFORM.grid 
code in gluon.sqlhtml to see how they work.

Anthony

On Monday, February 17, 2014 11:02:03 PM UTC-5, horridohobbyist wrote:

 I'm using SQLFORM.grid for my application. It's very powerful and saves me 
 a lot of work. However, I would like to alter/customize the search function 
 in the grid. Is there a way for me to do this?

 Thanks.


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


[web2py] Re: SQLFORM.grid Search

2014-02-17 Thread Anthony
Note, if you don't want to create a new search widget but just want to 
remove the default Javascript widget and instead have a basic search input 
field, you can do:

search_input = grid.element('#w2p_directory_keywords')
search_input and search_input.attributes.pop('_onfocus')

That simply removes the _onfocus event handler, which disables the 
Javascript functionality of the widget.

Anthony

On Monday, February 17, 2014 11:12:52 PM UTC-5, Anthony wrote:

 Yes. The searchable argument can be a callable that builds a query based 
 on the keywords, and there is a search_widget argument you can use to 
 generate a custom search widget. I suggest you check out the SQLFORM.grid 
 code in gluon.sqlhtml to see how they work.

 Anthony

 On Monday, February 17, 2014 11:02:03 PM UTC-5, horridohobbyist wrote:

 I'm using SQLFORM.grid for my application. It's very powerful and saves 
 me a lot of work. However, I would like to alter/customize the search 
 function in the grid. Is there a way for me to do this?

 Thanks.



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


Re: [web2py] Re: Social Login - Twitter logs out plus some other issues- web2py 2.8.2 / Mac OS X 10.9.1

2014-02-17 Thread Luciano Laporta Podazza
Hi Tito,

Actually yes but I forgot to tell you guys :P

I don't know if it's the best, compliant way of doing it but it works for
me. I just ended up using flags taking advantage of  'session' and under
the db.py. For instance:

*db.py:*
if session.facebook == 1:
auth.settings.login_form = FaceBookAccount()
elif session.facebook == 0:
pass

*controller.py:*
def index():
session.facebook = 0

def facebook():
session.facebook = 1
return dict(form=auth())


And that's all, whenever the user hits myapp/default/facebook it will
redirect the user to facebook auth, login, and register it leaving the
regular login/register intact and totally functional :)

Hope it makes sense and that it helps you.

Cheers



On Mon, Feb 17, 2014 at 7:07 PM, Tito Garrido titogarr...@gmail.com wrote:

 Hi Luciano,

 Did you find a way to use auth.settings.login_form in the controllers? I
 am facing the same issue.

 Regards,

 Tito


 On Mon, Dec 23, 2013 at 2:06 PM, Luciano Laporta Podazza 
 lucianopoda...@gmail.com wrote:

 Thanks for the advice Leonel!,

 You're totally right, I should change the workflow, for instance,
 register the user using web2py auth and then asking for Facebook/Twitter
 permissions to access their API.

 On the other hand, I'm still having some issues if I change the workflow:
 Web2py stores Facebook user's data only if I set *auth.settings.login_form
 *in *db.py *and I trigger /user/login. Otherwise it does not work as
 expected.

 This is the code I'm currently using:
 *db.py:*


 auth_table = db.define_table(
 auth.settings.table_user_name,
 Field('name', length=128, default=),
 Field('first_name', length=128, default=),
 Field('last_name', length=128, default=),
 Field('username', length=128, default=, unique=True),
 Field('password', 'password', length=256, readable=False, label=
 'Password'),
 Field('registration_id', length=128, default= , writable=False,readable
 =False),
 Field('registration_key', length=128, default= , writable=False,readable
 =False))


 auth_table.username.requires = IS_NOT_IN_DB(db, auth_table.username)
 auth.define_tables(username=False, signature=False)


 ## configure email
 mail = auth.settings.mailer
 mail.settings.server = 'logging' or 'smtp.gmail.com:587'
 mail.settings.sender = 'y...@gmail.com'
 mail.settings.login = 'username:password'


 ## configure auth policy
 auth.settings.registration_requires_verification = False
 auth.settings.registration_requires_approval = False
 auth.settings.reset_password_requires_verification = True


 ## Define oauth application id and secret.
 FB_CLIENT_ID='my_id'
 FB_CLIENT_SECRET=my_secret


 # import required modules
 try:
 import json
 except ImportError:
 from gluon.contrib import simplejson as json
 from facebook import GraphAPI, GraphAPIError
 from gluon.contrib.login_methods.oauth20_account import OAuthAccount




 ## extend the OAUthAccount class
 class FaceBookAccount(OAuthAccount):
 OAuth impl for FaceBook
 AUTH_URL=https://graph.facebook.com/oauth/authorize;
 TOKEN_URL=https://graph.facebook.com/oauth/access_token;


 def __init__(self):
 OAuthAccount.__init__(self, None, FB_CLIENT_ID, FB_CLIENT_SECRET,
   self.AUTH_URL, self.TOKEN_URL,
   scope='email,user_about_me,user_activities,
 user_birthday, user_education_history, user_groups, user_hometown,
 user_interests, user_likes, user_location, user_relationships,
 user_relationship_details, user_religion_politics, user_subscriptions,
 user_work_history, user_photos, user_status, user_videos, publish_actions,
 friends_hometown, friends_location,friends_photos',
   state=auth_provider=facebook,
   display='popup')
 self.graph = None


 def get_user(self):
 '''Returns the user using the Graph API.
 '''
 if not self.accessToken():
 return None


 if not self.graph:
 self.graph = GraphAPI((self.accessToken()))


 user = None
 try:
 user = self.graph.get_object(me)
 except GraphAPIError, e:
 session.token = None
 self.graph = None


 if user:
 if not user.has_key('username'):
 username = user['id']
 else:
 username = user['username']

 if not user.has_key('email'):
 email = '%s.fakemail' %(user['id'])
 else:
 email = user['email']


 return dict(first_name = user['first_name'],
 last_name = user['last_name'],
 username = username,
 email = '%s' %(email) )


 # auth.settings.login_form=FaceBookAccount()
 crud.settings.auth = None


 import oauth2 as oauth
 from gluon.contrib.login_methods.oauth10a_account import OAuthAccount as
 OAuthAccount10a


 consumer_key = my_key
 consumer_secret = 

[web2py] Setting default function in default controller with parametric router

2014-02-17 Thread HittingSmoke
I would like to change my 'index' function to 'page' so that when someone 
calls a specific page and the router doesn't remove the controller name 
from the url it will say 'page/1' instead of 'index/1'.

I found this answer via a 
search: 
https://stackoverflow.com/questions/17050196/web2py-change-default-controller-and-function

I have two problems with it.

1. It seems to be global. I would like this default function to be specific 
to a single app and only in the default controller.

2. The code in the answer doesn't actually work. It causes python to throw 
a syntax error when uWSGI is started.

-- 
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] apache windows 2.8.2 sending email blocks the server?

2014-02-17 Thread Tim Richardson
I've noticed that apache 2.4 with mod_wsgi and python 2.7 does not respond 
to other requests while a controller is doing mail.send
mod_wsgi on windows is one process and threads, which means that python is 
blocking on sending mail.
Could this be correct? 

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


Re: [web2py] Re: Free opensource Janrain alternative - Python Social auth

2014-02-17 Thread Quint
I'm working on a plugin. I expect to have an initial version somewhere this 
week..

Quint

-- 
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: Making a phone call from within Web2Py

2014-02-17 Thread 黄祥
i think can (not tested), if you had a pbx server running :
- pstn / digium card installed
- asterisk and dahdi configured
- pstn line connected to your modem /switch

and then use asterisk call function from / within web2py using python 
function : subprocess

best regards,
stifan

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


Re: [web2py] Re: Making a phone call from within Web2Py

2014-02-17 Thread António Ramos
i did the oposite

http://www.youtube.com/watch?v=vCNoAyKN86o


2014-02-18 6:40 GMT+00:00 黄祥 steve.van.chris...@gmail.com:

 i think can (not tested), if you had a pbx server running :
 - pstn / digium card installed
 - asterisk and dahdi configured
 - pstn line connected to your modem /switch

 and then use asterisk call function from / within web2py using python
 function : subprocess

 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.


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