[web2py] Re: SQLFORM.factory

2012-11-07 Thread Wouter Pronk
Yes, I did but no difference. I copied all the files in my app to a new app 
and now everthing is fine. Very strange! Thanks for you help Niphlod!

Op woensdag 7 november 2012 15:04:01 UTC+1 schreef Niphlod het volgende:
>
> did you try removing one Field at a time inside SQLFORM.factory and see 
> where the errors pops up ?
>
> On Wednesday, November 7, 2012 2:58:10 PM UTC+1, Wouter Pronk wrote:
>>
>> Did some other testing and found simular error on this controler:
>> def add_relatie():
>> adres = db.executesql('SELECT adressen.relatie_nummer, " | ", 
>> adressen.relatie_code, " | ", adressen.relatie_naam FROM adressen left join 
>> edirelaties on adressen.relatie_nummer = edirelaties.relatie_nummer WHERE 
>> edirelaties.relatie_nummer is null;')
>> form = SQLFORM.factory(
>> Field('relatie_nummer', requires=IS_IN_SET([a[0] for a in 
>> adres],labels
>> =[a for a in adres])),
>> Field('login_naam', requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db, 
>> 'edirelaties.login_naam'),IS_ALPHANUMERIC(error_message='must be 
>> alphanumeric!')]),
>> Field('password', requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db, 
>> 'edirelaties.password'),IS_ALPHANUMERIC(error_message='must be 
>> alphanumeric!')]),
>> Field('work_directory', requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db, 
>> 'edirelaties.work_directory'),IS_ALPHANUMERIC(error_message='must be 
>> alphanumeric!')]))
>> if form.process().accepted:
>> db.edirelaties.insert(**form.vars)
>> response.flash = 'Your new edirelatie has been added'
>> redirect(URL('show', args=form.vars.id))
>> elif form.errors:
>> response.flash = 'form has errors'
>> return dict(form=form)
>> Any idea?
>>
>>
>> Op woensdag 7 november 2012 12:42:58 UTC+1 schreef Niphlod het volgende:
>>>
>>> did you try with trunk ?
>>>
>>> On Wednesday, November 7, 2012 12:38:40 PM UTC+1, Wouter Pronk wrote:

 I just did and it did go in exception. Is my web2py corrupt?

 Op woensdag 7 november 2012 12:17:32 UTC+1 schreef Niphlod het volgende:
>
> create a fresh app and paste your code in it. It shouldn't go in 
> exception
>
> form = SQLFORM.factory(
> Field('relatie_id', writable=False, readable=False),
> Field('relatie_nummer', writable=False, readable=False),
> Field('direction', writable=False, readable=False),
> Field('protocol', writable=False, readable=False),
> Field('email', requires=IS_EMAIL())
> )
>
>
>
> This doesn't
>
> On Wednesday, November 7, 2012 12:12:24 PM UTC+1, Wouter Pronk wrote:
>>
>> Hello Niphlod,
>> this is the traceback:
>>
>> Traceback (most recent call last):
>>   File "/home/wouter/Web2py/web2py/gluon/restricted.py", line 212, in 
>> restricted
>> exec ccode in environment
>>   File 
>> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py"
>>  
>> ,
>>  line 381, in 
>>   File "/home/wouter/Web2py/web2py/gluon/globals.py", line 188, in 
>> 
>> self._caller = lambda f: f()
>>   File 
>> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py"
>>  
>> ,
>>  line 200, in add_protocol
>> Field('relatie_id', writable=False, readable=False),
>> TypeError: __init__() takes exactly 1 argument (4 given)
>>
>> Where should I look?
>>
>>
>> Op woensdag 7 november 2012 11:54:24 UTC+1 schreef Niphlod het 
>> volgende:
>>>
>>> something else is wrong in your app, that piece of code works 
>>> perfectly fine (the fact that you're declaring 5 fields to let display 
>>> only 
>>> one is quite not understandable but hey, it works nonetheless)
>>>
>>> On Wednesday, November 7, 2012 11:32:39 AM UTC+1, Wouter Pronk wrote:

 I have the following code:
 form = SQLFORM.factory(
 Field('relatie_id', writable=False, readable=False),
 Field('relatie_nummer', writable=False, readable=False),
 Field('direction', writable=False, readable=False),
 Field('protocol', writable=False, readable=False),
 Field('email', requires=[IS_EMAIL(),IS_NOT_IN_DB(db, 
 'comprotocol.email')]))

 and this is working perfectly in version 1.99 but not in 2.2.1. I 
 get an error:

  File 
 "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py"
  
 ,
  line 199, in add_protocol
 Field('relatieid', writable=False, readable=False),
 TypeError: __init__() ta

Re: [web2py] Re: Help with db query

2012-11-07 Thread hasan alnator
Dear Joe ,

I tried this :

values = []
values.append(request.args(0))
values.append('Both')
sup = db((db.Supplements.Category ==
(request.args(1)).replace('_',' ')) &
(db.Supplements.Users.contains(values))).select(db.Supplements.ALL)

And it didnt do anything !!!  i dont understand what is happening !!

Regards,


On Wed, Nov 7, 2012 at 1:37 PM, Joe Barnhart  wrote:

> There is a Field function called "contains()" which would be useful here.
> It is described in the online book here:
>
>
> http://www.web2py.com/books/default/chapter/29/06#like,-regexp,-startswith,-contains,-upper,-lower
>
> Your query would be something like:
>
> db.table.Field2.contains( [ 'value1', 'value2' ] )
>
> Notice that "contains" is a function and is on Field2 (where it gets its
> "self" argument).  The argument to contains is a list object -- note the
> square brackets!  The list gathers up your values into a single object
> which is then passed into "contains".  There is an optional keyword
> argument "all" which can be set to True which forces it to match all of the
> list instead of any of the list.
>
> -- Joe B.
>
>
> On Wednesday, November 7, 2012 3:01:58 AM UTC-8, Hassan Alnatour wrote:
>
>> and i even tried :
>>
>> items  =[]
>> items.append(request.args(0))
>> items.append('Both')
>>
>> db( (db.table.Field1 == value) & (db.table.Field2 in items))
>>
>>
>> regards,
>>
>>
>> On Wed, Nov 7, 2012 at 12:56 PM, hasan alnator > > wrote:
>>
>>> Dear Joe ,
>>>
>>> What i want to do is to have a query like this :
>>>
>>> db( (db.table.Field1 == value) & (db.table.Field2 == value or value))
>>>
>>> i tried it i get no errors but its now working
>>>
>>> Regards
>>>
>>>
>>> On Wed, Nov 7, 2012 at 10:10 AM, Joe Barnhart wrote:
>>>
 I see -- you're right.

 The request.args structure is a List() object which web2py defines to
 retrieve values without the exception if it doesn't exist.  It has some
 additional interesting capabilities...  You can define a default value,
 such as this:


 request.args(0,default='Both')


 This will substitute the value 'Both' for request.args[0] should it be
 set to None or be invalid.  Or you could cast a string value to an integer
 -- this often happens since the request.args are strings by default, but I
 often pass row ids to be processed elsewhere:


 URL('default','editrecord',arg**s=[22])


 Becomes:


 http://./default/**editrecord/22


 And request.args[0] is now '22' (the string).  So we use the "cast"
 keyword to change it to an int:


 request.args(0,cast=int)


 There is a ton of behavior in this little class!  Thanks for pointing
 it out to me.

 -- Joe Barnhart


 class List(list):
 """
 Like a regular python list but a[i] if i is out of bounds return
 None
 instead of IndexOutOfBounds
 """

 def __call__(self, i, default=None, cast=None, otherwise=None):
 """
 request.args(0,default=0,cast=**int,otherwise='http://error_**
 url ')
 request.args(0,default=0,cast=**int,otherwise=lambda:...)
 """
 n = len(self)
 if 0 <= i < n or -n <= i < 0:
 value = self[i]
 else:
 value = default
 if cast:
 try:
 value = cast(value)
 except (ValueError, TypeError):
 from http import HTTP, redirect
 if otherwise is None:
 raise HTTP(404)
 elif isinstance(otherwise, str):
 redirect(otherwise)
 elif callable(otherwise):
 return otherwise()
 else:
 raise RuntimeError("invalid otherwise")
 return value




 On Tuesday, November 6, 2012 2:24:53 PM UTC-8, Niphlod wrote:
>
>
> One more point -- your "request.args(1)" should be "request.args[1]"
>> (with square brackets).  The first form calls request.args as a function
>> and passes it the value "1".   The second form treats request.args as a
>> Storage object and asks for the subscript "1".
>>
>> -- Joe Barnhart
>>
>> Nope, request.args(1) does basically
> try:
>   result = request.args[1]
> except:
>   result = None
> return result
>
> the () notation is safer because using request.args[1] if there is no
> request.args[1] you get an exception.
>
  --




>>>
>>>
>>  --
>
>
>
>

-- 





[web2py] Re: Shortcut not working: del db.mytable[id]

2012-11-07 Thread Cliff Kachinske
Version 2.0.9, Postgres 9.X, Psycopg2

I don't know what else to tell you, except I know the record was there 
after the failed delete attempt.

Today the same syntax failed in another location in my code, with the same 
result.  I thought I caught them all, but apparently not.

On Wednesday, November 7, 2012 8:32:59 AM UTC-5, Niphlod wrote:
>
> but I tried in a shell and it doesn't raise an exception if the record 
> exists (and it gets correctly deleted too)
>
> On Wednesday, November 7, 2012 1:59:48 PM UTC+1, Cliff Kachinske wrote:
>>
>> The record was there.
>>
>> That's the problem.  The shortcut was erroneously reporting that it was 
>> gone.
>>
>> On Tuesday, November 6, 2012 2:40:38 PM UTC-5, Niphlod wrote:
>>>
>>> del db.sometable[something] requires that the id == something exists.
>>> db(db.sometable.id == something).delete() instead returns the number of 
>>> records deleted if there was any, otherwise it simply deletes nothing.
>>>
>>> On Tuesday, November 6, 2012 8:14:33 PM UTC+1, Cliff Kachinske wrote:

 This code works.  Note the commented out line.

 for v in form.vars:
 if v[:7] == 'remove_' and form.vars[v] == 'on':
 # del db.class_users[v[7:]]
 db(db.class_users.id==v[7:]).delete()


 This code, which should be equivalent, raises the exception shown below.

 for v in form.vars:
 if v[:7] == 'remove_' and form.vars[v] == 'on':
 del db.class_users[v[7:]]


 Traceback (most recent call last):
   File "/home/cjk/w2p09/web2py/gluon/restricted.py", line 209, in 
 restricted
 exec ccode in environment
   File 
 "/home/cjk/w2p09/web2py/applications/Training/controllers/class_users.py" 
 ,
  line 371, in 
   File "/home/cjk/w2p09/web2py/gluon/globals.py", line 186, in 
 self._caller = lambda f: f()
   File "/home/cjk/w2p09/web2py/gluon/tools.py", line 2809, in f
 return action(*a, **b)
   File 
 "/home/cjk/w2p09/web2py/applications/Training/controllers/class_users.py" 
 ,
  line 165, in list_
 if form.process(onvalidation=do_updates).accepted:
   File "/home/cjk/w2p09/web2py/gluon/html.py", line 2108, in process
 self.validate(**kwargs)
   File "/home/cjk/w2p09/web2py/gluon/html.py", line 2055, in validate
 if self.accepts(**kwargs):
   File "/home/cjk/w2p09/web2py/gluon/html.py", line 1969, in accepts
 onvalidation(self)
   File 
 "/home/cjk/w2p09/web2py/applications/Training/controllers/class_users.py" 
 ,
  line 134, in do_updates
 del db.class_users[v[7:]]
   File "/home/cjk/w2p09/web2py/gluon/dal.py", line 7691, in __delitem__
 raise SyntaxError, 'No such record: %s' % key
 SyntaxError: No such record: 7



-- 





Re: [web2py] Re: Problem in deploying ssl certificates to Rocket server.

2012-11-07 Thread Amit
Thanks Michele, I resolved the issue by overriding class X509Auth :), one
more clarification:
using openssl, i created CA certificates, private key then client and
server certificates with their private key signed by CA certificate,
everything is working fine except:
 when I access My application I always need to provide the server
certificate password on the command prompt (where server has started) to
access the page, is there any way to disable this? Means, user only needs
to import the client certificate to their browser and when they access the
application it will allow to access the pages of the application without
asking the password. Anyways user doesn't have access to the server so they
can't be able to provide the password so in this case, even though they
will be able to import the client certificate, automatically downloaded
server certificate to the browser when they make request for application
but can't be able to access the application pages because on server command
prompt it will ask for password, so how to make it password free?


On Wed, Nov 7, 2012 at 6:52 PM, Michele Comitini  wrote:

> Amit,
>
> A "self" was missing this should work:
>
> class MyX509Auth(X509Auth):
>  def get_user(self):
>   self.subject.surname = 
>   X509Auth.get_user(self)
> auth.settings.login_form = MyX509Auth()
>
>
> 2012/11/7 Michele Comitini 
>
>> Amit,
>>
>> in your model call the derived class
>>
>> auth.settings.login_form = MyX509Auth()
>>
>>
>>
>> 2012/11/7 Michele Comitini 
>>
>>> simpatiCA makes the client certificates already with needed fields.
>>> Since you use openssl directly you can set all the fields you need in
>>> the certificates by changing openssl.cnf in your openssl installation.
>>>  There is plenty of documentation on that.
>>>
>>> OR you can extend the class X509Auth to fit your needs by overriding
>>> get_user()
>>>
>>>
>>> class MyX509Auth(X509Auth):
>>>  def get_user():
>>>   self.subject.surname = 
>>>   X509Auth.get_user(self)
>>>
>>>
>>> mic
>>>
>>>
>>>
>>> 2012/11/7 Amit 
>>>
 Hi,
 I filled the email address in the certificate but what I think is
 problem with surname , please check below the log:


 *File D:\web2py2.1.1\web2py\gluon\contrib\login_methods\x509_auth.py
 in get_user at line 91* code arguments variables
  Function argument list

 (self=)
  Code listing

 86.
 87.
 88.
 89.
 90.
 91.

 92.
 93.
 94.
 95.


 p = profile = dict()

 username = p['username'] = reduce(lambda a,b: '%s | %s' % (a,b), 
 self.subject.CN or self.subject.commonName)




 p['first_name'] = reduce(lambda a,b: '%s | %s' % 
 (a,b),self.subject.givenName or username)



 p['last_name'] = reduce(lambda a,b: '%s | %s' % 
 (a,b),self.subject.surname)




 p['email'] = reduce(lambda a,b: '%s | %s' % 
 (a,b),self.subject.Email or self.subject.emailAddress)




 # IMPORTANT WE USE THE CERT SERIAL AS UNIQUE KEY FOR THE USER
 p['registration_id'] = self.serial

  Variables
 a undefined  b undefined  builtinreduce 
 self.subject.surname []  self 
 >>> object>  self.subject >>> ...SG'], 'organizationUnitName': ['HSG'], 'SN': []}>  p {'first_name':
 'A | m | i | t | 1 | | K | h | a | w | a | r | e', 'username': 'Amit1
 Khaware'}

 And while generating the certificates it is not asking about surname,
 it's asking below information:

 Country Name (2 letter code) [US]:
 State or Province Name (full name) [CA]:
 Locality Name (eg, city) [San Diego]:
 Organization Name (eg, company) [Cafesoft LLC]:
 Organizational Unit Name (eg, section) []:
 Common Name (eg, YOUR name) []:*Cafesoft CA*
 Email Address [c...@cafenet.com]:

 Please enter the following 'extra' attributes
 to be sent with your certificate request
 A challenge password []:*password*
 An optional company name []:


 please check the link :


 http://www.cafesoft.com/products/cams/ps/docs30/admin/ConfiguringApache2ForSSLTLSMutualAuthentication.html

 So x509_auth.py expects surname but above link doesn't provide option
 to fill surname :(


 Regards,

 Amit








 On Tue, Nov 6, 2012 at 8:34 PM, Michele Comitini <
 michele.comit...@gmail.com> wrote:

> self.subject.Email is [] i.e. an empty list.  Check if that is the
> problem.
>
> mic
> Il giorno 06/nov/2012 14:32, "Amit"  ha
> scritto:
>
>>  I have used below link to generate server certificates, client
>> certificates and CA certificates,  imported client  and CA certificates 
>> to
>> Mozilla Firefox browser and then deploy server certificates and CA
>> ce

Re: [web2py] Re: CONTAINS() takes exactly 3 arguments (2 given)

2012-11-07 Thread apps in tables


Thank you, Villas.

-- 





[web2py] Re: SQLFORM via AJAX - action is blank

2012-11-07 Thread Simon Carr
Thank you. I am grateful for all your help.

Simon

On Wednesday, 7 November 2012 22:43:32 UTC, Niphlod wrote:
>
> whoops, actually, the book needs a fix on that.
> now it's redirect with client_side=True
>
> On Wednesday, November 7, 2012 11:40:47 PM UTC+1, Niphlod wrote:
>>
>> sounds like premature optimization / I don't want to use a LOAD :P
>> did you try redirecting after the form with type='auto' ? (I think that 
>> that's a feature available in the last few releases...)
>>
>> On Wednesday, November 7, 2012 11:31:09 PM UTC+1, Simon Carr wrote:
>>>
>>> I want it to be loaded with AJAX and submitted normally. The reason is 
>>> two fold.
>>>
>>> 1. The page needs to be refreshed after the form is submitted.
>>> 2. By loading the form by AJAX and Submitting normally I am at least 
>>> cutting full page loads down by 50%
>>>
>>> On Wednesday, 7 November 2012 21:41:23 UTC, Niphlod wrote:

 I'm loosing you (too much asked, too little information). 
 - you have a page -->done
 - you want a form loaded into a page --> done
 - you want it to be submitted to the url that is loaded from --> done 
 (if it's loaded through ajax, that means that you don't want to reload the 
 main page, so it can't be submitted with anything else)

 now what ?

 On Wednesday, November 7, 2012 10:34:48 PM UTC+1, Simon Carr wrote:
>
> Your right. Thanks mate. I was getting confused over cid. But anyway 
> it works great for creating the form.
>
> I notice that the form also submits via AJAX. How do I make it submit 
> normally so that I can have the page refreshed? I need the users list of 
> subscribed Charts and some other details to be updated after submitting 
> the 
> form.
>
> Thanks
> Simon
>
> On Wednesday, 7 November 2012 21:04:35 UTC, Niphlod wrote:
>>
>> doesn't it already (provided that there is a > id='whatever'> in the page) ?
>>
>> On Wednesday, November 7, 2012 9:36:27 PM UTC+1, Simon Carr wrote:
>>>
>>> Thank you, but how do I implement this in my view so that it loads 
>>> the form into a div when the link is clicked?
>>>
>>> On Wednesday, 7 November 2012 20:00:52 UTC, Niphlod wrote:

 Wait a sec. callback and target are meant to load a fragment via 
 ajax, but that doesn't "fire" all the logic needed to intercept FORMs 
 etc. 
 _callback and _target are meant roughly as an "onclick" under 
 steroids. (under the hood it translates to an onclick="ajax(url, 
 target)")

 What you're trying to achieve is probably offered by the LOAD 
 helper, that can be exploited in an A() using _href and cid

 A('Add to My Charts',_href=URL('subscribe_form',vars={'chartname': 
 'whatever'}), cid='whatever')

 That will load the component and trap all links and form 
 submissions, because it translates to an 
 onclick="web2py_component(url, 
 target)"


 On Wednesday, November 7, 2012 8:39:50 PM UTC+1, Simon Carr wrote:
>
> The URL with the form in 
> is web2py_xlchart_dashboard/charts/user_charts so without an action 
> it will 
> submit to *user_charts*, but I need it to submit to*subscribe_form 
> *which is the function that was called by AJAX to generate the 
> Form.
>
> or am I not understanding something?
>
> Simon
>
> On Wednesday, 7 November 2012 19:26:46 UTC, Derek wrote:
>>
>> Why would you need to create an action for the form? Are you not 
>> using self submit?
>>
>> On Wednesday, November 7, 2012 12:22:03 PM UTC-7, Simon Carr 
>> wrote:
>>>
>>> I have this piece of code that calls a function in my controller 
>>> when clicked.
>>>
>>> {{=A('Add to My Charts',callback=URL('subscribe_form',vars={
>>> 'chartname':chart.chartName}),target=str(chart.chartName).
>>> replace('.','_'))}}
>>>
>>>
>>> The subscribe_form function looks like this
>>>
>>> def subscribe_form():
>>> 
>>> form = 
>>> SQLFORM(db.user_chart,fields=['title','description'],hidden=dict(chartname=request.vars['chartname']))
>>> if form.process().accepted:
>>> response.flash = 'form accepted'
>>> elif form.errors:
>>> response.flash = 'form has errors'
>>> else:
>>> response.flash = 'please fill out the form'
>>> return form
>>>
>>> The Form is created by AJAX, but it's action is blank.
>>>
>>> Do I have to specify the action myself if I am build a Form via 
>>> AJAX?
>>>
>>> Simon
>>>
>>

-- 





[web2py] Re: SQLFORM via AJAX - action is blank

2012-11-07 Thread Niphlod
whoops, actually, the book needs a fix on that.
now it's redirect with client_side=True

On Wednesday, November 7, 2012 11:40:47 PM UTC+1, Niphlod wrote:
>
> sounds like premature optimization / I don't want to use a LOAD :P
> did you try redirecting after the form with type='auto' ? (I think that 
> that's a feature available in the last few releases...)
>
> On Wednesday, November 7, 2012 11:31:09 PM UTC+1, Simon Carr wrote:
>>
>> I want it to be loaded with AJAX and submitted normally. The reason is 
>> two fold.
>>
>> 1. The page needs to be refreshed after the form is submitted.
>> 2. By loading the form by AJAX and Submitting normally I am at least 
>> cutting full page loads down by 50%
>>
>> On Wednesday, 7 November 2012 21:41:23 UTC, Niphlod wrote:
>>>
>>> I'm loosing you (too much asked, too little information). 
>>> - you have a page -->done
>>> - you want a form loaded into a page --> done
>>> - you want it to be submitted to the url that is loaded from --> done 
>>> (if it's loaded through ajax, that means that you don't want to reload the 
>>> main page, so it can't be submitted with anything else)
>>>
>>> now what ?
>>>
>>> On Wednesday, November 7, 2012 10:34:48 PM UTC+1, Simon Carr wrote:

 Your right. Thanks mate. I was getting confused over cid. But anyway it 
 works great for creating the form.

 I notice that the form also submits via AJAX. How do I make it submit 
 normally so that I can have the page refreshed? I need the users list of 
 subscribed Charts and some other details to be updated after submitting 
 the 
 form.

 Thanks
 Simon

 On Wednesday, 7 November 2012 21:04:35 UTC, Niphlod wrote:
>
> doesn't it already (provided that there is a  
> in the page) ?
>
> On Wednesday, November 7, 2012 9:36:27 PM UTC+1, Simon Carr wrote:
>>
>> Thank you, but how do I implement this in my view so that it loads 
>> the form into a div when the link is clicked?
>>
>> On Wednesday, 7 November 2012 20:00:52 UTC, Niphlod wrote:
>>>
>>> Wait a sec. callback and target are meant to load a fragment via 
>>> ajax, but that doesn't "fire" all the logic needed to intercept FORMs 
>>> etc. 
>>> _callback and _target are meant roughly as an "onclick" under 
>>> steroids. (under the hood it translates to an onclick="ajax(url, 
>>> target)")
>>>
>>> What you're trying to achieve is probably offered by the LOAD 
>>> helper, that can be exploited in an A() using _href and cid
>>>
>>> A('Add to My Charts',_href=URL('subscribe_form',vars={'chartname': 
>>> 'whatever'}), cid='whatever')
>>>
>>> That will load the component and trap all links and form 
>>> submissions, because it translates to an onclick="web2py_component(url, 
>>> target)"
>>>
>>>
>>> On Wednesday, November 7, 2012 8:39:50 PM UTC+1, Simon Carr wrote:

 The URL with the form in 
 is web2py_xlchart_dashboard/charts/user_charts so without an action it 
 will 
 submit to *user_charts*, but I need it to submit to*subscribe_form 
 *which is the function that was called by AJAX to generate the 
 Form.

 or am I not understanding something?

 Simon

 On Wednesday, 7 November 2012 19:26:46 UTC, Derek wrote:
>
> Why would you need to create an action for the form? Are you not 
> using self submit?
>
> On Wednesday, November 7, 2012 12:22:03 PM UTC-7, Simon Carr wrote:
>>
>> I have this piece of code that calls a function in my controller 
>> when clicked.
>>
>> {{=A('Add to My Charts',callback=URL('subscribe_form',vars={
>> 'chartname':chart.chartName}),target=str(chart.chartName).replace
>> ('.','_'))}}
>>
>>
>> The subscribe_form function looks like this
>>
>> def subscribe_form():
>> 
>> form = 
>> SQLFORM(db.user_chart,fields=['title','description'],hidden=dict(chartname=request.vars['chartname']))
>> if form.process().accepted:
>> response.flash = 'form accepted'
>> elif form.errors:
>> response.flash = 'form has errors'
>> else:
>> response.flash = 'please fill out the form'
>> return form
>>
>> The Form is created by AJAX, but it's action is blank.
>>
>> Do I have to specify the action myself if I am build a Form via 
>> AJAX?
>>
>> Simon
>>
>

-- 





[web2py] Re: SQLFORM via AJAX - action is blank

2012-11-07 Thread Niphlod
sounds like premature optimization / I don't want to use a LOAD :P
did you try redirecting after the form with type='auto' ? (I think that 
that's a feature available in the last few releases...)

On Wednesday, November 7, 2012 11:31:09 PM UTC+1, Simon Carr wrote:
>
> I want it to be loaded with AJAX and submitted normally. The reason is two 
> fold.
>
> 1. The page needs to be refreshed after the form is submitted.
> 2. By loading the form by AJAX and Submitting normally I am at least 
> cutting full page loads down by 50%
>
> On Wednesday, 7 November 2012 21:41:23 UTC, Niphlod wrote:
>>
>> I'm loosing you (too much asked, too little information). 
>> - you have a page -->done
>> - you want a form loaded into a page --> done
>> - you want it to be submitted to the url that is loaded from --> done (if 
>> it's loaded through ajax, that means that you don't want to reload the main 
>> page, so it can't be submitted with anything else)
>>
>> now what ?
>>
>> On Wednesday, November 7, 2012 10:34:48 PM UTC+1, Simon Carr wrote:
>>>
>>> Your right. Thanks mate. I was getting confused over cid. But anyway it 
>>> works great for creating the form.
>>>
>>> I notice that the form also submits via AJAX. How do I make it submit 
>>> normally so that I can have the page refreshed? I need the users list of 
>>> subscribed Charts and some other details to be updated after submitting the 
>>> form.
>>>
>>> Thanks
>>> Simon
>>>
>>> On Wednesday, 7 November 2012 21:04:35 UTC, Niphlod wrote:

 doesn't it already (provided that there is a  
 in the page) ?

 On Wednesday, November 7, 2012 9:36:27 PM UTC+1, Simon Carr wrote:
>
> Thank you, but how do I implement this in my view so that it loads the 
> form into a div when the link is clicked?
>
> On Wednesday, 7 November 2012 20:00:52 UTC, Niphlod wrote:
>>
>> Wait a sec. callback and target are meant to load a fragment via 
>> ajax, but that doesn't "fire" all the logic needed to intercept FORMs 
>> etc. 
>> _callback and _target are meant roughly as an "onclick" under 
>> steroids. (under the hood it translates to an onclick="ajax(url, 
>> target)")
>>
>> What you're trying to achieve is probably offered by the LOAD helper, 
>> that can be exploited in an A() using _href and cid
>>
>> A('Add to My Charts',_href=URL('subscribe_form',vars={'chartname': 
>> 'whatever'}), cid='whatever')
>>
>> That will load the component and trap all links and form submissions, 
>> because it translates to an onclick="web2py_component(url, target)"
>>
>>
>> On Wednesday, November 7, 2012 8:39:50 PM UTC+1, Simon Carr wrote:
>>>
>>> The URL with the form in 
>>> is web2py_xlchart_dashboard/charts/user_charts so without an action it 
>>> will 
>>> submit to *user_charts*, but I need it to submit to* subscribe_form 
>>> *which is the function that was called by AJAX to generate the Form.
>>>
>>> or am I not understanding something?
>>>
>>> Simon
>>>
>>> On Wednesday, 7 November 2012 19:26:46 UTC, Derek wrote:

 Why would you need to create an action for the form? Are you not 
 using self submit?

 On Wednesday, November 7, 2012 12:22:03 PM UTC-7, Simon Carr wrote:
>
> I have this piece of code that calls a function in my controller 
> when clicked.
>
> {{=A('Add to My Charts',callback=URL('subscribe_form',vars={
> 'chartname':chart.chartName}),target=str(chart.chartName).replace(
> '.','_'))}}
>
>
> The subscribe_form function looks like this
>
> def subscribe_form():
> 
> form = 
> SQLFORM(db.user_chart,fields=['title','description'],hidden=dict(chartname=request.vars['chartname']))
> if form.process().accepted:
> response.flash = 'form accepted'
> elif form.errors:
> response.flash = 'form has errors'
> else:
> response.flash = 'please fill out the form'
> return form
>
> The Form is created by AJAX, but it's action is blank.
>
> Do I have to specify the action myself if I am build a Form via 
> AJAX?
>
> Simon
>


-- 





[web2py] Re: SQLFORM via AJAX - action is blank

2012-11-07 Thread Simon Carr
I want it to be loaded with AJAX and submitted normally. The reason is two 
fold.

1. The page needs to be refreshed after the form is submitted.
2. By loading the form by AJAX and Submitting normally I am at least 
cutting full page loads down by 50%

On Wednesday, 7 November 2012 21:41:23 UTC, Niphlod wrote:
>
> I'm loosing you (too much asked, too little information). 
> - you have a page -->done
> - you want a form loaded into a page --> done
> - you want it to be submitted to the url that is loaded from --> done (if 
> it's loaded through ajax, that means that you don't want to reload the main 
> page, so it can't be submitted with anything else)
>
> now what ?
>
> On Wednesday, November 7, 2012 10:34:48 PM UTC+1, Simon Carr wrote:
>>
>> Your right. Thanks mate. I was getting confused over cid. But anyway it 
>> works great for creating the form.
>>
>> I notice that the form also submits via AJAX. How do I make it submit 
>> normally so that I can have the page refreshed? I need the users list of 
>> subscribed Charts and some other details to be updated after submitting the 
>> form.
>>
>> Thanks
>> Simon
>>
>> On Wednesday, 7 November 2012 21:04:35 UTC, Niphlod wrote:
>>>
>>> doesn't it already (provided that there is a  
>>> in the page) ?
>>>
>>> On Wednesday, November 7, 2012 9:36:27 PM UTC+1, Simon Carr wrote:

 Thank you, but how do I implement this in my view so that it loads the 
 form into a div when the link is clicked?

 On Wednesday, 7 November 2012 20:00:52 UTC, Niphlod wrote:
>
> Wait a sec. callback and target are meant to load a fragment via ajax, 
> but that doesn't "fire" all the logic needed to intercept FORMs etc. 
> _callback and _target are meant roughly as an "onclick" under 
> steroids. (under the hood it translates to an onclick="ajax(url, target)")
>
> What you're trying to achieve is probably offered by the LOAD helper, 
> that can be exploited in an A() using _href and cid
>
> A('Add to My Charts',_href=URL('subscribe_form',vars={'chartname': 
> 'whatever'}), cid='whatever')
>
> That will load the component and trap all links and form submissions, 
> because it translates to an onclick="web2py_component(url, target)"
>
>
> On Wednesday, November 7, 2012 8:39:50 PM UTC+1, Simon Carr wrote:
>>
>> The URL with the form in 
>> is web2py_xlchart_dashboard/charts/user_charts so without an action it 
>> will 
>> submit to *user_charts*, but I need it to submit to* subscribe_form 
>> *which 
>> is the function that was called by AJAX to generate the Form.
>>
>> or am I not understanding something?
>>
>> Simon
>>
>> On Wednesday, 7 November 2012 19:26:46 UTC, Derek wrote:
>>>
>>> Why would you need to create an action for the form? Are you not 
>>> using self submit?
>>>
>>> On Wednesday, November 7, 2012 12:22:03 PM UTC-7, Simon Carr wrote:

 I have this piece of code that calls a function in my controller 
 when clicked.

 {{=A('Add to My Charts',callback=URL('subscribe_form',vars={
 'chartname':chart.chartName}),target=str(chart.chartName).replace(
 '.','_'))}}


 The subscribe_form function looks like this

 def subscribe_form():
 
 form = 
 SQLFORM(db.user_chart,fields=['title','description'],hidden=dict(chartname=request.vars['chartname']))
 if form.process().accepted:
 response.flash = 'form accepted'
 elif form.errors:
 response.flash = 'form has errors'
 else:
 response.flash = 'please fill out the form'
 return form

 The Form is created by AJAX, but it's action is blank.

 Do I have to specify the action myself if I am build a Form via 
 AJAX?

 Simon

>>>

-- 





[web2py] Re: 'id'

2012-11-07 Thread Mike Anson
I had to remove the underscore in the method name too.

from:
save_message()
to:
savemessage()

#!/bin/bash

message=$1
uid=$2

url="https://host.com/ircmessage/rpc/call/jsonrpc";
curl -v -k -X POST -H "Content-Type: application/json" -d "{\"id\": 1, 
\"method\": \"savemessage\", \"params\": { \"${message}\": \"mymessage\", 
\"${uid}\" : \"myemail@localhost\"}}" $url

There is slightly strange behavior in that the value of the parameter name 
is what is saved instead of the value.

So the value of ${message} is saved rather than "mymessage"

Many thanks for your time Nyphlod.

On Wednesday, 7 November 2012 16:03:08 UTC-5, Niphlod wrote:
>
> supposedly you have call() and save_message() in default.py
>
> The url to call the webservice would then be /appname/default/call/jsonrpc 
> .
>
> On Wednesday, November 7, 2012 9:31:51 PM UTC+1, Mike Anson wrote:
>>
>> Thanks very much Niphlod. I am much closer now..
>>
>> However I am getting this response:
>> {"version": "1.1", "id": 1, "error": {"message": "method 
>> \"save_message\" does not exist", "code": 100, "name": "JSONRPCError"}}
>>
>> from this script:
>> url="https://domain.net:8000/ircmessage/rpc/call/jsonrpc";
>> curl -v -k -X POST -H "Content-Type: application/json" -d '{"id": 1, 
>> "method": "save_message", "params": { "message": "mymessage", "uid" : 
>> "myemail@localhost"}}' $url
>>
>> I guess my url is probably incorrect.
>>
>> Cheers again Niphlod.
>>
>> On Wednesday, 7 November 2012 15:16:42 UTC-5, Niphlod wrote:
>>>
>>> Yes, but without that I wouldn't have been able to tell you: "Follow the 
>>> protocol, Mike!" :P
>>>
>>> You are publishing a service behind the jsonrpc protocol, but you surely 
>>> missed on how to interact with them ^_^
>>>
>>> Every request per the spec has to carry an id , a method and a params 
>>> value in the json body of the request.
>>>
>>> So, you are trying to fire function that needs 'message' and 'uid' 
>>> parameters, and the function is called 'save_message'
>>> The following json must be POSTed (and using single quotes will save you 
>>> lots of backslashes if you're using cURL)
>>>
>>> '{"id": 1, "method": "save_message", "params": { "message": "mymessage", 
>>> "uid" : "myemail@localhost"}}'
>>>
>>> So, the complete cmdline is
>>> curl -v -k -X POST -H "Content-Type: application/json" -d '{"id": 1, 
>>> "method": "save_message", "params": { "message": "mymessage", "uid" : 
>>> "myemail@localhost"}}' $url
>>>
>>> This will generate a response like this
>>> {"error": null, "version": "1.1", "id": 1, "result": {"status": "saved"}}
>>>
>>> The 'id' is the one you sent (so, if you POST id=2, the response will 
>>> hold 2, and so on). In "result" you get what you return in the controller.
>>>
>>>
>>>

-- 





[web2py] Hope someone knows the answer to this one {was:....web2py math?}

2012-11-07 Thread Bill Thayer


So the same code above is now throwing an error and when I even visit 
http://127.0.0.1:8000/PROD/default/index. I know I don't feel right using 
request variable in my model file so I changed

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

Traceback (most recent call last):
  File "C:\web2py_src_2.2.1\web2py\gluon\restricted.py", line 212, in restricted
exec ccode in environment
  File "C:/web2py_src_2.2.1/web2py/applications/PROD/models/db_wizard.py" 
, line 105, 
in 
db.loadpull.points.requires=loadpull_points_in_range(request.vars.pstop, 
request.vars.pstart)
  File "C:/web2py_src_2.2.1/web2py/applications/PROD/models/db_wizard.py" 
, line 59, 
in loadpull_points_in_range
(int(Decimal(pstop)-Decimal(pstart))*1),
  File "C:\Python27\lib\decimal.py", line 658, in __new__
raise TypeError("Cannot convert %r to Decimal" % value)
TypeError: Cannot convert None to Decimal


I don't feel right about using the request variable anyway so I changed 
this line:


db.loadpull.points.requires=lambda row: loadpull_points_in_range(row.pstop, 
row.pstart)

And get  'str' object has no attribute 
'pstop'

File "C:\web2py_src_2.2.1\web2py\gluon\html.py", line 1743, in _validate
(value, errors) = validator(value)
  File "C:/web2py_src_2.2.1/web2py/applications/PROD/models/db_wizard.py" 
, line 105, 
in 
db.loadpull.points.requires=lambda row: loadpull_points_in_range(row.pstop, 
row.pstart)
AttributeError: 'str' object has no attribute 'pstop'



db.loadpull.points.requires=lambda row: loadpull_points_in_range(
'%(row.pstop)s', '%(row.pstart)')
Is not right either 
 Invalid literal for Decimal: 
'%(row.pstop)s'

I really don't know what happened when my original code worked (math error 
aside) when request.vars but now it won't even run.

I have been reading up on lambda functions too since I went through another 
round of not having the correct number of arguments.



-- 





[web2py] Re: SQLFORM via AJAX - action is blank

2012-11-07 Thread Niphlod
I'm loosing you (too much asked, too little information). 
- you have a page -->done
- you want a form loaded into a page --> done
- you want it to be submitted to the url that is loaded from --> done (if 
it's loaded through ajax, that means that you don't want to reload the main 
page, so it can't be submitted with anything else)

now what ?

On Wednesday, November 7, 2012 10:34:48 PM UTC+1, Simon Carr wrote:
>
> Your right. Thanks mate. I was getting confused over cid. But anyway it 
> works great for creating the form.
>
> I notice that the form also submits via AJAX. How do I make it submit 
> normally so that I can have the page refreshed? I need the users list of 
> subscribed Charts and some other details to be updated after submitting the 
> form.
>
> Thanks
> Simon
>
> On Wednesday, 7 November 2012 21:04:35 UTC, Niphlod wrote:
>>
>> doesn't it already (provided that there is a  in 
>> the page) ?
>>
>> On Wednesday, November 7, 2012 9:36:27 PM UTC+1, Simon Carr wrote:
>>>
>>> Thank you, but how do I implement this in my view so that it loads the 
>>> form into a div when the link is clicked?
>>>
>>> On Wednesday, 7 November 2012 20:00:52 UTC, Niphlod wrote:

 Wait a sec. callback and target are meant to load a fragment via ajax, 
 but that doesn't "fire" all the logic needed to intercept FORMs etc. 
 _callback and _target are meant roughly as an "onclick" under steroids. 
 (under the hood it translates to an onclick="ajax(url, target)")

 What you're trying to achieve is probably offered by the LOAD helper, 
 that can be exploited in an A() using _href and cid

 A('Add to My Charts',_href=URL('subscribe_form',vars={'chartname': 
 'whatever'}), cid='whatever')

 That will load the component and trap all links and form submissions, 
 because it translates to an onclick="web2py_component(url, target)"


 On Wednesday, November 7, 2012 8:39:50 PM UTC+1, Simon Carr wrote:
>
> The URL with the form in 
> is web2py_xlchart_dashboard/charts/user_charts so without an action it 
> will 
> submit to *user_charts*, but I need it to submit to* subscribe_form 
> *which 
> is the function that was called by AJAX to generate the Form.
>
> or am I not understanding something?
>
> Simon
>
> On Wednesday, 7 November 2012 19:26:46 UTC, Derek wrote:
>>
>> Why would you need to create an action for the form? Are you not 
>> using self submit?
>>
>> On Wednesday, November 7, 2012 12:22:03 PM UTC-7, Simon Carr wrote:
>>>
>>> I have this piece of code that calls a function in my controller 
>>> when clicked.
>>>
>>> {{=A('Add to My Charts',callback=URL('subscribe_form',vars={
>>> 'chartname':chart.chartName}),target=str(chart.chartName).replace(
>>> '.','_'))}}
>>>
>>>
>>> The subscribe_form function looks like this
>>>
>>> def subscribe_form():
>>> 
>>> form = 
>>> SQLFORM(db.user_chart,fields=['title','description'],hidden=dict(chartname=request.vars['chartname']))
>>> if form.process().accepted:
>>> response.flash = 'form accepted'
>>> elif form.errors:
>>> response.flash = 'form has errors'
>>> else:
>>> response.flash = 'please fill out the form'
>>> return form
>>>
>>> The Form is created by AJAX, but it's action is blank.
>>>
>>> Do I have to specify the action myself if I am build a Form via AJAX?
>>>
>>> Simon
>>>
>>

-- 





[web2py] Re: SQLFORM via AJAX - action is blank

2012-11-07 Thread Simon Carr
Your right. Thanks mate. I was getting confused over cid. But anyway it 
works great for creating the form.

I notice that the form also submits via AJAX. How do I make it submit 
normally so that I can have the page refreshed? I need the users list of 
subscribed Charts and some other details to be updated after submitting the 
form.

Thanks
Simon

On Wednesday, 7 November 2012 21:04:35 UTC, Niphlod wrote:
>
> doesn't it already (provided that there is a  in 
> the page) ?
>
> On Wednesday, November 7, 2012 9:36:27 PM UTC+1, Simon Carr wrote:
>>
>> Thank you, but how do I implement this in my view so that it loads the 
>> form into a div when the link is clicked?
>>
>> On Wednesday, 7 November 2012 20:00:52 UTC, Niphlod wrote:
>>>
>>> Wait a sec. callback and target are meant to load a fragment via ajax, 
>>> but that doesn't "fire" all the logic needed to intercept FORMs etc. 
>>> _callback and _target are meant roughly as an "onclick" under steroids. 
>>> (under the hood it translates to an onclick="ajax(url, target)")
>>>
>>> What you're trying to achieve is probably offered by the LOAD helper, 
>>> that can be exploited in an A() using _href and cid
>>>
>>> A('Add to My Charts',_href=URL('subscribe_form',vars={'chartname': 
>>> 'whatever'}), cid='whatever')
>>>
>>> That will load the component and trap all links and form submissions, 
>>> because it translates to an onclick="web2py_component(url, target)"
>>>
>>>
>>> On Wednesday, November 7, 2012 8:39:50 PM UTC+1, Simon Carr wrote:

 The URL with the form in is web2py_xlchart_dashboard/charts/user_charts 
 so without an action it will submit to *user_charts*, but I need it to 
 submit to* subscribe_form *which is the function that was called by 
 AJAX to generate the Form.

 or am I not understanding something?

 Simon

 On Wednesday, 7 November 2012 19:26:46 UTC, Derek wrote:
>
> Why would you need to create an action for the form? Are you not using 
> self submit?
>
> On Wednesday, November 7, 2012 12:22:03 PM UTC-7, Simon Carr wrote:
>>
>> I have this piece of code that calls a function in my controller when 
>> clicked.
>>
>> {{=A('Add to My Charts',callback=URL('subscribe_form',vars={
>> 'chartname':chart.chartName}),target=str(chart.chartName).replace('.'
>> ,'_'))}}
>>
>>
>> The subscribe_form function looks like this
>>
>> def subscribe_form():
>> 
>> form = 
>> SQLFORM(db.user_chart,fields=['title','description'],hidden=dict(chartname=request.vars['chartname']))
>> if form.process().accepted:
>> response.flash = 'form accepted'
>> elif form.errors:
>> response.flash = 'form has errors'
>> else:
>> response.flash = 'please fill out the form'
>> return form
>>
>> The Form is created by AJAX, but it's action is blank.
>>
>> Do I have to specify the action myself if I am build a Form via AJAX?
>>
>> Simon
>>
>

-- 





Re: [web2py] Re: Webfaction Deployment and Tuning Web2py Slice.

2012-11-07 Thread Vasile Ermicioi
PS: I also have websites on webfaction

-- 





Re: [web2py] Re: Webfaction Deployment and Tuning Web2py Slice.

2012-11-07 Thread Vasile Ermicioi
I prefer using built in uwsgi webserver - very fast and low memory usage

-- 





[web2py] Re: SQLFORM via AJAX - action is blank

2012-11-07 Thread Niphlod
doesn't it already (provided that there is a  in 
the page) ?

On Wednesday, November 7, 2012 9:36:27 PM UTC+1, Simon Carr wrote:
>
> Thank you, but how do I implement this in my view so that it loads the 
> form into a div when the link is clicked?
>
> On Wednesday, 7 November 2012 20:00:52 UTC, Niphlod wrote:
>>
>> Wait a sec. callback and target are meant to load a fragment via ajax, 
>> but that doesn't "fire" all the logic needed to intercept FORMs etc. 
>> _callback and _target are meant roughly as an "onclick" under steroids. 
>> (under the hood it translates to an onclick="ajax(url, target)")
>>
>> What you're trying to achieve is probably offered by the LOAD helper, 
>> that can be exploited in an A() using _href and cid
>>
>> A('Add to My Charts',_href=URL('subscribe_form',vars={'chartname': 
>> 'whatever'}), cid='whatever')
>>
>> That will load the component and trap all links and form submissions, 
>> because it translates to an onclick="web2py_component(url, target)"
>>
>>
>> On Wednesday, November 7, 2012 8:39:50 PM UTC+1, Simon Carr wrote:
>>>
>>> The URL with the form in is web2py_xlchart_dashboard/charts/user_charts 
>>> so without an action it will submit to *user_charts*, but I need it to 
>>> submit to* subscribe_form *which is the function that was called by 
>>> AJAX to generate the Form.
>>>
>>> or am I not understanding something?
>>>
>>> Simon
>>>
>>> On Wednesday, 7 November 2012 19:26:46 UTC, Derek wrote:

 Why would you need to create an action for the form? Are you not using 
 self submit?

 On Wednesday, November 7, 2012 12:22:03 PM UTC-7, Simon Carr wrote:
>
> I have this piece of code that calls a function in my controller when 
> clicked.
>
> {{=A('Add to My Charts',callback=URL('subscribe_form',vars={
> 'chartname':chart.chartName}),target=str(chart.chartName).replace('.',
> '_'))}}
>
>
> The subscribe_form function looks like this
>
> def subscribe_form():
> 
> form = 
> SQLFORM(db.user_chart,fields=['title','description'],hidden=dict(chartname=request.vars['chartname']))
> if form.process().accepted:
> response.flash = 'form accepted'
> elif form.errors:
> response.flash = 'form has errors'
> else:
> response.flash = 'please fill out the form'
> return form
>
> The Form is created by AJAX, but it's action is blank.
>
> Do I have to specify the action myself if I am build a Form via AJAX?
>
> Simon
>


-- 





[web2py] Re: 'id'

2012-11-07 Thread Niphlod
supposedly you have call() and save_message() in default.py

The url to call the webservice would then be /appname/default/call/jsonrpc .

On Wednesday, November 7, 2012 9:31:51 PM UTC+1, Mike Anson wrote:
>
> Thanks very much Niphlod. I am much closer now..
>
> However I am getting this response:
> {"version": "1.1", "id": 1, "error": {"message": "method \"save_message\" 
> does not exist", "code": 100, "name": "JSONRPCError"}}
>
> from this script:
> url="https://domain.net:8000/ircmessage/rpc/call/jsonrpc";
> curl -v -k -X POST -H "Content-Type: application/json" -d '{"id": 1, 
> "method": "save_message", "params": { "message": "mymessage", "uid" : 
> "myemail@localhost"}}' $url
>
> I guess my url is probably incorrect.
>
> Cheers again Niphlod.
>
> On Wednesday, 7 November 2012 15:16:42 UTC-5, Niphlod wrote:
>>
>> Yes, but without that I wouldn't have been able to tell you: "Follow the 
>> protocol, Mike!" :P
>>
>> You are publishing a service behind the jsonrpc protocol, but you surely 
>> missed on how to interact with them ^_^
>>
>> Every request per the spec has to carry an id , a method and a params 
>> value in the json body of the request.
>>
>> So, you are trying to fire function that needs 'message' and 'uid' 
>> parameters, and the function is called 'save_message'
>> The following json must be POSTed (and using single quotes will save you 
>> lots of backslashes if you're using cURL)
>>
>> '{"id": 1, "method": "save_message", "params": { "message": "mymessage", 
>> "uid" : "myemail@localhost"}}'
>>
>> So, the complete cmdline is
>> curl -v -k -X POST -H "Content-Type: application/json" -d '{"id": 1, 
>> "method": "save_message", "params": { "message": "mymessage", "uid" : 
>> "myemail@localhost"}}' $url
>>
>> This will generate a response like this
>> {"error": null, "version": "1.1", "id": 1, "result": {"status": "saved"}}
>>
>> The 'id' is the one you sent (so, if you POST id=2, the response will 
>> hold 2, and so on). In "result" you get what you return in the controller.
>>
>>
>>

-- 





[web2py] Re: SQLFORM via AJAX - action is blank

2012-11-07 Thread Simon Carr
Thank you, but how do I implement this in my view so that it loads the form 
into a div when the link is clicked?

On Wednesday, 7 November 2012 20:00:52 UTC, Niphlod wrote:
>
> Wait a sec. callback and target are meant to load a fragment via ajax, but 
> that doesn't "fire" all the logic needed to intercept FORMs etc. 
> _callback and _target are meant roughly as an "onclick" under steroids. 
> (under the hood it translates to an onclick="ajax(url, target)")
>
> What you're trying to achieve is probably offered by the LOAD helper, that 
> can be exploited in an A() using _href and cid
>
> A('Add to My Charts',_href=URL('subscribe_form',vars={'chartname': 
> 'whatever'}), cid='whatever')
>
> That will load the component and trap all links and form submissions, 
> because it translates to an onclick="web2py_component(url, target)"
>
>
> On Wednesday, November 7, 2012 8:39:50 PM UTC+1, Simon Carr wrote:
>>
>> The URL with the form in is web2py_xlchart_dashboard/charts/user_charts 
>> so without an action it will submit to *user_charts*, but I need it to 
>> submit to* subscribe_form *which is the function that was called by AJAX 
>> to generate the Form.
>>
>> or am I not understanding something?
>>
>> Simon
>>
>> On Wednesday, 7 November 2012 19:26:46 UTC, Derek wrote:
>>>
>>> Why would you need to create an action for the form? Are you not using 
>>> self submit?
>>>
>>> On Wednesday, November 7, 2012 12:22:03 PM UTC-7, Simon Carr wrote:

 I have this piece of code that calls a function in my controller when 
 clicked.

 {{=A('Add to My Charts',callback=URL('subscribe_form',vars={'chartname'
 :chart.chartName}),target=str(chart.chartName).replace('.','_'))}}


 The subscribe_form function looks like this

 def subscribe_form():
 
 form = 
 SQLFORM(db.user_chart,fields=['title','description'],hidden=dict(chartname=request.vars['chartname']))
 if form.process().accepted:
 response.flash = 'form accepted'
 elif form.errors:
 response.flash = 'form has errors'
 else:
 response.flash = 'please fill out the form'
 return form

 The Form is created by AJAX, but it's action is blank.

 Do I have to specify the action myself if I am build a Form via AJAX?

 Simon

>>>

-- 





[web2py] Re: 'id'

2012-11-07 Thread Mike Anson
Thanks very much Niphlod. I am much closer now..

However I am getting this response:
{"version": "1.1", "id": 1, "error": {"message": "method \"save_message\" 
does not exist", "code": 100, "name": "JSONRPCError"}}

from this script:
url="https://domain.net:8000/ircmessage/rpc/call/jsonrpc";
curl -v -k -X POST -H "Content-Type: application/json" -d '{"id": 1, 
"method": "save_message", "params": { "message": "mymessage", "uid" : 
"myemail@localhost"}}' $url

I guess my url is probably incorrect.

Cheers again Niphlod.

On Wednesday, 7 November 2012 15:16:42 UTC-5, Niphlod wrote:
>
> Yes, but without that I wouldn't have been able to tell you: "Follow the 
> protocol, Mike!" :P
>
> You are publishing a service behind the jsonrpc protocol, but you surely 
> missed on how to interact with them ^_^
>
> Every request per the spec has to carry an id , a method and a params 
> value in the json body of the request.
>
> So, you are trying to fire function that needs 'message' and 'uid' 
> parameters, and the function is called 'save_message'
> The following json must be POSTed (and using single quotes will save you 
> lots of backslashes if you're using cURL)
>
> '{"id": 1, "method": "save_message", "params": { "message": "mymessage", 
> "uid" : "myemail@localhost"}}'
>
> So, the complete cmdline is
> curl -v -k -X POST -H "Content-Type: application/json" -d '{"id": 1, 
> "method": "save_message", "params": { "message": "mymessage", "uid" : 
> "myemail@localhost"}}' $url
>
> This will generate a response like this
> {"error": null, "version": "1.1", "id": 1, "result": {"status": "saved"}}
>
> The 'id' is the one you sent (so, if you POST id=2, the response will hold 
> 2, and so on). In "result" you get what you return in the controller.
>
>
>

-- 





[web2py] Re: Automatic login if username contains @ : Is this normal ?

2012-11-07 Thread apinho
Hi,

Did you have the time to check it up ?


On Tuesday, November 6, 2012 1:40:39 PM UTC, Massimo Di Pierro wrote:
>
>
> This is not normal and it is scary. It could be a ldap issue of a 
> ldap_login issue. I will check it asap today.
>
> Massimo
>
>
> On Tuesday, 6 November 2012 05:24:26 UTC-6, apinho wrote:
>>
>> Hi,
>>
>> I'm working on a site, for my company. I want to give only access to 
>> accounts :
>>  - listed in my ldap server
>>  or
>>  - listed in local Auth db().
>>
>> So, I don't want other people to be able to register.
>>  
>> This is my Auth() config (Some values I replaced with '*' for 
>> confidentiallity sake) :
>> ### AUTH 
>> ##
>> # Create object
>> auth  = Auth(globals(),db)
>> # Define settings
>> auth.settings.hmac_key= 'sha512:'
>> auth.settings.mailer  = None
>> auth.settings.remember_me_form= False
>> auth.settings.allow_basic_login   = True
>> auth.settings.login_next  = URL('index')
>> auth.settings.logout_next = URL('index')
>> auth.settings.on_failed_authorization = URL('user',args=
>> 'on_failed_authorization')
>> auth.settings.login_onvalidation  = []   # func takes form 
>> obj, can modify attribs of form obj before db IO
>> auth.settings.login_onaccept  = []   # Func should be 
>> executed after db IO and before redirection
>> auth.settings.expiration  = 3600 # seconds
>> auth.settings.hideerror   = False 
>> auth.settings.formstyle   = 'table3cols' # "table2cols", 
>> "divs" and "ul"
>> auth.settings.long_expiration = 3600*24*30   # one month
>> auth.settings.remember_me_form= True
>> auth.settings.actions_disabled= ['register','change_password',
>> 'request_reset_password','retrieve_username',
>> 'profile']
>> # Define messages
>> auth.messages.access_denied   = T('Não tem a necessária 
>> permissão de acesso')
>> auth.messages.login_disabled  = T('Login desactivado pelo Admin')
>> auth.messages.logged_in   = T('Bem-vindo(a) !')
>> auth.messages.logged_out  = T('Até breve !')
>> auth.messages.invalid_login   = T('Acesso inválido')
>> auth.messages.label_username  = T('Utilizador')
>> auth.messages.label_password  = T('Senha')
>> auth.messages.label_remember_me   = T('Conservar este acesso aberto 
>> (Durante 30 dias)')
>> # LDAP method
>> auth.settings.login_methods.append(ldap_auth(mode='cn',server='.*
>> s.com',base_dn='ou=***,o=***'))
>> # Automigrate only if DEVELOPPMENT context
>> auth.define_tables(migrate=settings.migrate,username=True)
>> #--
>>  
>>  
>>
>> This works well for me, LDAP works fine too. But I have a problem :
>> If someone tries to connect to my site, with a username which contains @, 
>> he is automatically logged in, without event having to give a valid 
>> password.
>> You can just type 'blahblah@coocoo', and then Enter, and you're in. Auth 
>> automatically creates a 'blahblah' user.
>>
>> Is this behavior normal, or am I missing something ?
>>
>>
>>
>>

-- 





[web2py] Re: 'id'

2012-11-07 Thread Niphlod
Yes, but without that I wouldn't have been able to tell you: "Follow the 
protocol, Mike!" :P

You are publishing a service behind the jsonrpc protocol, but you surely 
missed on how to interact with them ^_^

Every request per the spec has to carry an id , a method and a params value 
in the json body of the request.

So, you are trying to fire function that needs 'message' and 'uid' 
parameters, and the function is called 'save_message'
The following json must be POSTed (and using single quotes will save you 
lots of backslashes if you're using cURL)

'{"id": 1, "method": "save_message", "params": { "message": "mymessage", 
"uid" : "myemail@localhost"}}'

So, the complete cmdline is
curl -v -k -X POST -H "Content-Type: application/json" -d '{"id": 1, 
"method": "save_message", "params": { "message": "mymessage", "uid" : 
"myemail@localhost"}}' $url

This will generate a response like this
{"error": null, "version": "1.1", "id": 1, "result": {"status": "saved"}}

The 'id' is the one you sent (so, if you POST id=2, the response will hold 
2, and so on). In "result" you get what you return in the controller.


-- 





[web2py] Re: SQLFORM via AJAX - action is blank

2012-11-07 Thread Niphlod
Wait a sec. callback and target are meant to load a fragment via ajax, but 
that doesn't "fire" all the logic needed to intercept FORMs etc. 
_callback and _target are meant roughly as an "onclick" under steroids. 
(under the hood it translates to an onclick="ajax(url, target)")

What you're trying to achieve is probably offered by the LOAD helper, that 
can be exploited in an A() using _href and cid

A('Add to My Charts',_href=URL('subscribe_form',vars={'chartname': 
'whatever'}), cid='whatever')

That will load the component and trap all links and form submissions, 
because it translates to an onclick="web2py_component(url, target)"


On Wednesday, November 7, 2012 8:39:50 PM UTC+1, Simon Carr wrote:
>
> The URL with the form in is web2py_xlchart_dashboard/charts/user_charts so 
> without an action it will submit to *user_charts*, but I need it to 
> submit to* subscribe_form *which is the function that was called by AJAX 
> to generate the Form.
>
> or am I not understanding something?
>
> Simon
>
> On Wednesday, 7 November 2012 19:26:46 UTC, Derek wrote:
>>
>> Why would you need to create an action for the form? Are you not using 
>> self submit?
>>
>> On Wednesday, November 7, 2012 12:22:03 PM UTC-7, Simon Carr wrote:
>>>
>>> I have this piece of code that calls a function in my controller when 
>>> clicked.
>>>
>>> {{=A('Add to My Charts',callback=URL('subscribe_form',vars={'chartname':
>>> chart.chartName}),target=str(chart.chartName).replace('.','_'))}}
>>>
>>>
>>> The subscribe_form function looks like this
>>>
>>> def subscribe_form():
>>> 
>>> form = 
>>> SQLFORM(db.user_chart,fields=['title','description'],hidden=dict(chartname=request.vars['chartname']))
>>> if form.process().accepted:
>>> response.flash = 'form accepted'
>>> elif form.errors:
>>> response.flash = 'form has errors'
>>> else:
>>> response.flash = 'please fill out the form'
>>> return form
>>>
>>> The Form is created by AJAX, but it's action is blank.
>>>
>>> Do I have to specify the action myself if I am build a Form via AJAX?
>>>
>>> Simon
>>>
>>

-- 





[web2py] Re: 'id'

2012-11-07 Thread Mike Anson
Hi Niphlod,

It's a super simple controller below:

def call():
"""
exposes services. for example:
http:///[app]/default/call/jsonrpc
decorate with @services.jsonrpc the functions to expose
supports xml, json, xmlrpc, jsonrpc, amfrpc, rss, csv
"""
return service()


@service.jsonrpc
def save_message(message, uid):
db.messages.insert(message=message, uid=uid)
db.commit()


message = {"status":"saved"}


return message


On Wednesday, 7 November 2012 14:38:35 UTC-5, Niphlod wrote:
>
> table is there, curl is there, but how about something you coded in the 
> controller ? Without that we can't help you .
>
> On Wednesday, November 7, 2012 7:48:28 PM UTC+1, Mike Anson wrote:
>>
>>
>> Greetings...
>>
>> I have a bash script that uses cURL to send a json packet of data in 
>> order to save it in sqlite DB.
>>
>> #!/bin/bash
>> message=$1
>> uid=$2
>> url="https://somehost";
>> curl -v -k -X POST -H "Content-Type: application/json" --data 
>> "{\"message\": \"This will prbbly be my lst post.\", \"uid\": \"
>> m...@email.com\"}" $url
>>
>> ** message and uid are hardcoded at this point but will take the values 
>> dynamically once I see it working.
>>
>> Here is my table defined:
>>
>> db.define_table('messages',
>> Field 
>> ('uid', 
>> 'string'),
>> Field 
>> ('message', 
>> 'text'),
>> Field 
>> ('status', 
>> 'string', default='unsent'),
>> Field 
>> ('added', 
>> 'datetime', default=request 
>> .now),
>> Field 
>> ('modified', 
>> 'datetime', default=request 
>> .now))
>>
>> *I've tried many variations of the cURL command and ran in to various 
>> errors. The above cURL command gives the error: *> 'exceptions.KeyError'> 'id'
>>
>> Any help would be greatly appreciated.
>>
>>

-- 





[web2py] Re: SQLFORM via AJAX - action is blank

2012-11-07 Thread Simon Carr
The URL with the form in is web2py_xlchart_dashboard/charts/user_charts so 
without an action it will submit to *user_charts*, but I need it to submit 
to* subscribe_form *which is the function that was called by AJAX to 
generate the Form.

or am I not understanding something?

Simon

On Wednesday, 7 November 2012 19:26:46 UTC, Derek wrote:
>
> Why would you need to create an action for the form? Are you not using 
> self submit?
>
> On Wednesday, November 7, 2012 12:22:03 PM UTC-7, Simon Carr wrote:
>>
>> I have this piece of code that calls a function in my controller when 
>> clicked.
>>
>> {{=A('Add to My Charts',callback=URL('subscribe_form',vars={'chartname':
>> chart.chartName}),target=str(chart.chartName).replace('.','_'))}}
>>
>>
>> The subscribe_form function looks like this
>>
>> def subscribe_form():
>> 
>> form = 
>> SQLFORM(db.user_chart,fields=['title','description'],hidden=dict(chartname=request.vars['chartname']))
>> if form.process().accepted:
>> response.flash = 'form accepted'
>> elif form.errors:
>> response.flash = 'form has errors'
>> else:
>> response.flash = 'please fill out the form'
>> return form
>>
>> The Form is created by AJAX, but it's action is blank.
>>
>> Do I have to specify the action myself if I am build a Form via AJAX?
>>
>> Simon
>>
>

-- 





[web2py] Re: 'id'

2012-11-07 Thread Niphlod
table is there, curl is there, but how about something you coded in the 
controller ? Without that we can't help you .

On Wednesday, November 7, 2012 7:48:28 PM UTC+1, Mike Anson wrote:
>
>
> Greetings...
>
> I have a bash script that uses cURL to send a json packet of data in order 
> to save it in sqlite DB.
>
> #!/bin/bash
> message=$1
> uid=$2
> url="https://somehost";
> curl -v -k -X POST -H "Content-Type: application/json" --data 
> "{\"message\": \"This will prbbly be my lst post.\", \"uid\": \"
> m...@email.com \"}" $url
>
> ** message and uid are hardcoded at this point but will take the values 
> dynamically once I see it working.
>
> Here is my table defined:
>
> db.define_table('messages',
> Field 
> ('uid', 
> 'string'),
> Field 
> ('message', 
> 'text'),
> Field 
> ('status', 
> 'string', default='unsent'),
> Field 
> ('added', 
> 'datetime', default=request 
> .now),
> Field 
> ('modified', 
> 'datetime', default=request 
> .now))
>
> *I've tried many variations of the cURL command and ran in to various errors. 
> The above cURL command gives the error: * 'id'
>
> Any help would be greatly appreciated.
>
>

-- 





[web2py] Re: SQLFORM via AJAX - action is blank

2012-11-07 Thread Derek
Why would you need to create an action for the form? Are you not using self 
submit?

On Wednesday, November 7, 2012 12:22:03 PM UTC-7, Simon Carr wrote:
>
> I have this piece of code that calls a function in my controller when 
> clicked.
>
> {{=A('Add to My Charts',callback=URL('subscribe_form',vars={'chartname':
> chart.chartName}),target=str(chart.chartName).replace('.','_'))}}
>
>
> The subscribe_form function looks like this
>
> def subscribe_form():
> 
> form = 
> SQLFORM(db.user_chart,fields=['title','description'],hidden=dict(chartname=request.vars['chartname']))
> if form.process().accepted:
> response.flash = 'form accepted'
> elif form.errors:
> response.flash = 'form has errors'
> else:
> response.flash = 'please fill out the form'
> return form
>
> The Form is created by AJAX, but it's action is blank.
>
> Do I have to specify the action myself if I am build a Form via AJAX?
>
> Simon
>

-- 





[web2py] SQLFORM via AJAX - action is blank

2012-11-07 Thread Simon Carr
I have this piece of code that calls a function in my controller when 
clicked.

{{=A('Add to My Charts',callback=URL('subscribe_form',vars={'chartname':
chart.chartName}),target=str(chart.chartName).replace('.','_'))}}


The subscribe_form function looks like this

def subscribe_form():

form = 
SQLFORM(db.user_chart,fields=['title','description'],hidden=dict(chartname=request.vars['chartname']))
if form.process().accepted:
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
else:
response.flash = 'please fill out the form'
return form

The Form is created by AJAX, but it's action is blank.

Do I have to specify the action myself if I am build a Form via AJAX?

Simon

-- 





[web2py] Re: Webfaction Deployment and Tuning Web2py Slice.

2012-11-07 Thread Neil
I'm certainly no expert, but I'm also on webfaction and you may want to 
consider using nginx/uwsgi. At least in my case, there was very little I 
needed to worry about in terms of configuration/memory management. Just two 
tricks:

- no need to install nginx, as you can just use webfaction's nginx instance 
(there is a recipe floating around that has you build/install a local copy. 
there may be some advantages to this, but I found it to be unnecessary)
- make sure to use uwsgi's "reload-on-rss" option to make sure the process 
doesn't keep consuming more and more memory - webfaction kill your 
processes if you go over your limit. There's a number of posts on this 
topic in this forum.

In general, it's a fast server and relatively straightforward set up. Might 
be more suitable for your needs than fiddling with apache config files.

Neil

On Tuesday, November 6, 2012 5:52:52 PM UTC, Mark Graves wrote:
>
> Dear Fellow Web2py Developers,
>
> Sorry for the extended email, I wanted to introduce myself and give some 
> background.
>
> I am enjoying web2py tremendously.  Two years ago, I came to web2py from 
> php where I had hacked together multiple web applications, despite a 
> non-programming background.  I am a second year medical student in Chicago, 
> and I've always had some ideas as to how to make people's lives better 
> through technology.  Now, I'm taking some time off from school to try to do 
> exactly that.
>
> It has been a wonderful learning experience for programming and web 
> application development.  I even managed to help three people who had never 
> written a single line of code begin writing web applications that they had 
> always dreamed about and never believed they could. (btw Massimo, if you 
> happen to see this, one is a bio major from Depaul)
>
> Now, I am trying to give back to my community.  Specifically, as I am 
> preparing to deploy an application for a production environment, I have 
> been learning about hosting, the most frustrating part of my learning 
> curve. Getting a local copy of web2py up and going is one thing.  Having a 
> fully functional, web deployed app is another. (I know this may sound 
> irresponsible - to put potentially insecure applications on the web, and I 
> believe empowerment, open information, and experience are the keys)
>
> I chose webfaction as my hosting environment because I had heard about 
> them on this board.  Now, I am trying to write a web2py slice to document 
> my process of going from local development to production with multiple 
> developers in a professional hosting environment.  It is both a learning 
> experience for me and an opportunity to give other non-programmers a better 
> understanding of the process, which I would have appreciated in the process.
>
> I am soliciting your help to try to offer this help better than I can.
>
> The areas I want to cover for webfaction are:
> 1.) 1 click web2py instance deployment script -- DONE(already on their 
> wiki)
> 2.) Version control using hg -- WORKING (using hgweb as a separate 
> application)
> 3.) Apache Optimization/mod_wsgi / Memory management  -- WORKING 
> (following the book and Graham Dumpleton's suggestions on the server)
> 4.) exposed /admin with ssh - WORKING
> 5.) Version control from admin interface - WORKING
> 6.) deployment under subdomain / sub url
>
> The area where I'd like the most help is the Apache/memory management 
> stuff.  Apache/mod_wsgi are confusing as a newbie non programmer.  I don't 
> think it has to be. I want to make production web application development 
> UNDERSTANDABLE for non programmers, to attract more people like myself to 
> the field and to the framework.
>
> If you are willing to lend your expertise please let me know, so we can 
> make this community better for everyone.
>
> Sincerely,
>
> Mark Graves
> GravesMedical Founder
>
>

-- 





[web2py] 'id'

2012-11-07 Thread Mike Anson

Greetings...

I have a bash script that uses cURL to send a json packet of data in order 
to save it in sqlite DB.

#!/bin/bash
message=$1
uid=$2
url="https://somehost";
curl -v -k -X POST -H "Content-Type: application/json" --data 
"{\"message\": \"This will prbbly be my lst post.\", \"uid\": 
\"m...@email.com\"}" $url

** message and uid are hardcoded at this point but will take the values 
dynamically once I see it working.

Here is my table defined:

db.define_table('messages',
Field ('uid', 
'string'),
Field 
('message', 
'text'),
Field 
('status', 
'string', default='unsent'),
Field 
('added', 
'datetime', default=request 
.now),
Field 
('modified', 
'datetime', default=request 
.now))

*I've tried many variations of the cURL command and ran in to various errors. 
The above cURL command gives the error: * 'id'

Any help would be greatly appreciated.

-- 





[web2py] Re: Here is one of my 81 tickets today....web2py math?

2012-11-07 Thread Bill Thayer
LOL Thanks,

On my re-design my previous table had

requires=lambda v,r:
IS_INTEGER_IN_RANGE(0, int((r.pstop-r.pstart)*1)), 

but that no longer works so I changed it and applied typecasting when I 
forgot forgot my order of ops.

Thanks a bunch.

-- 





Re: [web2py] Re: track_changes

2012-11-07 Thread Richard Vézina
Problem here to, I reboot web2py instead of trying if track_change true
work each time I make change to my module.

Richard

On Wed, Nov 7, 2012 at 8:26 AM, Massimiliano Belletti
wrote:

> From me it works never.
> I'm on osx.
>
> Massimiliano
>
> Il giorno 07/nov/2012, alle ore 13:38, David Marko  ha
> scritto:
>
> Having the problem with this as well. Sometimes its works for 5-10 reloads
> and then stops until I restart web2py server.
>
> Dne středa, 7. listopadu 2012 11:47:13 UTC+1 Massimiliano napsal(a):
>>
>> Version 2.2.1 (2012-11-06 14:26:21) stable
>>
>> It's just me or it doesn't work anymore?
>>
>> --
>> Massimiliano
>>
>  --
>
>
>
>
>  --
>
>
>
>

-- 





[web2py] Re: Alternative to Janrain: in pure Python

2012-11-07 Thread Finn Poitier
Has there been progress in integrating LoginRadius yet? They seem to have 
attractive rates compared to Janrain, which might be to costly for 
noncommercial projects with a huge user base above 10 or 20k.

On Thursday, July 12, 2012 8:56:25 PM UTC+2, Massimo Di Pierro wrote:
>
> Thank you Sakesh for the offer. We will work on intergation asap and we 
> may ask for help with your api.
>
> massimo
>
> On Monday, 9 July 2012 12:34:28 UTC-5, Rakesh Soni wrote:
>>
>> Great project. Let me know if you guys need some contribution from 
>> LoginRadius  Team. We also offer social 
>> authentication, social sharing, user profile data and social analytics for 
>> Python websites through our 
>> SDK
>> .
>>
>> Thanks,
>> Rakesh Soni
>>
>>
>>
>> On Saturday, July 7, 2012 3:47:19 AM UTC-6, David Marko wrote:
>>>
>>> That would be great having something like this integrated into web2py 
>>> .
>>>
>>> David
>>>
>>

-- 





[web2py] Re: join in DAL

2012-11-07 Thread Simon Carr
Thanks Batman,

I will give this a try now.

Simon

On Wednesday, 7 November 2012 17:24:34 UTC, Niphlod wrote:
>
> "english logic": a chart named 'abc' is mine if there is a record in the 
> 'user_chart' table whose id_user is my user_id and has a chart_id equal to 
> the id of the 'chart' table whose chartName is 'abc'
>
> DAL syntax:
> db(
> (db.user_chart.id_user == auth.user_id) & ##all charts of the user
> (db.chart.chartName == 'abc') & ##all charts named 'abc'
> (db.user_chart.id_chart == db.chart.id) ##the actual relation
> ).select()
>
>
>
>
> On Wednesday, November 7, 2012 5:30:42 PM UTC+1, Simon Carr wrote:
>>
>> Hi All,
>>
>> I have these 3 tables among others
>>
>> db.define_table('workbook',
>> Field('path',requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'workbook.path')]),
>> Field('title',requires=IS_NOT_EMPTY()),
>> format="%(title)s",
>> )
>>
>>
>> db.define_table('chart',
>> Field('chartName'),
>> Field('id_workbook',db.workbook),
>> Field('worksheet'),
>> Field('file','upload'),
>> format="%(id_workbook)s %(chartName)s",
>> )
>>
>> db.define_table('user_chart',
>>
>> Field('id_user',db.auth_user,writable=False,readable=False,default=auth.user_id),
>> Field('id_chart','reference chart'),
>> Field('title'),
>> Field('description','text'),
>> format="%(title)s",
>> )
>>
>> I have setup a function in my modal 
>>
>> def is_my_chart(chartname):
>> if db((db.user_chart.id_user == auth.user_id) & 
>> (db.user_chart.id_chart.chartName == chartname)).count() > 0:
>> return True
>> else:
>> return False
>>
>> But I get the following error
>>
>> AttributeError: 'Field' object has no attribute 'chartName'
>>
>>
>> How do I fetch the fields out of a joined table?
>>
>> Thanks
>> Simon
>>
>>

-- 





[web2py] Re: join in DAL

2012-11-07 Thread Simon Carr
Thanks for the reply Bill, but I don't need to know who uploaded the 
charts. They are more of a data warehouse. Users subscribe to them and a 
reference is created in user_chart.

The bit of my web site I am working on at the moment is where the user 
subscribes. I am showing a list of all the Charts available in Charts and 
another list of the charts they have subscribed to. Next to each of the 
charts in the Full List I will show either "Click here to subscribe" or 
"You are already subscribed".

So my is_my_chart function is called for each chart in the Data Warehouse 
and shows either a link to subscribe or tells they user they are already 
subscribed.  

On Wednesday, 7 November 2012 17:03:38 UTC, Bill Thayer wrote:
>
> I noticed that you do not add auth.signature to your table definition. 
> Does it not work for you?
>
> If is_my_chart was somthing I needed often like I'd be tempted to change: 
>   (full discloser: my track record is not good lately)
> db.define_table('chart',
> Field('chartName'),
> Field('id_workbook',db.workbook),
> Field('worksheet'),
> Field('file','upload'),
> auth.signature,
> common_filter = lambda query: db.chart.created_by==auth.user_id,
> format="%(id_workbook)s %(chartName)s",
> )
>
> Then when I needed a different controller function that returned all 
> records I could:
>
> db(query, ignore_common_filters=True).select(...) # copied from 
> http://www.web2py.com/books/default/chapter/29/06?search=common_filter
>
>
>
> Again I'm not that good at this but it seems logical.
>
> -Bill
>

-- 





[web2py] Re: join in DAL

2012-11-07 Thread Niphlod
"english logic": a chart named 'abc' is mine if there is a record in the 
'user_chart' table whose id_user is my user_id and has a chart_id equal to 
the id of the 'chart' table whose chartName is 'abc'

DAL syntax:
db(
(db.user_chart.id_user == auth.user_id) & ##all charts of the user
(db.chart.chartName == 'abc') & ##all charts named 'abc'
(db.user_chart.id_chart == db.chart.id) ##the actual relation
).select()




On Wednesday, November 7, 2012 5:30:42 PM UTC+1, Simon Carr wrote:
>
> Hi All,
>
> I have these 3 tables among others
>
> db.define_table('workbook',
> Field('path',requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'workbook.path')]),
> Field('title',requires=IS_NOT_EMPTY()),
> format="%(title)s",
> )
>
>
> db.define_table('chart',
> Field('chartName'),
> Field('id_workbook',db.workbook),
> Field('worksheet'),
> Field('file','upload'),
> format="%(id_workbook)s %(chartName)s",
> )
>
> db.define_table('user_chart',
>
> Field('id_user',db.auth_user,writable=False,readable=False,default=auth.user_id),
> Field('id_chart','reference chart'),
> Field('title'),
> Field('description','text'),
> format="%(title)s",
> )
>
> I have setup a function in my modal 
>
> def is_my_chart(chartname):
> if db((db.user_chart.id_user == auth.user_id) & 
> (db.user_chart.id_chart.chartName == chartname)).count() > 0:
> return True
> else:
> return False
>
> But I get the following error
>
> AttributeError: 'Field' object has no attribute 'chartName'
>
>
> How do I fetch the fields out of a joined table?
>
> Thanks
> Simon
>
>

-- 





[web2py] Re: join in DAL

2012-11-07 Thread Bill Thayer
I noticed that you do not add auth.signature to your table definition. Does 
it not work for you?

If is_my_chart was somthing I needed often like I'd be tempted to change:   
(full discloser: my track record is not good lately)
db.define_table('chart',
Field('chartName'),
Field('id_workbook',db.workbook),
Field('worksheet'),
Field('file','upload'),
auth.signature,
common_filter = lambda query: db.chart.created_by==auth.user_id,
format="%(id_workbook)s %(chartName)s",
)

Then when I needed a different controller function that returned all 
records I could:

db(query, ignore_common_filters=True).select(...) # copied from 
http://www.web2py.com/books/default/chapter/29/06?search=common_filter



Again I'm not that good at this but it seems logical.

-Bill

-- 





[web2py] join in DAL

2012-11-07 Thread Simon Carr
Hi All,

I have these 3 tables among others

db.define_table('workbook',
Field('path',requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'workbook.path')]),
Field('title',requires=IS_NOT_EMPTY()),
format="%(title)s",
)


db.define_table('chart',
Field('chartName'),
Field('id_workbook',db.workbook),
Field('worksheet'),
Field('file','upload'),
format="%(id_workbook)s %(chartName)s",
)

db.define_table('user_chart',
Field('id_user',db.auth_user,writable=False,readable=False,default=auth.user_id),
Field('id_chart','reference chart'),
Field('title'),
Field('description','text'),
format="%(title)s",
)

I have setup a function in my modal 

def is_my_chart(chartname):
if db((db.user_chart.id_user == auth.user_id) & 
(db.user_chart.id_chart.chartName == chartname)).count() > 0:
return True
else:
return False

But I get the following error

AttributeError: 'Field' object has no attribute 'chartName'


How do I fetch the fields out of a joined table?

Thanks
Simon

-- 





Re: [web2py] SQLFORM.grid exports the whole table

2012-11-07 Thread Niphlod
patch to apply to trunk. Please test it extensively with all the possible 
combinations.

On Wednesday, November 7, 2012 2:23:35 PM UTC+1, Niphlod wrote:
>
> at that point you miss formatting fields and references. In addition, 
> db.executesql() doesn't return an iterator either. You should code your own 
> exporter using db._adapter.execute() and a yielding fetchone()s.
>
> On Wednesday, November 7, 2012 2:01:45 PM UTC+1, Johann Spies wrote:
>>
>> On 7 November 2012 14:05, Niphlod  wrote:
>>
>>> if your set doesn't fit into memory, saving it to a temp file won't get 
>>> you out of troubles. One of DAL problems is that a Rows object does not 
>>> return an iterator from the cursor, it's fetched all into memory first.
>>>
>>>
>> In that case I would be inclined to use bypass DAL and db.executesql and 
>> use the backend to export to a file.  That should be more efficient.
>>
>> Regards
>> Johann
>> -- 
>> Because experiencing your loyal love is better than life itself, 
>> my lips will praise you.  (Psalm 63:3)
>>
>>

-- 



@@ -1934,25 +1934,23 @@ class SQLFORM(FORM):
 orderby = db[tablename][fieldname]
 if sign == '~':
 orderby = ~orderby
-
-table_fields = [f for f in fields if f._tablename in tablenames]
-if (export_type in ('csv_with_hidden_cols', 'tsv_with_hidden_cols')
-and export_type in exportManager):
+expcolumns = columns
+if export_type.endswith('with_hidden_cols'):
+expcolumns = [f for f in fields if f._tablename in tablenames]
+if export_type in exportManager:
 if request.vars.keywords:
 try:
 dbset = dbset(SQLFORM.build_query(
 fields, request.vars.get('keywords', '')))
-rows = dbset.select(cacheable=True)
+rows = dbset.select(cacheable=True, *expcolumns)
 except Exception, e:
 response.flash = T('Internal Error')
 rows = []
 else:
-rows = dbset.select(cacheable=True)
-else:
-rows = dbset.select(left=left, orderby=orderby,
-cacheable=True, *columns)
+rows = dbset.select(left=left, orderby=orderby,
+cacheable=True, *expcolumns)
 
-if export_type in exportManager:
+#begin building up exported file
 value = exportManager[export_type]
 clazz = value[0] if hasattr(value, '__getitem__') else value
 oExp = clazz(rows)


[web2py] Re: new feature in trunk: generic.map

2012-11-07 Thread Martín Miranda
(2, 0, 9, datetime.datetime(2012, 9, 13, 23, 51, 30), 'stable')  Python Python 
2.7.3: /usr/bin/python  Traceback 

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

Traceback (most recent call last):
  File "/home/www-data/web2py/gluon/restricted.py", line 209, in restricted
exec ccode in environment
  File "/home/www-data/web2py/applications/comisiones/views/default/map.html", 
line 98, in 
  File "/home/www-data/web2py/applications/comisiones/controllers/default.py" 
, line 
81, in 
maker = lambda point: A(row.name,_href='...'),
NameError: global name 'row' is not defined



El jueves, 5 de abril de 2012 20:54:32 UTC-3, Massimo Di Pierro escribió:
>
> Example:
>
> # model
> db.define_table('point',
> Field('name'),
> Field('latitude','double'),
> Field('longitude','double'))
>
> #controller
> def map():
> return dict(
>   googlemap_key='...',  # get this from google maps
>   center_latitude = 41.878,
>   center_longitude = -87.629,
>   scale = 7,
>   maker = lambda point: A(row.name,_href='...')
>   points = db(db.point).select() 
> )
>
> #in views/defaut/map.html:
>
> {{extend 'layout.html'}}
> 
>My Map
> {{include 'generic.map'}}
> 
>
>

-- 





[web2py] Re: how i can write a web2py code nto javascript

2012-11-07 Thread Leonel Câmara
Where is the pass to close the for cycle?

Anyway you seem to be doing it wrong. web2py code runs on the server, 
javascript runs on the client (browser), if you want python code to be 
executed you need to call a controller, for instance using ajax. Otherwise 
all you can put in the javascript using web2py is stuff you already have 
available in the view that generated it, the same way you put anything else 
in your view templates.

Quarta-feira, 7 de Novembro de 2012 9:39:36 UTC, Ali Alroomi escreveu:
>
> hello  plz i need help i need t write web2py code into javascript ike the 
> following my code plz any help with the this:
>
>
> $.fn.fancybox = function(options) {
> $(this).data('fancybox', $.extend({}, options));
>
> $(this).unbind('click.fb').bind('click.fb', function(e) {
> e.preventDefault();
>
> if (busy) return;
>
> busy = true;
>
> $(this).blur();
>
> selectedArray= [];
> selectedIndex= 0;
> {{for i in db().select(db.Project.ALL):}}
> var rel = $(this).attr('rel') || '';
> var message = {{=i.CategoryID}};
> var url = "?pro=" + escape(message);
>
> if (!rel || rel == '' || rel === 'nofollow') {
> selectedArray.push(this);
>
> } else {
> selectedArray= $("a[rel=" + rel + "], area[rel=" + rel 
> + "]");
> selectedIndex= selectedArray.index( this );
> /*window.open(url, "_self");*/
> history.replaceState({}, "Title", url);
>
> 
> }
> 
>
>
>
> 
>
> fancybox_start();
>
> return false;
> });
>
> return this;
> };
>

-- 





[web2py] Re: SQLFORM.factory

2012-11-07 Thread Niphlod
did you try removing one Field at a time inside SQLFORM.factory and see 
where the errors pops up ?

On Wednesday, November 7, 2012 2:58:10 PM UTC+1, Wouter Pronk wrote:
>
> Did some other testing and found simular error on this controler:
> def add_relatie():
> adres = db.executesql('SELECT adressen.relatie_nummer, " | ", 
> adressen.relatie_code, " | ", adressen.relatie_naam FROM adressen left join 
> edirelaties on adressen.relatie_nummer = edirelaties.relatie_nummer WHERE 
> edirelaties.relatie_nummer is null;')
> form = SQLFORM.factory(
> Field('relatie_nummer', requires=IS_IN_SET([a[0] for a in 
> adres],labels
> =[a for a in adres])),
> Field('login_naam', requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db, 
> 'edirelaties.login_naam'),IS_ALPHANUMERIC(error_message='must be 
> alphanumeric!')]),
> Field('password', requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db, 
> 'edirelaties.password'),IS_ALPHANUMERIC(error_message='must be 
> alphanumeric!')]),
> Field('work_directory', requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db, 
> 'edirelaties.work_directory'),IS_ALPHANUMERIC(error_message='must be 
> alphanumeric!')]))
> if form.process().accepted:
> db.edirelaties.insert(**form.vars)
> response.flash = 'Your new edirelatie has been added'
> redirect(URL('show', args=form.vars.id))
> elif form.errors:
> response.flash = 'form has errors'
> return dict(form=form)
> Any idea?
>
>
> Op woensdag 7 november 2012 12:42:58 UTC+1 schreef Niphlod het volgende:
>>
>> did you try with trunk ?
>>
>> On Wednesday, November 7, 2012 12:38:40 PM UTC+1, Wouter Pronk wrote:
>>>
>>> I just did and it did go in exception. Is my web2py corrupt?
>>>
>>> Op woensdag 7 november 2012 12:17:32 UTC+1 schreef Niphlod het volgende:

 create a fresh app and paste your code in it. It shouldn't go in 
 exception

 form = SQLFORM.factory(
 Field('relatie_id', writable=False, readable=False),
 Field('relatie_nummer', writable=False, readable=False),
 Field('direction', writable=False, readable=False),
 Field('protocol', writable=False, readable=False),
 Field('email', requires=IS_EMAIL())
 )



 This doesn't

 On Wednesday, November 7, 2012 12:12:24 PM UTC+1, Wouter Pronk wrote:
>
> Hello Niphlod,
> this is the traceback:
>
> Traceback (most recent call last):
>   File "/home/wouter/Web2py/web2py/gluon/restricted.py", line 212, in 
> restricted
> exec ccode in environment
>   File 
> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py"
>  
> ,
>  line 381, in 
>   File "/home/wouter/Web2py/web2py/gluon/globals.py", line 188, in 
> 
> self._caller = lambda f: f()
>   File 
> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py"
>  
> ,
>  line 200, in add_protocol
> Field('relatie_id', writable=False, readable=False),
> TypeError: __init__() takes exactly 1 argument (4 given)
>
> Where should I look?
>
>
> Op woensdag 7 november 2012 11:54:24 UTC+1 schreef Niphlod het 
> volgende:
>>
>> something else is wrong in your app, that piece of code works 
>> perfectly fine (the fact that you're declaring 5 fields to let display 
>> only 
>> one is quite not understandable but hey, it works nonetheless)
>>
>> On Wednesday, November 7, 2012 11:32:39 AM UTC+1, Wouter Pronk wrote:
>>>
>>> I have the following code:
>>> form = SQLFORM.factory(
>>> Field('relatie_id', writable=False, readable=False),
>>> Field('relatie_nummer', writable=False, readable=False),
>>> Field('direction', writable=False, readable=False),
>>> Field('protocol', writable=False, readable=False),
>>> Field('email', requires=[IS_EMAIL(),IS_NOT_IN_DB(db, 
>>> 'comprotocol.email')]))
>>>
>>> and this is working perfectly in version 1.99 but not in 2.2.1. I 
>>> get an error:
>>>
>>>  File 
>>> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py"
>>>  
>>> ,
>>>  line 199, in add_protocol
>>> Field('relatieid', writable=False, readable=False),
>>> TypeError: __init__() takes exactly 1 argument (4 given
>>>
>>> What is wrong?
>>>
>>

-- 





[web2py] Re: SQLFORM.factory

2012-11-07 Thread Wouter Pronk
Did some other testing and found simular error on this controler:
def add_relatie():
adres = db.executesql('SELECT adressen.relatie_nummer, " | ", 
adressen.relatie_code, " | ", adressen.relatie_naam FROM adressen left join 
edirelaties on adressen.relatie_nummer = edirelaties.relatie_nummer WHERE 
edirelaties.relatie_nummer is null;')
form = SQLFORM.factory(
Field('relatie_nummer', requires=IS_IN_SET([a[0] for a in adres],labels
=[a for a in adres])),
Field('login_naam', requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db, 
'edirelaties.login_naam'),IS_ALPHANUMERIC(error_message='must be 
alphanumeric!')]),
Field('password', requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db, 
'edirelaties.password'),IS_ALPHANUMERIC(error_message='must be 
alphanumeric!')]),
Field('work_directory', requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db, 
'edirelaties.work_directory'),IS_ALPHANUMERIC(error_message='must be 
alphanumeric!')]))
if form.process().accepted:
db.edirelaties.insert(**form.vars)
response.flash = 'Your new edirelatie has been added'
redirect(URL('show', args=form.vars.id))
elif form.errors:
response.flash = 'form has errors'
return dict(form=form)
Any idea?


Op woensdag 7 november 2012 12:42:58 UTC+1 schreef Niphlod het volgende:
>
> did you try with trunk ?
>
> On Wednesday, November 7, 2012 12:38:40 PM UTC+1, Wouter Pronk wrote:
>>
>> I just did and it did go in exception. Is my web2py corrupt?
>>
>> Op woensdag 7 november 2012 12:17:32 UTC+1 schreef Niphlod het volgende:
>>>
>>> create a fresh app and paste your code in it. It shouldn't go in 
>>> exception
>>>
>>> form = SQLFORM.factory(
>>> Field('relatie_id', writable=False, readable=False),
>>> Field('relatie_nummer', writable=False, readable=False),
>>> Field('direction', writable=False, readable=False),
>>> Field('protocol', writable=False, readable=False),
>>> Field('email', requires=IS_EMAIL())
>>> )
>>>
>>>
>>>
>>> This doesn't
>>>
>>> On Wednesday, November 7, 2012 12:12:24 PM UTC+1, Wouter Pronk wrote:

 Hello Niphlod,
 this is the traceback:

 Traceback (most recent call last):
   File "/home/wouter/Web2py/web2py/gluon/restricted.py", line 212, in 
 restricted
 exec ccode in environment
   File 
 "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py"
  
 ,
  line 381, in 
   File "/home/wouter/Web2py/web2py/gluon/globals.py", line 188, in 
 self._caller = lambda f: f()
   File 
 "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py"
  
 ,
  line 200, in add_protocol
 Field('relatie_id', writable=False, readable=False),
 TypeError: __init__() takes exactly 1 argument (4 given)

 Where should I look?


 Op woensdag 7 november 2012 11:54:24 UTC+1 schreef Niphlod het volgende:
>
> something else is wrong in your app, that piece of code works 
> perfectly fine (the fact that you're declaring 5 fields to let display 
> only 
> one is quite not understandable but hey, it works nonetheless)
>
> On Wednesday, November 7, 2012 11:32:39 AM UTC+1, Wouter Pronk wrote:
>>
>> I have the following code:
>> form = SQLFORM.factory(
>> Field('relatie_id', writable=False, readable=False),
>> Field('relatie_nummer', writable=False, readable=False),
>> Field('direction', writable=False, readable=False),
>> Field('protocol', writable=False, readable=False),
>> Field('email', requires=[IS_EMAIL(),IS_NOT_IN_DB(db, 
>> 'comprotocol.email')]))
>>
>> and this is working perfectly in version 1.99 but not in 2.2.1. I get 
>> an error:
>>
>>  File 
>> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py"
>>  
>> ,
>>  line 199, in add_protocol
>> Field('relatieid', writable=False, readable=False),
>> TypeError: __init__() takes exactly 1 argument (4 given
>>
>> What is wrong?
>>
>

-- 





Re: [web2py] Re: problem with share button

2012-11-07 Thread Nico Zanferrari
2012/11/7 peter 

> Does the share button work properly for anyone when using google+? If it
> works for you, is there any tip that you have. If it does not work for
> anyone, can this bug be fixed.
> Thanks
> Peter
>
>
>
Yes, for me it's working fine (I've just shared a test from
http://nicozanf.pythonanywhere.com/welcome/default/index with your G+
account). Maybe your Welcome app page must be reachable from internet...

Cheers,
Nico

-- 





[web2py] Re: Shortcut not working: del db.mytable[id]

2012-11-07 Thread Niphlod
but I tried in a shell and it doesn't raise an exception if the record 
exists (and it gets correctly deleted too)

On Wednesday, November 7, 2012 1:59:48 PM UTC+1, Cliff Kachinske wrote:
>
> The record was there.
>
> That's the problem.  The shortcut was erroneously reporting that it was 
> gone.
>
> On Tuesday, November 6, 2012 2:40:38 PM UTC-5, Niphlod wrote:
>>
>> del db.sometable[something] requires that the id == something exists.
>> db(db.sometable.id == something).delete() instead returns the number of 
>> records deleted if there was any, otherwise it simply deletes nothing.
>>
>> On Tuesday, November 6, 2012 8:14:33 PM UTC+1, Cliff Kachinske wrote:
>>>
>>> This code works.  Note the commented out line.
>>>
>>> for v in form.vars:
>>> if v[:7] == 'remove_' and form.vars[v] == 'on':
>>> # del db.class_users[v[7:]]
>>> db(db.class_users.id==v[7:]).delete()
>>>
>>>
>>> This code, which should be equivalent, raises the exception shown below.
>>>
>>> for v in form.vars:
>>> if v[:7] == 'remove_' and form.vars[v] == 'on':
>>> del db.class_users[v[7:]]
>>>
>>>
>>> Traceback (most recent call last):
>>>   File "/home/cjk/w2p09/web2py/gluon/restricted.py", line 209, in restricted
>>> exec ccode in environment
>>>   File 
>>> "/home/cjk/w2p09/web2py/applications/Training/controllers/class_users.py" 
>>> ,
>>>  line 371, in 
>>>   File "/home/cjk/w2p09/web2py/gluon/globals.py", line 186, in 
>>> self._caller = lambda f: f()
>>>   File "/home/cjk/w2p09/web2py/gluon/tools.py", line 2809, in f
>>> return action(*a, **b)
>>>   File 
>>> "/home/cjk/w2p09/web2py/applications/Training/controllers/class_users.py" 
>>> ,
>>>  line 165, in list_
>>> if form.process(onvalidation=do_updates).accepted:
>>>   File "/home/cjk/w2p09/web2py/gluon/html.py", line 2108, in process
>>> self.validate(**kwargs)
>>>   File "/home/cjk/w2p09/web2py/gluon/html.py", line 2055, in validate
>>> if self.accepts(**kwargs):
>>>   File "/home/cjk/w2p09/web2py/gluon/html.py", line 1969, in accepts
>>> onvalidation(self)
>>>   File 
>>> "/home/cjk/w2p09/web2py/applications/Training/controllers/class_users.py" 
>>> ,
>>>  line 134, in do_updates
>>> del db.class_users[v[7:]]
>>>   File "/home/cjk/w2p09/web2py/gluon/dal.py", line 7691, in __delitem__
>>> raise SyntaxError, 'No such record: %s' % key
>>> SyntaxError: No such record: 7
>>>
>>>

-- 





Re: [web2py] Re: track_changes

2012-11-07 Thread Massimiliano Belletti
>From me it works never. 
I'm on osx.

Massimiliano

Il giorno 07/nov/2012, alle ore 13:38, David Marko  ha 
scritto:

> Having the problem with this as well. Sometimes its works for 5-10 reloads 
> and then stops until I restart web2py server.
> 
> Dne středa, 7. listopadu 2012 11:47:13 UTC+1 Massimiliano napsal(a):
> Version 2.2.1 (2012-11-06 14:26:21) stable
> 
> It's just me or it doesn't work anymore? 
> 
> -- 
> Massimiliano
> -- 
>  
>  
>  

-- 





Re: [web2py] SQLFORM.grid exports the whole table

2012-11-07 Thread Niphlod
at that point you miss formatting fields and references. In addition, 
db.executesql() doesn't return an iterator either. You should code your own 
exporter using db._adapter.execute() and a yielding fetchone()s.

On Wednesday, November 7, 2012 2:01:45 PM UTC+1, Johann Spies wrote:
>
> On 7 November 2012 14:05, Niphlod > wrote:
>
>> if your set doesn't fit into memory, saving it to a temp file won't get 
>> you out of troubles. One of DAL problems is that a Rows object does not 
>> return an iterator from the cursor, it's fetched all into memory first.
>>
>>
> In that case I would be inclined to use bypass DAL and db.executesql and 
> use the backend to export to a file.  That should be more efficient.
>
> Regards
> Johann
> -- 
> Because experiencing your loyal love is better than life itself, 
> my lips will praise you.  (Psalm 63:3)
>
>

-- 





Re: [web2py] Re: Problem in deploying ssl certificates to Rocket server.

2012-11-07 Thread Michele Comitini
Amit,

A "self" was missing this should work:

class MyX509Auth(X509Auth):
def get_user(self):
  self.subject.surname = 
  X509Auth.get_user(self)
auth.settings.login_form = MyX509Auth()


2012/11/7 Michele Comitini 

> Amit,
>
> in your model call the derived class
>
> auth.settings.login_form = MyX509Auth()
>
>
>
> 2012/11/7 Michele Comitini 
>
>> simpatiCA makes the client certificates already with needed fields.
>> Since you use openssl directly you can set all the fields you need in the
>> certificates by changing openssl.cnf in your openssl installation.
>>  There is plenty of documentation on that.
>>
>> OR you can extend the class X509Auth to fit your needs by overriding
>> get_user()
>>
>>
>> class MyX509Auth(X509Auth):
>>  def get_user():
>>   self.subject.surname = 
>>   X509Auth.get_user(self)
>>
>>
>> mic
>>
>>
>>
>> 2012/11/7 Amit 
>>
>>> Hi,
>>> I filled the email address in the certificate but what I think is
>>> problem with surname , please check below the log:
>>>
>>>
>>> *File D:\web2py2.1.1\web2py\gluon\contrib\login_methods\x509_auth.py in
>>> get_user at line 91* code arguments variables
>>>  Function argument list
>>>
>>> (self=)
>>>  Code listing
>>>
>>> 86.
>>> 87.
>>> 88.
>>> 89.
>>> 90.
>>> 91.
>>>
>>> 92.
>>> 93.
>>> 94.
>>> 95.
>>>
>>>
>>> p = profile = dict()
>>>
>>> username = p['username'] = reduce(lambda a,b: '%s | %s' % (a,b), 
>>> self.subject.CN or self.subject.commonName)
>>>
>>>
>>>
>>> p['first_name'] = reduce(lambda a,b: '%s | %s' % 
>>> (a,b),self.subject.givenName or username)
>>>
>>>
>>> p['last_name'] = reduce(lambda a,b: '%s | %s' % 
>>> (a,b),self.subject.surname)
>>>
>>>
>>>
>>> p['email'] = reduce(lambda a,b: '%s | %s' % 
>>> (a,b),self.subject.Email or self.subject.emailAddress)
>>>
>>>
>>>
>>> # IMPORTANT WE USE THE CERT SERIAL AS UNIQUE KEY FOR THE USER
>>> p['registration_id'] = self.serial
>>>
>>>  Variables
>>> a undefined  b undefined  builtinreduce 
>>> self.subject.surname []  self 
>>> >> object>  self.subject >> ...SG'], 'organizationUnitName': ['HSG'], 'SN': []}>  p {'first_name':
>>> 'A | m | i | t | 1 | | K | h | a | w | a | r | e', 'username': 'Amit1
>>> Khaware'}
>>>
>>> And while generating the certificates it is not asking about surname,
>>> it's asking below information:
>>>
>>> Country Name (2 letter code) [US]:
>>> State or Province Name (full name) [CA]:
>>> Locality Name (eg, city) [San Diego]:
>>> Organization Name (eg, company) [Cafesoft LLC]:
>>> Organizational Unit Name (eg, section) []:
>>> Common Name (eg, YOUR name) []:*Cafesoft CA*
>>> Email Address [c...@cafenet.com]:
>>>
>>> Please enter the following 'extra' attributes
>>> to be sent with your certificate request
>>> A challenge password []:*password*
>>> An optional company name []:
>>>
>>>
>>> please check the link :
>>>
>>>
>>> http://www.cafesoft.com/products/cams/ps/docs30/admin/ConfiguringApache2ForSSLTLSMutualAuthentication.html
>>>
>>> So x509_auth.py expects surname but above link doesn't provide option
>>> to fill surname :(
>>>
>>>
>>> Regards,
>>>
>>> Amit
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Tue, Nov 6, 2012 at 8:34 PM, Michele Comitini <
>>> michele.comit...@gmail.com> wrote:
>>>
 self.subject.Email is [] i.e. an empty list.  Check if that is the
 problem.

 mic
 Il giorno 06/nov/2012 14:32, "Amit"  ha
 scritto:

>  I have used below link to generate server certificates, client
> certificates and CA certificates,  imported client  and CA certificates to
> Mozilla Firefox browser and then deploy server certificates and CA
> certificate to the Rocket server :
>
> D:\web2py2.1.1\web2py>web2py.py -a password -i 127.0.0.1 -p 8000 -c
> C:\OpenSSL-Win32\bin\cirrusAwareCA\server\certificates\server.test.com.crt
> -k C:\OpenSSL-Win32\bin\cirrusAwareCA\server\keys\server.test.com.key
> --ca-cert=C:\OpenSSL-Win32\bin\cirrusAwareCA\CA\cirrusAwareCA.crt
>
> Then Open browser type https://127.0.0.1:8000/MyApp/default/index
>
> Now its giving error:
>  reduce() of empty sequence with no
> initial value Error snapshot [image: help]
>
> (reduce() of empty sequence with no
> initial value)
>
> inspect attributes
>  Frames
>
>-
>
>*File D:\web2py2.1.1\web2py\gluon\restricted.py in restricted at
>line 209* code arguments variables
> -
>
>*File
>
> D:\web2py2.1.1\web2py\applications\AuthenticationApp\controllers\default.py
>in  at line 76* code arguments variables
> -
>
>*File D:\web2py2.1.1\web2py\gluon\globals.py in  at line
>187* code arguments variables
> -
>
>*File
>
> D:\web2py2.1.1\web2py\applications\AuthenticationApp\controllers\default.py
>in user at line 38* code arguments variables
> Code listing
>
>   

Re: [web2py] Re: Problem in deploying ssl certificates to Rocket server.

2012-11-07 Thread Michele Comitini
Amit,

in your model call the derived class

auth.settings.login_form = MyX509Auth()


2012/11/7 Michele Comitini 

> simpatiCA makes the client certificates already with needed fields.
> Since you use openssl directly you can set all the fields you need in the
> certificates by changing openssl.cnf in your openssl installation.
> There is plenty of documentation on that.
>
> OR you can extend the class X509Auth to fit your needs by overriding
> get_user()
>
>
> class MyX509Auth(X509Auth):
>  def get_user():
>   self.subject.surname = 
>   X509Auth.get_user(self)
>
>
> mic
>
>
>
> 2012/11/7 Amit 
>
>> Hi,
>> I filled the email address in the certificate but what I think is problem
>> with surname , please check below the log:
>>
>>
>> *File D:\web2py2.1.1\web2py\gluon\contrib\login_methods\x509_auth.py in
>> get_user at line 91* code arguments variables
>>  Function argument list
>>
>> (self=)
>>  Code listing
>>
>> 86.
>> 87.
>> 88.
>> 89.
>> 90.
>> 91.
>>
>> 92.
>> 93.
>> 94.
>> 95.
>>
>>
>> p = profile = dict()
>>
>> username = p['username'] = reduce(lambda a,b: '%s | %s' % (a,b), 
>> self.subject.CN or self.subject.commonName)
>>
>>
>> p['first_name'] = reduce(lambda a,b: '%s | %s' % 
>> (a,b),self.subject.givenName or username)
>>
>> p['last_name'] = reduce(lambda a,b: '%s | %s' % 
>> (a,b),self.subject.surname)
>>
>>
>> p['email'] = reduce(lambda a,b: '%s | %s' % (a,b),self.subject.Email 
>> or self.subject.emailAddress)
>>
>>
>> # IMPORTANT WE USE THE CERT SERIAL AS UNIQUE KEY FOR THE USER
>> p['registration_id'] = self.serial
>>
>>  Variables
>> a undefined  b undefined  builtinreduce 
>> self.subject.surname []  self > object>  self.subject > ...SG'], 'organizationUnitName': ['HSG'], 'SN': []}>  p {'first_name':
>> 'A | m | i | t | 1 | | K | h | a | w | a | r | e', 'username': 'Amit1
>> Khaware'}
>>
>> And while generating the certificates it is not asking about surname,
>> it's asking below information:
>>
>> Country Name (2 letter code) [US]:
>> State or Province Name (full name) [CA]:
>> Locality Name (eg, city) [San Diego]:
>> Organization Name (eg, company) [Cafesoft LLC]:
>> Organizational Unit Name (eg, section) []:
>> Common Name (eg, YOUR name) []:*Cafesoft CA*
>> Email Address [c...@cafenet.com]:
>>
>> Please enter the following 'extra' attributes
>> to be sent with your certificate request
>> A challenge password []:*password*
>> An optional company name []:
>>
>>
>> please check the link :
>>
>>
>> http://www.cafesoft.com/products/cams/ps/docs30/admin/ConfiguringApache2ForSSLTLSMutualAuthentication.html
>>
>> So x509_auth.py expects surname but above link doesn't provide option to
>> fill surname :(
>>
>>
>> Regards,
>>
>> Amit
>>
>>
>>
>>
>>
>>
>>
>>
>> On Tue, Nov 6, 2012 at 8:34 PM, Michele Comitini <
>> michele.comit...@gmail.com> wrote:
>>
>>> self.subject.Email is [] i.e. an empty list.  Check if that is the
>>> problem.
>>>
>>> mic
>>> Il giorno 06/nov/2012 14:32, "Amit"  ha scritto:
>>>
  I have used below link to generate server certificates, client
 certificates and CA certificates,  imported client  and CA certificates to
 Mozilla Firefox browser and then deploy server certificates and CA
 certificate to the Rocket server :

 D:\web2py2.1.1\web2py>web2py.py -a password -i 127.0.0.1 -p 8000 -c
 C:\OpenSSL-Win32\bin\cirrusAwareCA\server\certificates\server.test.com.crt
 -k C:\OpenSSL-Win32\bin\cirrusAwareCA\server\keys\server.test.com.key
 --ca-cert=C:\OpenSSL-Win32\bin\cirrusAwareCA\CA\cirrusAwareCA.crt

 Then Open browser type https://127.0.0.1:8000/MyApp/default/index

 Now its giving error:
  reduce() of empty sequence with no
 initial value Error snapshot [image: help]

 (reduce() of empty sequence with no
 initial value)

 inspect attributes
  Frames

-

*File D:\web2py2.1.1\web2py\gluon\restricted.py in restricted at
line 209* code arguments variables
 -

*File

 D:\web2py2.1.1\web2py\applications\AuthenticationApp\controllers\default.py
in  at line 76* code arguments variables
 -

*File D:\web2py2.1.1\web2py\gluon\globals.py in  at line 187
* code arguments variables
 -

*File

 D:\web2py2.1.1\web2py\applications\AuthenticationApp\controllers\default.py
in user at line 38* code arguments variables
 Code listing

33.
34.
35.
36.
37.
38.

39.
40.
41.
42.

use @auth.requires_login()
@auth.requires_membership('group name')




@auth.requires_permission('read','table name',record_id)




to decorate functions that need access control
"""
return dict(form=auth())


Re: [web2py] Re: Problem in deploying ssl certificates to Rocket server.

2012-11-07 Thread Michele Comitini
simpatiCA makes the client certificates already with needed fields.
Since you use openssl directly you can set all the fields you need in the
certificates by changing openssl.cnf in your openssl installation.
There is plenty of documentation on that.

OR you can extend the class X509Auth to fit your needs by overriding
get_user()


class MyX509Auth(X509Auth):
def get_user():
  self.subject.surname = 
  X509Auth.get_user(self)


mic



2012/11/7 Amit 

> Hi,
> I filled the email address in the certificate but what I think is problem
> with surname , please check below the log:
>
>
> *File D:\web2py2.1.1\web2py\gluon\contrib\login_methods\x509_auth.py in
> get_user at line 91* code arguments variables
>  Function argument list
>
> (self=)
>  Code listing
>
> 86.
> 87.
> 88.
> 89.
> 90.
> 91.
>
> 92.
> 93.
> 94.
> 95.
>
>
> p = profile = dict()
>
> username = p['username'] = reduce(lambda a,b: '%s | %s' % (a,b), 
> self.subject.CN or self.subject.commonName)
>
> p['first_name'] = reduce(lambda a,b: '%s | %s' % 
> (a,b),self.subject.givenName or username)
> p['last_name'] = reduce(lambda a,b: '%s | %s' % 
> (a,b),self.subject.surname)
>
> p['email'] = reduce(lambda a,b: '%s | %s' % (a,b),self.subject.Email 
> or self.subject.emailAddress)
>
> # IMPORTANT WE USE THE CERT SERIAL AS UNIQUE KEY FOR THE USER
> p['registration_id'] = self.serial
>
>  Variables
> a undefined  b undefined  builtinreduce 
> self.subject.surname []  self  object>  self.subject  ...SG'], 'organizationUnitName': ['HSG'], 'SN': []}>  p {'first_name': 'A
> | m | i | t | 1 | | K | h | a | w | a | r | e', 'username': 'Amit1 Khaware'}
>
> And while generating the certificates it is not asking about surname, it's
> asking below information:
>
> Country Name (2 letter code) [US]:
> State or Province Name (full name) [CA]:
> Locality Name (eg, city) [San Diego]:
> Organization Name (eg, company) [Cafesoft LLC]:
> Organizational Unit Name (eg, section) []:
> Common Name (eg, YOUR name) []:*Cafesoft CA*
> Email Address [c...@cafenet.com]:
>
> Please enter the following 'extra' attributes
> to be sent with your certificate request
> A challenge password []:*password*
> An optional company name []:
>
>
> please check the link :
>
>
> http://www.cafesoft.com/products/cams/ps/docs30/admin/ConfiguringApache2ForSSLTLSMutualAuthentication.html
>
> So x509_auth.py expects surname but above link doesn't provide option to
> fill surname :(
>
>
> Regards,
>
> Amit
>
>
>
>
>
>
>
>
> On Tue, Nov 6, 2012 at 8:34 PM, Michele Comitini <
> michele.comit...@gmail.com> wrote:
>
>> self.subject.Email is [] i.e. an empty list.  Check if that is the
>> problem.
>>
>> mic
>> Il giorno 06/nov/2012 14:32, "Amit"  ha scritto:
>>
>>>  I have used below link to generate server certificates, client
>>> certificates and CA certificates,  imported client  and CA certificates to
>>> Mozilla Firefox browser and then deploy server certificates and CA
>>> certificate to the Rocket server :
>>>
>>> D:\web2py2.1.1\web2py>web2py.py -a password -i 127.0.0.1 -p 8000 -c
>>> C:\OpenSSL-Win32\bin\cirrusAwareCA\server\certificates\server.test.com.crt
>>> -k C:\OpenSSL-Win32\bin\cirrusAwareCA\server\keys\server.test.com.key
>>> --ca-cert=C:\OpenSSL-Win32\bin\cirrusAwareCA\CA\cirrusAwareCA.crt
>>>
>>> Then Open browser type https://127.0.0.1:8000/MyApp/default/index
>>>
>>> Now its giving error:
>>>  reduce() of empty sequence with no initial
>>> value Error snapshot [image: help]
>>>
>>> (reduce() of empty sequence with no initial
>>> value)
>>>
>>> inspect attributes
>>>  Frames
>>>
>>>-
>>>
>>>*File D:\web2py2.1.1\web2py\gluon\restricted.py in restricted at
>>>line 209* code arguments variables
>>> -
>>>
>>>*File
>>>
>>> D:\web2py2.1.1\web2py\applications\AuthenticationApp\controllers\default.py
>>>in  at line 76* code arguments variables
>>> -
>>>
>>>*File D:\web2py2.1.1\web2py\gluon\globals.py in  at line 187*
>>>code arguments variables
>>> -
>>>
>>>*File
>>>
>>> D:\web2py2.1.1\web2py\applications\AuthenticationApp\controllers\default.py
>>>in user at line 38* code arguments variables
>>> Code listing
>>>
>>>33.
>>>34.
>>>35.
>>>36.
>>>37.
>>>38.
>>>
>>>39.
>>>40.
>>>41.
>>>42.
>>>
>>>use @auth.requires_login()
>>>@auth.requires_membership('group name')
>>>
>>>
>>>
>>>@auth.requires_permission('read','table name',record_id)
>>>
>>>
>>>
>>>to decorate functions that need access control
>>>"""
>>>return dict(form=auth())
>>>
>>>
>>>
>>>def download():
>>>"""
>>>
>>>  -
>>>
>>>*File D:\web2py2.1.1\web2py\gluon\tools.py in __call__ at line 1205*
>>>code arguments variables
>>> -
>>>
>>>*File D:\web2py2.1.1\web2py\gluon\tools.py in login at line 2016*
>>>code arguments variables
>>> -
>>>
>>>*File D:\web2py2.1.1\web2p

Re: [web2py] how i can write a web2py code nto javascript

2012-11-07 Thread Vinicius Assef
You're already doing it.

What is your doubt, actually?



On Wed, Nov 7, 2012 at 7:39 AM, Ali Alroomi  wrote:
> hello  plz i need help i need t write web2py code into javascript ike the
> following my code plz any help with the this:
>
>
> $.fn.fancybox = function(options) {
> $(this).data('fancybox', $.extend({}, options));
>
> $(this).unbind('click.fb').bind('click.fb', function(e) {
> e.preventDefault();
>
> if (busy) return;
>
> busy = true;
>
> $(this).blur();
>
> selectedArray= [];
> selectedIndex= 0;
> {{for i in db().select(db.Project.ALL):}}
> var rel = $(this).attr('rel') || '';
> var message = {{=i.CategoryID}};
> var url = "?pro=" + escape(message);
>
> if (!rel || rel == '' || rel === 'nofollow') {
> selectedArray.push(this);
>
> } else {
> selectedArray= $("a[rel=" + rel + "], area[rel=" + rel +
> "]");
> selectedIndex= selectedArray.index( this );
> /*window.open(url, "_self");*/
> history.replaceState({}, "Title", url);
>
>
> }
>
>
>
>
>
>
> fancybox_start();
>
> return false;
> });
>
> return this;
> };
>
> --
>
>
>

-- 





[web2py] extension handling in parametric router

2012-11-07 Thread Jim Gregory
How does the parametric router handle extensions?When I do a doctest 
using "app/controller/function.extension", it returns "app/controller/index 
['function.ext']" instead of "app/controller/function" as I would have 
expected.  What am I doing wrong?

-- 





Re: [web2py] SQLFORM.grid exports the whole table

2012-11-07 Thread Johann Spies
On 7 November 2012 15:01, Johann Spies  wrote:

>
> In that case I would be inclined to use bypass DAL and db.executesql and
> use the backend to export to a file.  That should be more efficient.
>

Sorry. That should read

... inclined to bypass DAL and use db.executesql ...
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

-- 





Re: [web2py] SQLFORM.grid exports the whole table

2012-11-07 Thread Johann Spies
On 7 November 2012 14:05, Niphlod  wrote:

> if your set doesn't fit into memory, saving it to a temp file won't get
> you out of troubles. One of DAL problems is that a Rows object does not
> return an iterator from the cursor, it's fetched all into memory first.
>
>
In that case I would be inclined to use bypass DAL and db.executesql and
use the backend to export to a file.  That should be more efficient.

Regards
Johann
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

-- 





[web2py] Re: Shortcut not working: del db.mytable[id]

2012-11-07 Thread Cliff Kachinske
The record was there.

That's the problem.  The shortcut was erroneously reporting that it was 
gone.

On Tuesday, November 6, 2012 2:40:38 PM UTC-5, Niphlod wrote:
>
> del db.sometable[something] requires that the id == something exists.
> db(db.sometable.id == something).delete() instead returns the number of 
> records deleted if there was any, otherwise it simply deletes nothing.
>
> On Tuesday, November 6, 2012 8:14:33 PM UTC+1, Cliff Kachinske wrote:
>>
>> This code works.  Note the commented out line.
>>
>> for v in form.vars:
>> if v[:7] == 'remove_' and form.vars[v] == 'on':
>> # del db.class_users[v[7:]]
>> db(db.class_users.id==v[7:]).delete()
>>
>>
>> This code, which should be equivalent, raises the exception shown below.
>>
>> for v in form.vars:
>> if v[:7] == 'remove_' and form.vars[v] == 'on':
>> del db.class_users[v[7:]]
>>
>>
>> Traceback (most recent call last):
>>   File "/home/cjk/w2p09/web2py/gluon/restricted.py", line 209, in restricted
>> exec ccode in environment
>>   File 
>> "/home/cjk/w2p09/web2py/applications/Training/controllers/class_users.py" 
>> ,
>>  line 371, in 
>>   File "/home/cjk/w2p09/web2py/gluon/globals.py", line 186, in 
>> self._caller = lambda f: f()
>>   File "/home/cjk/w2p09/web2py/gluon/tools.py", line 2809, in f
>> return action(*a, **b)
>>   File 
>> "/home/cjk/w2p09/web2py/applications/Training/controllers/class_users.py" 
>> ,
>>  line 165, in list_
>> if form.process(onvalidation=do_updates).accepted:
>>   File "/home/cjk/w2p09/web2py/gluon/html.py", line 2108, in process
>> self.validate(**kwargs)
>>   File "/home/cjk/w2p09/web2py/gluon/html.py", line 2055, in validate
>> if self.accepts(**kwargs):
>>   File "/home/cjk/w2p09/web2py/gluon/html.py", line 1969, in accepts
>> onvalidation(self)
>>   File 
>> "/home/cjk/w2p09/web2py/applications/Training/controllers/class_users.py" 
>> ,
>>  line 134, in do_updates
>> del db.class_users[v[7:]]
>>   File "/home/cjk/w2p09/web2py/gluon/dal.py", line 7691, in __delitem__
>> raise SyntaxError, 'No such record: %s' % key
>> SyntaxError: No such record: 7
>>
>>

-- 





Re: [web2py] Re: SQLFORM.smartgrid oncreate,ondelete not firing

2012-11-07 Thread vivek
Hmmm ,

  unsure of how to determine the different table , i tried using 
forms.vars.net - as this field is unique to my parent table in the same 
oncreate function. So basically , I have forms.vars.xyz from my child table 
and able to use it to do what i need. But forms.vars.net is unusable  which 
means oncreate ,onupdate doesnt trigger for parent table. 

  Any work arounds for this?




On Wednesday, November 7, 2012 5:21:50 AM UTC+4, howesc wrote:
>
> good question.i don't know the answer to it, but i suspect there is a 
> way in your oncreate method to determine which table just had a creation 
> and do different actions based on that.
>
> On Monday, November 5, 2012 11:41:17 PM UTC-8, vivek wrote:
>>
>>
>> Hi , 
>>
>>   So in this case how do I make sure it fires only when a new record 
>> is created for the child table in this case "quotelines" . Suppose if I 
>> have 2 different functions to be fired for the parent - oncreate and child 
>> - oncreate? 
>>
>> Regards,
>> Vivek
>>
>>
>>
>> On Monday, October 29, 2012 11:39:08 PM UTC+4, howesc wrote:
>>>
>>> something like:
>>>
>>> def myondelete(table, row_id):
>>>  
>>>  pass
>>>
>>> form = SQLFORM.smartgrid(..., ondelete=myondelete, ...)
>>>
>>>
>>>
>>> On Sunday, October 28, 2012 6:57:12 AM UTC-7, vivek wrote:

 So how would the new code be? I am a newbie a bit of direction needed!




 On Sun, Oct 28, 2012 at 5:39 PM, Niphlod  wrote:

> oncreate, ondelete, onupdate are callbacks to functions, not dicts
>
>
> On Sunday, October 28, 2012 12:26:39 PM UTC+1, vivek wrote:
>>
>> Hi,
>>
>> @auth.requires_login()
>> def index():
>> response.view = 'Final/pricelist.html'
>> form = SQLFORM.smartgrid(db.sourcelis**t,linked_tables=[
>> 'itemowner'],**deletable=dict(sourcelist=Fals**e,itemowner=True),editable
>> =dict(sourcelist=False**,itemowner=True), details=dict(sourcelist=
>> False,**itemowner=False),links = dict(project=[lambda row: A(SPAN(
>> _class='icol-find'),_**href=URL("sourcelist","**itemowner",args=[row.
>> id]))]),o**ncreate=dict(itemowner=[avgpri**ce]),ondelete=dict(
>> itemowner=[**'avgprice'])) 
>> return dict(form=form)
>>
>> @auth.requires_login()
>> def avgprice():
>> ...
>>
>> The above is my code . "itemowner" is my child table. I have manually 
>> tried running avgprice() from appadmin to make sure it works. There 
>> wasnt 
>> an issue. I just need to get the smartgrid to trigger avgprice.
>>
>> Thanks!
>>
>>  -- 
>  
>  
>  
>



-- 





[web2py] Re: track_changes

2012-11-07 Thread David Marko
Having the problem with this as well. Sometimes its works for 5-10 reloads 
and then stops until I restart web2py server.

Dne středa, 7. listopadu 2012 11:47:13 UTC+1 Massimiliano napsal(a):
>
> Version 2.2.1 (2012-11-06 14:26:21) stable
>
> It's just me or it doesn't work anymore? 
>
> -- 
> Massimiliano
>

-- 





Re: [web2py] SQLFORM.grid exports the whole table

2012-11-07 Thread Niphlod
if your set doesn't fit into memory, saving it to a temp file won't get you 
out of troubles. One of DAL problems is that a Rows object does not return 
an iterator from the cursor, it's fetched all into memory first.

On Wednesday, November 7, 2012 12:45:46 PM UTC+1, Johann Spies wrote:
>
> On 7 November 2012 13:32, Niphlod > wrote:
>
>> far too magic to check for something that basically isn't trustable: even 
>> if you code something like that and you check that there's x mb available, 
>> another user can ask for another huge set of data and your "previoulsy" 
>> free RAM is not free anymore.
>>
>>
> True.  What about writing it to a temporary file and stream it from 
> there.  What would the effect on resources be? 
>
> Regards
> Johann
> -- 
> Because experiencing your loyal love is better than life itself, 
> my lips will praise you.  (Psalm 63:3)
>
>

-- 





[web2py] Re: SQLFORM.factory

2012-11-07 Thread Niphlod
did you try with trunk ?

On Wednesday, November 7, 2012 12:38:40 PM UTC+1, Wouter Pronk wrote:
>
> I just did and it did go in exception. Is my web2py corrupt?
>
> Op woensdag 7 november 2012 12:17:32 UTC+1 schreef Niphlod het volgende:
>>
>> create a fresh app and paste your code in it. It shouldn't go in exception
>>
>> form = SQLFORM.factory(
>> Field('relatie_id', writable=False, readable=False),
>> Field('relatie_nummer', writable=False, readable=False),
>> Field('direction', writable=False, readable=False),
>> Field('protocol', writable=False, readable=False),
>> Field('email', requires=IS_EMAIL())
>> )
>>
>>
>>
>> This doesn't
>>
>> On Wednesday, November 7, 2012 12:12:24 PM UTC+1, Wouter Pronk wrote:
>>>
>>> Hello Niphlod,
>>> this is the traceback:
>>>
>>> Traceback (most recent call last):
>>>   File "/home/wouter/Web2py/web2py/gluon/restricted.py", line 212, in 
>>> restricted
>>> exec ccode in environment
>>>   File 
>>> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py"
>>>  
>>> ,
>>>  line 381, in 
>>>   File "/home/wouter/Web2py/web2py/gluon/globals.py", line 188, in 
>>> self._caller = lambda f: f()
>>>   File 
>>> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py"
>>>  
>>> ,
>>>  line 200, in add_protocol
>>> Field('relatie_id', writable=False, readable=False),
>>> TypeError: __init__() takes exactly 1 argument (4 given)
>>>
>>> Where should I look?
>>>
>>>
>>> Op woensdag 7 november 2012 11:54:24 UTC+1 schreef Niphlod het volgende:

 something else is wrong in your app, that piece of code works perfectly 
 fine (the fact that you're declaring 5 fields to let display only one is 
 quite not understandable but hey, it works nonetheless)

 On Wednesday, November 7, 2012 11:32:39 AM UTC+1, Wouter Pronk wrote:
>
> I have the following code:
> form = SQLFORM.factory(
> Field('relatie_id', writable=False, readable=False),
> Field('relatie_nummer', writable=False, readable=False),
> Field('direction', writable=False, readable=False),
> Field('protocol', writable=False, readable=False),
> Field('email', requires=[IS_EMAIL(),IS_NOT_IN_DB(db, 
> 'comprotocol.email')]))
>
> and this is working perfectly in version 1.99 but not in 2.2.1. I get 
> an error:
>
>  File 
> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py"
>  
> ,
>  line 199, in add_protocol
> Field('relatieid', writable=False, readable=False),
> TypeError: __init__() takes exactly 1 argument (4 given
>
> What is wrong?
>


-- 





[web2py] Re: SQLFORM.factory

2012-11-07 Thread Wouter Pronk
I just did and it did go in exception. Is my web2py corrupt?

Op woensdag 7 november 2012 12:17:32 UTC+1 schreef Niphlod het volgende:
>
> create a fresh app and paste your code in it. It shouldn't go in exception
>
> form = SQLFORM.factory(
> Field('relatie_id', writable=False, readable=False),
> Field('relatie_nummer', writable=False, readable=False),
> Field('direction', writable=False, readable=False),
> Field('protocol', writable=False, readable=False),
> Field('email', requires=IS_EMAIL())
> )
>
>
>
> This doesn't
>
> On Wednesday, November 7, 2012 12:12:24 PM UTC+1, Wouter Pronk wrote:
>>
>> Hello Niphlod,
>> this is the traceback:
>>
>> Traceback (most recent call last):
>>   File "/home/wouter/Web2py/web2py/gluon/restricted.py", line 212, in 
>> restricted
>> exec ccode in environment
>>   File 
>> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py" 
>> ,
>>  line 381, in 
>>   File "/home/wouter/Web2py/web2py/gluon/globals.py", line 188, in 
>> self._caller = lambda f: f()
>>   File 
>> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py" 
>> ,
>>  line 200, in add_protocol
>> Field('relatie_id', writable=False, readable=False),
>> TypeError: __init__() takes exactly 1 argument (4 given)
>>
>> Where should I look?
>>
>>
>> Op woensdag 7 november 2012 11:54:24 UTC+1 schreef Niphlod het volgende:
>>>
>>> something else is wrong in your app, that piece of code works perfectly 
>>> fine (the fact that you're declaring 5 fields to let display only one is 
>>> quite not understandable but hey, it works nonetheless)
>>>
>>> On Wednesday, November 7, 2012 11:32:39 AM UTC+1, Wouter Pronk wrote:

 I have the following code:
 form = SQLFORM.factory(
 Field('relatie_id', writable=False, readable=False),
 Field('relatie_nummer', writable=False, readable=False),
 Field('direction', writable=False, readable=False),
 Field('protocol', writable=False, readable=False),
 Field('email', requires=[IS_EMAIL(),IS_NOT_IN_DB(db, 
 'comprotocol.email')]))

 and this is working perfectly in version 1.99 but not in 2.2.1. I get 
 an error:

  File 
 "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py"
  
 ,
  line 199, in add_protocol
 Field('relatieid', writable=False, readable=False),
 TypeError: __init__() takes exactly 1 argument (4 given

 What is wrong?

>>>

-- 





Re: [web2py] Re: Help with db query

2012-11-07 Thread Joe Barnhart
There is a Field function called "contains()" which would be useful here.  
It is described in the online book here:

http://www.web2py.com/books/default/chapter/29/06#like,-regexp,-startswith,-contains,-upper,-lower

Your query would be something like: 

db.table.Field2.contains( [ 'value1', 'value2' ] )

Notice that "contains" is a function and is on Field2 (where it gets its 
"self" argument).  The argument to contains is a list object -- note the 
square brackets!  The list gathers up your values into a single object 
which is then passed into "contains".  There is an optional keyword 
argument "all" which can be set to True which forces it to match all of the 
list instead of any of the list.

-- Joe B.

On Wednesday, November 7, 2012 3:01:58 AM UTC-8, Hassan Alnatour wrote:
>
> and i even tried : 
>
> items  =[]
> items.append(request.args(0))
> items.append('Both') 
>
> db( (db.table.Field1 == value) & (db.table.Field2 in items))
>
>
> regards,
>
>
> On Wed, Nov 7, 2012 at 12:56 PM, hasan alnator 
> 
> > wrote:
>
>> Dear Joe , 
>>
>> What i want to do is to have a query like this : 
>>
>> db( (db.table.Field1 == value) & (db.table.Field2 == value or value))
>>
>> i tried it i get no errors but its now working 
>>
>> Regards
>>
>>
>> On Wed, Nov 7, 2012 at 10:10 AM, Joe Barnhart 
>> 
>> > wrote:
>>
>>> I see -- you're right.
>>>
>>> The request.args structure is a List() object which web2py defines to 
>>> retrieve values without the exception if it doesn't exist.  It has some 
>>> additional interesting capabilities...  You can define a default value, 
>>> such as this:
>>>
>>>
>>> request.args(0,default='Both')
>>>
>>>
>>> This will substitute the value 'Both' for request.args[0] should it be 
>>> set to None or be invalid.  Or you could cast a string value to an integer 
>>> -- this often happens since the request.args are strings by default, but I 
>>> often pass row ids to be processed elsewhere:
>>>
>>>
>>> URL('default','editrecord',args=[22])
>>>
>>>
>>> Becomes:
>>>
>>>
>>> http://./default/editrecord/22
>>>
>>>
>>> And request.args[0] is now '22' (the string).  So we use the "cast" 
>>> keyword to change it to an int:
>>>
>>>
>>> request.args(0,cast=int)
>>>
>>>
>>> There is a ton of behavior in this little class!  Thanks for pointing it 
>>> out to me.
>>>
>>> -- Joe Barnhart
>>>
>>>
>>> class List(list):
>>> """
>>> Like a regular python list but a[i] if i is out of bounds return None
>>> instead of IndexOutOfBounds
>>> """
>>>
>>> def __call__(self, i, default=None, cast=None, otherwise=None):
>>> """
>>> request.args(0,default=0,cast=int,otherwise='http://error_url')
>>> request.args(0,default=0,cast=int,otherwise=lambda:...)
>>> """
>>> n = len(self)
>>> if 0 <= i < n or -n <= i < 0:
>>> value = self[i]
>>> else:
>>> value = default
>>> if cast:
>>> try:
>>> value = cast(value)
>>> except (ValueError, TypeError):
>>> from http import HTTP, redirect
>>> if otherwise is None:
>>> raise HTTP(404)
>>> elif isinstance(otherwise, str):
>>> redirect(otherwise)
>>> elif callable(otherwise):
>>> return otherwise()
>>> else:
>>> raise RuntimeError("invalid otherwise")
>>> return value
>>>
>>>
>>>
>>>
>>> On Tuesday, November 6, 2012 2:24:53 PM UTC-8, Niphlod wrote:


 One more point -- your "request.args(1)" should be "request.args[1]" 
> (with square brackets).  The first form calls request.args as a function 
> and passes it the value "1".   The second form treats request.args as a 
> Storage object and asks for the subscript "1".
>
> -- Joe Barnhart
>
> Nope, request.args(1) does basically
 try:
   result = request.args[1]
 except:
   result = None
 return result

 the () notation is safer because using request.args[1] if there is no 
 request.args[1] you get an exception. 

>>>  -- 
>>>  
>>>  
>>>  
>>>
>>
>>
>

-- 





[web2py] how i can write a web2py code nto javascript

2012-11-07 Thread Ali Alroomi
hello  plz i need help i need t write web2py code into javascript ike the 
following my code plz any help with the this:


$.fn.fancybox = function(options) {
$(this).data('fancybox', $.extend({}, options));

$(this).unbind('click.fb').bind('click.fb', function(e) {
e.preventDefault();

if (busy) return;

busy = true;

$(this).blur();

selectedArray= [];
selectedIndex= 0;
{{for i in db().select(db.Project.ALL):}}
var rel = $(this).attr('rel') || '';
var message = {{=i.CategoryID}};
var url = "?pro=" + escape(message);

if (!rel || rel == '' || rel === 'nofollow') {
selectedArray.push(this);

} else {
selectedArray= $("a[rel=" + rel + "], area[rel=" + rel 
+ "]");
selectedIndex= selectedArray.index( this );
/*window.open(url, "_self");*/
history.replaceState({}, "Title", url);


}






fancybox_start();

return false;
});

return this;
};

-- 





Re: [web2py] SQLFORM.grid exports the whole table

2012-11-07 Thread Niphlod
far too magic to check for something that basically isn't trustable: even 
if you code something like that and you check that there's x mb available, 
another user can ask for another huge set of data and your "previoulsy" 
free RAM is not free anymore.

On Wednesday, November 7, 2012 11:59:18 AM UTC+1, Johann Spies wrote:
>
> On 7 November 2012 12:33, Niphlod > wrote:
>
>> woking on 1.
>>
>
> Thanks.
>  
>
>> for 2, how do you "foresee" how much time and RAM the present query will 
>> take to be serialized ?
>>
>
> I don't know.  I suspect a possible method would be:
>
> * Determine the average size of a record calculated on the result of the 
> present query handled by the grid.
> * Determine the available ram on the server
> * Calculate the size of the total result.  If it is more than say 80% of 
> the available ram, download in multiple files and warn   the   user about 
> it.
> * I don't know about the time-out issue.  
>
> An alternative (and easier option) would be to warn the user that the 
> result is too large to be downloaded in one file and advise him/her to 
> adapt the query to get the result in smaller portions.  
>
> Regards
> Johann
> -- 
> Because experiencing your loyal love is better than life itself, 
> my lips will praise you.  (Psalm 63:3)
>
>

-- 





Re: [web2py] Re: Help with db query

2012-11-07 Thread Niphlod
field in something is NOT supported (Man, you should check both the web2py 
book and general python syntax, or you'll loose a lot of time)

Your prototype in python pointed to have something ORed, i.e. if 
request.args(0) is None, then slip it in 'Both'.

What instead you're trying to achieve is querying for 'Both' AND 
request.args(0) at all times

you want a query like this in sql

select * from table 
where 
something1 = 'whatisthereinrequest.args(1)'
AND (
something2 = 'whatisthereinrequest.args(2)' 
OR
something2 = 'Both'
)



This is achieved with 
((something1 == request.args(1)) & ((something2 == request.args(0)) | 
(something2 
== 'Both')))



If you want instead something like 
select * from table 
where 
something1 = 'whatisthereinrequest.args(1)'
AND something2 IN ('whatisthereinrequest.args(2)' , 'Both')



you should do 
((something == request.args(1)) & (something2.belongs((request.args(0),
'Both'




-- 





[web2py] Re: SQLFORM.factory

2012-11-07 Thread Niphlod
create a fresh app and paste your code in it. It shouldn't go in exception

form = SQLFORM.factory(
Field('relatie_id', writable=False, readable=False),
Field('relatie_nummer', writable=False, readable=False),
Field('direction', writable=False, readable=False),
Field('protocol', writable=False, readable=False),
Field('email', requires=IS_EMAIL())
)



This doesn't

On Wednesday, November 7, 2012 12:12:24 PM UTC+1, Wouter Pronk wrote:
>
> Hello Niphlod,
> this is the traceback:
>
> Traceback (most recent call last):
>   File "/home/wouter/Web2py/web2py/gluon/restricted.py", line 212, in 
> restricted
> exec ccode in environment
>   File 
> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py" 
> ,
>  line 381, in 
>   File "/home/wouter/Web2py/web2py/gluon/globals.py", line 188, in 
> self._caller = lambda f: f()
>   File 
> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py" 
> ,
>  line 200, in add_protocol
> Field('relatie_id', writable=False, readable=False),
> TypeError: __init__() takes exactly 1 argument (4 given)
>
> Where should I look?
>
>
> Op woensdag 7 november 2012 11:54:24 UTC+1 schreef Niphlod het volgende:
>>
>> something else is wrong in your app, that piece of code works perfectly 
>> fine (the fact that you're declaring 5 fields to let display only one is 
>> quite not understandable but hey, it works nonetheless)
>>
>> On Wednesday, November 7, 2012 11:32:39 AM UTC+1, Wouter Pronk wrote:
>>>
>>> I have the following code:
>>> form = SQLFORM.factory(
>>> Field('relatie_id', writable=False, readable=False),
>>> Field('relatie_nummer', writable=False, readable=False),
>>> Field('direction', writable=False, readable=False),
>>> Field('protocol', writable=False, readable=False),
>>> Field('email', requires=[IS_EMAIL(),IS_NOT_IN_DB(db, 
>>> 'comprotocol.email')]))
>>>
>>> and this is working perfectly in version 1.99 but not in 2.2.1. I get an 
>>> error:
>>>
>>>  File 
>>> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py"
>>>  
>>> ,
>>>  line 199, in add_protocol
>>> Field('relatieid', writable=False, readable=False),
>>> TypeError: __init__() takes exactly 1 argument (4 given
>>>
>>> What is wrong?
>>>
>>

-- 





[web2py] Re: SQLFORM.factory

2012-11-07 Thread Wouter Pronk
Hello Niphlod,
this is the traceback:

Traceback (most recent call last):
  File "/home/wouter/Web2py/web2py/gluon/restricted.py", line 212, in restricted
exec ccode in environment
  File 
"/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py" 
, 
line 381, in 
  File "/home/wouter/Web2py/web2py/gluon/globals.py", line 188, in 
self._caller = lambda f: f()
  File 
"/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py" 
, 
line 200, in add_protocol
Field('relatie_id', writable=False, readable=False),
TypeError: __init__() takes exactly 1 argument (4 given)

Where should I look?


Op woensdag 7 november 2012 11:54:24 UTC+1 schreef Niphlod het volgende:
>
> something else is wrong in your app, that piece of code works perfectly 
> fine (the fact that you're declaring 5 fields to let display only one is 
> quite not understandable but hey, it works nonetheless)
>
> On Wednesday, November 7, 2012 11:32:39 AM UTC+1, Wouter Pronk wrote:
>>
>> I have the following code:
>> form = SQLFORM.factory(
>> Field('relatie_id', writable=False, readable=False),
>> Field('relatie_nummer', writable=False, readable=False),
>> Field('direction', writable=False, readable=False),
>> Field('protocol', writable=False, readable=False),
>> Field('email', requires=[IS_EMAIL(),IS_NOT_IN_DB(db, 
>> 'comprotocol.email')]))
>>
>> and this is working perfectly in version 1.99 but not in 2.2.1. I get an 
>> error:
>>
>>  File 
>> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py" 
>> ,
>>  line 199, in add_protocol
>> Field('relatieid', writable=False, readable=False),
>> TypeError: __init__() takes exactly 1 argument (4 given
>>
>> What is wrong?
>>
>

-- 





Re: [web2py] Re: Help with db query

2012-11-07 Thread hasan alnator
and i even tried :

items  =[]
items.append(request.args(0))
items.append('Both')

db( (db.table.Field1 == value) & (db.table.Field2 in items))


regards,


On Wed, Nov 7, 2012 at 12:56 PM, hasan alnator
wrote:

> Dear Joe ,
>
> What i want to do is to have a query like this :
>
> db( (db.table.Field1 == value) & (db.table.Field2 == value or value))
>
> i tried it i get no errors but its now working
>
> Regards
>
>
> On Wed, Nov 7, 2012 at 10:10 AM, Joe Barnhart wrote:
>
>> I see -- you're right.
>>
>> The request.args structure is a List() object which web2py defines to
>> retrieve values without the exception if it doesn't exist.  It has some
>> additional interesting capabilities...  You can define a default value,
>> such as this:
>>
>>
>> request.args(0,default='Both')
>>
>>
>> This will substitute the value 'Both' for request.args[0] should it be
>> set to None or be invalid.  Or you could cast a string value to an integer
>> -- this often happens since the request.args are strings by default, but I
>> often pass row ids to be processed elsewhere:
>>
>>
>> URL('default','editrecord',args=[22])
>>
>>
>> Becomes:
>>
>>
>> http://./default/editrecord/22
>>
>>
>> And request.args[0] is now '22' (the string).  So we use the "cast"
>> keyword to change it to an int:
>>
>>
>> request.args(0,cast=int)
>>
>>
>> There is a ton of behavior in this little class!  Thanks for pointing it
>> out to me.
>>
>> -- Joe Barnhart
>>
>>
>> class List(list):
>> """
>> Like a regular python list but a[i] if i is out of bounds return None
>> instead of IndexOutOfBounds
>> """
>>
>> def __call__(self, i, default=None, cast=None, otherwise=None):
>> """
>> request.args(0,default=0,cast=int,otherwise='http://error_url')
>> request.args(0,default=0,cast=int,otherwise=lambda:...)
>> """
>> n = len(self)
>> if 0 <= i < n or -n <= i < 0:
>> value = self[i]
>> else:
>> value = default
>> if cast:
>> try:
>> value = cast(value)
>> except (ValueError, TypeError):
>> from http import HTTP, redirect
>> if otherwise is None:
>> raise HTTP(404)
>> elif isinstance(otherwise, str):
>> redirect(otherwise)
>> elif callable(otherwise):
>> return otherwise()
>> else:
>> raise RuntimeError("invalid otherwise")
>> return value
>>
>>
>>
>>
>> On Tuesday, November 6, 2012 2:24:53 PM UTC-8, Niphlod wrote:
>>>
>>>
>>> One more point -- your "request.args(1)" should be "request.args[1]"
 (with square brackets).  The first form calls request.args as a function
 and passes it the value "1".   The second form treats request.args as a
 Storage object and asks for the subscript "1".

 -- Joe Barnhart

 Nope, request.args(1) does basically
>>> try:
>>>   result = request.args[1]
>>> except:
>>>   result = None
>>> return result
>>>
>>> the () notation is safer because using request.args[1] if there is no
>>> request.args[1] you get an exception.
>>>
>>  --
>>
>>
>>
>>
>
>

-- 





Re: [web2py] Re: Help with db query

2012-11-07 Thread hasan alnator
Dear Joe ,

What i want to do is to have a query like this :

db( (db.table.Field1 == value) & (db.table.Field2 == value or value))

i tried it i get no errors but its now working

Regards


On Wed, Nov 7, 2012 at 10:10 AM, Joe Barnhart wrote:

> I see -- you're right.
>
> The request.args structure is a List() object which web2py defines to
> retrieve values without the exception if it doesn't exist.  It has some
> additional interesting capabilities...  You can define a default value,
> such as this:
>
>
> request.args(0,default='Both')
>
>
> This will substitute the value 'Both' for request.args[0] should it be set
> to None or be invalid.  Or you could cast a string value to an integer --
> this often happens since the request.args are strings by default, but I
> often pass row ids to be processed elsewhere:
>
>
> URL('default','editrecord',args=[22])
>
>
> Becomes:
>
>
> http://./default/editrecord/22
>
>
> And request.args[0] is now '22' (the string).  So we use the "cast"
> keyword to change it to an int:
>
>
> request.args(0,cast=int)
>
>
> There is a ton of behavior in this little class!  Thanks for pointing it
> out to me.
>
> -- Joe Barnhart
>
>
> class List(list):
> """
> Like a regular python list but a[i] if i is out of bounds return None
> instead of IndexOutOfBounds
> """
>
> def __call__(self, i, default=None, cast=None, otherwise=None):
> """
> request.args(0,default=0,cast=int,otherwise='http://error_url')
> request.args(0,default=0,cast=int,otherwise=lambda:...)
> """
> n = len(self)
> if 0 <= i < n or -n <= i < 0:
> value = self[i]
> else:
> value = default
> if cast:
> try:
> value = cast(value)
> except (ValueError, TypeError):
> from http import HTTP, redirect
> if otherwise is None:
> raise HTTP(404)
> elif isinstance(otherwise, str):
> redirect(otherwise)
> elif callable(otherwise):
> return otherwise()
> else:
> raise RuntimeError("invalid otherwise")
> return value
>
>
>
>
> On Tuesday, November 6, 2012 2:24:53 PM UTC-8, Niphlod wrote:
>>
>>
>> One more point -- your "request.args(1)" should be "request.args[1]"
>>> (with square brackets).  The first form calls request.args as a function
>>> and passes it the value "1".   The second form treats request.args as a
>>> Storage object and asks for the subscript "1".
>>>
>>> -- Joe Barnhart
>>>
>>> Nope, request.args(1) does basically
>> try:
>>   result = request.args[1]
>> except:
>>   result = None
>> return result
>>
>> the () notation is safer because using request.args[1] if there is no
>> request.args[1] you get an exception.
>>
>  --
>
>
>
>

-- 





[web2py] Re: SQLFORM.factory

2012-11-07 Thread Niphlod
something else is wrong in your app, that piece of code works perfectly 
fine (the fact that you're declaring 5 fields to let display only one is 
quite not understandable but hey, it works nonetheless)

On Wednesday, November 7, 2012 11:32:39 AM UTC+1, Wouter Pronk wrote:
>
> I have the following code:
> form = SQLFORM.factory(
> Field('relatie_id', writable=False, readable=False),
> Field('relatie_nummer', writable=False, readable=False),
> Field('direction', writable=False, readable=False),
> Field('protocol', writable=False, readable=False),
> Field('email', requires=[IS_EMAIL(),IS_NOT_IN_DB(db, 
> 'comprotocol.email')]))
>
> and this is working perfectly in version 1.99 but not in 2.2.1. I get an 
> error:
>
>  File 
> "/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py" 
> ,
>  line 199, in add_protocol
> Field('relatieid', writable=False, readable=False),
> TypeError: __init__() takes exactly 1 argument (4 given
>
> What is wrong?
>

-- 





[web2py] track_changes

2012-11-07 Thread Massimiliano
Version 2.2.1 (2012-11-06 14:26:21) stable

It's just me or it doesn't work anymore?

-- 
Massimiliano

-- 





Re: [web2py] Re: DAL insert dictionary fails

2012-11-07 Thread Johann Spies
On 7 November 2012 12:16, Johann Spies  wrote:

> The result:
>
> {'ui': '0002851186', 'py': '2010', 'vl': '24', 'ris': '4', 'pd': 'NOV'}
> Traceback (most recent call last):
>   File "/home/js/web2py/gluon/shell.py", line 223, in run
> execfile(startfile, _env)
>   File "/home/js/dokumente/werk/senwet/isi-data/data/lees_isi.py", line
> 412, in 
> hanteer_data(data)
>   File "/home/js/dokumente/werk/senwet/isi-data/data/lees_isi.py", line
> 368, in hanteer_data
> hanteer_joernaal(data)
>   File "/home/js/dokumente/werk/senwet/isi-data/data/lees_isi.py", line
> 361, in hanteer_joernaal
> skryf_joernaaldata(joernaal, publisher, uitgawe)
>   File "/home/js/dokumente/werk/senwet/isi-data/data/lees_isi.py", line
> 322, in skryf_joernaaldata
> rpub_id = db.rjoern_uitgawe.insert(**uitg)
>   File "/home/js/web2py/gluon/dal.py", line 7867, in insert
> self._attempt_upload(fields)
>   File "/home/js/web2py/gluon/dal.py", line 7852, in _attempt_upload
> if field.type=='upload' and field.name in fields:
> AttributeError: 'str' object has no attribute 'type'
>
>
>
> What is going on here?
>
>
I found the problem:  'rj_id' was  missing from the dict.  How does the
error message relate to that?

Regards

Johann
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

-- 





Re: [web2py] SQLFORM.grid exports the whole table

2012-11-07 Thread Niphlod
woking on 1.
for 2, how do you "foresee" how much time and RAM the present query will 
take to be serialized ?

On Wednesday, November 7, 2012 11:25:29 AM UTC+1, Johann Spies wrote:
>
> On 7 November 2012 10:56, Niphlod > wrote:
>
>> uhm, good point on "if you want the entire table, just remove the 
>> filters".
>> how to handle something that is impossible to handle (export a table with 
>> so many rows that you can't export without timeouts or consuming 
>> memory). just timeout ?
>>
>
> I had a situation on Webfaction where a customer downloaded a csv file 
> (before the time of smartgrid) which put too much strain on the available 
> RAM and the result was incorrect and inconsistent. In the end I had to use 
> the backend (postgresql) through ssh to get the correct data.
>
> I suspect that one can put something like 'limitby' into the csv-query and 
> download several files if it exceeds a certain ceiling.
>
> I am working with sets of data of which some tables can contain millions 
> of records. 
>
> So there are two issues in this thread:
>
> 1.  The csv-download buttons in smartgrid/grid should download the result 
> of the present query
> 2.  Some safeguards should be build to prevent large datasets to consume 
> too much memory or time.
>
> Regards
> Johann
> -- 
> Because experiencing your loyal love is better than life itself, 
> my lips will praise you.  (Psalm 63:3)
>
>

-- 





[web2py] SQLFORM.factory

2012-11-07 Thread Wouter Pronk
I have the following code:
form = SQLFORM.factory(
Field('relatie_id', writable=False, readable=False),
Field('relatie_nummer', writable=False, readable=False),
Field('direction', writable=False, readable=False),
Field('protocol', writable=False, readable=False),
Field('email', requires=[IS_EMAIL(),IS_NOT_IN_DB(db, 
'comprotocol.email')]))

and this is working perfectly in version 1.99 but not in 2.2.1. I get an 
error:

 File 
"/home/wouter/Web2py/web2py/applications/edirelaties/controllers/default.py" 
, 
line 199, in add_protocol
Field('relatieid', writable=False, readable=False),
TypeError: __init__() takes exactly 1 argument (4 given

What is wrong?

-- 





[web2py] Re: DAL insert dictionary fails

2012-11-07 Thread Johann Spies
On Saturday, 1 October 2011 09:40:26 UTC+2, seongjoo wrote:
>
> I figured out what the problem was but forgot to come back to the 
> forum. 
>
> The problem was that the keys of the dictionary was encoded as 
> unicode, for example u'keyname'. It was in unicode because the dict is 
> loaded from json. Specify their encoding as UTF-8 with following 
> routine, solved the problem. 
>
> def loadFromJson(jsonData): 
> data=json.loads(jsonData, encoding='utf-8') 
>
> #encode the keys as UTF-8 
> return dict((k.encode('utf-8'),v) for (k,v) in data.items()) 
>

I have a related problem but this solution does not help me.


The model:

db.define_table('rjoern_uitgawe',
Field('ui', 'string', length=10), #unieke id
Field('rj_id',
requires = IS_IN_DB(db, db.rjoernaal.sn, '%(so)s')), 
#joernaal
Field('vl', length=10), # volume
Field('ris', length=10), # issue
Field('py', length=4), #publication year
Field('pd', length=20), #publication date
Field('su', length=10), #supplement
Field('si', length=10) #special issue
)

The code:

   
321 print uitg 
322 rpub_id = db.rjoern_uitgawe.insert(**uitg)


The result:

{'ui': '0002851186', 'py': '2010', 'vl': '24', 'ris': '4', 'pd': 'NOV'}
Traceback (most recent call last):
  File "/home/js/web2py/gluon/shell.py", line 223, in run
execfile(startfile, _env)
  File "/home/js/dokumente/werk/senwet/isi-data/data/lees_isi.py", line 412, 
in 
hanteer_data(data)
  File "/home/js/dokumente/werk/senwet/isi-data/data/lees_isi.py", line 368, 
in hanteer_data
hanteer_joernaal(data)
  File "/home/js/dokumente/werk/senwet/isi-data/data/lees_isi.py", line 361, 
in hanteer_joernaal
skryf_joernaaldata(joernaal, publisher, uitgawe)
  File "/home/js/dokumente/werk/senwet/isi-data/data/lees_isi.py", line 322, 
in skryf_joernaaldata
rpub_id = db.rjoern_uitgawe.insert(**uitg)
  File "/home/js/web2py/gluon/dal.py", line 7867, in insert
self._attempt_upload(fields)
  File "/home/js/web2py/gluon/dal.py", line 7852, in _attempt_upload
if field.type=='upload' and field.name in fields:
AttributeError: 'str' object has no attribute 'type'



What is going on here?

Regards
Johann

-- 





Re: [web2py] SQLFORM.grid exports the whole table

2012-11-07 Thread Niphlod
uhm, good point on "if you want the entire table, just remove the filters".
how to handle something that is impossible to handle (export a table with 
so many rows that you can't export without timeouts or consuming 
memory). just timeout ?

On Wednesday, November 7, 2012 2:17:02 AM UTC+1, howesc wrote:
>
> i agree that i expected the export buttons to export what is shown above.  
> if you want to export the whole table, remove all filters so that the whole 
> table is shown above and then click export.
>
> (note that i do expect export to export all the rows that match the query 
> even if the table above is paginated).  what i don't know is how we should 
> handle tables that are so large that the export function will timeout or 
> consume too much memory to complete.
>
> christian
>
> On Tuesday, November 6, 2012 8:34:58 AM UTC-8, Bill Thayer wrote:
>>
>> FWIW, My users will be filtering test station settings to upload the csv 
>> to thier test bench software. My users will need only thier own filtered 
>> data in the CSVso big Me Too! here
>
>

-- 





[web2py] Re: problem with share button

2012-11-07 Thread peter
Does the share button work properly for anyone when using google+? If it 
works for you, is there any tip that you have. If it does not work for 
anyone, can this bug be fixed.
Thanks
Peter

On Sunday, 4 November 2012 11:08:47 UTC, peter wrote:
>
> I just tried filling in this bit in db.py
>
> ## 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'
>
> with my details but I still get the same error message.
>
> Peter
>
> On Sunday, 4 November 2012 10:51:31 UTC, peter wrote:
>>
>> With 2.2.1 stable.
>> *On the welcome App, if I click the share button bottom right, and then 
>> google+, fill in the comment and target email address, and then click 
>> 'share' I get:*
>>
>> There was a problem saving your post. Please try again.
>>
>> this happens repeatedly.
>>
>> Peter
>>
>

-- 





[web2py] Re: Error when trying to upload large application to web2py.

2012-11-07 Thread Niphlod
were you seriously thinking about transferring 1.9gb of files through an 
"upload" form ?
transfer the app using other methods such as ssh or ftp.

On Wednesday, November 7, 2012 8:08:20 AM UTC+1, Kimmo wrote:
>
>
> Hi,
>
> I have a packed a Web2py application that is about 1.9Gb (lots of upload 
> files). When trying to upload it to production server the following error 
> occurs:
>
> Traceback (most recent call last):
>   File "/home/tempName/web2py/gluon/restricted.py", line 212, in restricted
> exec ccode in environment
>   File "/home/ 
> tempName/web2py/applications/admin/controllers/default.py"
>  , line 
> 1775, in 
>   File "/home/tempName/web2py/gluon/globals.py", line 188, in 
> self._caller = lambda f: f()
>   File "/home/ 
> tempName/web2py/applications/admin/controllers/default.py"
>  , line 
> 212, in site
> form_update.process()
>   File "/home/tempName/web2py/gluon/html.py", line 2170, in process
> self.validate(**kwargs)
>   File "/home/tempName/web2py/gluon/html.py", line 2109, in validate
> if self.accepts(**kwargs):
>   File "/home/tempName/web2py/gluon/sqlhtml.py", line 1281, in accepts
> **kwargs
>   File "/home/tempName/web2py/gluon/html.py", line 2022, in accepts
> self._traverse(False, hideerror)
>   File "/home/tempName/web2py/gluon/html.py", line 842, in _traverse
> newstatus = c._traverse(status, hideerror) and newstatus
>   File "/home/tempName/web2py/gluon/html.py", line 842, in _traverse
> newstatus = c._traverse(status, hideerror) and newstatus
>   File "/home/tempName/web2py/gluon/html.py", line 842, in _traverse
> newstatus = c._traverse(status, hideerror) and newstatus
>   File "/home/tempName/web2py/gluon/html.py", line 842, in _traverse
> newstatus = c._traverse(status, hideerror) and newstatus
>   File "/home/tempName/web2py/gluon/html.py", line 853, in _traverse
> self._postprocessing()
>   File "/home/tempName/web2py/gluon/html.py", line 1762, in _postprocessing
> _value = str(self['_value'])
>   File "/usr/lib/python2.7/cgi.py", line 515, in __repr__
> self.name, self.filename, self.value)
> OverflowError: string is too large to make repr
>
>
> Web2py is 2.2.1.
>
> Does anyone have clues why this is happening and how to get past this?
>
> Kimmo
>

-- 





Re: [web2py] Re: Prevent translation of the labels in the Log In form

2012-11-07 Thread Jan Rozhon
Sorry, I had a typo in the line. Now it is working - put 
auth.messages.label_password= 'Password ' with space in the model.


Thank you very much Niphlod


On 06/11/12 23:53, Niphlod wrote:

did you put that between
auth = Auth(...)
and
auth.define_tables() ?


On Tuesday, November 6, 2012 11:32:18 PM UTC+1, Jan Rozhon wrote:

Nope, no change still the local translation of the word "Password"
in the form :(. Inserted into db.py in the auth section.

Jan

Dne úterý, 6. listopadu 2012 16:18:49 UTC+1 Niphlod napsal(a):

if you don't change the string that has already a translation
it gets translated.
try with auth.messages.label_password= 'Password ##fixed in
english'

Il giorno martedě 6 novembre 2012 15:56:50 UTC+1, Jan Rozhon
ha scritto:

Hi, thanks for quick hint. Tried
adding auth.messages.label_password= 'Password' into my
model, but the label still gets translated. I modified it
to 'test', but the label didnt change.

Jan

Dne úterý, 6. listopadu 2012 15:29:48 UTC+1 Niphlod
napsal(a):

auth.messages settings... these are the defaults, but
they get to be translated by default (and normally is
a good thing). If you set them as
auth.messages.label_first_name = 'test' they shouldn't
be translated at all.

label_first_name='First name',
label_last_name='Last name',
label_username='Username',
label_email='E-mail',
label_password='Password',
label_registration_key='Registration key',
label_reset_password_key='Reset Password key',
label_registration_id='Registration identifier',
label_role='Role',
label_description='Description',
label_user_id='User ID',
label_group_id='Group ID',
label_name='Name',
label_table_name='Object or table name',
label_record_id='Record ID',
label_time_stamp='Timestamp',
label_client_ip='Client IP',
label_origin='Origin',
label_remember_me="Remember me (for 30 days)",

On Tuesday, November 6, 2012 3:06:08 PM UTC+1, Jan
Rozhon wrote:

Hi, I am facing the problem that my Login
(.../user/login) form uses translations for its
labels and I need to forbid this behavior. What is
the correct way of doing this?

Thanks, Jan

--





--





[web2py] Re: Help with db query

2012-11-07 Thread Joe Barnhart
I see -- you're right.

The request.args structure is a List() object which web2py defines to 
retrieve values without the exception if it doesn't exist.  It has some 
additional interesting capabilities...  You can define a default value, 
such as this:


request.args(0,default='Both')


This will substitute the value 'Both' for request.args[0] should it be set 
to None or be invalid.  Or you could cast a string value to an integer -- 
this often happens since the request.args are strings by default, but I 
often pass row ids to be processed elsewhere:


URL('default','editrecord',args=[22])


Becomes:


http://./default/editrecord/22


And request.args[0] is now '22' (the string).  So we use the "cast" keyword 
to change it to an int:


request.args(0,cast=int)


There is a ton of behavior in this little class!  Thanks for pointing it 
out to me.

-- Joe Barnhart


class List(list):
"""
Like a regular python list but a[i] if i is out of bounds return None
instead of IndexOutOfBounds
"""

def __call__(self, i, default=None, cast=None, otherwise=None):
"""
request.args(0,default=0,cast=int,otherwise='http://error_url')
request.args(0,default=0,cast=int,otherwise=lambda:...)
"""
n = len(self)
if 0 <= i < n or -n <= i < 0:
value = self[i]
else:
value = default
if cast:
try:
value = cast(value)
except (ValueError, TypeError):
from http import HTTP, redirect
if otherwise is None:
raise HTTP(404)
elif isinstance(otherwise, str):
redirect(otherwise)
elif callable(otherwise):
return otherwise()
else:
raise RuntimeError("invalid otherwise")
return value




On Tuesday, November 6, 2012 2:24:53 PM UTC-8, Niphlod wrote:
>
>
> One more point -- your "request.args(1)" should be "request.args[1]" 
>> (with square brackets).  The first form calls request.args as a function 
>> and passes it the value "1".   The second form treats request.args as a 
>> Storage object and asks for the subscript "1".
>>
>> -- Joe Barnhart
>>
>> Nope, request.args(1) does basically
> try:
>   result = request.args[1]
> except:
>   result = None
> return result
>
> the () notation is safer because using request.args[1] if there is no 
> request.args[1] you get an exception. 
>

--