Re: [web2py] Getting drop-down value names from grandparent record

2012-07-09 Thread Johann Spies
On 10 July 2012 01:09, MichaelF  wrote:

>
>lambda r: '%s' % (db.I1[db.C1_2[r.C1_2].I1].Name),
>_and=IS_NOT_IN_DB(db(db.C1_2_3.C1_2==request.vars.C1_2), 'C1_2_3.C3'))
> db.C1_2_3.C1_2.requires=IS_IN_DB(db, 'C1_2.id',
>
> ...

> 1. Am I even allowed to have a lambda function there?
> 2. In any case, how can I get the drop-down to show me I1.Name?
>

I would try the following:

A separate function to do what you tried to do in your lambda.
Let the lambda call that function which returns the value you want .

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


Re: [web2py] Re: Has anyone done a detailed security analysis or attempted a methodical attack on web2py?

2012-07-09 Thread Jason Brower
I know a few of these guys, and they relly seem to know their stuff.  
Let's see if they take the bait. :)  They know python and webservices 
very well.

BR,
Jason Brower

On 07/10/2012 01:24 AM, Massimo Di Pierro wrote:

No but I am willing to pay to get it done.

On Monday, 9 July 2012 10:48:39 UTC-5, scausten wrote:

One of the awesome things about web2py is of course the built-in
and well-documented resilience against a range of attack methods,
but I was wondering if anyone has attempted a methodical
(white-hat) attack to probe any potential weaknesses?

Just out of interest :)






[web2py] Re: Issue getting Janrain working

2012-07-09 Thread Dave
I figured it out...  The trunk welcome (and all default apps) are missing 
the conditional for the reset password in the view...  Here is a patch:

--- welcome/views/default/user.html 2012-07-04 17:54:18.0 -0400
+++ socialjack/views/default/user.html  2012-07-10 00:57:48.0 -0400
@@ -2,10 +2,12 @@
 {{=T( request.args(0).replace('_',' ').capitalize() )}}
 
 {{if request.args(0)=='login':}}
-{{if not 'register' in auth.settings.actions_disabled:}}
-{{form.add_button(T('Register'),URL(args='register'))}}
-{{pass}}
-{{form.add_button(T('Lost 
Password'),URL(args='request_reset_password'))}}
+{{if not 'register' in auth.settings.actions_disabled:}}
+{{form.add_button(T('Register'),URL(args='register'))}}
+{{pass}}
+{{if not 'request_reset_password' in 
auth.settings.actions_disabled:}}
+{{form.add_button(T('Lost 
Password'),URL(args='request_reset_password'))}}
+{{pass}}
 {{pass}}
 {{=form}}
 

On Tuesday, July 10, 2012 12:27:39 AM UTC-4, Dave wrote:
>
> I am running latest trunk.
>
> Added the private/janrain.key file as prescribed with the domain:key
>
> When navigating to the /default/user/login page I get a 500 server error. 
>  It appears that the reset_password button is trying to be rendered even 
> though using janrain should disable it.  I tried manually disabling as well.
>
> Any ideas?
>
> ('IFRAME' object has no attribute 
> 'add_button')
>
> 70.
> 71.
> 72.
> 73.
> 74.
> 75.
> 76.
> 77.
> 78.
> 79.
>
> 80.
> 81.
> 82.
> 83.
> 84.
> 85.
> 86.
> 87.
> 88.
> 89.
>
> response.write('\n\n', escape=False)
> if request.args(0)=='login':
> response.write('\n', escape=False)
> if not 'register' in auth.settings.actions_disabled:
> response.write('\n', escape=False)
> form.add_button(T('Register'),URL(args='register'))
> response.write('\n', escape=False)
> pass
> response.write('\n', escape=False)
> form.add_button(T('Lost Password'),URL(args='request_reset_password'))
>
> response.write('\n', escape=False)
> pass
> response.write('\n', escape=False)
> response.write(form)
>
>

[web2py] Multiple select Web2py

2012-07-09 Thread Kevin Miller
Hi all,

I have a multiple select that I attach to a  auth user profile.
However, after I save the profile and log back in, I don't see the selected
values when I am editing the profile form.

Any ideas.

Thank you all very much.


[web2py] Issue getting Janrain working

2012-07-09 Thread Dave
I am running latest trunk.

Added the private/janrain.key file as prescribed with the domain:key

When navigating to the /default/user/login page I get a 500 server error. 
 It appears that the reset_password button is trying to be rendered even 
though using janrain should disable it.  I tried manually disabling as well.

Any ideas?

('IFRAME' object has no attribute 
'add_button')

70.
71.
72.
73.
74.
75.
76.
77.
78.
79.

80.
81.
82.
83.
84.
85.
86.
87.
88.
89.

response.write('\n\n', escape=False)
if request.args(0)=='login':
response.write('\n', escape=False)
if not 'register' in auth.settings.actions_disabled:
response.write('\n', escape=False)
form.add_button(T('Register'),URL(args='register'))
response.write('\n', escape=False)
pass
response.write('\n', escape=False)
form.add_button(T('Lost Password'),URL(args='request_reset_password'))

response.write('\n', escape=False)
pass
response.write('\n', escape=False)
response.write(form)
response.write('\n\n\n\n', escape=False)
response.write('\r\n\r\n\r\n\r\n  
  ©2012 Social Jack\r\n\r\n', escape=False)
response.write(A(IMG(_src=URL('static', 'images/btn_facebook.png')), 
_href='http://www.facebook.com/ForwardProgress', _title='Like Us On Facebook' 
,_target='_blank'))
response.write('\r\n', escape=False)
response.write(A(IMG(_src=URL('static', 'images/btn_twitter.png')), 
_href='http://twitter.com/#!/deandelisle', _title='Follow Us On Twitter' 
,_target='_blank'))
response.write('\r\n', escape=False)



[web2py] Re: list:string & crud form entry -- what's the latest?

2012-07-09 Thread Anthony

>
> Yah, I tried the Enter key, and a lot of other combinations of control 
> and/or shift + enter as well as an abracadabra (on Chrome (didn't try any 
> other browser)), but none of them got the list:string to represent except 
> as a single string field. No additional string fields magically appeared, 
> as hoped for.


Hmm, it works for me. What does your code look like?
 

> I think a stronger widget is needed for this very useful construct. I use 
> list:string in lots of places and having a handy way of editing them is 
> essential.
>

+1
 

> Obviously, not being able to delete a string after entry makes any 
> list:string editor DOA.
>

Agreed, though I think if you simply delete the content of the text box, no 
value is submitted for it.
 

> I will submit a formal enhancement request, if it hasn't already been done.
>

It probably makes sense to find a nice existing JS widget and adopt it.

Anthony


[web2py] Re: Upload file into DB without SQLFORM

2012-07-09 Thread Anthony
Makes sense. I updated the book to reflect this: 
http://web2py.com/books/default/chapter/29/6#Manual-uploads.

Anthony

On Monday, July 9, 2012 10:26:52 PM UTC-4, Massimo Di Pierro wrote:
>
> The problem is this:
>
> db.table.insert(field = db.table.field.store(...))
>
> db.field.store is executed before db.table.insert therefore before the 
> record is created.
>
> there are three options:
> 1) db.table.field.uploadfield==True (the default) no problem. store() 
> uploads to filesystem because it filesystem exists before insert()
> 2) db.table.field.uploadfield=='blobfield' store() cannot upload because 
> insert was not executed therefore there is no pace to read it into.
> 3) db.table.field.uploadfield==db.othertable.field  in this case store() 
> will upload into the other table (a table used only to store uploaded 
> files) a new record is created in the othertable before the current insert()
>
> One could do more automation in 2 but there would be a lot of magic under 
> the hood that would result in non-intuitive behavior. Moreover it would 
> make more difficult manipulation of the file content on upload.
>
> On Monday, 9 July 2012 19:39:34 UTC-5, Anthony wrote:
>>
>> On Monday, July 9, 2012 7:59:50 PM UTC-4, Derek wrote:
>>>
>>> That is correct, that's how it's documented as well.
>>>
>>
>> Is it documented that the file storage is not handled when the file is 
>> stored in a blob field rather than the filesystem?
>>
>> Anthony 
>>
>

[web2py] Re: Upload file into DB without SQLFORM

2012-07-09 Thread Massimo Di Pierro
The problem is this:

db.table.insert(field = db.table.field.store(...))

db.field.store is executed before db.table.insert therefore before the 
record is created.

there are three options:
1) db.table.field.uploadfield==True (the default) no problem. store() 
uploads to filesystem because it filesystem exists before insert()
2) db.table.field.uploadfield=='blobfield' store() cannot upload because 
insert was not executed therefore there is no pace to read it into.
3) db.table.field.uploadfield==db.othertable.field  in this case store() 
will upload into the other table (a table used only to store uploaded 
files) a new record is created in the othertable before the current insert()

One could do more automation in 2 but there would be a lot of magic under 
the hood that would result in non-intuitive behavior. Moreover it would 
make more difficult manipulation of the file content on upload.

On Monday, 9 July 2012 19:39:34 UTC-5, Anthony wrote:
>
> On Monday, July 9, 2012 7:59:50 PM UTC-4, Derek wrote:
>>
>> That is correct, that's how it's documented as well.
>>
>
> Is it documented that the file storage is not handled when the file is 
> stored in a blob field rather than the filesystem?
>
> Anthony 
>


[web2py] Re: IDs position in URLs and SEO

2012-07-09 Thread Massimo Di Pierro
After lots of experimentation I think the stack overflow approach is best 
(assuming the slug part is generated in the links but ignored).

First of all you already have the record id therefore you do not need to 
look-it up. Second you can edit the slug (because for example of a mistake) 
and you do not break the url. It is still very readable. If somebody needs 
to dictate the url over the phone, they only need to get the numeric part 
right.

The numeric part can be compressed using a URL shortened and does not need 
to be a number.

Massimo

On Monday, 9 July 2012 18:38:20 UTC-5, Francisco Costa wrote:
>
> Some web applications with restful URLs like Foursquare (
> https://foursquare.com/v/restaurante-baobab/*4bed589a75feef3b8d0197e6*)
>  
> put ID's at the end of the URL, some others like StackOverflow (
> http://stackoverflow.com/questions/*11394640*
> /pros-and-cons-of-ids-at-the-end-of-the-url)
>  
> put them in the middle, just before the title slug..
>
> There are even others like Quora (
> http://www.quora.com/Is-there-any-difference-in-terms-of-SEO-between-the-URL-REST-formats-on-Quora-and-StackOverflow)
>  
> that don't put them at all, only use the slug.
>
> In your opinion wish one is best for information management and 
> performance? What is the impact in terms of SEO?
>


[web2py] Re: list:string & crud form entry -- what's the latest?

2012-07-09 Thread weheh
Yah, I tried the Enter key, and a lot of other combinations of control 
and/or shift + enter as well as an abracadabra (on Chrome (didn't try any 
other browser)), but none of them got the list:string to represent except 
as a single string field. No additional string fields magically appeared, 
as hoped for.

I think a stronger widget is needed for this very useful construct. I use 
list:string in lots of places and having a handy way of editing them is 
essential. Obviously, not being able to delete a string after entry makes 
any list:string editor DOA. (Needs an (x) button at end of string field 
that, if clicked, prompts user to confirm delete & then deletes field from 
form and db entry when submitted.

I will submit a formal enhancement request, if it hasn't already been done.

Thanks for the tip on IS_LIST_OF. Must print out & read doc again one of 
these days.


On Monday, July 9, 2012 11:11:53 PM UTC+8, Anthony wrote:
>
> Well, by default, the list:string field type does get a special Javascript 
> widget, though the functionality could probably be improved. After you 
> enter an item in the initial text box, hit enter, and a new box should 
> appear below it, and so on. There is no way to remove a box once created.
>
> Regardless of the widget, you can apply an email validator to each item in 
> a list:string input using IS_LIST_OF(IS_EMAIL()). The only caveat is that 
> validation errors will not automatically be displayed on the form, so you 
> have to explicitly check for a validation error on that field and implement 
> a custom error display.
>
> Anthony
>
> On Monday, July 9, 2012 10:15:34 AM UTC-4, weheh wrote:
>>
>> This has been an oft-disucssed topic. Just search for "list:string crud" 
>> But having just experienced the pain myself, and not easily locating the 
>> status of this issue, I felt compelled to ask for myself: 
>>
>> Shouldn't list:string have a default interactive (jQuery OK) widget that 
>> is an expandable/collapsible list of user-input text data that works with 
>> crud? Validators like IS_EMAIL() would then have to iterate on list:string. 
>> This would be handy for storing entities with multiple emails, for example.
>>
>> Seems like a gap in web2py's form-input armor and a pretty useful 
>> capability, to boot. So what's the latest?
>>
>

[web2py] Re: Dangerous web2py object-reuse pattern?

2012-07-09 Thread Massimo Di Pierro
2) Sorry, not by web2py. Threads and processes are managed (started and 
killed) by the web server. Web applications (in any framework) should never 
start their own threads.


On Monday, 9 July 2012 18:02:37 UTC-5, Daniel Gonzalez wrote:
>
> Sorry to bug you here, but:
>
> 1) Thread safety: sure, i need to handle that.
> 2) Threads and processes will be killed by web2py? How? My libraries are 
> creating threads (for example, to track the _changes api of couchdb). This 
> is not at all in control of web2py. I mean, of course, initially a request 
> to web2py is triggering the instantiation of an object which creates the 
> thread (via the "threading" python library). Is web2py in control of this 
> background thread? I do not think so, since I am not using any web2py 
> facilities to create it.
> 3) couchdb and REST: sure, couchdb follows REST, which is very lightweight 
> in terms of object instantiation to "connect" to the database. But it is 
> still not zero cost, and since I could have lots of requests, I would like 
> to avoid repeatedly creating these objects. Besides, there are some threads 
> which must be always running, like the client of the _changes api (which is 
> basically a long-poller to couchdb).
>
> I think most of my problems are coming from the fact that I want to 
> *reuse* my libraries with web2py. Which I think should be somehow feasible.
>
> Daniel
>
> On Tuesday, July 10, 2012 12:23:58 AM UTC+2, Massimo Di Pierro wrote:
>>
>> As long as you do not use DAL to connect to couchdb then you do not need 
>> to worry about web2py closing the connections.
>>
>> You still have two problems:
>> 1) thread safety, you may need to mutex lock the objects
>> 2) threads and processes will be killed by the web server at will and 
>> therefore you have no guarantee they will persist across requests.
>>
>> I you have sized number of connections and the number is not too high, 
>> you can create a background process that communicates only with localhost 
>> via - for example - xmlrpc. Then your web app would basically act as a 
>> proxy of that background process.
>>
>> I cannot help more, since there are many details involved. Mover couchdb 
>> talks over rest therefore I am not sure I understand the meaning of 
>> persistent connection. Perhaps web2py's cache.ram may be sufficient.
>>
>> Massimo
>>
>> On Monday, 9 July 2012 09:45:36 UTC-5, Daniel Gonzalez wrote:
>>>
>>> I can make subscriber_pool threadsafe, can't I?
>>>
>>> The point is that I would like to have some objects to be persistent 
>>> between requests, to avoid the cost of re-creating them each time. This is 
>>> nothing that can be managed by the DAL. You could think of it as a 
>>> long-to-setup object that I need to obtain the results expected by the 
>>> JSONRPC requests hitting web2py.
>>>
>>> To give you more detail: I have a pool of subscribers, belonging to 
>>> different "organizations". They are requesting data related to their 
>>> organization, via JSONRPC requests to web2py. The data is not controlled by 
>>> web2py, but is in external couchdb instances. I already have libraries to 
>>> access and manipulate this data, so I do not want to create new models for 
>>> it. *But* I need to connecto to those couchdb instances, and create my 
>>> library objects which know how to process this external data. Those are the 
>>> objects that I want to be persistent, because:
>>>
>>>1. A user can send requests very fast (1 s period)
>>>2. Several users can belong to the same organization. Thus, they can 
>>>reuse the same subscriber object.
>>>
>>> For how long must these objects be in the pool? This is something that I 
>>> have not yet decided myself. Probably for as long as they are being needed, 
>>> which means that I will implement a timeout (let's say 30s). If they are 
>>> used within that timeframe, they get to stay alive. If they timeout, they 
>>> get destroyed and will be recreated in the next request, thus incurring in 
>>> a penalty. This is a trade-off between speed and cache size (or memory 
>>> leak, if you want to see it that way).
>>>
>>> I could use a message queue (beanstalkd, celery?) to communicate with 
>>> these "workers", but in my first implementation I would like to keep it as 
>>> simple as possible. I am directly using the libraries from withing web2py. 
>>> So far, this is working fine, but I must confess that I have not yet 
>>> performed concurrent access tests.
>>>
>>> On Monday, July 9, 2012 4:03:36 PM UTC+2, Massimo Di Pierro wrote:

 I am not sure what class Subscriber does but, if it uses the DAL, than 
 you code is problematic.
 The DAL is "smart" in the sense that it keep tracks of all connection 
 open in certain thread and closes them all (or pools them) when the thread 
 ends. By using a module, you store references to those connections (which 
 may be closed or no, depending on the thread) in a persistent object, 
 subscriber_pool, thus maki

[web2py] Re: Upload file into DB without SQLFORM

2012-07-09 Thread Anthony
On Monday, July 9, 2012 7:59:50 PM UTC-4, Derek wrote:
>
> That is correct, that's how it's documented as well.
>

Is it documented that the file storage is not handled when the file is 
stored in a blob field rather than the filesystem?

Anthony 


[web2py] Re: Generating pdf using web2py-appreport (xhtmltopdf) in Python Web2py webapp

2012-07-09 Thread Limedrop
Hi Akash,

Your example controller code seems good and shouldwork.  The issue is that 
PISA is a bit sensitive and only supports a reduced subset of CSS.  The 
error suggests PISA does not know how to handle "Alpha(Opacity=0)".  You 
will need to somehow strip out the unsupported CSS from the html before it 
is rendered by REPORTPISA.  Note that images are also problematic (you will 
need PIL installed if you want anything other than JPG and even then they 
are rendered in separate paragraphs), so you might need to play with this 
too.

Cheers
Russell


On Saturday, July 7, 2012 5:40:29 PM UTC+12, Akash Kakkar wrote:
>
> *
> *
>
> I am from a non coding background so python, web2py is very new to me. I 
> am trying to send html content using json and then use that in controller 
> to generate pdf. If I am able to send json data and then use it in 
> controller function, i should be able to get the pdf. More details below. I 
> am missing out on correct json syntax , encoding and decoding.
>
> My app needs to export textarea content (using RTE redactor) to pdf. I get 
> html content from textarea (redactor), can you please advice me on how to 
> use pyfpdf to generate a pdf file on button click.
>
> I don't know how to get the html content (images and text) on button click 
> in view to generate pdf using appreport.
>
> I was able to use app-report to generate a pdf (using PISA, PYPDF does not 
> work) from an existing html file (without css) if html file has css it 
> throws an error,
>
> *** Terminal function expression 
> expected closing ')':: (u'Alpha(Opacity', u'=0); }\n\n\n\n.ui-state-')***
>
> This might be due to a mistake in the controller code:
>
> def myreport():
> html = response.render('myreport.html', dict())
> return plugin_appreport.REPORTPISA(html = html)
>
> --
>
> Another thing I tried was passing the html from my view to the controller 
> using ajax post (in Javascript). Redactor is the textarea RTE I am using 
> and alert gives me the desired html result.
>
> View:
>
> function getContent() {
> var t= jQuery('#redactor_content').getCode();
> alert(t);
> jQuery.ajax({ 
> type: "POST", 
> url: "http://127.0.0.1:8000/Test50/default/myreport2";, 
> data: "{g : 'jQuery('#redactor_content').getCode()'}" 
>
> }); 
>  }
>
> Controller:
>
> def myreport2():
> g = request.get_vars
> html = response.render(g)
> return plugin_appreport.REPORTPISA(html = html)
>
> Due to my less knowledge in coding , I am not able to figure out and 
> correct my mistake. I will be thankful if anybody can help me with this 
> problem.
>
> Regards, Akash
>


[web2py] Re: Upload file into DB without SQLFORM

2012-07-09 Thread Derek
That is correct, that's how it's documented as well.

On Monday, July 9, 2012 10:48:07 AM UTC-7, Athelionas wrote:
>
> Alright, finally I got it working by manually assigning file content to 
> uploaded_data field. Looks like store() function does not actually store 
> data if files are to be placed in DB rather than in filesystem.
>
> 2012. július 9., hétfő 19:32:06 UTC+2 időpontban Athelionas a következőt 
> írta:
>>
>> Ok, I read the book, but I still don't really know how this should be 
>> done.
>> What I have is this table:
>>
>> db.define_table('files',
>> Field('original_filename', 'string', required = True,notnull 
>> = True),
>> Field('uploaded_file', 'upload', uploadfield = 
>> 'uploaded_data', required = True, notnull = True, requires = IS_NOT_EMPTY
>> ()),
>> Field('uploaded_data', 'blob', notnull = True),
>> Field('created_on', 'datetime', notnull = True))
>>
>> and this code:
>>
>> db.files.insert(original_filename = upload.filename,
>> uploaded_file = 
>> db.files.uploaded_file.store(upload.file,upload
>> .filename),
>> created_on = datetime.today())
>>
>> But this doesn't work because uploaded_data field is NULL. Shouldn't 
>> store() take care of that field?
>> Or do I need to put file content there manually?
>> Thanks in advance.
>>
>> 2012. július 9., hétfő 16:54:26 UTC+2 időpontban Anthony a következőt 
>> írta:
>>>
>>> http://web2py.com/books/default/chapter/29/6#Manual-uploads
>>>
>>> On Monday, July 9, 2012 10:15:27 AM UTC-4, Athelionas wrote:

 What is the proper way of uploading a file without SQLFORM into the 
 following database table?

 db.define_table('files',
 Field('original_filename', 'string'),
 Field('file', 'upload', uploadfield='file_data'),
 Field('file_data', 'blob'))

 A simple insert won't help here so I'm sure there's some kind of trick 
 to it which I'm unable to figure out on my own.

 Any help is highly appreciated!

>>>

Re: [web2py] Looking for multi-select widget that uses two text boxes

2012-07-09 Thread villas
That's good,  I thought you still might have some other requirement(s). 
 Anyhow,  if you implement it, please advise how it goes.  I might try 
switch to that one if you found it easy to use.  All the best,  David


On Tuesday, July 10, 2012 12:10:50 AM UTC+1, MichaelF wrote:
>
> Nothing's wrong with Anthony's answer; I like it.
>
> On Monday, July 9, 2012 4:54:42 PM UTC-6, villas wrote:
>>
>> I used this one once:
>> http://www.senamion.com/blog/jmultiselect2side.html
>>
>> However,  it appears the one Anthony suggested would be better -- what's 
>> wrong with that suggestion?
>>
>>
>> On Sunday, July 8, 2012 9:00:04 PM UTC+1, MichaelF wrote:
>>>
>>> Thanks, Bruno. That's not quite what I need for this job, but I do need 
>>> that in another. I need something more like what Anthony posted (
>>> http://quasipartikel.at/multiselect_next/).
>>>
>>> On Sunday, July 8, 2012 12:42:09 PM UTC-6, rochacbruno wrote:

 I guess you need this:


 http://www.web2pyslices.com/slice/show/1526/cascading-drop-down-lists-with-ajax-2



 *Bruno Cezar Rocha*

 http://www.CursoDePython.com.br
 [image: Facebook]  [image: 
 Twitter] [image: 
 LinkedIn]  [image: 
 about.me] [image: 
 Amazon]  [image: 
 AngelList] [image: 
 Blog RSS]  [image: 
 Facebook Page]  [image: 
 foursquare] [image: 
 Google Plus]  
 [image: 
 pinterest]  [image: 
 SlideShare] [image: 
 YouTube] 
  [image: Google Talk] rochacbruno [image: Skype] blouweb
 Blog: Generate a thumbnail that fits in a 
 box
   Get a signature like this. 
 
  Click 
 here.




 On Sun, Jul 8, 2012 at 3:10 PM, MichaelF wrote:

> I'm aware of the multiple and checkbox widgets. I'm looking for a 
> widget whose name I don't know. It consists of two side-by-side boxes, 
> each 
> box can contain a list of items, and usually starts off with all the 
> items 
> in the left-hand box. Between the two boxes are two arrows, usually one 
> on 
> top of the other, one pointing to the right, one to the left. The 
> left-hand 
> box contains those items not 'chosen'; the right-hand box contains those 
> chosen. To 'choose' items (that is, to move an item from the left-hand 
> box 
> to the right-hand box) one selects the item(s) (ctrl-click, shift-click, 
> etc.) in the left-hand box, then presses the right-pointing arrow. The 
> selected items move from the left-hand box to the right-hand box. To 
> 'un-choose' items one selects items in the right-hand box, then presses 
> the 
> left-pointing arrow.
>
> 1. What is this widget usually called?
>
> 2. Does web2py have such a widget?
>



[web2py] Re: is this a bug in editor?

2012-07-09 Thread Anthony
I'm not sure it's in stable, but in trunk there is an entirely new editor (
ACE ), which may work better.

Anthony

On Monday, July 9, 2012 7:41:07 PM UTC-4, Derek wrote:
>
> I've seen that happen before. If you have selected text, and you scroll, 
> you get that. 
>
> I switched to Amy editor, and now I just have issues when I paste...
> if you go into /admin/default/peek/admin/models/0.py and change 
> TEXT_EDITOR='amy' it seems to work better. Of course, if you scroll with 
> text selected, the selection gets changed though.
>
> You can also just use any python editor to edit your files directly. I'm 
> not really happy with either editor, but it does seem that Amy works best 
> for me.
>
> On Monday, July 9, 2012 10:05:05 AM UTC-7, Janath wrote:
>>
>> Hi,
>>
>> The controller shown in attached image has ~800 lines. When I search, 
>> scroll or copy it shows me wired selection. A hidden grayed text appears on 
>> background. I have another controller, that I wrote before I started 
>> writing shorter controllers :), having ~1000 lines with the same sort of 
>> issues.
>>
>> When I increased the font size to 12, the disorder become higher.
>>
>> Thank you
>>
>>
>>
>>

[web2py] Re: is this a bug in editor?

2012-07-09 Thread Derek
I've seen that happen before. If you have selected text, and you scroll, 
you get that. 

I switched to Amy editor, and now I just have issues when I paste...
if you go into /admin/default/peek/admin/models/0.py and change 
TEXT_EDITOR='amy' it seems to work better. Of course, if you scroll with 
text selected, the selection gets changed though.

You can also just use any python editor to edit your files directly. I'm 
not really happy with either editor, but it does seem that Amy works best 
for me.

On Monday, July 9, 2012 10:05:05 AM UTC-7, Janath wrote:
>
> Hi,
>
> The controller shown in attached image has ~800 lines. When I search, 
> scroll or copy it shows me wired selection. A hidden grayed text appears on 
> background. I have another controller, that I wrote before I started 
> writing shorter controllers :), having ~1000 lines with the same sort of 
> issues.
>
> When I increased the font size to 12, the disorder become higher.
>
> Thank you
>
>
>
>

[web2py] IDs position in URLs and SEO

2012-07-09 Thread Francisco Costa
 

Some web applications with restful URLs like Foursquare (
https://foursquare.com/v/restaurante-baobab/*4bed589a75feef3b8d0197e6*)
 
put ID's at the end of the URL, some others like StackOverflow (
http://stackoverflow.com/questions/*11394640*
/pros-and-cons-of-ids-at-the-end-of-the-url)
 
put them in the middle, just before the title slug..

There are even others like Quora (
http://www.quora.com/Is-there-any-difference-in-terms-of-SEO-between-the-URL-REST-formats-on-Quora-and-StackOverflow)
 
that don't put them at all, only use the slug.

In your opinion wish one is best for information management and 
performance? What is the impact in terms of SEO?


Re: [web2py] Looking for multi-select widget that uses two text boxes

2012-07-09 Thread MichaelF
Nothing's wrong with Anthony's answer; I like it.

On Monday, July 9, 2012 4:54:42 PM UTC-6, villas wrote:
>
> I used this one once:
> http://www.senamion.com/blog/jmultiselect2side.html
>
> However,  it appears the one Anthony suggested would be better -- what's 
> wrong with that suggestion?
>
>
> On Sunday, July 8, 2012 9:00:04 PM UTC+1, MichaelF wrote:
>>
>> Thanks, Bruno. That's not quite what I need for this job, but I do need 
>> that in another. I need something more like what Anthony posted (
>> http://quasipartikel.at/multiselect_next/).
>>
>> On Sunday, July 8, 2012 12:42:09 PM UTC-6, rochacbruno wrote:
>>>
>>> I guess you need this:
>>>
>>>
>>> http://www.web2pyslices.com/slice/show/1526/cascading-drop-down-lists-with-ajax-2
>>>
>>>
>>>
>>> *Bruno Cezar Rocha*
>>>
>>> http://www.CursoDePython.com.br
>>> [image: Facebook]  [image: 
>>> Twitter] [image: 
>>> LinkedIn]  [image: 
>>> about.me] [image: 
>>> Amazon]  [image: 
>>> AngelList] [image: 
>>> Blog RSS]  [image: 
>>> Facebook Page]  [image: 
>>> foursquare] [image: 
>>> Google Plus]  
>>> [image: 
>>> pinterest]  [image: 
>>> SlideShare] [image: 
>>> YouTube] 
>>>  [image: Google Talk] rochacbruno [image: Skype] blouweb
>>> Blog: Generate a thumbnail that fits in a 
>>> box
>>>   Get a signature like this. 
>>> 
>>>  Click 
>>> here.
>>>
>>>
>>>
>>>
>>> On Sun, Jul 8, 2012 at 3:10 PM, MichaelF wrote:
>>>
 I'm aware of the multiple and checkbox widgets. I'm looking for a 
 widget whose name I don't know. It consists of two side-by-side boxes, 
 each 
 box can contain a list of items, and usually starts off with all the items 
 in the left-hand box. Between the two boxes are two arrows, usually one on 
 top of the other, one pointing to the right, one to the left. The 
 left-hand 
 box contains those items not 'chosen'; the right-hand box contains those 
 chosen. To 'choose' items (that is, to move an item from the left-hand box 
 to the right-hand box) one selects the item(s) (ctrl-click, shift-click, 
 etc.) in the left-hand box, then presses the right-pointing arrow. The 
 selected items move from the left-hand box to the right-hand box. To 
 'un-choose' items one selects items in the right-hand box, then presses 
 the 
 left-pointing arrow.

 1. What is this widget usually called?

 2. Does web2py have such a widget?

>>>
>>>

[web2py] Getting drop-down value names from grandparent record

2012-07-09 Thread MichaelF
In short, I'm having problems getting the drop-down value for a field in a 
child-of-a-child record; I want that value to be a field from the 
grandparent.

In more detail:

   1. I have three 'independent' tables ('independent' in that they have no 
   parents). Let's call them I1, I2, and I3.
   2. I have a child table that links I1 and I2 in a many-many 
   relationship. Let's call that table C1_2.
   3. I have a child table that links I3 and C1_2 in a many-to-many. Let's 
   call that table C1_2_3.
   4. When I add a C1_2_3 record, I'd like the values in the drop-down for 
   the C1_2 field to be taken from two of its parents' fields: I1.Name and 
   I2.I2.

Here's the table definitions:

db.define_table('I1',
Field('Name', 'string', length=60, required=True),
format='%(Name)s')

db.define_table('I2',
Field('I2', 'string', length=60, required=True,
   unique=True),
format='%(I2)s')

db.define_table('C1_2',
Field('I1', db.I1),
Field('I2', db.I2),
Field('Start_date', 'date', required=True),
format=lambda r: '%s %s' % (db.I1[r.I1].Name, 
db.I2[r.I2].I2))
db.C1_2.Start_date.requires = \
[IS_DATE(),
 IS_NOT_IN_DB(
   db((db.C1_2.I1==request.vars.I1) &\
  (db.C1_2.I2==request.vars.I2)),
   'C1_2.Start_date')]

db.define_table('I3',
Field('I3_name', 'string', required=True, unique=True),
format='%(I3_name)s')

db.define_table('C1_2_3',
Field('C1_2', db.C1_2),
Field('C3', db.I3))
db.C1_2_3.C1_2.requires=IS_IN_DB(db, 'C1_2.id',
   lambda r: '%s' % (db.I1[db.C1_2[r.C1_2].I1].Name),
   _and=IS_NOT_IN_DB(db(db.C1_2_3.C1_2==request.vars.C1_2), 'C1_2_3.C3'))

For simplicity, in this example the value I want to see for the dropdown 
for field C1_2_3.C1_2 is just I1.Name (not I1.name and I2.I2 as described 
above).

Without the highlighted line the dropdown shows only the C1_2 id values.

With the highlighted line I get the error, " 
'C1_2'" on the lambda definition.

1. Am I even allowed to have a lambda function there?
2. In any case, how can I get the drop-down to show me I1.Name?


[web2py] Re: Dangerous web2py object-reuse pattern?

2012-07-09 Thread Daniel Gonzalez
Sorry to bug you here, but:

1) Thread safety: sure, i need to handle that.
2) Threads and processes will be killed by web2py? How? My libraries are 
creating threads (for example, to track the _changes api of couchdb). This 
is not at all in control of web2py. I mean, of course, initially a request 
to web2py is triggering the instantiation of an object which creates the 
thread (via the "threading" python library). Is web2py in control of this 
background thread? I do not think so, since I am not using any web2py 
facilities to create it.
3) couchdb and REST: sure, couchdb follows REST, which is very lightweight 
in terms of object instantiation to "connect" to the database. But it is 
still not zero cost, and since I could have lots of requests, I would like 
to avoid repeatedly creating these objects. Besides, there are some threads 
which must be always running, like the client of the _changes api (which is 
basically a long-poller to couchdb).

I think most of my problems are coming from the fact that I want to *reuse* 
my libraries with web2py. Which I think should be somehow feasible.

Daniel

On Tuesday, July 10, 2012 12:23:58 AM UTC+2, Massimo Di Pierro wrote:
>
> As long as you do not use DAL to connect to couchdb then you do not need 
> to worry about web2py closing the connections.
>
> You still have two problems:
> 1) thread safety, you may need to mutex lock the objects
> 2) threads and processes will be killed by the web server at will and 
> therefore you have no guarantee they will persist across requests.
>
> I you have sized number of connections and the number is not too high, you 
> can create a background process that communicates only with localhost via - 
> for example - xmlrpc. Then your web app would basically act as a proxy of 
> that background process.
>
> I cannot help more, since there are many details involved. Mover couchdb 
> talks over rest therefore I am not sure I understand the meaning of 
> persistent connection. Perhaps web2py's cache.ram may be sufficient.
>
> Massimo
>
> On Monday, 9 July 2012 09:45:36 UTC-5, Daniel Gonzalez wrote:
>>
>> I can make subscriber_pool threadsafe, can't I?
>>
>> The point is that I would like to have some objects to be persistent 
>> between requests, to avoid the cost of re-creating them each time. This is 
>> nothing that can be managed by the DAL. You could think of it as a 
>> long-to-setup object that I need to obtain the results expected by the 
>> JSONRPC requests hitting web2py.
>>
>> To give you more detail: I have a pool of subscribers, belonging to 
>> different "organizations". They are requesting data related to their 
>> organization, via JSONRPC requests to web2py. The data is not controlled by 
>> web2py, but is in external couchdb instances. I already have libraries to 
>> access and manipulate this data, so I do not want to create new models for 
>> it. *But* I need to connecto to those couchdb instances, and create my 
>> library objects which know how to process this external data. Those are the 
>> objects that I want to be persistent, because:
>>
>>1. A user can send requests very fast (1 s period)
>>2. Several users can belong to the same organization. Thus, they can 
>>reuse the same subscriber object.
>>
>> For how long must these objects be in the pool? This is something that I 
>> have not yet decided myself. Probably for as long as they are being needed, 
>> which means that I will implement a timeout (let's say 30s). If they are 
>> used within that timeframe, they get to stay alive. If they timeout, they 
>> get destroyed and will be recreated in the next request, thus incurring in 
>> a penalty. This is a trade-off between speed and cache size (or memory 
>> leak, if you want to see it that way).
>>
>> I could use a message queue (beanstalkd, celery?) to communicate with 
>> these "workers", but in my first implementation I would like to keep it as 
>> simple as possible. I am directly using the libraries from withing web2py. 
>> So far, this is working fine, but I must confess that I have not yet 
>> performed concurrent access tests.
>>
>> On Monday, July 9, 2012 4:03:36 PM UTC+2, Massimo Di Pierro wrote:
>>>
>>> I am not sure what class Subscriber does but, if it uses the DAL, than 
>>> you code is problematic.
>>> The DAL is "smart" in the sense that it keep tracks of all connection 
>>> open in certain thread and closes them all (or pools them) when the thread 
>>> ends. By using a module, you store references to those connections (which 
>>> may be closed or no, depending on the thread) in a persistent object, 
>>> subscriber_pool, thus making your code not thread safe.
>>>
>>> Can you please explain in more detail what are you trying to accomplish? 
>>> How long should the connections be cached? What is their scope? I am sure 
>>> there is a better way. :-)
>>>
>>>
>>> On Monday, 9 July 2012 02:32:28 UTC-5, Daniel Gonzalez wrote:

 Hi,

 I am using the following patt

Re: [web2py] Looking for multi-select widget that uses two text boxes

2012-07-09 Thread villas
I used this one once:
http://www.senamion.com/blog/jmultiselect2side.html

However,  it appears the one Anthony suggested would be better -- what's 
wrong with that suggestion?


On Sunday, July 8, 2012 9:00:04 PM UTC+1, MichaelF wrote:
>
> Thanks, Bruno. That's not quite what I need for this job, but I do need 
> that in another. I need something more like what Anthony posted (
> http://quasipartikel.at/multiselect_next/).
>
> On Sunday, July 8, 2012 12:42:09 PM UTC-6, rochacbruno wrote:
>>
>> I guess you need this:
>>
>>
>> http://www.web2pyslices.com/slice/show/1526/cascading-drop-down-lists-with-ajax-2
>>
>>
>>
>> *Bruno Cezar Rocha*
>>
>> http://www.CursoDePython.com.br
>> [image: Facebook]  [image: 
>> Twitter] [image: 
>> LinkedIn]  [image: 
>> about.me] [image: 
>> Amazon]  [image: 
>> AngelList] [image: 
>> Blog RSS]  [image: 
>> Facebook Page]  [image: 
>> foursquare] [image: 
>> Google Plus]  
>> [image: 
>> pinterest]  [image: 
>> SlideShare] [image: 
>> YouTube] 
>>  [image: Google Talk] rochacbruno [image: Skype] blouweb
>> Blog: Generate a thumbnail that fits in a 
>> box
>>   Get a signature like this. 
>> 
>>  Click 
>> here.
>>
>>
>>
>>
>> On Sun, Jul 8, 2012 at 3:10 PM, MichaelF wrote:
>>
>>> I'm aware of the multiple and checkbox widgets. I'm looking for a widget 
>>> whose name I don't know. It consists of two side-by-side boxes, each box 
>>> can contain a list of items, and usually starts off with all the items in 
>>> the left-hand box. Between the two boxes are two arrows, usually one on top 
>>> of the other, one pointing to the right, one to the left. The left-hand box 
>>> contains those items not 'chosen'; the right-hand box contains those 
>>> chosen. To 'choose' items (that is, to move an item from the left-hand box 
>>> to the right-hand box) one selects the item(s) (ctrl-click, shift-click, 
>>> etc.) in the left-hand box, then presses the right-pointing arrow. The 
>>> selected items move from the left-hand box to the right-hand box. To 
>>> 'un-choose' items one selects items in the right-hand box, then presses the 
>>> left-pointing arrow.
>>>
>>> 1. What is this widget usually called?
>>>
>>> 2. Does web2py have such a widget?
>>>
>>
>>

[web2py] Re: with versioning how can you list the deleted records

2012-07-09 Thread Massimo Di Pierro
When versioning is on and you delete a record, the record is not actually 
deleted but is_active is set to False. All queries for tables for 
versioning automatically add a query is_active==True to filter them out and 
you no longer see deleted records. You do not need to look for them into 
the archive tables. You can simply do

db(db.table.is_active==False,ignore_common_filters=True).select()





On Monday, 9 July 2012 15:54:10 UTC-5, simon wrote:
>
> How can I find the deleted records when using versioning?
>
> When I delete a record it is deleted from the table and appears in the 
> archive table. Now I can run a query that looks for all records in the 
> archive table that are not in the table. However is there a better way of 
> identifying the deleted records?
>
> I note that there is an is_active field but this does not seem to be used?
>


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

2012-07-09 Thread Rakesh Soni
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: Error with Janrain integration

2012-07-09 Thread Geek999
Maybe, try its alternatives like Gigya  or 
LoginRadius;)



On Sunday, July 1, 2012 3:01:25 AM UTC-6, Hassan Alnatour wrote:
>
> Dear ALL,
>
> I am using Janrain with the normal login in my site it works well 
> but lately i have notice that if i am login in using it and using use 
> normal links on the site like : *www.i3zif.com/PlayVideo/18*  , it logs 
> out but if i am using the normal login it works well , what do you think 
> the problem is ?
>
>
> Best Regards,
>


Re: [web2py] problem with custom primarykey

2012-07-09 Thread Massimo Di Pierro
No. I am not sure this belongs to DAL but if you have ideas, feel free to 
share them.

On Monday, 9 July 2012 11:13:21 UTC-5, Vincenzo Ampolo wrote:
>
> On 07/09/2012 12:48 AM, Andrew wrote: 
> > See the dot point 
> > Keyed table can only refer are to other keyed tables. 
> > You have a mixture of Id fields and keys. 
> > 
>
> I've fixed my issue using a unique index. I just wanted to make sure 
> that there were no (iuser, imovie) duplicate tuples in my datased. 
>
> Is somebody working in implementing indexes in DAL? 
>
> -- 
> Vincenzo Ampolo 
> http://vincenzo-ampolo.net 
> http://goshawknest.wordpress.com 
>
>
>

[web2py] Re: Has anyone done a detailed security analysis or attempted a methodical attack on web2py?

2012-07-09 Thread Massimo Di Pierro
No but I am willing to pay to get it done.

On Monday, 9 July 2012 10:48:39 UTC-5, scausten wrote:
>
> One of the awesome things about web2py is of course the built-in and 
> well-documented resilience against a range of attack methods, but I was 
> wondering if anyone has attempted a methodical (white-hat) attack to probe 
> any potential weaknesses?
>
> Just out of interest :)
>


[web2py] Re: Dangerous web2py object-reuse pattern?

2012-07-09 Thread Massimo Di Pierro
As long as you do not use DAL to connect to couchdb then you do not need to 
worry about web2py closing the connections.

You still have two problems:
1) thread safety, you may need to mutex lock the objects
2) threads and processes will be killed by the web server at will and 
therefore you have no guarantee they will persist across requests.

I you have sized number of connections and the number is not too high, you 
can create a background process that communicates only with localhost via - 
for example - xmlrpc. Then your web app would basically act as a proxy of 
that background process.

I cannot help more, since there are many details involved. Mover couchdb 
talks over rest therefore I am not sure I understand the meaning of 
persistent connection. Perhaps web2py's cache.ram may be sufficient.

Massimo

On Monday, 9 July 2012 09:45:36 UTC-5, Daniel Gonzalez wrote:
>
> I can make subscriber_pool threadsafe, can't I?
>
> The point is that I would like to have some objects to be persistent 
> between requests, to avoid the cost of re-creating them each time. This is 
> nothing that can be managed by the DAL. You could think of it as a 
> long-to-setup object that I need to obtain the results expected by the 
> JSONRPC requests hitting web2py.
>
> To give you more detail: I have a pool of subscribers, belonging to 
> different "organizations". They are requesting data related to their 
> organization, via JSONRPC requests to web2py. The data is not controlled by 
> web2py, but is in external couchdb instances. I already have libraries to 
> access and manipulate this data, so I do not want to create new models for 
> it. *But* I need to connecto to those couchdb instances, and create my 
> library objects which know how to process this external data. Those are the 
> objects that I want to be persistent, because:
>
>1. A user can send requests very fast (1 s period)
>2. Several users can belong to the same organization. Thus, they can 
>reuse the same subscriber object.
>
> For how long must these objects be in the pool? This is something that I 
> have not yet decided myself. Probably for as long as they are being needed, 
> which means that I will implement a timeout (let's say 30s). If they are 
> used within that timeframe, they get to stay alive. If they timeout, they 
> get destroyed and will be recreated in the next request, thus incurring in 
> a penalty. This is a trade-off between speed and cache size (or memory 
> leak, if you want to see it that way).
>
> I could use a message queue (beanstalkd, celery?) to communicate with 
> these "workers", but in my first implementation I would like to keep it as 
> simple as possible. I am directly using the libraries from withing web2py. 
> So far, this is working fine, but I must confess that I have not yet 
> performed concurrent access tests.
>
> On Monday, July 9, 2012 4:03:36 PM UTC+2, Massimo Di Pierro wrote:
>>
>> I am not sure what class Subscriber does but, if it uses the DAL, than 
>> you code is problematic.
>> The DAL is "smart" in the sense that it keep tracks of all connection 
>> open in certain thread and closes them all (or pools them) when the thread 
>> ends. By using a module, you store references to those connections (which 
>> may be closed or no, depending on the thread) in a persistent object, 
>> subscriber_pool, thus making your code not thread safe.
>>
>> Can you please explain in more detail what are you trying to accomplish? 
>> How long should the connections be cached? What is their scope? I am sure 
>> there is a better way. :-)
>>
>>
>> On Monday, 9 July 2012 02:32:28 UTC-5, Daniel Gonzalez wrote:
>>>
>>> Hi,
>>>
>>> I am using the following pattern to use my libraries with web2py: some 
>>> of my utilities are creating connections to databases where I have data 
>>> that I need to serve with web2py. This data is not modeled with web2py 
>>> models. In order to avoid re-creating these connections with every single 
>>> request (I have a site which is performing requests with a 1s period), I 
>>> have discovered that the importing of modules is not cleaning the module 
>>> global variables. So now what I am doing is creating a cache for the 
>>> objects that I want to be persistent across requests. This is my code, in 
>>> file subscribers.py:
>>>
>>> class SubscriberPoolCls:
>>> def __init__(self):
>>> self.subscriber_pool = { }
>>>
>>>
>>> def get_subscriber(self, subsriber_id, myorg):
>>> log.info('get_subscriber > Requested subscriber_id=%s myorg=%d' 
>>> % (subsriber_id, myorg))
>>> if not subsriber_id in self.subscriber_pool:
>>> self.subscriber_pool[subsriber_id] = 
>>> Subscriber(myorg,subsriber_id
>>> )
>>> return self.subscriber_pool[subsriber_id]
>>>
>>>
>>> def unsubscribe_all(self):
>>> for subsriber_id in self.subscriber_pool:
>>> self.subscriber_pool[subsriber_id].unsubscribe()
>>>
>>>
>>> _subscriber_pool = None
>

Re: [web2py] default function in a non default controller with args - routing

2012-07-09 Thread Jonathan Lundell
On 9 Jul 2012, at 1:29 PM, Francisco Costa wrote:
> I'm using the Parameter-based system for routing
> 
> In my routes.py I have this
> 
> routers = dict(
> 
> # base router
> BASE = dict(
> applications = ['admin', 'app', 'blog'],
> default_application = 'app',
> map_hyphen = True,
> domains = {
> 'blog.domain.com'   : 'blog',
> 'domain.com'  : 'app'
> },
> ),
> app = dict(
> controllers = ['default', 'user'],
> functions = ['index', 'show', 'list'],
> default_controller = 'default',
> default_function = dict(default='index', user='show')
> ),
> blog = dict(
> default_controller = 'default',
> ),
> )
> 
> 
> When I go to http://localhost/user/john i get this: "invalid function 
> (user/john)"
> 
> I would like it to map it to http://localhost/user/show/john
> 
> So it is possible to pass args to a default function in a non default 
> controller without the name of the function?

Try specifying functions as a dict of lists keyed by controller names, and 
include and entry for user. Something like

app = dict( 
...
functions = dict(
default = [ list of functions],
user = [ list of functions ],
).
...

One other thing to pay attention to is that by default there's a function 
app/default/user that manages your auth object. The router will do the right 
thing, but there may be some omissions that it won't be able to do because the 
conflict creates an ambiguity. In particular, the router can normally shorten 
/app/default/user/whatever to /user/whatever, but it can't do that if you have 
a function named user.

You can work around that by renaming your controller, or by renaming the 
auth-support function and telling Auth: auth = Auth(... 
function='somethingotherthanuser'...)

[web2py] Re: default function in a non default controller with args - routing

2012-07-09 Thread Anthony
I think functions needs to be a dictionary of lists if you want to specify 
functions for multiple controllers:

app = dict(
controllers = ['default', 'user'],
functions = {'default': ['index'], 'user': ['show', 'list']},

Anthony

On Monday, July 9, 2012 4:29:07 PM UTC-4, Francisco Costa wrote:
>
> Hi,
> I'm using the Parameter-based system for routing
>
> In my routes.py I have this
>
> routers = dict(
>
> # base router
> BASE = dict(
> applications = ['admin', 'app', 'blog'],
> default_application = 'app',
> map_hyphen = True,
> domains = {
> 'blog.domain.com'   : 'blog',
> 'domain.com'  : 'app'
> },
> ),
> app = dict(
> controllers = ['default', 'user'],
> functions = ['index', 'show', 'list'],
> default_controller = 'default',
> default_function = dict(default='index', user='show')
> ),
> blog = dict(
> default_controller = 'default',
> ),
> )
>
>
> When I go to http://localhost/user/john i get this: "invalid function 
> (user/john)"
>
> I would like it to map it to http://localhost/user/show/john
>
> So it is possible to pass args to a default function in a non default 
> controller without the name of the function?
>


[web2py] Re: Any difference passing a string vs. a field for arg #2 in IS_IN_DB?

2012-07-09 Thread Anthony
No. The code does str(self.field), which converts db.image.id to 'image.id' 
-- http://code.google.com/p/web2py/source/browse/gluon/validators.py#417.

Anthony

On Monday, July 9, 2012 4:42:39 PM UTC-4, MichaelF wrote:
>
> The doc shows two calling patterns for IS_IN_DB, the difference being the 
> type of the second positional argument:
>
> The example in section 3.6 shows:
> db.comment.image_id.requires = IS_IN_DB(db, db.image.id, '%(title)s')
>
> Section 6.5 has a table for default validators:
> IS_IN_DB(db,table.field,format)
>
> Section 7.6.2 *Database Validators* (and other places) shows:
> db.dog.owner.requires = IS_IN_DB(db, 'person.id', 
> '%(name)s', zero=T('choose one'))
>
> Is there a functional difference in passing the string vs. passing the 
> field?
>


[web2py] Re: web2py vs ROR

2012-07-09 Thread Cliff Kachinske
Maybe I can answer your question by describing how I use Web2py.

I begin with models.  The DAL has so far provided all the functionality I 
need.  That said, I also will need to implement a union query in the future 
and I don't think the DAL supports it.  However, on this forum there was 
recently a thread about how to process the rows that came back from 
processing a raw SQL query, so no problems there.

As far as controllers go, I begin by using crud, SQLFORM.grid and 
SQLFORM.smartgrid.  Sometimes these are all I need, especially if the 
controllers address a single table only or just have one-to-may 
relationships.

If I need more flexibility, such as processing on validation or after and 
insert or update.  In that case I use SQLFORM or SQLFORM.factory.

You can even hand build your pages using the view helpers.  

Web2py generates css-friendly pages, so you can style as much as you like.

On Monday, July 9, 2012 4:46:24 AM UTC-4, murtaza52 wrote:
>
> Massimo,
>
> Appreciate your comments.
>
> As mentioned by you, web2py has packaged all the functionality needed  by 
> a web app in a single api, and I am finding this very interesting. This 
> certainly allows one to create a web app pretty fast.
>
> The only remaining question is that how easy is it to pull apart things 
> and modify them as needed. As I understand web2py will certainly speed up 
> my development. However when I need flexibility will I still be easily able 
> to change defaults and tweak things ? ( something that loosely couple 
> frameworks provide over full stack frameworks)
>
> Thanks,
> Murtaza
>
> On Saturday, July 7, 2012 1:26:34 AM UTC+5:30, Massimo Di Pierro wrote:
>>
>> As pointed out what I said is that I would pick ROR of "most" python 
>> frameworks.
>>
>> In general I prefer to program in Python rather then  Ruby. Indentation 
>> makes the code more readable and there are more libraries. Ruby is used in 
>> Rails but not much else. Python is used for all kind of things (think about 
>> numpy, blender, pyglet, etc.).
>>
>> Yet Ruby is better designed than most Python framework because if favors 
>> convention over configuration. Most Python frameworks instead follow the 
>> Python motto "explicit is better the implicit" and the authors despise the 
>> concept of "default behaviour" which they refer to as "magic". This means 
>> that even very simple simple such as serving a static file require a fair 
>> amount of programing. Moreover, as a corollary, most frameworks come in 
>> pieces. Ever piece has a name and its own marketing people. This exposes 
>> the visibility of the component but it means you have to separately find 
>> and install the components you need, learn their api and make sure they are 
>> compatible with your own version of the code.
>>
>> In web2py we tried to copied the RoR approach (everything has a 
>> configuration) and we try to package and maintain as many components as 
>> possible into the same code base (API for authentication, scheduler, cron, 
>> PDF printing, SOAP services, WIKI markup, syntax highlighting, etc.). 
>> Moreover we do not rely on third party modules (only on Python standard 
>> libraries). 99% of what you may want to can be done with basic web2py 
>> without needing external packages. This means the apps are very portable 
>> between one installation and another.
>>
>> The main difference between web2py and other frameworks in practice is 
>> not soo much in the its API (which more or less are the same for all 
>> frameworks) but for what web2py does for you on the management site: no 
>> packages to install, manage through the web interface, no shell programming 
>> unless you want to, automatic migrations.
>>
>> Massimo
>>
>>
>>
>> On Friday, 6 July 2012 00:58:36 UTC-5, murtaza52 wrote:
>>>
>>> Hi,
>>>
>>> I am considering three frameworks for developing our commercial 
>>> applications- 
>>>
>>> 1) web2py (choice #1)
>>> 2) ROR
>>> 3) Play framework
>>>
>>> While my research I was intrigued by Massimo's post where he says that 
>>> he would pick ROR over any of the current python frameworks. My question is 
>>> how does web2py itself compare to ROR ? What are the views of those 
>>> experienced with both the ecosystems ? 
>>>
>>> http://www.ruby-forum.com/topic/209343
>>>
>>> I have expereince with none so will rely on your answers :) The purpose 
>>> of the question is not to start a flame war, but to understand why should 
>>> web2py be chose over other frameworks which have much more traction today?
>>>
>>> Thanks,
>>> Murtaza
>>>
>>>

[web2py] with versioning how can you list the deleted records

2012-07-09 Thread simon
How can I find the deleted records when using versioning?

When I delete a record it is deleted from the table and appears in the 
archive table. Now I can run a query that looks for all records in the 
archive table that are not in the table. However is there a better way of 
identifying the deleted records?

I note that there is an is_active field but this does not seem to be used?


[web2py] Any difference passing a string vs. a field for arg #2 in IS_IN_DB?

2012-07-09 Thread MichaelF
The doc shows two calling patterns for IS_IN_DB, the difference being the 
type of the second positional argument:

The example in section 3.6 shows:
db.comment.image_id.requires = IS_IN_DB(db, db.image.id, '%(title)s')

Section 6.5 has a table for default validators:
IS_IN_DB(db,table.field,format)

Section 7.6.2 *Database Validators* (and other places) shows:
db.dog.owner.requires = IS_IN_DB(db, 'person.id', 
'%(name)s', zero=T('choose one'))

Is there a functional difference in passing the string vs. passing the 
field?


[web2py] default function in a non default controller with args - routing

2012-07-09 Thread Francisco Costa
Hi,
I'm using the Parameter-based system for routing

In my routes.py I have this

routers = dict(

# base router
BASE = dict(
applications = ['admin', 'app', 'blog'],
default_application = 'app',
map_hyphen = True,
domains = {
'blog.domain.com'   : 'blog',
'domain.com'  : 'app'
},
),
app = dict(
controllers = ['default', 'user'],
functions = ['index', 'show', 'list'],
default_controller = 'default',
default_function = dict(default='index', user='show')
),
blog = dict(
default_controller = 'default',
),
)


When I go to http://localhost/user/john i get this: "invalid function 
(user/john)"

I would like it to map it to http://localhost/user/show/john

So it is possible to pass args to a default function in a non default 
controller without the name of the function?


Re: [web2py] Re: SQLFORM.grid id representation bug?

2012-07-09 Thread Anthony

>
> db.sessions.client_id.requires = IS_IN_DB(db, db.clients.id, '%(name)s')
>
>
No, as I mentioned, you should *not* explicitly define the IS_IN_DB 
validator. You will get one automatically when you create a reference 
field. If the referenced table has a "format" attribute, then that format 
attribute will be used both in the reference field's IS_IN_DB validator and 
as the "represent" attribute for the reference field. However, if you 
explicitly define an IS_IN_DB validator, then you no longer get a default 
"represent" attribute, and you therefore also have to explicitly define 
that attribute as well. So, either get rid of your IS_IN_DB, or add the 
following:

db.define_table('sessions',
Field('client_id', db.clients,
  requires=IS_IN_DB(db, db.clients.id, '%(name)s'),
  represent=lambda id, row: db.clients(id).name))
 
There's no need for the above, though, as this will get you the equivalent 
by default (as long as you have the "format" attribute defined in the 
db.clients table):

db.define_table('sessions',
Field('client_id', db.clients))

Anthony


[web2py] Re: paymentech: post request

2012-07-09 Thread howesc
how about:

import urllib2
r = urllib2.Request('https://orbitalvar1.paymentech.net/authorize:443', 
xml_request, {'Content-Type', 'application/PTI46', ...})
resp = urllib2.urlopen(r)

see http://docs.python.org/library/urllib2.html

On Sunday, July 8, 2012 6:44:12 PM UTC-7, Adi wrote:
>
> Thanks for the response. 
>
> Even though I got this response: 412 Precondition Failed, the code bellow 
> seems to work fine. Will check more tomorrow. 
>
> import sys, httplib, urllib, urllib2
> target = "https://orbitalvar1.paymentech.net/authorize:443";
> HOST, API_URL = urllib2.splithost(urllib2.splittype(target)[1])
> xml_request="proper security and order details..."
>
> conn = httplib.HTTPS(HOST)
> conn.putrequest('POST', API_URL)
> conn.putheader("Content-Type", "application/PTI46")
> conn.putheader("Content-transfer-encoding", "text")
> conn.putheader("Document-type", "Request")
> conn.putheader("Trace-number", "123456")
> conn.putheader("MIME-Version", "1.0")
> conn.endheaders()
> conn.send(xml_request)
> statuscode, statusmessage, header = conn.getreply()
>
>
>
>
> On Sunday, July 8, 2012 2:52:14 PM UTC-4, howesc wrote:
>>
>> i've never used HTTP lib before, and i found "This module defines classes 
>> which implement the client side of the HTTP and HTTPS protocols. It is 
>> normally not used directly — the module 
>> urllibuses it to 
>> handle URLs that use HTTP and HTTPS." here 
>> http://docs.python.org/library/httplib.html
>>
>> perhaps give urllib or urllib2 a try - i use those all the time with 
>> great success!
>>
>> cfh
>>
>> On Friday, July 6, 2012 10:30:34 AM UTC-7, Adi wrote:
>>>
>>>
>>> Could anyone please advise if I'm doing this correctly? I'm trying to 
>>> post a request to Paymentech gateway. When I try the link in a browser, it 
>>> responds fine (https://orbitalvar1.paymentech.net/authorize:443), but 
>>> using post as bellow returns an error. Most likely I'm doing something 
>>> wrong, but can't figure out what.
>>>
>>> Thanks,
>>> Adnan
>>>
>>>
>>> *CODE:*
>>> import sys, httplib
>>>
>>> request = xml_string # "proper xml request..."
>>>
>>> HOST = "https://orbitalvar1.paymentech.net/authorize:443";
>>> # tried without https as well: HOST = "
>>> orbitalvar1.paymentech.net/authorize:443"
>>> webservice = httplib.HTTPS(HOST)
>>> webservice.putrequest("POST", '')
>>> webservice.putheader("Host", HOST)
>>> webservice.putheader("User-Agent","Python post")
>>> webservice.putheader("Content-Type", "application/PTI46")
>>> webservice.putheader("Content-transfer-encoding", "text")
>>> webservice.putheader("Content-length", "%d" % len(request))
>>> webservice.endheaders()
>>> webservice.send(request)
>>> statuscode, statusmessage, header = webservice.getreply()
>>> print statuscode, statusmessage, header
>>>
>>> *TRACEBACK:*
>>> Traceback (most recent call last):
>>>   File "/Users/adnan/web2py-dev-branch8/gluon/restricted.py", line 205, 
>>> in restricted
>>> exec ccode in environment
>>>   File 
>>> "/Users/adnan/web2py-dev-branch8/applications/dev_thanemobile/controllers/default.py",
>>>  
>>> line 898, in 
>>>   File "/Users/adnan/web2py-dev-branch8/gluon/globals.py", line 173, in 
>>> 
>>> self._caller = lambda f: f()
>>>   File 
>>> "/Users/adnan/web2py-dev-branch8/applications/dev_thanemobile/controllers/default.py",
>>>  
>>> line 43, in test_pmt
>>> paymentech.do_request(xml_string)
>>>   File "applications/dev_thanemobile/modules/paymentech.py", line 46, in 
>>> do_request
>>> webservice.endheaders()
>>>   File 
>>> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
>>>  
>>> line 937, in endheaders
>>>   File 
>>> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
>>>  
>>> line 797, in _send_output
>>>   File 
>>> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
>>>  
>>> line 759, in send
>>>   File 
>>> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
>>>  
>>> line 1140, in connect
>>>   File 
>>> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py",
>>>  
>>> line 553, in create_connection
>>> *gaierror: [Errno 8] nodename nor servname provided, or not known*
>>>
>>>

Re: [web2py] Re: SQLFORM.grid id representation bug?

2012-07-09 Thread Remco K
Hmm oke. I tried it on different ways. Now i use the PowerTable plugin and 
it's working. There is nothing wrong with the IS_IN_DB() validator as far 
as i can see. I use:

db.define_table('clients',
 Field('number'),
 Field('name'),
 Field('created_on','datetime', default=request.now,update=
request.now,writable=False, readable=False),
 Field('created_by',db.auth_user, default=auth.user_id,
update=auth.user_id,writable=False,readable=False),
 format='%(name)s'
 )
 
db.define_table('sessions',
 Field('client_id', db.clients),
 Field('creation_date'),
 Field('created_on','datetime', default=request.now,update=
request.now,writable=False, readable=False),
 Field('created_by',db.auth_user, default=auth.user_id,
update=auth.user_id,writable=False, readable=False),
 )
 
db.sessions.client_id.requires = IS_IN_DB(db, db.clients.id, '%(name)s')

Maybe i'm missing something. I also tried to use the following way to 
define the IS_IN_DB():

db.define_table('sessions',
 Field('client_id', db.clients, requires=IS_IN_DB(db, db.
clients.id, %'name's)),

But also no success. For now I'm going to use the PowerTable plugin but if 
you can find my blind spot on this, please let me know!

Thanks a lot for helping!

 Remco


On Monday, July 9, 2012 7:34:40 PM UTC+2, Anthony wrote:
>
> On Monday, July 9, 2012 12:32:11 PM UTC-4, Remco K wrote:
>>
>> Thanks for the answers.
>>
>> This representation works perfectly when i show the content in a dropdown 
>> so i think this has more to do with SQLFORM.grid...
>>
>
> The dropdown is controlled by the IS_IN_DB validator, not the field's 
> "represent" attribute. SQLFORM.grid, SQLTABLE, and read-only SQLFORMs, 
> however, depend on the represent attribute. If you set the "format" 
> attribute of the referenced table and do not explicitly set your own 
> IS_IN_DB validator for the reference field, then the reference field will 
> adopt that format attribute for both its IS_IN_DB validator and its 
> represent attribute -- otherwise, you have to handle each separately.
>
> Anthony
>


[web2py] Re: web2py ajax function returns only non readonly fields

2012-07-09 Thread Anthony
On Monday, July 9, 2012 11:58:45 AM UTC-4, Yuval wrote:
>
> To duplicate the fields once as a label and once as a hidden field?
> Its doable, but not too classy, Tx.
>

Feel free to submit a patch. :-)


[web2py] Re: Upload file into DB without SQLFORM

2012-07-09 Thread Athelionas
Alright, finally I got it working by manually assigning file content to 
uploaded_data field. Looks like store() function does not actually store 
data if files are to be placed in DB rather than in filesystem.

2012. július 9., hétfő 19:32:06 UTC+2 időpontban Athelionas a következőt 
írta:
>
> Ok, I read the book, but I still don't really know how this should be done.
> What I have is this table:
>
> db.define_table('files',
> Field('original_filename', 'string', required = True,notnull 
> = True),
> Field('uploaded_file', 'upload', uploadfield = 
> 'uploaded_data', required = True, notnull = True, requires = IS_NOT_EMPTY
> ()),
> Field('uploaded_data', 'blob', notnull = True),
> Field('created_on', 'datetime', notnull = True))
>
> and this code:
>
> db.files.insert(original_filename = upload.filename,
> uploaded_file = 
> db.files.uploaded_file.store(upload.file,upload
> .filename),
> created_on = datetime.today())
>
> But this doesn't work because uploaded_data field is NULL. Shouldn't 
> store() take care of that field?
> Or do I need to put file content there manually?
> Thanks in advance.
>
> 2012. július 9., hétfő 16:54:26 UTC+2 időpontban Anthony a következőt írta:
>>
>> http://web2py.com/books/default/chapter/29/6#Manual-uploads
>>
>> On Monday, July 9, 2012 10:15:27 AM UTC-4, Athelionas wrote:
>>>
>>> What is the proper way of uploading a file without SQLFORM into the 
>>> following database table?
>>>
>>> db.define_table('files',
>>> Field('original_filename', 'string'),
>>> Field('file', 'upload', uploadfield='file_data'),
>>> Field('file_data', 'blob'))
>>>
>>> A simple insert won't help here so I'm sure there's some kind of trick 
>>> to it which I'm unable to figure out on my own.
>>>
>>> Any help is highly appreciated!
>>>
>>

Re: [web2py] Re: SQLFORM.grid id representation bug?

2012-07-09 Thread Anthony
On Monday, July 9, 2012 12:32:11 PM UTC-4, Remco K wrote:
>
> Thanks for the answers.
>
> This representation works perfectly when i show the content in a dropdown 
> so i think this has more to do with SQLFORM.grid...
>

The dropdown is controlled by the IS_IN_DB validator, not the field's 
"represent" attribute. SQLFORM.grid, SQLTABLE, and read-only SQLFORMs, 
however, depend on the represent attribute. If you set the "format" 
attribute of the referenced table and do not explicitly set your own 
IS_IN_DB validator for the reference field, then the reference field will 
adopt that format attribute for both its IS_IN_DB validator and its 
represent attribute -- otherwise, you have to handle each separately.

Anthony


[web2py] Re: Upload file into DB without SQLFORM

2012-07-09 Thread Athelionas
Ok, I read the book, but I still don't really know how should this be done.
What I have is this table:

db.define_table('files',
Field('original_filename', 'string', required = True,notnull 
= True),
Field('uploaded_file', 'upload', uploadfield = 
'uploaded_data', required = True, notnull = True, requires = IS_NOT_EMPTY
()),
Field('uploaded_data', 'blob', notnull = True),
Field('created_on', 'datetime', notnull = True))

and this code:

db.files.insert(original_filename = upload.filename,
uploaded_file = db.files.uploaded_file.store(upload.file,upload
.filename),
created_on = datetime.today())

But this doesn't work because uploaded_data field is NULL. Shouldn't 
store() take care of that field?
Or do I need to put file content there manually?
Thanks in advance.

2012. július 9., hétfő 16:54:26 UTC+2 időpontban Anthony a következőt írta:
>
> http://web2py.com/books/default/chapter/29/6#Manual-uploads
>
> On Monday, July 9, 2012 10:15:27 AM UTC-4, Athelionas wrote:
>>
>> What is the proper way of uploading a file without SQLFORM into the 
>> following database table?
>>
>> db.define_table('files',
>> Field('original_filename', 'string'),
>> Field('file', 'upload', uploadfield='file_data'),
>> Field('file_data', 'blob'))
>>
>> A simple insert won't help here so I'm sure there's some kind of trick to 
>> it which I'm unable to figure out on my own.
>>
>> Any help is highly appreciated!
>>
>

Re: [web2py] Re: SQLFORM.grid id representation bug?

2012-07-09 Thread Remco K
Thanks for the answers.

This representation works perfectly when i show the content in a dropdown
so i think this has more to do with SQLFORM.grid...

2012/7/9 Anthony 

> db.define_table('clients',
> Field('number'),
>
> Field('name'),
> format='%(name)s')
>
> Then you don't have to explicitly define the IS_IN_DB validator, as
> sessions.client_id will get one by default with the format set to the
> db.clients format attribute. In that case, the sessions.client_id represent
> attribute will also be set to the db.clients format attribute.
>
> Anthony
>
>
> On Monday, July 9, 2012 8:35:41 AM UTC-4, Remco K wrote:
>>
>> Hi everyone,
>>
>> I'm working with SQLFORM.grid but I cant get the referenced table
>> representation to work. The only thing i get is the ID of the referenced
>> table(s):
>>
>> *db.py: *
>> db.define_table('clients',
>> Field('number'),
>> Field('name')
>> )
>>
>> db.define_table('sessions',
>> Field('client_id', db.clients),
>> Field('state')
>> )
>>
>> db.sessions.client_id.requires = IS_IN_DB(db, db.clients, '%(name)s')
>>
>> *controller:*
>> fields = (db.sessions.client_id)
>> headers = {'sessions.client_id':"Client"**}
>>
>> _form = SQLFORM.grid(db.sessions.id>0 ,fields=fields, 
>> headers=headers,maxtextlength
>> =500)
>> *
>> I get:*
>> Client
>> 111
>>
>> *Instead of:*
>> Client
>> 
>>
>> I've Googled for a while but i cant find any solution yet.
>>
>> The version of Web2Py i'm using:
>>
>> Version 2.0.0 (2012-06-29 20:55:40) dev
>>
>> Thanks in advance!Remco
>>
>


-- 
Met vriendelijke groet,

Remco Klappe


Re: [web2py] problem with custom primarykey

2012-07-09 Thread Vincenzo Ampolo
On 07/09/2012 12:48 AM, Andrew wrote:
> See the dot point 
> Keyed table can only refer are to other keyed tables.
> You have a mixture of Id fields and keys.
> 

I've fixed my issue using a unique index. I just wanted to make sure
that there were no (iuser, imovie) duplicate tuples in my datased.

Is somebody working in implementing indexes in DAL?

-- 
Vincenzo Ampolo
http://vincenzo-ampolo.net
http://goshawknest.wordpress.com




[web2py] Re: web2py ajax function returns only non readonly fields

2012-07-09 Thread Yuval
To duplicate the fields once as a label and once as a hidden field?
Its doable, but not too classy, Tx.

On Monday, July 9, 2012 8:21:00 AM UTC-7, Anthony wrote:
>
> You might put the value in a hidden field as well.
>
> Anthony
>
> On Monday, July 9, 2012 11:09:50 AM UTC-4, Yuval wrote:
>>
>> The ajax function is defined as:
>> ajax(url, [name1, name2, ...], target)
>>
>> where the 'name1' 'name2' are defined as ids of an input fields.
>> *This is working fine for fields that are defined as:*
>> *
>> Field('first_name', label=T('First Name'))
>>
>> When the field is set to be read only, it is rendered as a label, and the 
>> value is not returned.*
>> *
>> Field('first_name', label=T('First Name'), default=db.auth_user.
>> first_name, readable=True, writable=False),
>>
>>
>> *
>> *Is there a way to get back the value when the field is defined as read 
>> only?*
>>
>>
>>

[web2py] Has anyone done a detailed security analysis or attempted a methodical attack on web2py?

2012-07-09 Thread scausten
One of the awesome things about web2py is of course the built-in and 
well-documented resilience against a range of attack methods, but I was 
wondering if anyone has attempted a methodical (white-hat) attack to probe 
any potential weaknesses?

Just out of interest :)


[web2py] Web2py JS problem with the dropdown arrows in top menu (submenu) not showing up anymore !!??

2012-07-09 Thread Don_X
Hello,
I went on vacation and now I am back to keep on thriving with my web2py pet 
project ! 
how is everyone doing ?? ...

OK .. It is a small problem .. but a problem anyways ...
the problem I am having is with the dropdown arrows managed by the web2py 
JS ..

Let me elaborate a bit : -->  in the welcome app, in the serialized format  
in firefox ( with inspect element(Q) ), there is an additional  
that manages the arrows showing for the submenus like this :

web2py
 » 

the second span tag does not show up in my serialized custom view 
application anymore ... and
 I don't know how to make it show up 
for now I am using the exact same web2py menu  before I customize it with 
my own links and naming

 ... i want these arrows to show up to indicate that there is a submenu

any assistance with this will be greatly appreciated !

thank you

Don



[web2py] Re: web2py ajax function returns only non readonly fields

2012-07-09 Thread Anthony
You might put the value in a hidden field as well.

Anthony

On Monday, July 9, 2012 11:09:50 AM UTC-4, Yuval wrote:
>
> The ajax function is defined as:
> ajax(url, [name1, name2, ...], target)
>
> where the 'name1' 'name2' are defined as ids of an input fields.
> *This is working fine for fields that are defined as:*
> *
> Field('first_name', label=T('First Name'))
>
> When the field is set to be read only, it is rendered as a label, and the 
> value is not returned.*
> *
> Field('first_name', label=T('First Name'), default=db.auth_user.first_name
> , readable=True, writable=False),
>
>
> *
> *Is there a way to get back the value when the field is defined as read 
> only?*
>
>
>

[web2py] Re: list:string & crud form entry -- what's the latest?

2012-07-09 Thread Anthony
Well, by default, the list:string field type does get a special Javascript 
widget, though the functionality could probably be improved. After you 
enter an item in the initial text box, hit enter, and a new box should 
appear below it, and so on. There is no way to remove a box once created.

Regardless of the widget, you can apply an email validator to each item in 
a list:string input using IS_LIST_OF(IS_EMAIL()). The only caveat is that 
validation errors will not automatically be displayed on the form, so you 
have to explicitly check for a validation error on that field and implement 
a custom error display.

Anthony

On Monday, July 9, 2012 10:15:34 AM UTC-4, weheh wrote:
>
> This has been an oft-disucssed topic. Just search for "list:string crud" 
> But having just experienced the pain myself, and not easily locating the 
> status of this issue, I felt compelled to ask for myself: 
>
> Shouldn't list:string have a default interactive (jQuery OK) widget that 
> is an expandable/collapsible list of user-input text data that works with 
> crud? Validators like IS_EMAIL() would then have to iterate on list:string. 
> This would be handy for storing entities with multiple emails, for example.
>
> Seems like a gap in web2py's form-input armor and a pretty useful 
> capability, to boot. So what's the latest?
>


[web2py] web2py ajax function returns only non readonly fields

2012-07-09 Thread Yuval
The ajax function is defined as:
ajax(url, [name1, name2, ...], target)

where the 'name1' 'name2' are defined as ids of an input fields.
*This is working fine for fields that are defined as:*
*
Field('first_name', label=T('First Name'))

When the field is set to be read only, it is rendered as a label, and the 
value is not returned.*
*
Field('first_name', label=T('First Name'), 
default=db.auth_user.first_name,readable
=True, writable=False),


*
*Is there a way to get back the value when the field is defined as read 
only?*




[web2py] Re: Upload file into DB without SQLFORM

2012-07-09 Thread Anthony
http://web2py.com/books/default/chapter/29/6#Manual-uploads

On Monday, July 9, 2012 10:15:27 AM UTC-4, Athelionas wrote:
>
> What is the proper way of uploading a file without SQLFORM into the 
> following database table?
>
> db.define_table('files',
> Field('original_filename', 'string'),
> Field('file', 'upload', uploadfield='file_data'),
> Field('file_data', 'blob'))
>
> A simple insert won't help here so I'm sure there's some kind of trick to 
> it which I'm unable to figure out on my own.
>
> Any help is highly appreciated!
>


[web2py] Re: Dangerous web2py object-reuse pattern?

2012-07-09 Thread Daniel Gonzalez
I can make subscriber_pool threadsafe, can't I?

The point is that I would like to have some objects to be persistent 
between requests, to avoid the cost of re-creating them each time. This is 
nothing that can be managed by the DAL. You could think of it as a 
long-to-setup object that I need to obtain the results expected by the 
JSONRPC requests hitting web2py.

To give you more detail: I have a pool of subscribers, belonging to 
different "organizations". They are requesting data related to their 
organization, via JSONRPC requests to web2py. The data is not controlled by 
web2py, but is in external couchdb instances. I already have libraries to 
access and manipulate this data, so I do not want to create new models for 
it. *But* I need to connecto to those couchdb instances, and create my 
library objects which know how to process this external data. Those are the 
objects that I want to be persistent, because:

   1. A user can send requests very fast (1 s period)
   2. Several users can belong to the same organization. Thus, they can 
   reuse the same subscriber object.
   
For how long must these objects be in the pool? This is something that I 
have not yet decided myself. Probably for as long as they are being needed, 
which means that I will implement a timeout (let's say 30s). If they are 
used within that timeframe, they get to stay alive. If they timeout, they 
get destroyed and will be recreated in the next request, thus incurring in 
a penalty. This is a trade-off between speed and cache size (or memory 
leak, if you want to see it that way).

I could use a message queue (beanstalkd, celery?) to communicate with these 
"workers", but in my first implementation I would like to keep it as simple 
as possible. I am directly using the libraries from withing web2py. So far, 
this is working fine, but I must confess that I have not yet performed 
concurrent access tests.

On Monday, July 9, 2012 4:03:36 PM UTC+2, Massimo Di Pierro wrote:
>
> I am not sure what class Subscriber does but, if it uses the DAL, than you 
> code is problematic.
> The DAL is "smart" in the sense that it keep tracks of all connection open 
> in certain thread and closes them all (or pools them) when the thread ends. 
> By using a module, you store references to those connections (which may be 
> closed or no, depending on the thread) in a persistent object, 
> subscriber_pool, thus making your code not thread safe.
>
> Can you please explain in more detail what are you trying to accomplish? 
> How long should the connections be cached? What is their scope? I am sure 
> there is a better way. :-)
>
>
> On Monday, 9 July 2012 02:32:28 UTC-5, Daniel Gonzalez wrote:
>>
>> Hi,
>>
>> I am using the following pattern to use my libraries with web2py: some of 
>> my utilities are creating connections to databases where I have data that I 
>> need to serve with web2py. This data is not modeled with web2py models. In 
>> order to avoid re-creating these connections with every single request (I 
>> have a site which is performing requests with a 1s period), I have 
>> discovered that the importing of modules is not cleaning the module global 
>> variables. So now what I am doing is creating a cache for the objects that 
>> I want to be persistent across requests. This is my code, in file 
>> subscribers.py:
>>
>> class SubscriberPoolCls:
>> def __init__(self):
>> self.subscriber_pool = { }
>>
>>
>> def get_subscriber(self, subsriber_id, myorg):
>> log.info('get_subscriber > Requested subscriber_id=%s myorg=%d' % 
>> (subsriber_id, myorg))
>> if not subsriber_id in self.subscriber_pool:
>> self.subscriber_pool[subsriber_id] = 
>> Subscriber(myorg,subsriber_id
>> )
>> return self.subscriber_pool[subsriber_id]
>>
>>
>> def unsubscribe_all(self):
>> for subsriber_id in self.subscriber_pool:
>> self.subscriber_pool[subsriber_id].unsubscribe()
>>
>>
>> _subscriber_pool = None
>>
>>
>> def SubscriberPool():
>> global _subscriber_pool
>> if not _subscriber_pool:
>> _subscriber_pool = SubscriberPoolCls()
>> return _subscriber_pool
>>
>> And then in a request I do the following (default.py):
>>
>> from   subscribers  import SubscriberPool
>>
>> subscriber_pool   = SubscriberPool()
>>
>> ...
>>
>> def init_session():
>> if not session.my_session_id:
>> session.my_session_id = get_uuid()
>>
>> ...
>>
>> @auth.requires_login()
>> @service.jsonrpc
>> def get_call_details(pars_json):
>> init_session()
>> myorg = session.auth.user.org_id
>> pars = simplejson.loads(pars_json)
>> subscriber = subscriber_pool.get_subscriber(session.my_session_id,myorg
>> )
>> activity_cdr = subscriber.get_call_details(pars['cdr_doc_id'])
>> response = {
>>
>> 'cdr_details' : activity_cdr,
>> }
>> return simplejson.dumps(response)
>>
>> By doing this I can create a subscriber object associated to the session 
>> 

[web2py] OpenID Server Implementations

2012-07-09 Thread murtaza52
Hi,

I was looking to deploy an openid server which can be used for maintaining 
my user logins. This server can then interact with my web2py app for 
authenticating users. Any recommendations for any open source openid 
servers ? Added advantage if it can be deployed on to GAE. 

Thanks,
Murtaza 


[web2py] list:string & crud form entry -- what's the latest?

2012-07-09 Thread weheh
This has been an oft-disucssed topic. Just search for "list:string crud" 
But having just experienced the pain myself, and not easily locating the 
status of this issue, I felt compelled to ask for myself: 

Shouldn't list:string have a default interactive (jQuery OK) widget that is 
an expandable/collapsible list of user-input text data that works with 
crud? Validators like IS_EMAIL() would then have to iterate on list:string. 
This would be handy for storing entities with multiple emails, for example.

Seems like a gap in web2py's form-input armor and a pretty useful 
capability, to boot. So what's the latest?


[web2py] Upload file into DB without SQLFORM

2012-07-09 Thread Athelionas
What is the proper way of uploading a file without SQLFORM into the 
following database table?

db.define_table('files',
Field('original_filename', 'string'),
Field('file', 'upload', uploadfield='file_data'),
Field('file_data', 'blob'))

A simple insert won't help here so I'm sure there's some kind of trick to 
it which I'm unable to figure out on my own.

Any help is highly appreciated!


[web2py] Slightly OT: Python for iOS

2012-07-09 Thread Jonathan Lundell
FYI, this app just became free. I haven't tried it yet, but it looks like a 
fairly solid implementation. Nice just to have the docs at hand, and a Python 
prompt to play with.

Python for iOS
   iOS Universal
Python for iOS is a Python 2.7.2 environment for the iOS.

🐍 Features 🐍
⇒ Interactive interpreter
⇒ Separate tab for writing and testing script files
⇒ Complete Python 2.7.2 Documentation
⇒ Import saved scripts / modules in the interpreter or other scripts
⇒ Optimized for both Portrait and Lanscape orientations
⇒ Automatic indent / dedent for interpreter and script editor
⇒ Save Interpreter session as a script file to edit / run in the script editor 
tab
⇒ All standard modules and a few extras (like SymPy) included

🐍 In Development 🐍
⇒ Ability to load scripts into the interpreter
⇒ Downloadable documentation of any python version (2.6 - 3.2.2) for offline use

🐍 Planned 🐍
⇒ Python 3.2

[web2py] Re: Create a custom layout based on existing web site css

2012-07-09 Thread Massimo Di Pierro
Simply copy all your static files in static/
Then copy your index.html into views/layout.html
Edit layout.html and replace 
   href="xyz" -> href="{{=URL('static','xyz')}}"
   src="xyz" -> src="{{=URL('static','xyz')}}"
Edit the place where the content goes and add {{include}}

Now you should have a working layout.

You may want to replace the ... with 
{{=MENU(response.menu)}} and add a few things like
{{=response.flash or ''}}
{{=auth.navbar()}}
{{include 'web2py_ajax.html'}}




On Monday, 9 July 2012 03:16:00 UTC-5, Mark Kirkwood wrote:
>
> I am currently developing a web application using web2py. It is at the 
> point where I want to customize the appearance to blend in with an existing 
> html/templated site that I run - so I need to understand how to customize 
> the web2py layout etc to make this happen. While there seems to be many 
> templates/styles around that I could use, there does *not* seem to be a 
> straightforward set of steps to describe how to use or adapt an existing 
> set of css styles within web2py - or have I missed something?
>


[web2py] Re: Dangerous web2py object-reuse pattern?

2012-07-09 Thread Massimo Di Pierro
I am not sure what class Subscriber does but, if it uses the DAL, than you 
code is problematic.
The DAL is "smart" in the sense that it keep tracks of all connection open 
in certain thread and closes them all (or pools them) when the thread ends. 
By using a module, you store references to those connections (which may be 
closed or no, depending on the thread) in a persistent object, 
subscriber_pool, thus making your code not thread safe.

Can you please explain in more detail what are you trying to accomplish? 
How long should the connections be cached? What is their scope? I am sure 
there is a better way. :-)


On Monday, 9 July 2012 02:32:28 UTC-5, Daniel Gonzalez wrote:
>
> Hi,
>
> I am using the following pattern to use my libraries with web2py: some of 
> my utilities are creating connections to databases where I have data that I 
> need to serve with web2py. This data is not modeled with web2py models. In 
> order to avoid re-creating these connections with every single request (I 
> have a site which is performing requests with a 1s period), I have 
> discovered that the importing of modules is not cleaning the module global 
> variables. So now what I am doing is creating a cache for the objects that 
> I want to be persistent across requests. This is my code, in file 
> subscribers.py:
>
> class SubscriberPoolCls:
> def __init__(self):
> self.subscriber_pool = { }
>
>
> def get_subscriber(self, subsriber_id, myorg):
> log.info('get_subscriber > Requested subscriber_id=%s myorg=%d' % 
> (subsriber_id, myorg))
> if not subsriber_id in self.subscriber_pool:
> self.subscriber_pool[subsriber_id] = Subscriber(myorg,subsriber_id
> )
> return self.subscriber_pool[subsriber_id]
>
>
> def unsubscribe_all(self):
> for subsriber_id in self.subscriber_pool:
> self.subscriber_pool[subsriber_id].unsubscribe()
>
>
> _subscriber_pool = None
>
>
> def SubscriberPool():
> global _subscriber_pool
> if not _subscriber_pool:
> _subscriber_pool = SubscriberPoolCls()
> return _subscriber_pool
>
> And then in a request I do the following (default.py):
>
> from   subscribers  import SubscriberPool
>
> subscriber_pool   = SubscriberPool()
>
> ...
>
> def init_session():
> if not session.my_session_id:
> session.my_session_id = get_uuid()
>
> ...
>
> @auth.requires_login()
> @service.jsonrpc
> def get_call_details(pars_json):
> init_session()
> myorg = session.auth.user.org_id
> pars = simplejson.loads(pars_json)
> subscriber = subscriber_pool.get_subscriber(session.my_session_id,myorg
> )
> activity_cdr = subscriber.get_call_details(pars['cdr_doc_id'])
> response = {
>
> 'cdr_details' : activity_cdr,
> }
> return simplejson.dumps(response)
>
> By doing this I can create a subscriber object associated to the session 
> and the organization, and I get to reuse this object in subsequent requests.
>
> Now I have the following questions:
>
>1. Why are the imported modules keeping the global variables? 
>default.py is not, as far as I can tell. I would say it is reparsed with 
>each request.
>2. I have the problem that my object cache 
>(SubscriberPoolCls.subscriber_pool) can grow indefinitely. I do not know 
>how or when to delete entries from this cache.
>3. Do you think this pattern is dangerous? Do you have an alternative?
>
> Thanks,
>
> Daniel
>


[web2py] Re: [Newbie] Using existing Mysql DB with web2py app

2012-07-09 Thread Anthony

>
> 1. Can I use web2py to connect to the existing DB? Is there any automated 
> way of creating the model classes from existing DB tables? Any specific 
> things to keep in mind?
>

http://code.google.com/p/web2py/source/browse/scripts/extract_pgsql_models.py
 


[web2py] Re: how to avoid (catch) sqllite operational error

2012-07-09 Thread Massimo Di Pierro
The problem is that when you catch an OperationalError, you must rollback. 
Else the database does not allow commit anymore.

On Sunday, 8 July 2012 22:55:43 UTC-5, Janath wrote:
>
> It worked :) Thank you
>
> On Sunday, July 8, 2012 6:47:59 PM UTC-5, Massimo Di Pierro wrote:
>>
>> try:
>>
>> except: #catch all
>>db.rollback()
>>.
>>
>> On Sunday, 8 July 2012 17:39:46 UTC-5, Janath wrote:
>>>
>>> Hi,
>>>
>>> I populate a database table by a csv file.
>>>
>>> In run time, if the user tries to upload a file having different format 
>>> to the table. A sqllite operational error is detected.
>>>
>>> In that case I need to inform the user that the file has invalid format.
>>>
>>> I tried with
>>>
>>> try:
>>> 
>>> 
>>> except RuntimeError:
>>> response.flash='Error'
>>> return dict(form=form)
>>>
>>>
>>> I'm unable to catch the error... I have attached the error report
>>>
>>> Plase advice as to how I can avoid a run time error and display a 
>>> message instead.
>>>
>>> Thank you
>>>
>>>
>>>

[web2py] [Newbie] Using existing Mysql DB with web2py app

2012-07-09 Thread Pankaj Chawla
Hi

I am new to web development but have been trying my hands at various python 
frameworks and web2py looks very good. Now my problem is that there is an 
existing web application based on CakePHP and MySQL. While that application is 
complete in itself, the plan is to write an android application that will also 
interact with the same DB through an exposed API using JSON as the protocol 
medium. Since I am not a PHP developer, I will like to use Python for doing 
that API interface and Web2py seems like a good choice to do it. But before I 
dive in there are some questions I have in mind:

1. Can I use web2py to connect to the existing DB? Is there any automated way 
of creating the model classes from existing DB tables? Any specific things to 
keep in mind?

2. Will it create any problems with a CakePHP based web application and an 
android application using a web2py based API to do CRUD on the same Mysql DB? 

3. Can both be hosted on the same apache server? Is the built-in rocket based 
webserver in web2py good for production deployment or only for internal 
development and testing? Since the Web2py app will only be exposing a JSON 
based API I can always have it served on a different port.


---
Take care,
Pankaj



[web2py] Re: SQLFORM.grid id representation bug?

2012-07-09 Thread Anthony
db.define_table('clients',
Field('number'),
Field('name'),
format='%(name)s')

Then you don't have to explicitly define the IS_IN_DB validator, as 
sessions.client_id will get one by default with the format set to the 
db.clients format attribute. In that case, the sessions.client_id represent 
attribute will also be set to the db.clients format attribute.

Anthony

On Monday, July 9, 2012 8:35:41 AM UTC-4, Remco K wrote:
>
> Hi everyone,
>
> I'm working with SQLFORM.grid but I cant get the referenced table 
> representation to work. The only thing i get is the ID of the referenced 
> table(s):
>
> *db.py: *
> db.define_table('clients',
> Field('number'),
> Field('name')
> )
>
> db.define_table('sessions',
> Field('client_id', db.clients),
> Field('state')
> )
>
> db.sessions.client_id.requires = IS_IN_DB(db, db.clients, '%(name)s')
>
> *controller:*
> fields = (db.sessions.client_id)
> headers = {'sessions.client_id':"Client"}
> 
> _form = SQLFORM.grid(db.sessions.id>0 ,fields=fields, 
> headers=headers,maxtextlength
> =500)
> *
> I get:*
> Client
> 111
>
> *Instead of:*
> Client
> 
>
> I've Googled for a while but i cant find any solution yet.
>
> The version of Web2Py i'm using:
>
> Version 2.0.0 (2012-06-29 20:55:40) dev
>
> Thanks in advance!Remco
>


[web2py] Re: SQLFORM.grid id representation bug?

2012-07-09 Thread Johann Spies
On Monday, 9 July 2012 14:35:41 UTC+2, Remco K wrote:
>
> Hi everyone,
>
> I'm working with SQLFORM.grid but I cant get the referenced table 
> representation to work. The only thing i get is the ID of the referenced 
> table(s):
>
> *db.py: *
> db.define_table('clients',
> Field('number'),
> Field('name')
> )
>
> db.define_table('sessions',
> Field('client_id', db.clients),
> Field('state')
> )
>
> db.sessions.client_id.requires = IS_IN_DB(db, db.clients, '%(name)s')
>
> **
>

Search the online book for 
"Record representation"  and you will get your answer.


Regards

Johann


[web2py] SQLFORM.grid id representation bug?

2012-07-09 Thread Remco K
Hi everyone,

I'm working with SQLFORM.grid but I cant get the referenced table 
representation to work. The only thing i get is the ID of the referenced 
table(s):

*db.py: *
db.define_table('clients',
Field('number'),
Field('name')
)

db.define_table('sessions',
Field('client_id', db.clients),
Field('state')
)

db.sessions.client_id.requires = IS_IN_DB(db, db.clients, '%(name)s')

*controller:*
fields = (db.sessions.client_id)
headers = {'sessions.client_id':"Client"}

_form = SQLFORM.grid(db.sessions.id>0 ,fields=fields, 
headers=headers,maxtextlength
=500)
*
I get:*
Client
111

*Instead of:*
Client


I've Googled for a while but i cant find any solution yet.

The version of Web2Py i'm using:

Version 2.0.0 (2012-06-29 20:55:40) dev

Thanks in advance!Remco


[web2py] Re: Working with custom form

2012-07-09 Thread Chris


> which web2py version? Do you have a custom auth_user table? Looks like 
> something wrong with the list of validators for a field containing the 
> IS_UPPER validator.


This is on 1.99.7 stable. I do have two extra field to the auth_user table, 
and use a custom name instead of 'auth_user', but such customization should 
be fairly minimal. I just searched for the use of 'IS_UPPER' validator in 
my code, but didn't find any. The only thing related to it is the use of
 
IS_STRONG(min=7, special=0, upper=0, number=0)

but as you can see, there is no restriction on upper case characters.

I wonder if it has anything to do the javascript form 
(jquery.h5form-2.4.1.min.js) I have in the custom view, as it does some 
validation to the fields as well. Thank you for looking into this.


[web2py] Re: web2py vs ROR

2012-07-09 Thread murtaza52
Massimo,

Appreciate your comments.

As mentioned by you, web2py has packaged all the functionality needed  by a 
web app in a single api, and I am finding this very interesting. This 
certainly allows one to create a web app pretty fast.

The only remaining question is that how easy is it to pull apart things and 
modify them as needed. As I understand web2py will certainly speed up my 
development. However when I need flexibility will I still be easily able to 
change defaults and tweak things ? ( something that loosely couple 
frameworks provide over full stack frameworks)

Thanks,
Murtaza

On Saturday, July 7, 2012 1:26:34 AM UTC+5:30, Massimo Di Pierro wrote:
>
> As pointed out what I said is that I would pick ROR of "most" python 
> frameworks.
>
> In general I prefer to program in Python rather then  Ruby. Indentation 
> makes the code more readable and there are more libraries. Ruby is used in 
> Rails but not much else. Python is used for all kind of things (think about 
> numpy, blender, pyglet, etc.).
>
> Yet Ruby is better designed than most Python framework because if favors 
> convention over configuration. Most Python frameworks instead follow the 
> Python motto "explicit is better the implicit" and the authors despise the 
> concept of "default behaviour" which they refer to as "magic". This means 
> that even very simple simple such as serving a static file require a fair 
> amount of programing. Moreover, as a corollary, most frameworks come in 
> pieces. Ever piece has a name and its own marketing people. This exposes 
> the visibility of the component but it means you have to separately find 
> and install the components you need, learn their api and make sure they are 
> compatible with your own version of the code.
>
> In web2py we tried to copied the RoR approach (everything has a 
> configuration) and we try to package and maintain as many components as 
> possible into the same code base (API for authentication, scheduler, cron, 
> PDF printing, SOAP services, WIKI markup, syntax highlighting, etc.). 
> Moreover we do not rely on third party modules (only on Python standard 
> libraries). 99% of what you may want to can be done with basic web2py 
> without needing external packages. This means the apps are very portable 
> between one installation and another.
>
> The main difference between web2py and other frameworks in practice is not 
> soo much in the its API (which more or less are the same for all 
> frameworks) but for what web2py does for you on the management site: no 
> packages to install, manage through the web interface, no shell programming 
> unless you want to, automatic migrations.
>
> Massimo
>
>
>
> On Friday, 6 July 2012 00:58:36 UTC-5, murtaza52 wrote:
>>
>> Hi,
>>
>> I am considering three frameworks for developing our commercial 
>> applications- 
>>
>> 1) web2py (choice #1)
>> 2) ROR
>> 3) Play framework
>>
>> While my research I was intrigued by Massimo's post where he says that he 
>> would pick ROR over any of the current python frameworks. My question is 
>> how does web2py itself compare to ROR ? What are the views of those 
>> experienced with both the ecosystems ? 
>>
>> http://www.ruby-forum.com/topic/209343
>>
>> I have expereince with none so will rely on your answers :) The purpose 
>> of the question is not to start a flame war, but to understand why should 
>> web2py be chose over other frameworks which have much more traction today?
>>
>> Thanks,
>> Murtaza
>>
>>

Re: [web2py] Re: Standalone DAL leaves mysql connections opened

2012-07-09 Thread Daniel González Zaballos
No (or at least not me), the many connections are from the web 
navigator, that send many get / options or propfind requests for 
dav/svn, when i try only one time to access. Its the same if I use a dav 
or svn client, and with the file explorer included in the application 
they send many request.


I suposse that apache opens a thread in each request.

But with a direct mysql connection (using the mysql library included in 
gluon) we can close all the connections without problems.



El 08/07/12 00:06, Massimo Di Pierro escribió:

Are you using threads?

On Saturday, July 7, 2012 9:21:51 AM UTC-5, demetrio wrote:

It's not working :(

In the best scenario i can leave one connection opened in a whole
request (with other combinations it leaves at least 10 more or less)
only with:

self.db.commit()
from gluon.dal import BaseAdapter
BaseAdapter.close_all_instances('commit')



2012/7/7 Daniel Gonzale mailto:dgzabal...@gmail.com>>:
> Of course, i will try this afternoon.
>
>
>
> El 07/07/2012, a las 03:33, Massimo Di Pierro
mailto:massimo.dipie...@gmail.com>>
> escribió:
>
> Meanwhile, can you check the new db.close() in trunk?
>
> On Friday, 6 July 2012 15:40:57 UTC-5, demetrio wrote:
>>
>> Mail with the code sended :)
>>
>> 2012/7/6 Massimo Di Pierro mailto:massimo.dipie...@gmail.com>>:
>> > I do not recall. Can you resend it please. My personal inbox
is a bit
>> > messy.
>> >
>> >
>> > On Friday, 6 July 2012 05:51:04 UTC-5, demetrio wrote:
>> >>
>> >> I will try this weekend.
>> >>
>> >> Massimo did you received the code of the apllication?
>> >>
>> >> Thanks everyone
>> >>
>> >>
>> >>
>> >> El 06/07/2012, a las 04:32, Massimo Di Pierro
>> >> mailto:massimo.dipie...@gmail.com>>
>> >> escribió:
>> >>
>> >> Looks like I prematurely close the issue. There is now a
db.close() in
>> >> trunk. Please check it out.
>> >>
>> >> massimo
>> >>
>> >> On Thursday, 5 July 2012 13:05:47 UTC-5, nick name wrote:
>> >>>
>> >>> On Thursday, June 28, 2012 10:47:15 AM UTC-4, Massimo Di
Pierro wrote:
>> 
>>  why not simply?
>> 
>>  db.commit()
>>  db.close()
>> 
>>  if db in an on object attribute like self.db you can do
>> 
>>  if self.db:
>> self.db.commit()
>> self.db.close()
>> self.db = 0
>> 
>>  you can also do:
>> 
>>  BaseAdapter.close_all_instances('commit')
>> >>>
>> >>>
>> >>> This is not enough, as was documented on issue
>> >>> http://code.google.com/p/web2py/issues/detail?id=731
. The code that
>> >>> works
>> >>> for me for sqlite is as follows:
>> >>>
>> >>> def closebase(base):
>> >>> if not base: return
>> >>> # see:
http://code.google.com/p/web2py/issues/detail?id=731

>> >>> # see:
>> >>>
https://groups.google.com/d/topic/web2py/hmsupVHdDHo/discussion

>> >>> # was: base._adapter.close()
>> >>> from gluon.dal import thread
>> >>> thread.instances.remove(base._adapter)
>> >>> base._adapter.close()
>> >>>
>> >>> and then I call closebase(db); db = None which is enough
for me with
>> >>> sqlite -- but apparently, the original poster has tried
that, and that
>> >>> is
>> >>> not sufficient for mysql.






Re: [web2py] Re: please help us test web2py

2012-07-09 Thread Andrew
Paolo's bootstrap menu change looks OK to me. 


On Monday, July 9, 2012 6:38:41 PM UTC+12, backseat wrote:
>
> On Sun, 8 Jul 2012 23:31:31 -0700 (PDT), too...@gmail.com said: 
>
> > +1 on removing it... 
> > The internet is covered with too many meaningless share buttons already. 
>
> Surely the whole point of the 'welcome' application is to be a scaffolding 
> to be modified as required? It is much easier for someone new to web2py to 
> work out how to remove it from their new app than to work out how to add 
> it if it isn't there. 
> -- 
> We're looking for smart Linux people: 
> http://www.tiger-computing.co.uk/jobs 
>


[web2py] Create a custom layout based on existing web site css

2012-07-09 Thread Mark Kirkwood
I am currently developing a web application using web2py. It is at the 
point where I want to customize the appearance to blend in with an existing 
html/templated site that I run - so I need to understand how to customize 
the web2py layout etc to make this happen. While there seems to be many 
templates/styles around that I could use, there does *not* seem to be a 
straightforward set of steps to describe how to use or adapt an existing 
set of css styles within web2py - or have I missed something?


[web2py] problem with custom primarykey

2012-07-09 Thread Andrew
See the dot point 
Keyed table can only refer are to other keyed tables.
You have a mixture of Id fields and keys.



Re: [web2py] increase column size

2012-07-09 Thread Johann Spies
On 9 July 2012 09:27, Janath  wrote:

> when I have following:
>
> return dict(form=form, path=form.vars.rule_path, recs=recs)
>
>
> and,  even if the recs have one column, when I display, it does limit the
> column size to some value as follows:
>
> rules.rule_name
> branch_indivi...
> bus_individua...
> bus_individua...
> psse32envset.py
>
>
> how can I increase the column size, so everything is displayed rather than
> having ...
>
> Appreciate a workaround!
>

It depends on what you are using to display the data.

If you use SQLFORM.grid you can apply maxtextwidth = ...

In SQLTABLE you can use the 'truncate' argument.

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


[web2py] Dangerous web2py object-reuse pattern?

2012-07-09 Thread Daniel Gonzalez
Hi,

I am using the following pattern to use my libraries with web2py: some of 
my utilities are creating connections to databases where I have data that I 
need to serve with web2py. This data is not modeled with web2py models. In 
order to avoid re-creating these connections with every single request (I 
have a site which is performing requests with a 1s period), I have 
discovered that the importing of modules is not cleaning the module global 
variables. So now what I am doing is creating a cache for the objects that 
I want to be persistent across requests. This is my code, in file 
subscribers.py:

class SubscriberPoolCls:
def __init__(self):
self.subscriber_pool = { }


def get_subscriber(self, subsriber_id, myorg):
log.info('get_subscriber > Requested subscriber_id=%s myorg=%d' % (
subsriber_id, myorg))
if not subsriber_id in self.subscriber_pool:
self.subscriber_pool[subsriber_id] = Subscriber(myorg,subsriber_id
)
return self.subscriber_pool[subsriber_id]


def unsubscribe_all(self):
for subsriber_id in self.subscriber_pool:
self.subscriber_pool[subsriber_id].unsubscribe()


_subscriber_pool = None


def SubscriberPool():
global _subscriber_pool
if not _subscriber_pool:
_subscriber_pool = SubscriberPoolCls()
return _subscriber_pool

And then in a request I do the following (default.py):

from   subscribers  import SubscriberPool

subscriber_pool   = SubscriberPool()

...

def init_session():
if not session.my_session_id:
session.my_session_id = get_uuid()

...

@auth.requires_login()
@service.jsonrpc
def get_call_details(pars_json):
init_session()
myorg = session.auth.user.org_id
pars = simplejson.loads(pars_json)
subscriber = subscriber_pool.get_subscriber(session.my_session_id, myorg
)
activity_cdr = subscriber.get_call_details(pars['cdr_doc_id'])
response = {

'cdr_details' : activity_cdr,
}
return simplejson.dumps(response)

By doing this I can create a subscriber object associated to the session 
and the organization, and I get to reuse this object in subsequent requests.

Now I have the following questions:

   1. Why are the imported modules keeping the global variables? default.py 
   is not, as far as I can tell. I would say it is reparsed with each request.
   2. I have the problem that my object cache 
   (SubscriberPoolCls.subscriber_pool) can grow indefinitely. I do not know 
   how or when to delete entries from this cache.
   3. Do you think this pattern is dangerous? Do you have an alternative?

Thanks,

Daniel


[web2py] increase column size

2012-07-09 Thread Janath
when I have following:

return dict(form=form, path=form.vars.rule_path, recs=recs)


and,  even if the recs have one column, when I display, it does limit the 
column size to some value as follows:

rules.rule_name
branch_indivi...
bus_individua...
bus_individua...
psse32envset.py

 
how can I increase the column size, so everything is displayed rather than 
having ... 

Appreciate a workaround!