Re: [web2py] How to remove 'default' from all URLs?

2012-06-25 Thread Alec Taylor
Hmm, I'm not sure.

I'm running the latest trunk from github:
https://github.com/web2py/web2py - If that makes a difference.

Yes, the /profile/ URL is the one giving me trouble. It could be
something on the facebook side, though I'm not sure.

On Mon, Jun 25, 2012 at 7:04 AM, Jonathan Lundell jlund...@pobox.com wrote:
 On Jun 24, 2012, at 2:02 PM, Jonathan Lundell wrote:

 On Jun 24, 2012, at 1:38 PM, Jonathan Lundell wrote:

 On Jun 24, 2012, at 9:30 AM, Alec Taylor wrote:

 To be as clear as possible, here is a gist containing all the files I
 changed (for a test-case) since creating this simple new project:

 https://gist.github.com/61a6b9f8e71f706e4255

 I installed that app under 1.99.7 (I had to disable signature=False and 
 turn off the Facebook stuff; no libraries) and URL(f='profile') returned 
 '/profile'.

 Ditto for the current nightly build (actually June 9), with 
 signature=False turned back on.

 Are you using something more current than that? I'm doubtful that the 
 presence of the FB logic would affect things one way or the other.

 My code:

 import logging
 logger = logging.getLogger(web2py.app.social)

 ...

 logger.error(db.py: %s % URL(f='profile'))

 --




-- 





[web2py] why is form self submit getting executed on cancel?

2012-06-25 Thread weheh
My controller has a componentized form with an added Cancel button 
like this (this is an excerpt, so sorry for any typos):

def update( ):

  myform = SQLFORM.factory(
Field('text_in','text',requires=IS_NOT_EMPTY()),
buttons=[INPUT(_type='submit',_value=T('Update'))],
_id='myform',
formstyle='divs'
)
  form.element('input[type=submit]').parent.append(
TAG.BUTTON(T('Cancel')),_onclick='ajax(%s,[],:eval);' % URL(
c='my_controller', f='cancel_update')
)
  if myform.process(formanem='myform').accepted:
...do stuff...
 return dict(myform=myform)



The form submits 
properly when the Update button is pressed. However, when the Cancel 
button is pressed, not only does 
the cancel_update callback get called, the form also gets submitted 
erroneously. The question is, why does the update action get called and 
its form get submitted at all when the Cancel button is pressed?

-- 





[web2py] Re: why is form self submit getting executed on cancel?

2012-06-25 Thread Cliff Kachinske
How about something like,  

myform[0].insert(-1, TAG.BUTTON(T('Cancel')),_onclick=
'ajax(%s,[],:eval);' % URL(
c='my_controller', f='cancel_update')
)

If you want the cancel button to appear in the same table row as the submit 
button, you may need something like 

myform[0][1]...


On Monday, June 25, 2012 6:13:31 AM UTC-4, weheh wrote:

 My controller has a componentized form with an added Cancel button 
 like this (this is an excerpt, so sorry for any typos):

 def update( ):

   myform = SQLFORM.factory(
 Field('text_in','text',requires=IS_NOT_EMPTY()),
 buttons=[INPUT(_type='submit',_value=T('Update'))],
 _id='myform',
 formstyle='divs'
 )
   form.element('input[type=submit]').parent.append(
 TAG.BUTTON(T('Cancel')),_onclick='ajax(%s,[],:eval);' % URL(
 c='my_controller', f='cancel_update')
 )
   if myform.process(formanem='myform').accepted:
 ...do stuff...
  return dict(myform=myform)



 The form submits 
 properly when the Update button is pressed. However, when the Cancel 
 button is pressed, not only does 
 the cancel_update callback get called, the form also gets submitted 
 erroneously. The question is, why does the update action get called and 
 its form get submitted at all when the Cancel button is pressed?



-- 





[web2py] Problem with IMG helper function

2012-06-25 Thread zeon

Hi,

Newbie here.

In my db I have a link to a local image file located in static/images. From 
my index page I now want to show these images, but I can't figure out how 
to do that with the IMG helper function.

My code:
{{for movie in movies:}}
{{=IMG(_src=URL(r=request,c='static/images/',f='
{{=movie.local_poster_link}}'), _height=150)}}
Plot: {{=movie.plot}}br
Title: {{=movie.title}}br
Rating: {{=movie.rating}}br
Votes: {{=movie.votes}}br
Genre: {{=movie.genre}}br
{{pass}}

The value of movie.local_poster_link could be mypicture.jpg as an example.

How do I generate the correct IMG function call?

Thanks,

zeon

-- 





[web2py] Re: why is form self submit getting executed on cancel?

2012-06-25 Thread Anthony
The onclick event doesn't cancel the standard submit behavior -- it just 
adds the onclick behavior before submitting. If you want to prevent the 
submit action, do:

_onclick='ajax(%s,[],:eval);return false'

return false prevents the submit. An alternative to using onclick is to 
register a jQuery event handler and call preventDefault() at the end of the 
handler. That is sometimes preferable because although it prevents the 
submit, it does not  stop the propagation of the event itself, in case 
there are other handlers set up to catch the same event (return false 
will prevent any other event handlers from being triggered).

Anthony

On Monday, June 25, 2012 6:13:31 AM UTC-4, weheh wrote:

 My controller has a componentized form with an added Cancel button 
 like this (this is an excerpt, so sorry for any typos):

 def update( ):

   myform = SQLFORM.factory(
 Field('text_in','text',requires=IS_NOT_EMPTY()),
 buttons=[INPUT(_type='submit',_value=T('Update'))],
 _id='myform',
 formstyle='divs'
 )
   form.element('input[type=submit]').parent.append(
 TAG.BUTTON(T('Cancel')),_onclick='ajax(%s,[],:eval);' % URL(
 c='my_controller', f='cancel_update')
 )
   if myform.process(formanem='myform').accepted:
 ...do stuff...
  return dict(myform=myform)



 The form submits 
 properly when the Update button is pressed. However, when the Cancel 
 button is pressed, not only does 
 the cancel_update callback get called, the form also gets submitted 
 erroneously. The question is, why does the update action get called and 
 its form get submitted at all when the Cancel button is pressed?



-- 





[web2py] external link in menu with target option

2012-06-25 Thread Manuele Pesenti
What if I want to put a voice in the menu that link a page external to 
my application that I want to open in a new tab?


thanks in advance

Manuele

--





Re: [web2py] How to remove 'default' from all URLs?

2012-06-25 Thread Jonathan Lundell
On Jun 24, 2012, at 11:26 PM, Alec Taylor wrote:
 
 Hmm, I'm not sure.
 
 I'm running the latest trunk from github:
 https://github.com/web2py/web2py - If that makes a difference.
 
 Yes, the /profile/ URL is the one giving me trouble. It could be
 something on the facebook side, though I'm not sure.

I'll make one more run, with the current trunk, to see whether any recent 
changes might have caused a regression.

Would you please try logging the result of a URL call, either in your model or 
controller (I tried both)? Use whatever logging mechanism is convenient for 
you. 

If those steps don't help, I'll ask you to insert some logging into the routing 
code itself so we can see what's going on.

 
 On Mon, Jun 25, 2012 at 7:04 AM, Jonathan Lundell jlund...@pobox.com wrote:
 On Jun 24, 2012, at 2:02 PM, Jonathan Lundell wrote:
 
 On Jun 24, 2012, at 1:38 PM, Jonathan Lundell wrote:
 
 On Jun 24, 2012, at 9:30 AM, Alec Taylor wrote:
 
 To be as clear as possible, here is a gist containing all the files I
 changed (for a test-case) since creating this simple new project:
 
 https://gist.github.com/61a6b9f8e71f706e4255
 
 I installed that app under 1.99.7 (I had to disable signature=False and 
 turn off the Facebook stuff; no libraries) and URL(f='profile') returned 
 '/profile'.
 
 Ditto for the current nightly build (actually June 9), with 
 signature=False turned back on.
 
 Are you using something more current than that? I'm doubtful that the 
 presence of the FB logic would affect things one way or the other.
 
 My code:
 
 import logging
 logger = logging.getLogger(web2py.app.social)
 
 ...
 
 logger.error(db.py: %s % URL(f='profile'))
 


-- 





[web2py] Re: Problem with IMG helper function

2012-06-25 Thread Anthony


 {{=IMG(_src=URL(r=request,c='static/images/',f='
 {{=movie.local_poster_link}}'), _height=150)}}


{{=IMG(_src=URL('static', 'images/%(local_poster_link)s' % movie, _height=
150)}}

Anthony

-- 





[web2py] Re: external link in menu with target option

2012-06-25 Thread Massimo Di Pierro
Instead of 

menu = [...('title',None,'http:...')...] 

do

menu = [...('title',None,A('title',_href='http:...',_target='_blank'))...] 



On Monday, 25 June 2012 08:06:20 UTC-5, Manuele wrote:

 What if I want to put a voice in the menu that link a page external to 
 my application that I want to open in a new tab? 

 thanks in advance 

  Manuele 


-- 





[web2py] Re: external link in menu with target option

2012-06-25 Thread Anthony
You can control exactly what goes inside the li for a given menu item by 
making the third element of that item a web2py HTML helper instead of just 
a URL. So, instead of:

('External Link', False, 'http://somesite.com')

You can do:

('', False, A('External Link', _href='http://somesite.com', _target='_blank'
))

Anthony

On Monday, June 25, 2012 9:06:20 AM UTC-4, Manuele wrote:

 What if I want to put a voice in the menu that link a page external to 
 my application that I want to open in a new tab? 

 thanks in advance 

  Manuele 


-- 





Re: [web2py] How to remove 'default' from all URLs?

2012-06-25 Thread Jonathan Lundell
On Jun 25, 2012, at 6:07 AM, Jonathan Lundell wrote:
 
 On Jun 24, 2012, at 11:26 PM, Alec Taylor wrote:
 
 Hmm, I'm not sure.
 
 I'm running the latest trunk from github:
 https://github.com/web2py/web2py - If that makes a difference.
 
 Yes, the /profile/ URL is the one giving me trouble. It could be
 something on the facebook side, though I'm not sure.
 
 I'll make one more run, with the current trunk, to see whether any recent 
 changes might have caused a regression.
 
 Would you please try logging the result of a URL call, either in your model 
 or controller (I tried both)? Use whatever logging mechanism is convenient 
 for you. 
 
 If those steps don't help, I'll ask you to insert some logging into the 
 routing code itself so we can see what's going on.

Report: the 18 June trunk works fine for me.

-- 





[web2py] Re: Problem with IMG helper function

2012-06-25 Thread zeon
Hi Anthony,

Unfortunately it does not work

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.

Traceback (most recent call last):
  File C:\MyDev\web2py_src\gluon\restricted.py, line 204, in restricted
ccode = compile2(code,layer)
  File C:\MyDev\web2py_src\gluon\restricted.py, line 189, in compile2
return compile(code.rstrip().replace('\r\n','\n')+'\n', layer, 'exec')
  File 
C:\MyDev\web2py_src\applications\PrettyNZBViewer\views\default/index.html, 
line 89
response.write('br\nPlot: ', escape=False)
   ^
SyntaxError: invalid syntax

-- 





[web2py] Map database values to display values

2012-06-25 Thread Daniel Gonzalez
Hello,

I am extending the registration data with some custom fields (pretty 
standard). This is my code:

from gluon.tools import Service
from gluon.tools import Auth

db  = DAL('sqlite://storage.sqlite')
auth= Auth(db)
service = Service()

db.define_table(
auth.settings.table_user_name,
Field('first_name',   length=128, default=''),
Field('last_name',length=128, default=''),
Field('email',length=128, default='', unique=True),
Field('address',  length=256, default=''),
Field('postcode', length=128, default=''),
Field('city', length=128, default=''),
Field('country',  length=128),
Field('password', 'password', length=512, readable=False, 
label='Password'),
Field('registration_key', length=512, writable=False, 
readable=False, default=''),
Field('reset_password_key',   length=512, writable=False, 
readable=False, default=''),
Field('registration_id',  length=512, writable=False, 
readable=False, default=''),
format='%(first_name)s %(last_name)s')

ISO_COUNTRY_CODES = ('DE', 'ES', 'IT', 'US')

# get the custom_auth_table
member = db[auth.settings.table_user_name]
member.first_name.requires = 
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
member.last_name.requires  = 
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
member.password.requires   = [IS_STRONG(min=5, special=0, upper=0), CRYPT()]
member.email.requires  = 
[IS_EMAIL(error_message=auth.messages.invalid_email), IS_NOT_IN_DB(db, 
'auth_user.email')]
member.country.requires= IS_IN_SET(ISO_COUNTRY_CODES)

auth.define_tables()

The problem that I have is that in the registration form I am offered the 
choice among DE, ES, IT, US ...
I would like to convert those ISO country codes (I need that in my 
database) to human readable contry names.
Besides, this must be done according to the selected language (T operator?)

Is it possible to tell the form serializer to map one of the fields?
How can I specifiy the map function? Do you have an example to clarify the 
syntax?

Thanks,
Daniel

-- 





[web2py] Re: How to effectively use the select_datewidget instead of the popup datepicker calendar !! ???

2012-06-25 Thread Don_X
Hello Anthony,

What i can tell you is : 
1) Even on a standalone test ... with no previous field define in a table 
... the widget as shown in the web2py dev cookbook does not work the way 
they have said that it would work ... they might want to update it or to 
revise it  ... ! .. well .. more precisely ... it does not show up as 
stipulated in the corresponding view file ! .. we get as a result 3 input 
fields that takes the default width plus an additional input field where 
the final chosen date  is shown ! ( so we get 4 rows in total  stacked on 
top of the other ) .. ( I do understand there might be conflicts with the 
various uploaded css / js files )

2) Please help me with this : - If I know how I can specify or isolate the 
different portion of the date in the corresponding table field of the db 
... ( mainly in the view for serialisation  ) without modifying the 
original table in models .. i should be able to make it work for me ? 
example : db.table.datefield-day  ( for the day )  and  
db.table.datefield-month  ( for the month ) and db.table.datefield-year  
( for the year )

something similar like in a custom form recipe, we can isolate the label 
fieldname the following way : 

{{=form.custom.label.fieldname}}

what about the 3 portions of the date ( day, month, year )

can it be done ? ... is this possible in python/web2py without to many 
coding !! ???

your input will be greatly appreciated  ...
 ( PS. the datefield is consumming a lot of my time lately ... I tried so 
many different things to manipulate them in the view within a form  with 
very small success rate  !! )

thx

Don




 form = SQLFORM.factory(db.auth_user,
 Field('birth_date','date',default=request.now,widget=
 select_datewidget)) 

 I just noticed you mentioned that your db.auth_user table already includes 
 a birth_date field. In that case, SQLFORM.factory will ignore the 
 Field('birth_date', 
 ...) argument because a table cannot have two fields with the same name. 
 If you want to add the widget to the db.auth_user.birth_date field, you can 
 either do so when you first define that field, or subsequently via:

 db.auth_user.birth_date.widget = select_datewidget

 Note, for the widget to work, it may not be necessary to disable the 
 standard datepicker -- try it and see what happens.

 Anthony


-- 





Re: [web2py] Problem with IMG helper function

2012-06-25 Thread Jonathan Lundell
On Jun 25, 2012, at 6:20 AM, Anthony wrote:
 {{=IMG(_src=URL(r=request,c='static/images/',f='{{=movie.local_poster_link}}'),
  _height=150)}}
 
 {{=IMG(_src=URL('static', 'images/%(local_poster_link)s' % movie, 
 _height=150)}}
 

The (parens) are unbalanced.

 {{=IMG(_src=URL('static', 'images/%(local_poster_link)s' % movie), 
 _height=150)}}

-- 





[web2py] Re: How to effectively use the select_datewidget instead of the popup datepicker calendar !! ???

2012-06-25 Thread Anthony


 1) Even on a standalone test ... with no previous field define in a table 
 ... the widget as shown in the web2py dev cookbook does not work the way 
 they have said that it would work ... they might want to update it or to 
 revise it  ... ! .. well .. more precisely ... it does not show up as 
 stipulated in the corresponding view file ! .. we get as a result 3 input 
 fields that takes the default width plus an additional input field where 
 the final chosen date  is shown ! ( so we get 4 rows in total  stacked on 
 top of the other ) .. ( I do understand there might be conflicts with the 
 various uploaded css / js files )


I don't have time to fully debug, but looking at the Javascript (
https://github.com/mdipierro/web2py-recipes-source/blob/master/source/05_adding_ajax_effects/04_Creating_a_dropdown_date_selector/db.py#L96),
 
it appears you might need to wrap it all in a Jquery document ready handler:

jQuery(function() {
   [existing JS code goes here]
})

The JS code is supposed to hide the text input field, parse any existing 
date in the field and transfer those values to the dropdowns, and then 
whenever a new value is selected in a dropdown, it grabs the value and 
updates the date in the hidden text field. When you submit, it is the value 
in the hidden text field that gets submitted -- the dropdowns are used only 
on the client side.

Hopefully the above change will get the JS working (including hiding the 
text field). As for how the select dropdowns are displayed, you may have to 
play with the HTML/CSS to get that to look the way you want. It looks like 
they should display inline, but if the container is too narrow, they will 
wrap to additional lines.
 

 2) Please help me with this : - If I know how I can specify or isolate the 
 different portion of the date in the corresponding table field of the db 
 ... ( mainly in the view for serialisation  ) without modifying the 
 original table in models .. i should be able to make it work for me ? 
 example : db.table.datefield-day  ( for the day )  and  
 db.table.datefield-month  ( for the month ) and db.table.datefield-year  
 ( for the year )


I'm not quite sure what this means.

Anthony 

-- 





[web2py] Re: Map database values to display values

2012-06-25 Thread Anthony
Check out the IS_IN_SET documentation at 
http://web2py.com/books/default/chapter/29/7. Instead of a list of 
individual items, it can be a list of two-tuples or a dictionary, where the 
first tuple item or dictionary key is the value and the second tuple item 
or dictionary value is the label to be displayed in the select widget.

Anthony

On Monday, June 25, 2012 10:08:36 AM UTC-4, Daniel Gonzalez wrote:

 Hello,

 I am extending the registration data with some custom fields (pretty 
 standard). This is my code:

 from gluon.tools import Service
 from gluon.tools import Auth

 db  = DAL('sqlite://storage.sqlite')
 auth= Auth(db)
 service = Service()

 db.define_table(
 auth.settings.table_user_name,
 Field('first_name',   length=128, default=''),
 Field('last_name',length=128, default=''),
 Field('email',length=128, default='', unique=True),
 Field('address',  length=256, default=''),
 Field('postcode', length=128, default=''),
 Field('city', length=128, default=''),
 Field('country',  length=128),
 Field('password', 'password', length=512, readable=False, 
 label='Password'),
 Field('registration_key', length=512, writable=False, 
 readable=False, default=''),
 Field('reset_password_key',   length=512, writable=False, 
 readable=False, default=''),
 Field('registration_id',  length=512, writable=False, 
 readable=False, default=''),
 format='%(first_name)s %(last_name)s')

 ISO_COUNTRY_CODES = ('DE', 'ES', 'IT', 'US')

 # get the custom_auth_table
 member = db[auth.settings.table_user_name]
 member.first_name.requires = 
 IS_NOT_EMPTY(error_message=auth.messages.is_empty)
 member.last_name.requires  = 
 IS_NOT_EMPTY(error_message=auth.messages.is_empty)
 member.password.requires   = [IS_STRONG(min=5, special=0, upper=0), 
 CRYPT()]
 member.email.requires  = 
 [IS_EMAIL(error_message=auth.messages.invalid_email), IS_NOT_IN_DB(db, 
 'auth_user.email')]
 member.country.requires= IS_IN_SET(ISO_COUNTRY_CODES)

 auth.define_tables()

 The problem that I have is that in the registration form I am offered the 
 choice among DE, ES, IT, US ...
 I would like to convert those ISO country codes (I need that in my 
 database) to human readable contry names.
 Besides, this must be done according to the selected language (T operator?)

 Is it possible to tell the form serializer to map one of the fields?
 How can I specifiy the map function? Do you have an example to clarify the 
 syntax?

 Thanks,
 Daniel



-- 





Re: [web2py] Problem with IMG helper function

2012-06-25 Thread Anthony
Oops. Fixed in original post.

On Monday, June 25, 2012 10:31:05 AM UTC-4, Jonathan Lundell wrote:

 On Jun 25, 2012, at 6:20 AM, Anthony wrote: 
  
 {{=IMG(_src=URL(r=request,c='static/images/',f='{{=movie.local_poster_link}}'),
  
 _height=150)}} 
  
  {{=IMG(_src=URL('static', 'images/%(local_poster_link)s' % movie, 
 _height=150)}} 
  

 The (parens) are unbalanced. 

  {{=IMG(_src=URL('static', 'images/%(local_poster_link)s' % movie), 
 _height=150)}} 



-- 





Re: [web2py] How to remove 'default' from all URLs?

2012-06-25 Thread Alec Taylor
print auth.settings.login_next
/default/profile

On Mon, Jun 25, 2012 at 11:37 PM, Jonathan Lundell jlund...@pobox.com wrote:
 On Jun 25, 2012, at 6:07 AM, Jonathan Lundell wrote:

 On Jun 24, 2012, at 11:26 PM, Alec Taylor wrote:

 Hmm, I'm not sure.

 I'm running the latest trunk from github:
 https://github.com/web2py/web2py - If that makes a difference.

 Yes, the /profile/ URL is the one giving me trouble. It could be
 something on the facebook side, though I'm not sure.

 I'll make one more run, with the current trunk, to see whether any recent 
 changes might have caused a regression.

 Would you please try logging the result of a URL call, either in your model 
 or controller (I tried both)? Use whatever logging mechanism is convenient 
 for you.

 If those steps don't help, I'll ask you to insert some logging into the 
 routing code itself so we can see what's going on.

 Report: the 18 June trunk works fine for me.

 --




-- 





Re: [web2py] How to remove 'default' from all URLs?

2012-06-25 Thread Jonathan Lundell
On Jun 25, 2012, at 7:48 AM, Alec Taylor wrote:
 
 print auth.settings.login_next
 /default/profile

Would you also print the direct result of a separate URL call, with %s? Thanks.

 
 On Mon, Jun 25, 2012 at 11:37 PM, Jonathan Lundell jlund...@pobox.com wrote:
 On Jun 25, 2012, at 6:07 AM, Jonathan Lundell wrote:
 
 On Jun 24, 2012, at 11:26 PM, Alec Taylor wrote:
 
 Hmm, I'm not sure.
 
 I'm running the latest trunk from github:
 https://github.com/web2py/web2py - If that makes a difference.
 
 Yes, the /profile/ URL is the one giving me trouble. It could be
 something on the facebook side, though I'm not sure.
 
 I'll make one more run, with the current trunk, to see whether any recent 
 changes might have caused a regression.
 
 Would you please try logging the result of a URL call, either in your model 
 or controller (I tried both)? Use whatever logging mechanism is convenient 
 for you.
 
 If those steps don't help, I'll ask you to insert some logging into the 
 routing code itself so we can see what's going on.
 
 Report: the 18 June trunk works fine for me.
 


-- 





Re: [web2py] How to remove 'default' from all URLs?

2012-06-25 Thread Jonathan Lundell
On Jun 25, 2012, at 7:48 AM, Alec Taylor wrote:
 
 print auth.settings.login_next
 /default/profile

Is it possible that you have a file controllers/profile.py? 

If you do, the router will not omit 'default' in the above case because it 
would be ambiguous.

 
 On Mon, Jun 25, 2012 at 11:37 PM, Jonathan Lundell jlund...@pobox.com wrote:
 On Jun 25, 2012, at 6:07 AM, Jonathan Lundell wrote:
 
 On Jun 24, 2012, at 11:26 PM, Alec Taylor wrote:
 
 Hmm, I'm not sure.
 
 I'm running the latest trunk from github:
 https://github.com/web2py/web2py - If that makes a difference.
 
 Yes, the /profile/ URL is the one giving me trouble. It could be
 something on the facebook side, though I'm not sure.
 
 I'll make one more run, with the current trunk, to see whether any recent 
 changes might have caused a regression.
 
 Would you please try logging the result of a URL call, either in your model 
 or controller (I tried both)? Use whatever logging mechanism is convenient 
 for you.
 
 If those steps don't help, I'll ask you to insert some logging into the 
 routing code itself so we can see what's going on.
 
 Report: the 18 June trunk works fine for me.
 


-- 





[web2py] Re: Map database values to display values

2012-06-25 Thread Daniel Gonzalez

On Monday, June 25, 2012 4:45:22 PM UTC+2, Anthony wrote:

 Check out the IS_IN_SET documentation at 
 http://web2py.com/books/default/chapter/29/7. Instead of a list of 
 individual items, it can be a list of two-tuples or a dictionary, where the 
 first tuple item or dictionary key is the value and the second tuple item 
 or dictionary value is the label to be displayed in the select widget.

 Anthony


Thanks, this worked. For othesr who might have the same problem, this is 
what I have done:

 ISO_COUNTRY_CODES_MAPPING = {
'DE': 'Germany',
'ES': 'Spain',
'IT': 'Italy',
'US': 'United States'
}
...
member.country.requires= IS_IN_SET(ISO_COUNTRY_CODES_MAPPING)

Now, to support internationalization here, I see two options:

- I implement a function which returns the desired predefined mapping, 
according to the language of the user. How can I know this? How does the T 
operator know this?
- I walk the list of ISO country codes applying the T operator to return 
the mapping.

Since it is not clear for me when this mapping will be created (at startup? 
in each request?) I do not understand the performance implications.
Maybe somebody can comment.

Thanks,
Daniel

-- 





[web2py] Re: Map database values to display values

2012-06-25 Thread Anthony


 Now, to support internationalization here, I see two options:

 - I implement a function which returns the desired predefined mapping, 
 according to the language of the user. How can I know this? How does the T 
 operator know this?
 - I walk the list of ISO country codes applying the T operator to return 
 the mapping.


Can't you just do:

ISO_COUNTRY_CODES_MAPPING = {
'DE': T('Germany'),
'ES': T('Spain'),
'IT': T('Italy'),
'US': T('United States')
} 

-- 





[web2py] Re: Map database values to display values

2012-06-25 Thread Daniel Gonzalez
Yes, that is one of the options I mentioned. If I include all possible 
countries, my list would have200 entries.

I still do not fully understand the process in which 
modules/views/controllers are loaded when requests are received.
But, if I am not completely mistaken, these files are parsed each time that 
a request is received.
That means that, for each request, the list of *200 countries* will be 
translated to the user language.
That means, lots of times the same translation will be performed (most of 
my users will have the same language settings). Even if this is highly 
efficient (caching of the translated objects?), this is still a lot of 
processing, which could be avoided if I had a list of pre-translated 
dictionaries (one for each language that I want to support).

Of course it could be that I am not understanding at all how localization 
in web2py is done ...

On Monday, June 25, 2012 5:22:10 PM UTC+2, Anthony wrote:

 Now, to support internationalization here, I see two options:

 - I implement a function which returns the desired predefined mapping, 
 according to the language of the user. How can I know this? How does the T 
 operator know this?
 - I walk the list of ISO country codes applying the T operator to return 
 the mapping.


 Can't you just do:

 ISO_COUNTRY_CODES_MAPPING = {
 'DE': T('Germany'),
 'ES': T('Spain'),
 'IT': T('Italy'),
 'US': T('United States')
 } 



-- 





[web2py] label_separator on SQLFORM.factory

2012-06-25 Thread Marco Prosperi

hi all, I've put:
crud.settings.label_separator = '' 
in db.py to avoid ':' in forms but it seems that this is not read by a 
SQLFORM.factory form. Is there any way to circumvent this?

thanks in advance,

Marco

-- 





Re: [web2py] How to remove 'default' from all URLs?

2012-06-25 Thread Alec Taylor
On Tue, Jun 26, 2012 at 12:59 AM, Jonathan Lundell jlund...@pobox.com wrote:
 On Jun 25, 2012, at 7:48 AM, Alec Taylor wrote:

 print auth.settings.login_next
 /default/profile

 Is it possible that you have a file controllers/profile.py?

.

That was the case. I thought I'd renamed everything to profile2 but it
seemed that I had only renamed my views. Thanks a heap for finding the
problem!

There is still the secondary problem of #_=_ being appended, but
that isn't really an issue so I'm happy to call case closed!

:D


 If you do, the router will not omit 'default' in the above case because it 
 would be ambiguous.


 On Mon, Jun 25, 2012 at 11:37 PM, Jonathan Lundell jlund...@pobox.com 
 wrote:
 On Jun 25, 2012, at 6:07 AM, Jonathan Lundell wrote:

 On Jun 24, 2012, at 11:26 PM, Alec Taylor wrote:

 Hmm, I'm not sure.

 I'm running the latest trunk from github:
 https://github.com/web2py/web2py - If that makes a difference.

 Yes, the /profile/ URL is the one giving me trouble. It could be
 something on the facebook side, though I'm not sure.

 I'll make one more run, with the current trunk, to see whether any recent 
 changes might have caused a regression.

 Would you please try logging the result of a URL call, either in your 
 model or controller (I tried both)? Use whatever logging mechanism is 
 convenient for you.

 If those steps don't help, I'll ask you to insert some logging into the 
 routing code itself so we can see what's going on.

 Report: the 18 June trunk works fine for me.



 --




-- 





[web2py] Re: Map database values to display values

2012-06-25 Thread Anthony
Do you already have the mapping, perhaps in a dictionary (or can you get it 
into one)? If so, maybe something like:

ISO_COUNTRY_CODE_MAPPINGS = {k: T(v) for (k, v) in original_mapping.
iteritems()} # requires Python 2.7

Anthony

On Monday, June 25, 2012 11:53:24 AM UTC-4, Daniel Gonzalez wrote:

 Yes, that is one of the options I mentioned. If I include all possible 
 countries, my list would have200 entries.

 I still do not fully understand the process in which 
 modules/views/controllers are loaded when requests are received.
 But, if I am not completely mistaken, these files are parsed each time 
 that a request is received.
 That means that, for each request, the list of *200 countries* will be 
 translated to the user language.
 That means, lots of times the same translation will be performed (most of 
 my users will have the same language settings). Even if this is highly 
 efficient (caching of the translated objects?), this is still a lot of 
 processing, which could be avoided if I had a list of pre-translated 
 dictionaries (one for each language that I want to support).

 Of course it could be that I am not understanding at all how localization 
 in web2py is done ...

 On Monday, June 25, 2012 5:22:10 PM UTC+2, Anthony wrote:

 Now, to support internationalization here, I see two options:

 - I implement a function which returns the desired predefined mapping, 
 according to the language of the user. How can I know this? How does the T 
 operator know this?
 - I walk the list of ISO country codes applying the T operator to return 
 the mapping.


 Can't you just do:

 ISO_COUNTRY_CODES_MAPPING = {
 'DE': T('Germany'),
 'ES': T('Spain'),
 'IT': T('Italy'),
 'US': T('United States')
 } 



-- 





[web2py] Re: label_separator on SQLFORM.factory

2012-06-25 Thread Anthony
SQLFORM.factory(..., separator='')


On Monday, June 25, 2012 11:59:49 AM UTC-4, Marco Prosperi wrote:


 hi all, I've put:
 crud.settings.label_separator = '' 
 in db.py to avoid ':' in forms but it seems that this is not read by a 
 SQLFORM.factory form. Is there any way to circumvent this?

 thanks in advance,

 Marco


-- 





[web2py] Re: Creating users on checkout?

2012-06-25 Thread RKS
Not so easy?

-- 





Re: [web2py] Re: Creating users on checkout?

2012-06-25 Thread Bruno Rocha
auth.register

On Mon, Jun 25, 2012 at 2:26 PM, RKS sean.sambor...@live.com wrote:

 Not so easy?

 --


-- 





[web2py] unsigned DAL integer

2012-06-25 Thread Horus
Is there a way to get unsigned DAL integers ?
Is there a way to represent BIGINT using DAL?


-- 





[web2py] Re: Parsing python from db fields?

2012-06-25 Thread RKS
This all works, but I can't wrap my head around why everything after this 
snippet is no longer displayed. It does not even exist in the source. For 
example, my code is like this:

div class=wrapper
{{import os}}
{{from gluon.template import render}}
{{=XML(render(blog.body,path=os.path.join(request.folder, 
'views'), context=globals()))}}
{{pass}}
!--start--
 div class=clear/div
ul class=customer_purchase
li class=whiteNEW USER?/li
lia href={{=URL('register')}}img 
src={{=URL('static','images/button_register.png')}} alt=Login/Register 
to comment! //a/li
/ul
ul class=customer_purchase
li class=whiteCURRENT USER?/li
li class=blog_form{{=blog_form}}/li
/ul
div class=clear/div
/div

Everything from the inserted comment (!--start--) will not exist any more 
after this. Go back to simple {{=XML(blog.body)}} and everything after it 
displays fine. I've tried adding a pass, no pass, two passes, etc. But it 
still appears from that point web2py is not recognizing regular html 
anymore. Nothing after that will display at all.

-- 





[web2py] Re: Parsing python from db fields?

2012-06-25 Thread RKS
BTW, it's EVERYTHING in html after that snippet. It won't display the 
footer or anything.

-- 





Re: [web2py] Parsing python from db fields?

2012-06-25 Thread RKS
Both of these solutions ended up working. Passing URL and using globals(). 
Just wanted to let you know and say thanks for helping.

-- 





[web2py] Re: unsigned DAL integer

2012-06-25 Thread Anthony


 Is there a way to get unsigned DAL integers ?


I don't think so. If you have created the table outside the DAL, perhaps 
telling the DAL it's a regular integer field will still work, though.
 

 Is there a way to represent BIGINT using DAL?


I'm not sure if this is in current stable, but in trunk, you can do:

Field('mybigint', 'bigint') 

And to get the DAL to use bigint's for all ID fields, do:

DAL(..., bigint_id=True)

Anthony

-- 





Re: [web2py] Re: Creating users on checkout?

2012-06-25 Thread RKS
I see that there are auth.register() and auth.login(), I'm already using 
login_form=auth.login(), in the controller, but otherwise I'm not certain 
the checkoutform would be form=auth.register(). Maybe it can be, but is 
that the best practice? Or just creating a function that writes into the 
same auth.user db?


-- 





[web2py] limit to one logged user (and a single active session)

2012-06-25 Thread Janath
Hi,

The web2py application I work on uses an API to automate another 
application. Only one instance of that application is allowed to 
initialise. therefore, at the time of login to web2py, I need to check if 
someone is already logged in. If so I can notify the other to wait.

I thought of writing a record to a table and check that at the time of log 
in. But if the user closes the particular tab without logging out, I wont 
get the chance to modify the said table. 

Further, I also need to limit concurrent sessions, even for the the logged 
user, as it might end up the same situation in my context.

Workarounds appreciated!

Janath

-- 





Re: [web2py] limit to one logged user (and a single active session)

2012-06-25 Thread Bruno Rocha
You can check the table auth_event to see if user logged in.

But you will need an extra code to ensure that user logs out.

On Mon, Jun 25, 2012 at 4:10 PM, Janath jana...@gmail.com wrote:

 Hi,

 The web2py application I work on uses an API to automate another
 application. Only one instance of that application is allowed to
 initialise. therefore, at the time of login to web2py, I need to check if
 someone is already logged in. If so I can notify the other to wait.

 I thought of writing a record to a table and check that at the time of log
 in. But if the user closes the particular tab without logging out, I wont
 get the chance to modify the said table.

 Further, I also need to limit concurrent sessions, even for the the logged
 user, as it might end up the same situation in my context.

 Workarounds appreciated!

 Janath

 --


-- 





Re: [web2py] limit to one logged user (and a single active session)

2012-06-25 Thread Janath
do you thin I can trigger an event when the session expires


On Monday, June 25, 2012 2:13:23 PM UTC-5, rochacbruno wrote:

 You can check the table auth_event to see if user logged in.

 But you will need an extra code to ensure that user logs out.

 On Mon, Jun 25, 2012 at 4:10 PM, Janath jana...@gmail.com wrote:

 Hi,

 The web2py application I work on uses an API to automate another 
 application. Only one instance of that application is allowed to 
 initialise. therefore, at the time of login to web2py, I need to check if 
 someone is already logged in. If so I can notify the other to wait.

 I thought of writing a record to a table and check that at the time of 
 log in. But if the user closes the particular tab without logging out, I 
 wont get the chance to modify the said table. 

 Further, I also need to limit concurrent sessions, even for the the 
 logged user, as it might end up the same situation in my context.

 Workarounds appreciated!

 Janath

 -- 




-- 





Re: [web2py] Re: Creating users on checkout?

2012-06-25 Thread RKS
Also, if you were to use the {{=*.custom.widget.email}} method you get 
errors when a logged in user is using the form. The form tries to act like 
a registration form instead of a checkout form. 

If I use things in the inputs like {{=auth.user.first_name}} it works to 
prefill values if users are logged in. But afaik it looks like setting the 
values to the auth.users db manually after checkout is the only way to go. 
I could be wrong thought since I'm not as good on web2py as many/most other 
people here.

-- 





[web2py] Re: unsigned DAL integer

2012-06-25 Thread Horus
Thanks Anthony.

On Monday, June 25, 2012 2:27:19 PM UTC-4, Anthony wrote:

 Is there a way to get unsigned DAL integers ?


 I don't think so. If you have created the table outside the DAL, perhaps 
 telling the DAL it's a regular integer field will still work, though.
  

 Is there a way to represent BIGINT using DAL?


 I'm not sure if this is in current stable, but in trunk, you can do:

 Field('mybigint', 'bigint') 

 And to get the DAL to use bigint's for all ID fields, do:

 DAL(..., bigint_id=True)

 Anthony


-- 





[web2py] Redirecting to user/profile?

2012-06-25 Thread RKS
I'm having some issues I don't fully understand. I've customized an 
auth.login using login_form.custom.widget.email etc in a controller. It 
works fine and logs in users like you would expect.

However, I have a view, checkout_test.html where I have included another 
form=auth.register() in the controller. By default, a logged in user who 
teis to access a page with auth.register() gets redirected to user/profile. 

How can I stop this behavior on at least this one view? The reason this is 
all here is that I'm extending the option to users on checkout to login or 
create an account on successful checkout. So I'm trying to expose all the 
auth.registration functions for non-logged in users. With the redirection, 
these functions are preventing any logged in user from ever checking out.

[SIDENOTE: I haven't been able to perfect my registering users on 
successful checkout just yet so I could end up not having to include any 
standard auth.register anything in this view once all is said and done.]

-- 





[web2py] Re: Redirecting to user/profile?

2012-06-25 Thread Anthony
It may help if you show some code.

On Monday, June 25, 2012 5:04:03 PM UTC-4, RKS wrote:

 I'm having some issues I don't fully understand. I've customized an 
 auth.login using login_form.custom.widget.email etc in a controller. It 
 works fine and logs in users like you would expect.

 However, I have a view, checkout_test.html where I have included another 
 form=auth.register() in the controller. By default, a logged in user who 
 teis to access a page with auth.register() gets redirected to user/profile. 

 How can I stop this behavior on at least this one view? The reason this is 
 all here is that I'm extending the option to users on checkout to login or 
 create an account on successful checkout. So I'm trying to expose all the 
 auth.registration functions for non-logged in users. With the redirection, 
 these functions are preventing any logged in user from ever checking out.

 [SIDENOTE: I haven't been able to perfect my registering users on 
 successful checkout just yet so I could end up not having to include any 
 standard auth.register anything in this view once all is said and done.]


-- 





[web2py] Re: How to effectively use the select_datewidget instead of the popup datepicker calendar !! ???

2012-06-25 Thread Don_X
Finally, .. i got this to work in a semi satisfactory manner  .. thank you 
Again Anthony  !

For the ones who may have had or will have the same issue  with the  
select_datewidget ! ...
The idea here is
1)  put the widget  def select_datewidget(field,value):   at the end 
of a model file ( in this case it was db.py )
2) Then, the trick here is, put the following line at the end of the same 
file right after step (1) : db.yourtable.your_date_field.widget = 
select_datewidget
3) wheter you use SQLFORM.factory or not in the controller, the 
select_datewidget will be by default ! instead of the datepicker popup 
calendar ! but you may have to use it ( or SQLFORM ) to customise
the form you want ...

BECAUSE :
in the view, with the help of css, you will need to customise the width of 
the HTML select tag otherwise, it will use the size defined by the css 
included in the app.
like the following :
{{=form.custom.begin}}
  .
  .
  html_tag  (class_or_id) = defined_width
{{=form.custom.widget.datefield}}   /html_tag
  .
  .

{{=form.custom.end}}

The main problem with this approach  is .. all the select fields for the 
date to be chosen will be the same width  ... I have not found a way to 
make them with different width .. that was very frustrating ...
 I cannot play with the different 3 date fields in the view ( year, month, 
day ) embedded in the datefield of the table !
 ... unless someone else come up with a way to do it !! 

Else where ... I had to look into the select_datewidget solution simply 
because, if someone uses another grid system in web2py, the datepicker 
popup breaks ! ... it will popup but does not show up properly  this 
may be a bug ! .. All the Thead items of the popup table show up on the 
left side even when there is no float left anywhere in the css used !


-- 





[web2py] Re: Redirecting to user/profile?

2012-06-25 Thread RKS
I actually just decided that I probably just need to manually add new 
values to db.auth.users. That way this is actually a non-issue and I won't 
even need to worry about it.

I think it may be harder since I don't know how to do that, especially with 
the checks on if auth.user or IS_IN_DB references but I can't see this 
working any other way for what I want to do. The end goal is to take a 
checkout form that will submit like normal to the payment gateway but at 
the same time register users if they don't have accounts, not register 
users if they're logged in or the email value exists already in the 
auth.user db.

The code I have already in the controller is:

def checkout_test():
order = []
balance = 0
for product_id, qty, option_ids in session.cart:
products = db(db.product.id == product_id).select()
if products:
product = products[0]
options = [db.option[id] for id in option_ids]
total_price = qty * (product.price + sum([option.price for 
option in options]))
order.append((product_id, qty, total_price, product, options))
balance += total_price
else:
pass
session.balance = balance
if form.accepts(request, formname=None):
#if not auth.user:
#if field.email IS_NOT_IN_DB:
#register email field in auth.users db
   # pass
#pass
mail.send(to=['r...@rks.com','customer_email'],subject='Test 
Success',message=', '.join('%s: %s' % (k, v) for (k, v) in 
request.vars.iteritems()))
return dict(order=order, merchant_id=session.paypal_id)
elif form.errors:
return TABLE(*[TR(k, v) for k, v in form.errors.items()])

Of course, you'll notice some invalid code in there that I have as 
placeholders for myself to logically symbolize what I need done. 

-- 





[web2py] Re: Map database values to display values

2012-06-25 Thread Daniel Gonzalez


On Monday, June 25, 2012 6:38:47 PM UTC+2, Anthony wrote:

 Do you already have the mapping, perhaps in a dictionary (or can you get 
 it into one)? If so, maybe something like:

 ISO_COUNTRY_CODE_MAPPINGS = {k: T(v) for (k, v) in original_mapping.
 iteritems()} # requires Python 2.7

 Anthony


I  see. It is still iterating through the whole mapping for each request, 
though. Why not just use the original_mapping directly?

-- 





[web2py] Hook to automatically fill in some registration details

2012-06-25 Thread Daniel Gonzalez
Hello,

My application has a special requirement: the user details contain some 
values which should not be entered by the user, but automatically generated 
by the system,
I am planning to add that information to the auth.settings.table_user_name. 
In this case the field that I am adding is:

Field('org_id',   'integer', unique=True)

What I am planning is, once the user has registered, assign a computed 
generated value to this field (I get the organization id from a list of 
available IDs which is stored in another system). Then I need to update the 
database with this information.

How can I hook into the registration process, without modifying much the 
registration flow? I would like to leverage as much as possible from the 
web2py user management process.

Thanks,
Daniel

-- 





[web2py] Reopening: problems running from subfolder with mod_wsgi

2012-06-25 Thread Larry Weinberg
I am again running into occasional problems trying to run the trunk code 
from a subfolder instead of from a root folder under apache and mod_wsgi.

Maybe my problem is compounded because I also have another web2py installed 
at the root, but it seems that some of the internal web2py
functions are not working properly and are sometimes not obeying the route 
specifications.

I have a subdomain set up which has web2py 1.99 installed at the root of 
the domain.
   WSGIScriptAlias /  /opt/web-apps/web2py/wsgihandler.py
   WSGIScriptAlias /trunk /opt/web-apps/w2p_trunk/web2py/wsgihandler.py

I now have my routes.py file like this:

routes_in=(('/trunk/(?Pany.*)','/\gany'),)
routes_out=(('/(?Pany.*)','/trunk/\gany'),)

In general, most things seem to work.  The problems I am having:
1) Sometimes -- not always -- the links to tickets will link to the top 
level web2py install instead of the site under trunk
2) I cannot use or edit (without error) any python modules added to an 
application's modules folder. 
Failed to reload module:  because no module named xxx.modules.test

If I load the site using the internal rocket server there are no problems.



-- 





[web2py] Re: Map database values to display values

2012-06-25 Thread Anthony


 Do you already have the mapping, perhaps in a dictionary (or can you get 
 it into one)? If so, maybe something like:

 ISO_COUNTRY_CODE_MAPPINGS = {k: T(v) for (k, v) in original_mapping.
 iteritems()} # requires Python 2.7

 I  see. It is still iterating through the whole mapping for each request, 
 though. Why not just use the original_mapping directly?


The T() object is created per request. How would you use the 
original_mapping directly -- I'm assuming that has all the country names in 
English, but you want them translated to the current language? Anyway, I'm 
not sure this adds too much overhead. First, by default, calls to T(v) are 
lazy -- translation isn't done until serialization in the view, so 
translation will only happen for requests that serialize the auth_user form 
in a view, not all requests. Second, the translation itself is just a 
dictionary lookup in a dictionary that is already in memory. Third, if you 
use T.set_current_languages(), you can specify the language used in 
original_mappings, and whenever that language is requested, no translation 
will happen at all. Finally, you can move the definition of this particular 
validator to the user() function that handles the Auth forms, so even the 
dictionary comprehension will only be executed on requests involving Auth 
forms.

You can also have pre-translated dictionaries for every language, but 
you'll have to store them somewhere (maybe a module). In that case, you can 
use T.accepted_language to determine the language of the current request. 
Another option might be adding an item like the following to all language 
files:

'COUNTRY_NAMES':'Germany|Spain|Italy|United States|...'

Then in the application, do:

member.country.requests = IS_IN_SET(zip(COUNTRY_CODES, T('COUNTRY_NAMES').
split('|')))

That puts all the translated country names in a single pipe-separated list, 
so it involves only one translator lookup. Then split the list and zip it 
with the matching country codes to get a list of tuples for the validator.

Anthony

-- 





[web2py] Re: Hook to automatically fill in some registration details

2012-06-25 Thread Anthony
You could make org_id a computed 
fieldhttp://web2py.com/books/default/chapter/29/6#Computed-fields. 
Or maybe set readable and writable to False and specify a default value 
(which can be a function).

Anthony

On Monday, June 25, 2012 6:29:22 PM UTC-4, Daniel Gonzalez wrote:

 Hello,

 My application has a special requirement: the user details contain some 
 values which should not be entered by the user, but automatically generated 
 by the system,
 I am planning to add that information to 
 the auth.settings.table_user_name. In this case the field that I am adding 
 is:

 Field('org_id',   'integer', unique=True)

 What I am planning is, once the user has registered, assign a computed 
 generated value to this field (I get the organization id from a list of 
 available IDs which is stored in another system). Then I need to update the 
 database with this information.

 How can I hook into the registration process, without modifying much the 
 registration flow? I would like to leverage as much as possible from the 
 web2py user management process.

 Thanks,
 Daniel



-- 





[web2py] Adding reference tables to auth

2012-06-25 Thread Horus
is there a way to add other tables to the current auth table setup ?
I am aware of customizing existing tables but not adding tables to the 
database structure. 

e.g. 

Is it VALID to add other tables such at a country table and have auth_user 
reference this table without breaking web2py internals?
How can this be done if possible?

-- 





[web2py] Re: Best practice using scheduler as a task queue?

2012-06-25 Thread Michael Toomim
This scenario is working out worse and worse.

Now I'm getting tasks stuck in the 'RUNNING' state... even when there 
aren't any scheduler processes running behind them running! I'm guessing 
the server got killed mid-process, and now it doesn't know how to recover. 
Looks like a bug in the scheduler.

I don't recommend using the scheduler as a task queue to anybody.

On Tuesday, June 12, 2012 10:24:15 PM UTC-7, Michael Toomim wrote:

 Here's a common scenario. I'm looking for the best implementation using 
 the scheduler.

 I want to support a set of background tasks (task1, task2...), where each 
 task:
   • processes a queue of items
   • waits a few seconds

 It's safe to have task1 and task2 running in parallel, but I cannot have 
 two task1s running in parallel. They will duplicately process the same 
 queue of items.

 I found the scheduler supports this nicely with parameters like:

 db.scheduler_task.insert(function_name='task1',
  task_name='task1',
  stop_time = now + timedelta(days=9),
  repeats=0,
  period=10)

 I can launch 3 workers, and they coordinate amongst themselves to make 
 sure that only one will run the task at a time. Great! This task will last 
 forever...

 ...but now we encounter my problem...

 What happens if it crashes, or passes stop_time? Then the task will turn 
 off, and the queue is no longer processed. Or what happens if I reset the 
 database, or install this code on a new server? It isn't nice if I have to 
 re-run the insert function by hand.

 So how can I ensure there is always EXACTLY ONE of each task in the 
 database?

 I tried putting this code into models:

 def initialize_task_queue(task_name):
 num_tasks = db((db.scheduler_task.function_name == task_name)
 ((db.scheduler_task.status == 'QUEUED')
   | (db.scheduler_task.status == 'ASSIGNED')
   | (db.scheduler_task.status == 'RUNNING')
   | (db.scheduler_task.status == 'ACTIVE'))).count()

 # Add a task if there isn't one already
 if num_tasks  1:
 db.scheduler_task.insert(function_name=task_name,
  task_name=task_name,
  stop_time = now + timedelta(days=9),
  repeats=0,
  period=period)
 db.commit()

 initialize_task_queue('task1')
 initialize_task_queue('task2')
 initialize_task_queue('task3')

 This worked, except it introduces a race condition! If you start three 
 web2py processes simultaneously (e.g., for three scheduler processes), they 
 will insert duplicate tasks:
 process 1: count number of 'task1' tasks
 process 2: count number of 'task1' tasks
 process 1: there are less than 1, insert a 'task1' task
 process 2: there are less than 1, insert a 'task1' task

 I was counting on postgresql's MVCC transaction support to make each of 
 these atomic. Unfortunately, that's not how it works. I do not understand 
 why. As a workaround, I'm currently wrapping the code inside 
 initialize_task_queue with postgresql advisory lock:

 if not db.executesql('select pg_try_advisory_lock(1);')[0][0]:
 return

 ... count tasks, add one if needed ...

 db.executesql('select pg_advisory_unlock(1);')

 But this sucks.
 What's a better way to ensure there is always 1 infinite-repeat task in 
 the scheduler? Or... am I using the wrong design entirely?


-- 





[web2py] Re: Best practice using scheduler as a task queue?

2012-06-25 Thread Michael Toomim
Er, let me rephrase: I don't recommend using the scheduler for *infinitely 
looping background tasks*.

On Monday, June 25, 2012 4:54:30 PM UTC-7, Michael Toomim wrote:

 This scenario is working out worse and worse.

 Now I'm getting tasks stuck in the 'RUNNING' state... even when there 
 aren't any scheduler processes running behind them running! I'm guessing 
 the server got killed mid-process, and now it doesn't know how to recover. 
 Looks like a bug in the scheduler.

 I don't recommend using the scheduler as a task queue to anybody.

 On Tuesday, June 12, 2012 10:24:15 PM UTC-7, Michael Toomim wrote:

 Here's a common scenario. I'm looking for the best implementation using 
 the scheduler.

 I want to support a set of background tasks (task1, task2...), where each 
 task:
   • processes a queue of items
   • waits a few seconds

 It's safe to have task1 and task2 running in parallel, but I cannot have 
 two task1s running in parallel. They will duplicately process the same 
 queue of items.

 I found the scheduler supports this nicely with parameters like:

 db.scheduler_task.insert(function_name='task1',
  task_name='task1',
  stop_time = now + timedelta(days=9),
  repeats=0,
  period=10)

 I can launch 3 workers, and they coordinate amongst themselves to make 
 sure that only one will run the task at a time. Great! This task will last 
 forever...

 ...but now we encounter my problem...

 What happens if it crashes, or passes stop_time? Then the task will turn 
 off, and the queue is no longer processed. Or what happens if I reset the 
 database, or install this code on a new server? It isn't nice if I have to 
 re-run the insert function by hand.

 So how can I ensure there is always EXACTLY ONE of each task in the 
 database?

 I tried putting this code into models:

 def initialize_task_queue(task_name):
 num_tasks = db((db.scheduler_task.function_name == task_name)
 ((db.scheduler_task.status == 'QUEUED')
   | (db.scheduler_task.status == 'ASSIGNED')
   | (db.scheduler_task.status == 'RUNNING')
   | (db.scheduler_task.status == 'ACTIVE'))).count()

 # Add a task if there isn't one already
 if num_tasks  1:
 db.scheduler_task.insert(function_name=task_name,
  task_name=task_name,
  stop_time = now + timedelta(days=9),
  repeats=0,
  period=period)
 db.commit()

 initialize_task_queue('task1')
 initialize_task_queue('task2')
 initialize_task_queue('task3')

 This worked, except it introduces a race condition! If you start three 
 web2py processes simultaneously (e.g., for three scheduler processes), they 
 will insert duplicate tasks:
 process 1: count number of 'task1' tasks
 process 2: count number of 'task1' tasks
 process 1: there are less than 1, insert a 'task1' task
 process 2: there are less than 1, insert a 'task1' task

 I was counting on postgresql's MVCC transaction support to make each of 
 these atomic. Unfortunately, that's not how it works. I do not understand 
 why. As a workaround, I'm currently wrapping the code inside 
 initialize_task_queue with postgresql advisory lock:

 if not db.executesql('select pg_try_advisory_lock(1);')[0][0]:
 return

 ... count tasks, add one if needed ...

 db.executesql('select pg_advisory_unlock(1);')

 But this sucks.
 What's a better way to ensure there is always 1 infinite-repeat task in 
 the scheduler? Or... am I using the wrong design entirely?



-- 





[web2py] Re: Reopening: problems running from subfolder with mod_wsgi

2012-06-25 Thread Larry Weinberg
More info:

I restart apache.  
Log in to admin in the subfolder version.  
Everything works properly.

Log in to admin in the top level version.   
Visit the admin of the lower level version. 
Sometimes errors occur.  Sometimes not.
Sometimes it makes me log in again sometimes not.
It appears that there is some kind of confusion between the sessions.


-- 





[web2py] Re: Hook to automatically fill in some registration details

2012-06-25 Thread Daniel Gonzalez
That worked, thanks. I took the computed field route. For other newbies 
like me, this is my code, for the time being very simple, but shows what I 
am doing:

def reserve_org_id(row):
return random.randint(0, 1)

db.define_table(
auth.settings.table_user_name,
...
Field('org_id',   'integer',  compute=reserve_org_id),
...
format='%(first_name)s %(last_name)s')

I guess the other option would be very similar (I guess the function is 
also called with a row object - it is not specified in the documentation)

On Tuesday, June 26, 2012 1:23:19 AM UTC+2, Anthony wrote:

 You could make org_id a computed 
 fieldhttp://web2py.com/books/default/chapter/29/6#Computed-fields. 
 Or maybe set readable and writable to False and specify a default value 
 (which can be a function).

 Anthony



-- 





[web2py] Re: Reopening: problems running from subfolder with mod_wsgi

2012-06-25 Thread Larry Weinberg
This error is always repeatable:

The Internal error page always links incorrectly to the ticket.

It links back to the top site.
admin/default/ticket/up/10.102.67.127.2012-06-25.17-37-36.38cfaa82-a858-4e7b-9a69-9afc0fb3e7e7

If I visit the errors link normally I can see the error.

-- 





[web2py] Re: problem with redirect using plugin_gmap

2012-06-25 Thread greaneym
I found that I made a mistake and altered the plugin_gmap/index.html file 
and this is the reason things were not working.  After I copied back
the original plugin_gmap/index.html file from the plugin, it worked fine. 
 I did have to add a {{pass}}  like so for it to work and I don't 
understand that.

{{if 'message' in globals():}}
h3{{=message}}/h3
{{pass}}
{{=LOAD('plugin_gmap')}}


Margaret

On Thursday, June 21, 2012 9:33:33 PM UTC-5, greaneym wrote:

 I made an app called testmap using the plugin_gmap mentioned in an 
 earlier
 post and this worked fine.  But then I wanted to put the app inside of 
 another
 app and am having problems with this. What ever I've tried causes the 
 webp2y to
 quit.  

 The new app is called geoschool and has the following entries, with 4 
 attempts
 listed in the view.  Can anyone suugest how this can be shown in a view?

 thank you,
 Margaret



 models/
 plugin_gmap.py
 db.py

 controllers
 plugin_gmap.py
 default.py (doesn't contain any references to plugin_gmap.py)

 views/plugin_gmap/index.html 
 {{response.files.append(URL('static','js/jquery-1.6.2.min.js'))}}
 {{extend 'layout.html'}}

 html

 {{=LOAD('plugin_gmap')}}
 {{pass}}

 script
 etc.



 I am trying to call this view by another view file located in 
 views/default/quizzes.html:

 {{extend 'layout.html'}}

 html


 div
 
 br
 !--1--
 a 
 href=(=URL(request.geoschool=geoschool,request.controller=plugin_gmap,'index'))
  
 test of capitals page/a
 !--2--
 a href={{=URL(a=geoschool,c=plugin_gmap,f=index)}} test of 
 capitals page/a
 !--3--
 a href={{=URL('plugin_gmap')}} test of capitals page/a

 !--4--
 br
 a href=plugin_gmap/index.htmlh3Locate State Capitals 
 /h3/aFind the capitals of the states./p

 /div

 /html



-- 





[web2py] How capable is the ajax function in web2py.js?

2012-06-25 Thread Daniel Gonzalez
Hello, 

Currently I have a pyjamas application doing some JSONRPC requests to 
web2py, in order to update a quite complex HTML table (6 columns, 20 rows, 
the markup in the cells is quiet complex, with images and nested td/tr 
elements). The pyjamas application is embedded into my web2py pages inside 
an iframe. The communication pyjamas - web2py is working fine.

Now I realize that in order to interact with the table, which is managed by 
pyjamas, for example to select a certain row, I need to define a complex 
JSONRPCs interface (select row, un-select, paginate to next page, previous 
page, last page, page number, ...), passing back and forth parameters and 
results between web2py and pyjamas. This looks quite complex.

I think everything would be much easier if I could control all this 
interface directly from within web2py, ditching the pyjamas part. I have 
two important requirements:

   1. I do not want to reload pages: everything needs to work smoothly as a 
   desktop app. (of course, not all interactions with web2py, just the ones 
   related to this one real-time component). I guess the right tool for this 
   job would be the ajax function in web2py.ps. Is this tool able to handle 
   complex data?
   2. the ajax events must not only be generated by the user, but also 
   autonomously by the web browser. In pyjamas I am doing this with a Timer, 
   which translates to some timer javascript events. Is this possible in 
   web2py? Is there an example of a javascript timer triggering ajax requests 
   in web2py?

Thanks,
Daniel

-- 





[web2py] Dashboard in web2py?

2012-06-25 Thread Paulo Couto
I'm taking the first steps in web2py but I have a question that for me is 
very important as to continue or not with web2py.
Does web2py have a admin dashboard as Wordpress, Textpattern, etc, so the 
client can update the site like they will normally do in a cms?? I know 
web2py it's not a CMS, but the option to my clients can update the site, 
posting pictures, etc. is very important.
So far I've always been a CMS tweaker, but I would like change the course 
of my career and web2py and python seems to me the most intelligent 
solution.

Thank you.

-- 





[web2py] Distinct in Autocomplete widget select

2012-06-25 Thread Brent Zeiben
Hi,
I noticed the Autocomplete widget in gluon/sqlhtml.py does not support the 
distinct value for the select query.  In a project I was working on instead 
of creating a new category like table I modified the sqlhtml.py to allow 
for setting a distinct value (default is false) attached is a patch file 
from mercurial trunk this morning.

Are there any issues with this?

Thanks,
Brent

-- 



# HG changeset patch
# User Brent Zeiben bzei...@tuheadz.com
# Date 1340642532 21600
# Node ID d545ea44624a80d1f23f212a8f23ce7647dba36a
# Parent  22468f606668303251baa88547143ec507faac19
Added Distinct to Autocomplete Widget

diff -r 22468f606668 -r d545ea44624a gluon/sqlhtml.py
--- a/gluon/sqlhtml.py	Sat Jun 23 09:11:55 2012 -0500
+++ b/gluon/sqlhtml.py	Mon Jun 25 10:42:12 2012 -0600
@@ -536,7 +536,7 @@
 _class = 'string'
 
 def __init__(self, request, field, id_field=None, db=None,
- orderby=None, limitby=(0,10),
+ orderby=None, limitby=(0,10), distinct=False,
  keyword='_autocomplete_%(fieldname)s',
  min_length=2, help_fields=None, help_string=None):
 
@@ -550,6 +550,7 @@
 self.db = db or field._db
 self.orderby = orderby
 self.limitby = limitby
+self.distinct = distinct
 self.min_length = min_length
 self.fields=[field]
 if id_field:
@@ -568,7 +569,8 @@
 if self.keyword in self.request.vars:
 field = self.fields[0]
 rows = self.db(field.like(self.request.vars[self.keyword]+'%'))\
-.select(orderby=self.orderby,limitby=self.limitby,*self.fields)
+.select(orderby=self.orderby,limitby=self.limitby,
+distinct=self.distinct,*self.fields)
 if rows:
 if self.is_reference:
 id_field = self.fields[1]


[web2py] web2py DAL, migration

2012-06-25 Thread aungsan
Hi,

I got web2py dal very wired problem.

I follow that link.

http://vimeo.com/23145118

db.define_table('stock_price2',
  Field('symbol'),
  Field('price', 'double'),
  Field('price_change', 'double'),
)

Accidentally, i type chnage in the last field name. So I want to change it 
back to change. MySQL  does not accept that field name. And then later 
web2py give me no much problem Cos I go and change directly in mysql.

db.define_table('stock_price2',
  Field('symbol'),
  Field('price', 'double'),
  Field('price_change', 'double'),
  migrate = False, fake_migrate = True
)

Nothing work.

I really want to know simple example how to change field name after table 
is crated.

Thanks you very much. Web2py ROCK !

-- 





[web2py] Adding a field in a table

2012-06-25 Thread anubhav aggarwal
Hi all,

 I am a GSOC student developer for Sahana Eden, a web2py based disaster
management Application .

I was trying to *add a field in the already defined table* *through DAL
object* . The table also has some records in it . I don't want to use sql
as this script might be used by many developers who have different
databases like sqlite , postgresql etc .

Could you please help me in doing this .

Thank You
Anubhav Aggarwal

-- 





[web2py] Re: Best practice using scheduler as a task queue?

2012-06-25 Thread pbreit
I see Rails is adding some sort of queue:
http://news.ycombinator.com/item?id=3899080

-- 





[web2py] Re: How capable is the ajax function in web2py.js?

2012-06-25 Thread Anthony



1. I do not want to reload pages: everything needs to work smoothly as 
a desktop app. (of course, not all interactions with web2py, just the ones 
related to this one real-time component). I guess the right tool for this 
job would be the ajax function in web2py.ps. Is this tool able to 
handle complex data?

 The ajax() function is just a basic convenience function. It pulls values 
from input elements, posts them via Ajax using jQuery, and places the 
returned HTML in a specified target (or executes some returned Javascript). 
It relies on jQuery for the actual Ajax calls, so if you need to do 
anything more sophisticated, you can just use jQuery directly. You should 
be able to handle whatever Ajax you need.


1. the ajax events must not only be generated by the user, but also 
autonomously by the web browser. In pyjamas I am doing this with a Timer, 
which translates to some timer javascript events. Is this possible in 
web2py? Is there an example of a javascript timer triggering ajax requests 
in web2py?

 If you use a web2py Ajax component (which uses the web2py_component() JS 
function), in trunk there is now a timer option. Otherwise, you should be 
able to implement your own timer. Note, anything you can do with Ajax is 
technically possible with web2py -- web2py is a server-side framework and 
is happy to receive Ajax requests and return responses. Most of the effort 
will be on the client side -- for that, web2py provides some convenience 
methods, but you are free to use other third-party libraries or build your 
own JS/Ajax solution.

Anthony

-- 





[web2py] which files are checked for menu?

2012-06-25 Thread song
Hi!

I'm studying  hard.
I will change the  menu in the top of the screen. There are some menus like 
Login, Lost Password.
But unhappily there are no menu.py ( in  models directory).

I want to change the menus including some others like the Login, Lost 
Password, Register   etc..

Which files will be changed ?  main  db files, or controllers ?

-- 





[web2py] Re: web2py DAL, migration

2012-06-25 Thread Massimo Di Pierro
You cannot change a field name. Changing a field name will be interpreted 
as the previous field being deleted and a new field with the new name bing 
created.

In your case this worked when you replace change with chnage. 

When you changed it back to change it should have worked too. What error 
did you get exactly?

massimo

On Monday, 25 June 2012 16:46:34 UTC-5, aungsan wrote:

 Hi,

 I got web2py dal very wired problem.

 I follow that link.

 http://vimeo.com/23145118

 db.define_table('stock_price2',
   Field('symbol'),
   Field('price', 'double'),
   Field('price_change', 'double'),
 )

 Accidentally, i type chnage in the last field name. So I want to change it 
 back to change. MySQL  does not accept that field name. And then later 
 web2py give me no much problem Cos I go and change directly in mysql.

 db.define_table('stock_price2',
   Field('symbol'),
   Field('price', 'double'),
   Field('price_change', 'double'),
   migrate = False, fake_migrate = True
 )

 Nothing work.

 I really want to know simple example how to change field name after table 
 is crated.

 Thanks you very much. Web2py ROCK !


-- 





[web2py] Re: Adding reference tables to auth

2012-06-25 Thread Massimo Di Pierro
You can defined your own auth_user before auth.define_table and your own 
will be used. Or you can use

auth.settings.extra_fields['auth_user'] = 
[Field(...),Field(...),Field(...), ... ]

before auth.define_tables()

On Monday, 25 June 2012 18:43:33 UTC-5, Horus wrote:

 is there a way to add other tables to the current auth table setup ?
 I am aware of customizing existing tables but not adding tables to the 
 database structure. 

 e.g. 

 Is it VALID to add other tables such at a country table and have auth_user 
 reference this table without breaking web2py internals?
 How can this be done if possible?


-- 





[web2py] Re: Dashboard in web2py?

2012-06-25 Thread Massimo Di Pierro
web2py does not. You need to add a CMS to web2py. You can look into 
InstantPress or Movuca or cube2py.

On Monday, 25 June 2012 19:31:25 UTC-5, Paulo Couto wrote:

 I'm taking the first steps in web2py but I have a question that for me is 
 very important as to continue or not with web2py.
 Does web2py have a admin dashboard as Wordpress, Textpattern, etc, so the 
 client can update the site like they will normally do in a cms?? I know 
 web2py it's not a CMS, but the option to my clients can update the site, 
 posting pictures, etc. is very important.
 So far I've always been a CMS tweaker, but I would like change the 
 course of my career and web2py and python seems to me the most intelligent 
 solution.

 Thank you.


-- 





[web2py] Re: which files are checked for menu?

2012-06-25 Thread Massimo Di Pierro
The scaffolding application uses views/layout.html which displays

{{=MENU(response.menu)}} on the left and
{{=auth.navbar()}} on the right.

response.menu contains the menu items defined in modes/menu.py

The auth.navbav() returns a helper object. You cannot alter it but you can 
defined your own or you can modify it. For example:

{{
navbar=auth.navbar()
navbar.append(A('mylink',_href=URL()))
=navbar
}}



On Monday, 25 June 2012 20:45:09 UTC-5, song wrote:

 Hi!

 I'm studying  hard.
 I will change the  menu in the top of the screen. There are some menus 
 like Login, Lost Password.
 But unhappily there are no menu.py ( in  models directory).

 I want to change the menus including some others like the Login, Lost 
 Password, Register   etc..

 Which files will be changed ?  main  db files, or controllers ?



-- 





[web2py] type 'exceptions.ValueError' invalid literal for int() with base 10: ''

2012-06-25 Thread Horus
I am currently getting this error working with DAL based on


db.define_table('base_tags',
Field('name', 'string', length=64, required=True, 
notnull=True),
format='%(name)'
)



db.define_table('base_timezones',
Field('name', 'string', length=64, required=True, 
notnull=True),
Field('offset_time', 'integer', required=True, 
notnull=True),
format='%(name)'
)


db.define_table('base_types',
Field('name', 'string', length=64, required=True, 
notnull=True),
format='%(name)'
)


db.define_table('base_sexes',
Field('name', 'string', length=16, required=True, 
notnull=True),
format='%(name)'
)


db.define_table('base_countries',
Field('name', 'string', length=64, required=True, 
notnull=True),
Field('latitude', 'decimal', required=True, notnull=True),
Field('longitude', 'decimal', required=True, notnull=True),
format='%(name)s'
)


db.define_table('base_states',
Field('country_id', db.base_countries),
Field('name', 'string', length=64, required=True, 
notnull=True),
Field('latitude', 'decimal', required=True, notnull=True),
Field('longitude', 'decimal', required=True, notnull=True),
format='%(name)'
)


db.define_table('base_cities',
Field('state_id', db.base_states),
Field('name', 'string', length=64, required=True, 
notnull=True),
Field('latitude', 'decimal', required=True, notnull=True),
Field('longitude', 'decimal', required=True, notnull=True),
format='%(name)'
)


type 'exceptions.ValueError' invalid literal for int() with base 10: ''

VERSIONweb2py™(1, 99, 7, datetime.datetime(2012, 3, 4, 22, 12, 8), 'stable')
PythonPython 2.7.2: C:\Python27\python.exeTRACEBACK

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.

Traceback (most recent call last):
  File C:\web2py\gluon\restricted.py, line 205, in restricted
exec ccode in environment
  File C:/web2py/applications/histreet/models/db.py 
http://127.0.0.1:8000/admin/default/edit/histreet/models/db.py, line 79, in 
module
format='%(name)s'
  File C:\web2py\gluon\dal.py, line 6320, in define_table
polymodel=polymodel)
  File C:\web2py\gluon\dal.py, line 633, in create_table
precision, scale = map(int,field.type[8:-1].split(','))
ValueError: invalid literal for int() with base 10: ''

ERROR SNAPSHOT [image: help]

type 'exceptions.ValueError'(invalid literal for int() with base 10: '')

-- 





[web2py] Re: Distinct in Autocomplete widget select

2012-06-25 Thread Massimo Di Pierro
Thank you! It is now in trunk.

On Monday, 25 June 2012 15:08:02 UTC-5, Brent Zeiben wrote:

 Hi,
 I noticed the Autocomplete widget in gluon/sqlhtml.py does not support the 
 distinct value for the select query.  In a project I was working on instead 
 of creating a new category like table I modified the sqlhtml.py to allow 
 for setting a distinct value (default is false) attached is a patch file 
 from mercurial trunk this morning.

 Are there any issues with this?

 Thanks,
 Brent


-- 





[web2py] Re: Adding reference tables to auth

2012-06-25 Thread Horus
I saw that in the documentation. Can auth_user reference a table I create? 
so...


auth.settings.extra_fields['auth_user']= [
Field('timezone_id',db.base_timezones),
Field('type_id',db.base_types),
Field('sex_id',db.base_sexes),
Field('photo', 
uploadfolder=os.path.join(request.folder,'uploads/users')),
Field('ip', 'string', length=40),
Field('agent', 'text'),
Field('phone', 'string', length=16),
Field('zip', 'string', length=16),
Field('city', 'string', length=64),
Field('state' 'string', length=64),
Field('country', 'string', length=64),
Field('latitude', 'decimal', required=True, notnull=True),
Field('longitude', 'decimal', required=True, notnull=True)
]


where

Field('timezone_id',db.base_timezones),
Field('type_id',db.base_types),
Field('sex_id',db.base_sexes),

are other tables


On Monday, June 25, 2012 10:33:47 PM UTC-4, Massimo Di Pierro wrote:

 You can defined your own auth_user before auth.define_table and your own 
 will be used. Or you can use

 auth.settings.extra_fields['auth_user'] = 
 [Field(...),Field(...),Field(...), ... ]

 before auth.define_tables()

 On Monday, 25 June 2012 18:43:33 UTC-5, Horus wrote:

 is there a way to add other tables to the current auth table setup ?
 I am aware of customizing existing tables but not adding tables to the 
 database structure. 

 e.g. 

 Is it VALID to add other tables such at a country table and have 
 auth_user reference this table without breaking web2py internals?
 How can this be done if possible?



-- 





[web2py] Re: type 'exceptions.ValueError' invalid literal for int() with base 10: ''

2012-06-25 Thread Horus
additional info...

Function argument list

(self=gluon.dal.PostgreSQLAdapter object, table=Table {'ALL': 
gluon.dal.SQLALL object at 0x035..., 'id': gluon.dal.Field object at 
0x0359A230}, migrate=True, fake_migrate=False, polymodel=None)
Code listing

628.
629.
630.
631.
632.
633.

634.
635.
636.
637.

   foreign_key=referenced + ('(%s)' % id_fieldname),
   on_delete_action=field.ondelete)
elif field.type.startswith('list:reference'):
ftype = self.types[field.type[:14]]
elif field.type.startswith('decimal'):
precision, scale = map(int,field.type[8:-1].split(','))

ftype = self.types[field.type[:7]] % \
dict(precision=precision,scale=scale)
elif not field.type in self.types:
raise SyntaxError, 'Field: unknown field type: %s for %s' % \


On Monday, June 25, 2012 10:39:38 PM UTC-4, Horus wrote:

 I am currently getting this error working with DAL based on


 db.define_table('base_tags',
 Field('name', 'string', length=64, required=True, 
 notnull=True),
 format='%(name)'
 )



 db.define_table('base_timezones',
 Field('name', 'string', length=64, required=True, 
 notnull=True),
 Field('offset_time', 'integer', required=True, 
 notnull=True),
 format='%(name)'
 )


 db.define_table('base_types',
 Field('name', 'string', length=64, required=True, 
 notnull=True),
 format='%(name)'
 )


 db.define_table('base_sexes',
 Field('name', 'string', length=16, required=True, 
 notnull=True),
 format='%(name)'
 )


 db.define_table('base_countries',
 Field('name', 'string', length=64, required=True, 
 notnull=True),
 Field('latitude', 'decimal', required=True, notnull=True),
 Field('longitude', 'decimal', required=True, notnull=True),
 format='%(name)s'
 )


 db.define_table('base_states',
 Field('country_id', db.base_countries),
 Field('name', 'string', length=64, required=True, 
 notnull=True),
 Field('latitude', 'decimal', required=True, notnull=True),
 Field('longitude', 'decimal', required=True, notnull=True),
 format='%(name)'
 )


 db.define_table('base_cities',
 Field('state_id', db.base_states),
 Field('name', 'string', length=64, required=True, 
 notnull=True),
 Field('latitude', 'decimal', required=True, notnull=True),
 Field('longitude', 'decimal', required=True, notnull=True),
 format='%(name)'
 )


 type 'exceptions.ValueError' invalid literal for int() with base 10: ''

 VERSIONweb2py™(1, 99, 7, datetime.datetime(2012, 3, 4, 22, 12, 8), 
 'stable')PythonPython 2.7.2: C:\Python27\python.exeTRACEBACK

 1.
 2.
 3.
 4.
 5.
 6.
 7.
 8.
 9.
 10.
 11.

 Traceback (most recent call last):
   File C:\web2py\gluon\restricted.py, line 205, in restricted
 exec ccode in environment
   File C:/web2py/applications/histreet/models/db.py 
 http://127.0.0.1:8000/admin/default/edit/histreet/models/db.py, line 79, in 
 module
 format='%(name)s'
   File C:\web2py\gluon\dal.py, line 6320, in define_table
 polymodel=polymodel)
   File C:\web2py\gluon\dal.py, line 633, in create_table
 precision, scale = map(int,field.type[8:-1].split(','))
 ValueError: invalid literal for int() with base 10: ''

 ERROR SNAPSHOT [image: help]

 type 'exceptions.ValueError'(invalid literal for int() with base 10: '')


-- 





[web2py] Short way to update or insert data from SQLFORM.factory into the main db.my_table ??? ...

2012-06-25 Thread Don_X
Hello web2py users,

I have made a quick sign up form using SQLFORM.factory,
all the data entered on the various fields of the form are validating 
correctly, my error msgs are poping up the way I want ( and not into the 
form )
My SQLFORM.factory in the controller index file goes like this ( I have a 
login header like facebook ..and a short sign up form similar to facebook  
on the index page .. this explains the return of 2 form objects below ) :
def index():
   
auth.settings.hideerror = True
form = SQLFORM.factory(
Field('first_name', type='string',requires=IS_NOT_EMPTY(
error_message='Field is empty !'),
  label=T('First Name')),
Field('last_name', type='string', requires=IS_NOT_EMPTY(
error_message=' Empty Field !!'),
  label=T('Last Name')),
Field('email', type='string', 
requires=IS_NOT_EMPTY(error_message='Invalid 
email address !'),
  label=T('E-mail')),
Field('email_check', type='string',requires=IS_EQUAL_TO(request.vars
.email),
  label=T('Re-enter E-mail')),
Field('password', type='password',requires=IS_NOT_EMPTY(
error_message='Minimum 6 Alpha Numeric Characters - Should not be empty !'),
  readable=False,
  label=T('New Password')),
Field('sex',requires=IS_IN_SET((T('male'),T('female'))),label=T('My 
Sex is')),
Field('birth_date','date',default=request.now,
widget=select_datewidget,label=T('Birth Date')),
Field('Iagreeto','boolean',requires=IS_NOT_EMPTY(error_message='you 
must agree to this !'),
label=T('I agree to the Terms of service, Privacy policy, and 
Codes of conduct.')),
hideerror = True)
if form.process().accepted:
   
   response.flash = T('Quick Sign-up Accepted ! - Check your e-mail !')
   
elif form.errors:
   response.flash = T('Quick Sign up form has errors ')
   
   
return dict(toplogin_form = auth.login(),quicksignup_form = form)
  

What I want to do Now :
1) To update the datable table so the same user can sign in whenever !

with SQLFORM it was not a problem it seems it was done automatically  ... 
but with SQLFORM.factory, because of my need to customise a few things 
. now ...
 the data is not going straight into the database table ( db.auth-user ) 
..  is there a quick way to do this ??? ... without doing it field by  
field ? if field by field is a must ...
what about the hidden user's registration timestamp  ?? how do I make sure 
the timestamp fields are updated correctly ?

Can someone Please assist me a  bit ...


thanks



-- 





Re: [web2py] Short way to update or insert data from SQLFORM.factory into the main db.my_table ??? ...

2012-06-25 Thread Bruno Rocha
if form.process().accepted:

   db.auth_user.insert(**form.vars)

   response.flash = T('Quick Sign-up Accepted ! - Check your e-mail !')

-- 





[web2py] Re: Adding reference tables to auth

2012-06-25 Thread Anthony
I believe that should work.

Anthony

On Monday, June 25, 2012 10:41:48 PM UTC-4, Horus wrote:

 I saw that in the documentation. Can auth_user reference a table I create? 
 so...


 auth.settings.extra_fields['auth_user']= [
 Field('timezone_id',db.base_timezones),
 Field('type_id',db.base_types),
 Field('sex_id',db.base_sexes),
 Field('photo', 
 uploadfolder=os.path.join(request.folder,'uploads/users')),
 Field('ip', 'string', length=40),
 Field('agent', 'text'),
 Field('phone', 'string', length=16),
 Field('zip', 'string', length=16),
 Field('city', 'string', length=64),
 Field('state' 'string', length=64),
 Field('country', 'string', length=64),
 Field('latitude', 'decimal', required=True, notnull=True),
 Field('longitude', 'decimal', required=True, notnull=True)
 ]


 where

 Field('timezone_id',db.base_timezones),
 Field('type_id',db.base_types),
 Field('sex_id',db.base_sexes),

 are other tables


 On Monday, June 25, 2012 10:33:47 PM UTC-4, Massimo Di Pierro wrote:

 You can defined your own auth_user before auth.define_table and your own 
 will be used. Or you can use

 auth.settings.extra_fields['auth_user'] = 
 [Field(...),Field(...),Field(...), ... ]

 before auth.define_tables()

 On Monday, 25 June 2012 18:43:33 UTC-5, Horus wrote:

 is there a way to add other tables to the current auth table setup ?
 I am aware of customizing existing tables but not adding tables to the 
 database structure. 

 e.g. 

 Is it VALID to add other tables such at a country table and have 
 auth_user reference this table without breaking web2py internals?
 How can this be done if possible?



-- 





[web2py] Re: web2py DAL, migration

2012-06-25 Thread aungsan
Hey 

thanks you so much. I guess it is mysql wired thing. keyword reserve. But 
sometimes it does work. sometimes it does not.  ^_^

-- 





[web2py] Authentication

2012-06-25 Thread aungsan
I got following issue with web2py Authentication.

I have to authenticate through URL 
http://www.example.com/something/q?ID='username'pass='password'

It return true or false. I cannot go and change it. And I have to do 
authentication with it for sure.

After I got true or false, I would like to insert username and password 
into web2py auth database and set login flag. So that user is logged in.

How could I implement it ?

-- 





[web2py] Re: type 'exceptions.ValueError' invalid literal for int() with base 10: ''

2012-06-25 Thread Annet
In all your table definitions you have format='%(name)' except in 
base_countries table, where you have format='%(name)s'.

I don't understand the trace back, the error is caused by 
format='%(name)s', which is what I have in my table definitions, and which 
doesn't cause any errors.


Kind regards,

Annet

-- 





[web2py] ldap

2012-06-25 Thread aungsan
from gluon.contrib.login_methods.ldap_auth import ldap_auth
auth.settings.login_methods = [ldap_auth(mode='ad',
   server='abc.google.com', base_dn='ou=Users, dc=google,dc=com')]

I am having the following error.

File gluon/contrib/login_methods/ldap_auth.py, line 9, in module
ImportError: No module named ldap


I installed easy_install python-ldap.

I test with just a line in test.py and run python test.py

import ldap

See no error.

i re-install by msi packages. 

http://pypi.python.org/packages/2.7/p/python-ldap/python-ldap-2.4.10.win32-py2.7.msi#md5=7bcf356c590ea093f7c3ad410c155f82

Test with simple import. It work. But web2py still giving error.

--