[web2py] Re: Validating Registration fields

2012-03-28 Thread Peter G.
Thank you so much! That worked like a charm :). I'm guessing this type of 
construct is valid for other validators as well?

On Tuesday, March 27, 2012 5:57:28 PM UTC-7, Anthony wrote:
>
> Try
>
> IS_EMPTY_OR(IS_IMAGE())
>
>
> Anthony
>
> On Tuesday, March 27, 2012 7:12:45 PM UTC-4, Peter G. wrote:
>>
>> Thanks for the code snippets Anthony--but a minor caveat I didn't realize 
>> ahead of time is that the user is free to either upload an image or not. If 
>> the user does not upload an image, the IS_IMAGE() validators barks at the 
>> user. Is there a easy way of implementing such a logic: "if a file is 
>> uploaded, check for IS_IMAGE(), otherwise ignore."?
>>
>>
>> On Thursday, March 22, 2012 3:38:01 PM UTC-7, Anthony wrote:
>>>
>>> On Thursday, March 22, 2012 6:09:25 PM UTC-4, Peter G. wrote:

 I'm using the auth.settengs.extra_fields to add an extra upload field 
 for the user to upload an avatar, how can I add an IS_IMAGE validator to 
 the upload field so that the user can't upload random files?
>>>
>>>
>>> When you define the field, you can do:
>>>
>>> Field('avatar', 'upload', requires=IS_IMAGE())
>>>
>>> or after the tables have been defined:
>>>
>>> db.auth_user.avatar.requires = IS_IMAGE()
>>>  
>>>

 Also, how would I add an IS_ALPHANUMERIC to the built in First name and 
 Last name form fields? Right now there are users registering with names 
 like "!@#$%^~" and some such...

>>>
>>> After the tables have been defined, you can do:
>>>
>>> db.auth_user.first_name.requires.append(IS_ALPHANUMERIC())
>>>
>>> That adds the validator to the existing IS_NOT_EMPTY validator.
>>>
>>> However, I wouldn't use that validator for names because it doesn't 
>>> allow valid name characters such as spaces, hyphens, and apostrophes. 
>>> Anyway, if you prevent fake names with special characters, those users will 
>>> just create fake names with alphanumeric characters, so either way you 
>>> don't have a real name.
>>>
>>> Anthony
>>>
>>

[web2py] Re: Modify T() function

2012-03-28 Thread John-Kim Murphy
Hmm.. I had this idea a long time ago. Never got around to implementing it, 
though. Here's an email that was sitting in my drafts box for over a year. 
It's got some additional suggestions, too:

The T object and simple internationalization is one of the reasons I chose 
the Web2Py framework. After toying with it for a bit, I have some 
suggestions to make it even better:

Even the simple Welcome app already has pages of translation strings! How 
about some tools to organize them?

   - Optionally hide strings that have already been translated.
   - Add an optional hint parameter to T(). This string is displayed next 
   to the original string in the admin interface. It simply gives more 
   clues/context for the translation. Example: T("Enter ", hint="Noun: also 
   called Return key (not the verb!)")
   - Add optional translation contexts. These would be useful for grouping 
   strings that belong together, for example those that appear in the same 
   form or page. These could be defined like the authorization decorations 
   over a block of code, or explicitly opened and closed with calls to 
   TCONTEXT().
   - Common strings (like "yes" and "no") may end up with multiple 
   contexts--I imagine contexts more like tags. Although the same translation 
   is applied to every context by default, certain contexts could be 
   over-ridden when they don't fit. (For example, 
contronyms may 
   need context-based translation to other languages.)
   

If I end up developing an app that needs heavy-duty localization, I will 
probably end up implementing some of the ideas from above.

John-Kim

On Thursday, March 22, 2012 10:18:16 PM UTC+9, Kalpa Welivitigoda wrote:
>
> Hi,
>
> I am working on a translation enhancement project on sahana-eden[1]. 
> sahana-eden uses the translation feature of web2py. Is it possible to have 
> a modified T() function so that the developer can leave a comment for the 
> translator, for example T("This is a SAMPLE", "keep SAMPLE as it is") where 
> the second argument is the comment. Or is there any other mechanism in 
> web2py to accomplish this task. Further the language file in 
> /applications//languages/.py should be in the format
>
> "source string": "target string": "comment"
>
> I may be able to modify my local web2py so that this is accomplished. 
> Rather I would like to see this upstream as for 
> 1) sahana-eden is deployed with web2py framework so it needs it's core 
> functions build into it (patching is not so nice)
> 2) there will be many other projects existing or about to deploy on web2py 
> which will be benefited with this method.
>
> The whole idea is that the translator has more information that will 
> ultimately help to end in a better translation.
>
> I'm willing to contribute in code if the developers want me to.
>
> [1] eden.sahanafoundation.org
>
> Thank you
>


Re: [web2py] how to redirect from ajax

2012-03-28 Thread Bruno Rocha
On your javascript code you can do.

location = "url"

http://zerp.ly/rochacbruno
Em 28/03/2012 01:01, "weheh"  escreveu:

> I'm trying to figure out how the proper syntax to redirect from an ajax
> call using HTTP(200,Location=URL(...)).
>
> The problem is the ajax call points to either an id or an :eval. But I
> want to refresh the entire page -- wiping the slate clean. Is this possible?
>


[web2py] Viewing tickets outside of admin

2012-03-28 Thread tsvim
Hi,

Lately, I've been using pythonanywhere to work on my pet project together 
with Dropbox. It's very fun, as it allows me to test all kinds of access 
(mobile, desktop), various environments (work, home), os's etc.
Obviously I'm unable to access the admin as I'm not at a local machine and 
I don't want to enable remote access to the admin.
I was wondering since I'm using Dropbx to sync my files, I do have local 
access to the ticket files themselves.
Is there some parser that would allow me to look at the tickets without 
needing to run web2py locally to have access to the admin?
I would even imagine a hook that would automagically parse the ticket into 
text form and save a text version of it.

Thanks,

Tsvi


[web2py] Re: Validating Registration fields

2012-03-28 Thread Anthony
On Wednesday, March 28, 2012 5:34:05 AM UTC-4, Peter G. wrote:
>
> Thank you so much! That worked like a charm :). I'm guessing this type of 
> construct is valid for other validators as well?
>

Yes, it's documented here: 
http://web2py.com/books/default/chapter/29/7#Validators
 


[web2py] Re: Form validation on passwords

2012-03-28 Thread Anthony
I tried your code, and it works fine for me. However, the password 
"Testpwd" should actually result in an error because the IS_STRONG() 
validator defaults to number=1 (i.e., at least one number in the password), 
and you didn't change that default. So, you should get an error on the 
password field. If the error isn't showing up, perhaps there's a problem 
with your view code. Have you created a custom form in the HTML?

Anthony

On Tuesday, March 27, 2012 11:53:37 PM UTC-4, cyan wrote:
>
>
> Thanks for the pointer. Anthony.
>
> So now I have the following in my controller:
>
> def register():
>  form = SQLFORM.factory( 
>  Field('email', requires=[IS_NOT_EMPTY(), IS_EMAIL(forced=
> '^.*\.edu(|\..*)$', 
>  error_message='email must be .edu address')]), 
>  Field('pwd', requires=[IS_NOT_EMPTY(), IS_STRONG(min=6, special=0, upper=
> 1, 
>  error_message='minimum 6 characters, and at least 1 uppercase character'
> ), CRYPT()]), 
>  Field('re_pwd', requires=IS_EXPR('value==%s' % repr(request.vars.get(
> 'pwd', None)), 
>  error_message='passwords do not match'))) 
>
>  if form.process().accepted: 
>  session.email = form.vars.email 
>  session.pwd = form.vars.pwd 
>  redirect(URL('registered')) 
>  return dict(form=form)
>
>
> And, for testing, I input the following:
>
> a...@abc.edu
>
> Testpwd
>
> Testpwd
>
>
> I didn't get any error messages, so presumably all three validations went 
> fine. However, using a debugger revealed that form.accepted is still None 
> after calling process() on the form. I wonder what went wrong here. Thanks.
> On Tuesday, March 27, 2012 5:54:02 PM UTC-4, Anthony wrote:
>>
>> Here's how auth.register() does it (slightly edited):
>>
>> requires=IS_EXPR('value==%s' % repr(request.vars.get('password', None)),
>>  error_message="Password fields don't match")
>>
>> Anthony
>>
>> On Tuesday, March 27, 2012 5:40:29 PM UTC-4, cyan wrote:
>>>
>>>
>>> Hi group,
>>>
>>> How do I enforce some simple validation for passwords matching on a form 
>>> in a controller? All I want to do is to check the second password is the 
>>> same as the first one, and here is some code I've come up so far:
>>>
>>> form = SQLFORM.factory(
>>>  Field('email', requires=IS_NOT_EMPTY()),
>>>  Field('pwd', requires=[IS_NOT_EMPTY(), IS_STRONG(min=6, special=0,upper
>>> =1), CRYPT()]),
>>>  Field('re_pwd', requires=IS_MATCH(???)))
>>>
>>> I am attempting to use the validator 'IS_MATCH()' for the second 
>>> password, but not sure how I reference the the input in the first password 
>>> field of the same form. Any suggestion would be welcome. Thanks.
>>>
>>

[web2py] Re: New Google Groups functionality

2012-03-28 Thread Anthony
On question posts, if you're using the web interface, you can now vote 
responses to the question up or down (the best response will be displayed 
on top). You'll see a green up arrow and red down arrow at the bottom of 
each response (except for your own).

On Tuesday, March 27, 2012 4:50:49 PM UTC-4, Anthony wrote:
>
> Google Groups has added some new functionality that enables us to 
> distinguish between discussion, question, and announcement posts. If you 
> use the (new) web interface to make a post (
> https://groups.google.com/forum/?fromgroups#!forum/web2py), it will now 
> default to a "question" post. However, you can easily change that to 
> "discussion" or "announcement" once you are creating the post. It is also 
> now possible to add a comma separated list of tags to each post. Enjoy.
>
> Anthony
>


[web2py] Re: how to redirect from ajax

2012-03-28 Thread weheh
I don't understand why HTTP(200,Location=URL(...)) isn't redirecting to 
URL(...)?


On Wednesday, March 28, 2012 12:01:05 PM UTC+8, weheh wrote:
>
> I'm trying to figure out how the proper syntax to redirect from an ajax 
> call using HTTP(200,Location=URL(...)).
>
> The problem is the ajax call points to either an id or an :eval. But I 
> want to refresh the entire page -- wiping the slate clean. Is this possible?
>


[web2py] Re: SQLFORM & deletable=True -- buggy behavior

2012-03-28 Thread weheh
I've switched over to web2py.js from web2py_ajax.js but the problem of 
multiple popups is still there.



On Thursday, March 22, 2012 9:39:46 PM UTC+8, Anthony wrote:
>
> No, I'm only using the web2py_trap_form out of the cookbook. The rest 
>> of the web2py_ajax.js file is the same.
>>
>
> If the name of the file is web2py_ajax.js, it's probably old -- it was 
> changed to web2py.js quite a while ago.
>
> Anthony 
>


Re: [web2py] Re: how to redirect from ajax

2012-03-28 Thread Jonathan Lundell
On Mar 28, 2012, at 6:18 AM, weheh wrote:
> I don't understand why HTTP(200,Location=URL(...)) isn't redirecting to 
> URL(...)?

Shouldn't you be using a 30x response here?

> 
> 
> On Wednesday, March 28, 2012 12:01:05 PM UTC+8, weheh wrote:
> I'm trying to figure out how the proper syntax to redirect from an ajax call 
> using HTTP(200,Location=URL(...)).
> 
> The problem is the ajax call points to either an id or an :eval. But I want 
> to refresh the entire page -- wiping the slate clean. Is this possible?




[web2py] Re: skeleton.css resetting possible css mistake

2012-03-28 Thread Massimo Di Pierro
We did not add that line to skeleton but looks like a mistake in skeleton. 
Anyway, we'll soon move away from skeleton to bootstrap 2.

On Tuesday, 27 March 2012 16:20:16 UTC-5, jep wrote:
>
> With web2py 1.99.7 i try to display preformatted code between "   
>    " but the result does not look like preformatted text should 
> look like. .
>
> In skeleton.css on line 28 i found that  pre is being reset to default 
> (inherit) font, I think this might be the cause. 
> After I removed pre from line 28 in skeleton.css  it looked ok.
>
> Can somebody confirm this is a mistake ? 
>


[web2py] Re: how to redirect from ajax

2012-03-28 Thread Anthony

>
> I don't understand why HTTP(200,Location=URL(...)) isn't redirecting to 
> URL(...)?


You need to issue a 303 to get the browser to redirect to the URL in the 
"Location" header. But if it is an ajax request, that will only redirect 
the ajax request itself -- it won't reload the whole page. If you want an 
ajax call to result in the whole page reloading, you'll have to do that via 
Javascript at the completion of the ajax call. If you are using the ajax() 
function to make the ajax call, you could do something like this:

In the view:

ajax("{{=URL('default', 'myfunc')}}", [], ":eval")

In default.py:

def myfunc():
return 'window.location = "%s";' % URL('default', 'otherfunc')

Anthony



Re: [web2py] unable to parse csv file 'NoneType' object is unsubscriptable with list:reference type field

2012-03-28 Thread Massimo Di Pierro
Please open a ticket.

On Tuesday, 27 March 2012 16:04:47 UTC-5, Richard wrote:
>
> Same thing with trunk...
>
> Richard
>
> On Tue, Mar 27, 2012 at 3:52 PM, Richard wrote:
>
>> This one to : 
>> https://groups.google.com/forum/?fromgroups#!topic/web2py/H_QqV2g8IgQ
>>
>> I experimented the problem with 1.99.4 and 1.99.7
>>
>> What I understand so far is that id_map get None by default, so when it 
>> get here :
>>
>> [id_map[ref_table][int(v)] \
>>  for v in bar_decode_string('|35|1|')]
>>
>> It clears that it will raise the exception...
>>
>> I try to call my import function like this :
>>
>> def import_csv(table, file):
>> table.import_from_csv_file(file, id_map = {})
>>
>> Noting better.
>>
>> Please help.
>>
>> Richard
>>
>>
>> Le mardi 27 mars 2012 15:45:50 UTC-4, Richard a écrit :
>>
>>> Seems related : https://groups.google.com/**forum/#!topic/web2py/**
>>> nYKsFPumXk0 
>>>
>>>
>>>
>>> Le mardi 27 mars 2012 15:20:27 UTC-4, Richard a écrit :

 Hello,

 Is it possible the table csv import method be broken?

 When I use list:reference type field I can't import back a exported CSV 
 with the appadmin.

 I don't understand where the None value could come from...

 When I try to implement my own csv import function base on this thread 
 : https://groups.google.com/**forum/?fromgroups#!topic/**
 web2py/lDi0lLK_Wm0

 That work fine, until I try to import data with list:reference type 
 field (|id| or |id|id|, etc.)

 I get this traceback :

 for v in bar_decode_string(value)]

 TypeError: 'NoneType' object is unsubscriptable

  
-  


  Function argument list

 (field=, value='|35|1|', id_map=None)
  Code listing




 5683.
 5684.
 5685.
 5686.
 5687.


 5688.

 5689.
 5690.
 5691.
 5692.

 elif field.type.startswith('list:**string'):


 value = bar_decode_string(value)


 elif field.type.startswith(list_**reference_s):


 ref_table = field.type[len(list_reference_**s):].strip()


 value = [id_map[ref_table][int(v)] \



  for v in bar_decode_string(value)]


 elif field.type.startswith('list:')**:


 value = bar_decode_integer(value)


 elif id_map and field.type.startswith('**reference'):


 try:

  Variables  global bar_decode_string  
 value'|35|1|' 
 v '35'

 What is exactly id_map?

 I think problem is coming from there...

 Thanks

 Richard

>>>
>

[web2py] Re: Viewing tickets outside of admin

2012-03-28 Thread Alan Etkin
Well, the admin web interface has to parse it somehow to render it in the 
browser, there must be a function in appadmin or in the admin app for that 
purpose.

El miércoles 28 de marzo de 2012 08:33:11 UTC-3, tsvim escribió:
>
> Hi,
>
> Lately, I've been using pythonanywhere to work on my pet project together 
> with Dropbox. It's very fun, as it allows me to test all kinds of access 
> (mobile, desktop), various environments (work, home), os's etc.
> Obviously I'm unable to access the admin as I'm not at a local machine and 
> I don't want to enable remote access to the admin.
> I was wondering since I'm using Dropbx to sync my files, I do have local 
> access to the ticket files themselves.
> Is there some parser that would allow me to look at the tickets without 
> needing to run web2py locally to have access to the admin?
> I would even imagine a hook that would automagically parse the ticket into 
> text form and save a text version of it.
>
> Thanks,
>
> Tsvi
>


[web2py] Re: SQLFORM & deletable=True -- buggy behavior

2012-03-28 Thread Anthony
On Wednesday, March 28, 2012 9:28:03 AM UTC-4, weheh wrote:
>
> I've switched over to web2py.js from web2py_ajax.js but the problem of 
> multiple popups is still there.


Can you pack up and attach a minimal app that reproduces the problem?

Anthony


[web2py] Re: Form validation on passwords

2012-03-28 Thread cyan

My view code is fairly minimal, but I suspect it is where the bug lies:

{{extend 'layout.html'}} 
 
  Email address:  
  Password:  
  Confirm password:  
   



Do I need to kinda specify the error message here as well? Thanks again.

On Wednesday, March 28, 2012 8:54:55 AM UTC-4, Anthony wrote:
>
> I tried your code, and it works fine for me. However, the password 
> "Testpwd" should actually result in an error because the IS_STRONG() 
> validator defaults to number=1 (i.e., at least one number in the password), 
> and you didn't change that default. So, you should get an error on the 
> password field. If the error isn't showing up, perhaps there's a problem 
> with your view code. Have you created a custom form in the HTML?
>
> Anthony
>
> On Tuesday, March 27, 2012 11:53:37 PM UTC-4, cyan wrote:
>>
>>
>> Thanks for the pointer. Anthony.
>>
>> So now I have the following in my controller:
>>
>> def register():
>>  form = SQLFORM.factory( 
>>  Field('email', requires=[IS_NOT_EMPTY(), IS_EMAIL(forced=
>> '^.*\.edu(|\..*)$', 
>>  error_message='email must be .edu address')]), 
>>  Field('pwd', requires=[IS_NOT_EMPTY(), IS_STRONG(min=6, special=0, upper
>> =1, 
>>  error_message='minimum 6 characters, and at least 1 uppercase character'
>> ), CRYPT()]), 
>>  Field('re_pwd', requires=IS_EXPR('value==%s' % repr(request.vars.get(
>> 'pwd', None)), 
>>  error_message='passwords do not match'))) 
>>
>>  if form.process().accepted: 
>>  session.email = form.vars.email 
>>  session.pwd = form.vars.pwd 
>>  redirect(URL('registered')) 
>>  return dict(form=form)
>>
>>
>> And, for testing, I input the following:
>>
>> a...@abc.edu
>>
>> Testpwd
>>
>> Testpwd
>>
>>
>> I didn't get any error messages, so presumably all three validations went 
>> fine. However, using a debugger revealed that form.accepted is still None 
>> after calling process() on the form. I wonder what went wrong here. Thanks.
>> On Tuesday, March 27, 2012 5:54:02 PM UTC-4, Anthony wrote:
>>>
>>> Here's how auth.register() does it (slightly edited):
>>>
>>> requires=IS_EXPR('value==%s' % repr(request.vars.get('password', None)),
>>>  error_message="Password fields don't match")
>>>
>>> Anthony
>>>
>>> On Tuesday, March 27, 2012 5:40:29 PM UTC-4, cyan wrote:


 Hi group,

 How do I enforce some simple validation for passwords matching on a 
 form in a controller? All I want to do is to check the second password is 
 the same as the first one, and here is some code I've come up so far:

 form = SQLFORM.factory(
  Field('email', requires=IS_NOT_EMPTY()),
  Field('pwd', requires=[IS_NOT_EMPTY(), IS_STRONG(min=6, special=0,upper
 =1), CRYPT()]),
  Field('re_pwd', requires=IS_MATCH(???)))

 I am attempting to use the validator 'IS_MATCH()' for the second 
 password, but not sure how I reference the the input in the first password 
 field of the same form. Any suggestion would be welcome. Thanks.

>>>

Re: [web2py] Re: how to redirect from ajax

2012-03-28 Thread weheh
Many thanks, Jonathan, Anthony. I didn't realize the HTTP return value (200 
vs. 300 etc.) might actually make a difference in the execution of the 
Location argument. Again, I must go back and look even more closely at the 
HTTP source and auth source. It's always a balance between slogging through 
the source or throwing a slow pitch out to you guys, who routinely hit the 
ball out of the park.

On Wednesday, March 28, 2012 9:32:45 PM UTC+8, Jonathan Lundell wrote:
>
> On Mar 28, 2012, at 6:18 AM, weheh wrote:
>
> I don't understand why HTTP(200,Location=URL(...)) isn't redirecting to 
> URL(...)?
>
>
> Shouldn't you be using a 30x response here?
>
>
>
> On Wednesday, March 28, 2012 12:01:05 PM UTC+8, weheh wrote:
>>
>> I'm trying to figure out how the proper syntax to redirect from an ajax 
>> call using HTTP(200,Location=URL(...)).
>>
>> The problem is the ajax call points to either an id or an :eval. But I 
>> want to refresh the entire page -- wiping the slate clean. Is this possible?
>>
>
>
>

Re: [web2py] Re: how to redirect from ajax

2012-03-28 Thread weheh
Oh, and credit also to Bruno for actually being the first to swing and 
connect with the location answer. I have some more tinkering to do before 
I'm fully out of the woods on this issue.

On Wednesday, March 28, 2012 9:56:02 PM UTC+8, weheh wrote:
>
> Many thanks, Jonathan, Anthony. I didn't realize the HTTP return value 
> (200 vs. 300 etc.) might actually make a difference in the execution of the 
> Location argument. Again, I must go back and look even more closely at the 
> HTTP source and auth source. It's always a balance between slogging through 
> the source or throwing a slow pitch out to you guys, who routinely hit the 
> ball out of the park.
>
> On Wednesday, March 28, 2012 9:32:45 PM UTC+8, Jonathan Lundell wrote:
>>
>> On Mar 28, 2012, at 6:18 AM, weheh wrote:
>>
>> I don't understand why HTTP(200,Location=URL(...)) isn't redirecting to 
>> URL(...)?
>>
>>
>> Shouldn't you be using a 30x response here?
>>
>>
>>
>> On Wednesday, March 28, 2012 12:01:05 PM UTC+8, weheh wrote:
>>>
>>> I'm trying to figure out how the proper syntax to redirect from an ajax 
>>> call using HTTP(200,Location=URL(...)).
>>>
>>> The problem is the ajax call points to either an id or an :eval. But I 
>>> want to refresh the entire page -- wiping the slate clean. Is this possible?
>>>
>>
>>
>>

[web2py] Re: Modify T() function

2012-03-28 Thread Anthony
On Wednesday, March 28, 2012 9:48:47 AM UTC-4, Massimo Di Pierro wrote:
>
> We actually have that already. The way to do is:
>
> T(' hello world ## comment')
>

Another secret feature. Find them all, and you get a prize. :-)
 


[web2py] New HackerNews discussion about python frameworks - web2py is not getting enough love

2012-03-28 Thread nick name
Come say the good things you have to say about web2py on 
http://news.ycombinator.com/item?id=3765610


Re: [web2py] Re: how to redirect from ajax

2012-03-28 Thread Anthony

>
> Many thanks, Jonathan, Anthony. I didn't realize the HTTP return value 
> (200 vs. 300 etc.) might actually make a difference in the execution of the 
> Location argument. Again, I must go back and look even more closely at the 
> HTTP source and auth source.
>

Note, this is not an issue with how the web2py HTTP() class works. This is 
simply how browsers deal with response codes. A response code of 200 means 
OK, so does not prompt the browser to redirect. If you want the browser to 
redirect, you have to send a 3xx code (or use Javascript to change the 
window.location, as already suggested). 
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.

Anthony


[web2py] Re: New HackerNews discussion about python frameworks - web2py is not getting enough love

2012-03-28 Thread Richard Penman
yes quite hostile:

"the smartest web hackers I know universally regard web2py as a 
fundamentally incorrect way to approach web development—but usually say so 
in far more colorful terms."

"web2py appears both bad and unpopular to me"




[web2py] Re: Form validation on passwords

2012-03-28 Thread Anthony

>
> My view code is fairly minimal, but I suspect it is where the bug lies:
>
> {{extend 'layout.html'}} 
>  
>   Email address:  
>   Password:  
>   Confirm password:  
>
> 
>

Yes, you have created your form manually in pure HTML, and you have not 
included the error divs, so no errors will appear when one occurs. You 
might consider just using web2py's standard form serialization via:

{{=form}}

You can change the formstyle if you like (see 
http://web2py.com/books/default/chapter/29/7#SQLFORM for details). If you 
need more customization, try the method shown here: 
http://web2py.com/books/default/chapter/29/7#Custom-forms. That let's you 
control the layout but still uses the field widgets generated by web2py 
(which include the errors when they occur). Also, for details on how to 
handle your own error displaying, see 
here: http://web2py.com/books/default/chapter/29/7#Hide-errors.

Anthony 


Re: [web2py] Re: how to redirect from ajax

2012-03-28 Thread Bruno Rocha
[off-topic]

A note about JavaScript, something that I learned on JS workshop last week.

in JS "window" is the same as globals() in python, so we do not need to use
that explicitly, int the same way we do in Python.

Ex:
Python.

*globals()["__name__"]* is the same of simply *__name__*

JavaScript

*window.location* is the same as simply *location*

So even your own objects are stored into window object (the same way your
python objects are stored in globals())

name ="Bruno" the same as window.name = "Bruno"

Not that gain of performance or something like, just curiosity.



On Wed, Mar 28, 2012 at 10:36 AM, Anthony  wrote:

> I don't understand why HTTP(200,Location=URL(...)) isn't redirecting to
>> URL(...)?
>
>
> You need to issue a 303 to get the browser to redirect to the URL in the
> "Location" header. But if it is an ajax request, that will only redirect
> the ajax request itself -- it won't reload the whole page. If you want an
> ajax call to result in the whole page reloading, you'll have to do that via
> Javascript at the completion of the ajax call. If you are using the ajax()
> function to make the ajax call, you could do something like this:
>
> In the view:
>
> ajax("{{=URL('default', 'myfunc')}}", [], ":eval")
>
> In default.py:
>
> def myfunc():
> return 'window.location = "%s";' % URL('default', 'otherfunc')
>
> Anthony
>
>


-- 

Bruno Rocha
[http://rochacbruno.com.br]


Re: [web2py] Re: how to redirect from ajax

2012-03-28 Thread Jonathan Lundell
On Mar 28, 2012, at 6:56 AM, weheh wrote:
> Many thanks, Jonathan, Anthony. I didn't realize the HTTP return value (200 
> vs. 300 etc.) might actually make a difference in the execution of the 
> Location argument. Again, I must go back and look even more closely at the 
> HTTP source and auth source. It's always a balance between slogging through 
> the source or throwing a slow pitch out to you guys, who routinely hit the 
> ball out of the park.

Well, the whole Ajax business gives me a headache. At any rate, as Anthony 
points out, you need to tailor your redirection request to its intended 
audience, and in this context passing the new location to your JavaScript is 
likely to make more sense.

web2py's ajax() function ultimately makes its request with jQuery.ajax(), which 
is making the http request and (I assume) handling 30x redirects. You *could* 
use  HTTP(200, Location=URL(...)), but then your JavaScript code would have to 
check the returned headers and do the redirection itself, and it doesn't look 
like ajax() has hooks for that; you'd have to call jQuery.ajax yourself. I 
think.

So the question is whether you want the browser to load the new URL as a page, 
or you want the new URL to be the real reply to the ajax() call. I think.

> 
> On Wednesday, March 28, 2012 9:32:45 PM UTC+8, Jonathan Lundell wrote:
> On Mar 28, 2012, at 6:18 AM, weheh wrote:
>> I don't understand why HTTP(200,Location=URL(...)) isn't redirecting to 
>> URL(...)?
> 
> Shouldn't you be using a 30x response here?
> 
>> 
>> 
>> On Wednesday, March 28, 2012 12:01:05 PM UTC+8, weheh wrote:
>> I'm trying to figure out how the proper syntax to redirect from an ajax call 
>> using HTTP(200,Location=URL(...)).
>> 
>> The problem is the ajax call points to either an id or an :eval. But I want 
>> to refresh the entire page -- wiping the slate clean. Is this possible?
> 




[web2py] Re: how to redirect from ajax [closed]

2012-03-28 Thread weheh
OK, this issue is now put to bed. Thank you all for your help.

P.S. -- what this issue has taught me touches on what pbreit said in 
another thread about the hazards of bypassing wonderful web2py built-in 
auth login/logout facilities when you choose the route of auth by dialog. 
My approach, has been to explore a fully-componentized version of my 
website. What I didn't fully appreciate is that if you take that approach, 
it's an all or nothing game. And the all-component approach touches more of 
the site than I had originally anticipated.

Now that I realize how big a commitment it is, I understand what needs to 
be done to make it all work. It means more work up front, but the upshot is 
a much more dynamic website with (usually) much faster response times once 
you get past the initial page load. The remarkable thing is that you can 
compress a multi-multi-multi-page website down to a single page. If planned 
properly up front, it's not that much overhead to do. My problem is that 
I've evolved to it over a long time, so I've had to rework lots of 
old-think stuff in order to get to nirvana. Sounds a lot like life, doesn't 
it? ;-)


[web2py] Re: Modify T() function

2012-03-28 Thread Massimo Di Pierro
We actually have that already. The way to do is:

T(' hello world ## comment')

This was introduced for a different purpose, allow the same string to have 
two different translations in different places. The comment causes the 
string to be treated as different in different places.

Check if this works for you and, if not, we can improve it.

Notice that you may need to include ## in the actual translated string. You 
can do this by adding a ## at the end

T(' hello world ## not a comment ## a comment')




On Thursday, 22 March 2012 08:18:16 UTC-5, Kalpa Welivitigoda wrote:
>
> Hi,
>
> I am working on a translation enhancement project on sahana-eden[1]. 
> sahana-eden uses the translation feature of web2py. Is it possible to have 
> a modified T() function so that the developer can leave a comment for the 
> translator, for example T("This is a SAMPLE", "keep SAMPLE as it is") where 
> the second argument is the comment. Or is there any other mechanism in 
> web2py to accomplish this task. Further the language file in 
> /applications//languages/.py should be in the format
>
> "source string": "target string": "comment"
>
> I may be able to modify my local web2py so that this is accomplished. 
> Rather I would like to see this upstream as for 
> 1) sahana-eden is deployed with web2py framework so it needs it's core 
> functions build into it (patching is not so nice)
> 2) there will be many other projects existing or about to deploy on web2py 
> which will be benefited with this method.
>
> The whole idea is that the translator has more information that will 
> ultimately help to end in a better translation.
>
> I'm willing to contribute in code if the developers want me to.
>
> [1] eden.sahanafoundation.org
>
> Thank you
>


[web2py] Re: how to redirect from ajax [closed]

2012-03-28 Thread weheh
P.P.S. As I was saying about compressing the site down to one page ... the 
real reason why I was having to do this contortion with redirect is because 
I HAVEN'T compressed the site down to one page. It's actually more like 2 
or 3 pages. When I have a little more time, I will compress it down to 1 
and then see how it changes things.

@Jonathan -- yes the whole ajax business is headache inducing. Much like 
quantum physics. But after awhile, the old way of thinking (Newtonian 
viewpoint in the case of physics, or static pages in the case of web stuff) 
just seems so limited, and frankly, in the case of physics, insane. Said 
differently, just as Newtonian physics (classical mechanics) is a limiting 
case of quantum physics, static pages is a limiting case of ajax.


[web2py] Re: SQLFORM & deletable=True -- buggy behavior

2012-03-28 Thread weheh
I'll have to think hard about how to extract my example whilst isolating 
the bug. I'll need some time ...

On Wednesday, March 28, 2012 9:42:54 PM UTC+8, Anthony wrote:
>
> On Wednesday, March 28, 2012 9:28:03 AM UTC-4, weheh wrote:
>>
>> I've switched over to web2py.js from web2py_ajax.js but the problem of 
>> multiple popups is still there.
>
>
> Can you pack up and attach a minimal app that reproduces the problem?
>
> Anthony
>


[web2py] Apache+virtualhosts+wsgi, loading always the same content

2012-03-28 Thread Sergi Pons Freixes
Hi All,

After checking the apache documentation and looking at older related 
discussions in the group, I still don't get what's wrong on my setup. What 
I want to achieve is:

cub3.net -> Load my home page
www.cub3.net -> Load my home page
web2py.cub3.net -> Load web2py

Using Apache with mod_wsgi. My current config files are:

  

ServerName cub3.net 
ServerAlias www.cub3.net
DocumentRoot 
/srv/www/cub3.net/public_html/  
   ErrorLog /srv/www/cub3.net/logs/error.log
   CustomLog /srv/www/cub3.net/logs/access.log combined 

  

and 

  

ServerName web2py.cub3.net  

WSGIDaemonProcess web2py user=www-data group=www-data display-name=%{GROUP} 

WSGIProcessGroup web2py 

WSGIScriptAlias / /srv/www/cub3.net/public_html/web2py/wsgihandler.py   




AllowOverride None  
Order Allow,Deny

Deny from all   

  

Allow from all  




AliasMatch ^/([^/]+)/static/(.*) 
/srv/www/cub3.net/public_html/web2py/applications/$1/static/$2  
  
 Order Allow,Deny   
 Allow from all 
  

   

Deny from all   
 


  

Deny from all   



CustomLog /var/log/apache2/web2py/acces.log common  
ErrorLog 
/var/log/apache2/web2py/error.log   
   

Everything looks ok, and the wgsi process can be seen with ps. But when you go 
to http://web2py.cub3.net, it always loads the default home page, the same that 
you get at http://cub3.net or http://www.cub3.net. Any clue?



Re: [web2py] unable to parse csv file 'NoneType' object is unsubscriptable with list:reference type field

2012-03-28 Thread Richard Vézina
Done!

 Issue 738 :unable to
parse csv file 'NoneType' object is unsubscriptable with list:reference
type field

Thanks

Richard

On Wed, Mar 28, 2012 at 9:34 AM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> Please open a ticket.
>
>
> On Tuesday, 27 March 2012 16:04:47 UTC-5, Richard wrote:
>>
>> Same thing with trunk...
>>
>> Richard
>>
>> On Tue, Mar 27, 2012 at 3:52 PM, Richard wrote:
>>
>>> This one to : https://groups.google.com/**forum/?fromgroups#!topic/**
>>> web2py/H_QqV2g8IgQ
>>>
>>> I experimented the problem with 1.99.4 and 1.99.7
>>>
>>> What I understand so far is that id_map get None by default, so when it
>>> get here :
>>>
>>> [id_map[ref_table][int(v)] \
>>>  for v in bar_decode_string('|35|1|')]
>>>
>>> It clears that it will raise the exception...
>>>
>>> I try to call my import function like this :
>>>
>>> def import_csv(table, file):
>>> table.import_from_csv_file(**file, id_map = {})
>>>
>>> Noting better.
>>>
>>> Please help.
>>>
>>> Richard
>>>
>>>
>>> Le mardi 27 mars 2012 15:45:50 UTC-4, Richard a écrit :
>>>
 Seems related : https://groups.google.com/**fo**rum/#!topic/web2py/**
 nYKsFPumXk0



 Le mardi 27 mars 2012 15:20:27 UTC-4, Richard a écrit :
>
> Hello,
>
> Is it possible the table csv import method be broken?
>
> When I use list:reference type field I can't import back a exported
> CSV with the appadmin.
>
> I don't understand where the None value could come from...
>
> When I try to implement my own csv import function base on this thread
> : https://groups.google.com/**fo**rum/?fromgroups#!topic/**web2py/**
> lDi0lLK_Wm0
>
> That work fine, until I try to import data with list:reference type
> field (|id| or |id|id|, etc.)
>
> I get this traceback :
>
> for v in bar_decode_string(value)]
>
> TypeError: 'NoneType' object is unsubscriptable
>
>
>-
>
>
>  Function argument list
>
> (field=, value='|35|1|', id_map=None)
>  Code listing
>
>
>
>
> 5683.
> 5684.
> 5685.
> 5686.
> 5687.
>
>
> 5688.
>
> 5689.
> 5690.
> 5691.
> 5692.
>
> elif field.type.startswith('list:**st**ring'):
>
>
> value = bar_decode_string(value)
>
>
> elif field.type.startswith(list_**ref**erence_s):
>
>
> ref_table = field.type[len(list_reference_s):].strip()
>
>
> value = [id_map[ref_table][int(v)] \
>
>
>
>  for v in bar_decode_string(value)]
>
>
> elif field.type.startswith('list:'):
>
>
> value = bar_decode_integer(value)
>
>
> elif id_map and field.type.startswith('**referen**ce'):
>
>
> try:
>
>  Variables  global bar_decode_string 
> value '|35|1|' v '35'
>
> What is exactly id_map?
>
> I think problem is coming from there...
>
> Thanks
>
> Richard
>

>>


[web2py] Re: New HackerNews discussion about python frameworks - web2py is not getting enough love

2012-03-28 Thread nick name
On Wednesday, March 28, 2012 10:13:52 AM UTC-4, Richard Penman wrote:
>
> "the smartest web hackers I know universally regard web2py as a 
> fundamentally incorrect way to approach web development—but usually say so 
> in far more colorful terms."


I just went and re-read the original threads (from jan-2011) where the 
flask & django guys were attacking web2py.

Looking at it a year later, I'm amazed how clueless (or bigotted, take your 
pick) both Jacob Moss-Kaplan (django) and Armin Ronacher (flask) had been 
about web2py, and still are. Their arguments boil down to two specific 
problems:

JMK: web2py adds a few more "builtins" to python (i.e., python already has 
"dict", "list", "len", that's fine. web2py adds "request", "response", 
"session" and a few others - that's unforgivable, harmful and divisive to 
the  python community at large). And confusing to everyone.

AR: What JMK said. And also, if you define classes with __del__ methods 
that don't call object.__del__, you might leak resources. Doesn't matter 
that it's a python problem in general, it's web2py's fault.

The first is a difference in opinion. The 2nd is just dumb. And up until 
this morning, I thought this guys weren't playing politics.


Re: [web2py] New HackerNews discussion about python frameworks - web2py is not getting enough love

2012-03-28 Thread Philip Kilner

Hi,

On 28/03/2012 15:08, nick name wrote:

Come say the good things you have to say about web2py on
http://news.ycombinator.com/item?id=3765610


Late catching up here because I've been following that!

Had to call the Django guy out on his (completely unsupported) statement 
that web2py is "a fundamentally incorrect way to approach web 
development", a statement that he made *AFTER* admitting that he'd never 
used it!


Not being a fan of flame-wars, I try to restrict myself to establishing 
whether people who criticise web2py have actually used it - so far 100% 
of critics that I've encountered have /not/ used it, which I think 
speaks volumes...




--

Regards,

PhilK


'a bell is a cup...until it is struck'



[web2py] Re: Viewing tickets outside of admin

2012-03-28 Thread Alan Etkin
The web ticket output is managed by this code:

/applications/admin/controllers/default.py (see function ticket and 
ticketdb and errors)
/applications/admin/views/default/ (see function ticket 
and ticketdb and errors)

Errors is the error panel to show and classify the tickets, ticket and 
ticketdb return a single ticket for examination.

It seems that the html output is handled at the controller using the gluon 
RestrictedError and TRACEBACK class (defined in default.py)
If you don't want html output then it would be enough to instantiate the 
RestrictedError object and use it's methods.

El miércoles 28 de marzo de 2012 10:40:49 UTC-3, Alan Etkin escribió:
>
> Well, the admin web interface has to parse it somehow to render it in the 
> browser, there must be a function in appadmin or in the admin app for that 
> purpose.
>
> El miércoles 28 de marzo de 2012 08:33:11 UTC-3, tsvim escribió:
>>
>> Hi,
>>
>> Lately, I've been using pythonanywhere to work on my pet project together 
>> with Dropbox. It's very fun, as it allows me to test all kinds of access 
>> (mobile, desktop), various environments (work, home), os's etc.
>> Obviously I'm unable to access the admin as I'm not at a local machine 
>> and I don't want to enable remote access to the admin.
>> I was wondering since I'm using Dropbx to sync my files, I do have local 
>> access to the ticket files themselves.
>> Is there some parser that would allow me to look at the tickets without 
>> needing to run web2py locally to have access to the admin?
>> I would even imagine a hook that would automagically parse the ticket 
>> into text form and save a text version of it.
>>
>> Thanks,
>>
>> Tsvi
>>
>

Re: [web2py] Re: Viewing tickets outside of admin

2012-03-28 Thread Tsvi Mostovicz
I'll have a look at it maybe tomorrow on my train commute or else during
the coming week.
Thanks,

Tsvi Mostovicz
ttm...@gmail.com
www.linkedin.com/in/tsvim



On Wed, Mar 28, 2012 at 17:09, Alan Etkin  wrote:

> The web ticket output is managed by this code:
>
> /applications/admin/controllers/default.py (see function ticket
> and ticketdb and errors)
> /applications/admin/views/default/ (see function ticket
> and ticketdb and errors)
>
> Errors is the error panel to show and classify the tickets, ticket and
> ticketdb return a single ticket for examination.
>
> It seems that the html output is handled at the controller using the gluon
> RestrictedError and TRACEBACK class (defined in default.py)
> If you don't want html output then it would be enough to instantiate the
> RestrictedError object and use it's methods.
>
> El miércoles 28 de marzo de 2012 10:40:49 UTC-3, Alan Etkin escribió:
>
>> Well, the admin web interface has to parse it somehow to render it in the
>> browser, there must be a function in appadmin or in the admin app for that
>> purpose.
>>
>> El miércoles 28 de marzo de 2012 08:33:11 UTC-3, tsvim escribió:
>>>
>>> Hi,
>>>
>>> Lately, I've been using pythonanywhere to work on my pet project
>>> together with Dropbox. It's very fun, as it allows me to test all kinds of
>>> access (mobile, desktop), various environments (work, home), os's etc.
>>> Obviously I'm unable to access the admin as I'm not at a local machine
>>> and I don't want to enable remote access to the admin.
>>> I was wondering since I'm using Dropbx to sync my files, I do have local
>>> access to the ticket files themselves.
>>> Is there some parser that would allow me to look at the tickets without
>>> needing to run web2py locally to have access to the admin?
>>> I would even imagine a hook that would automagically parse the ticket
>>> into text form and save a text version of it.
>>>
>>> Thanks,
>>>
>>> Tsvi
>>>
>>


[web2py] Re: how to redirect from ajax [closed]

2012-03-28 Thread Anthony
If you want to build a single-page app, you might also consider options 
like AngularJS  (supported by Google) and 
batman.js(by Shopify). They move templating to the client, 
so your server just 
delivers the initial "page" (i.e., the whole app, including JS templates) 
and then takes Ajax requests and returns JSON rather than HTML.

Anthony

On Wednesday, March 28, 2012 10:37:09 AM UTC-4, weheh wrote:
>
> P.P.S. As I was saying about compressing the site down to one page ... the 
> real reason why I was having to do this contortion with redirect is because 
> I HAVEN'T compressed the site down to one page. It's actually more like 2 
> or 3 pages. When I have a little more time, I will compress it down to 1 
> and then see how it changes things.
>
> @Jonathan -- yes the whole ajax business is headache inducing. Much like 
> quantum physics. But after awhile, the old way of thinking (Newtonian 
> viewpoint in the case of physics, or static pages in the case of web stuff) 
> just seems so limited, and frankly, in the case of physics, insane. Said 
> differently, just as Newtonian physics (classical mechanics) is a limiting 
> case of quantum physics, static pages is a limiting case of ajax.
>


[web2py] Re: Using single instance of LibreOffice to convert documents - is this safe?

2012-03-28 Thread DenesL
Hi Cliff,

could you post more details on your interface to LibreOffice?

Last time I looked at this it did not work properly (UNO bridge with 
OpenOffice) but from your initial post it sounds like a viable alternative 
now.

Thanks,
Denes

On Tuesday, March 27, 2012 7:47:15 AM UTC-4, Cliff wrote:
>
> Thanks Wilkus. 
>
> Further research this AM says Libre/Open Office does not multi-thread 
> well. 
>
> The scheduler is just what I need. 
>
> On Mar 27, 6:33 am, Wikus van de Merwe  
> wrote: 
> > If this processing is done after the form submission you can delegate 
> that 
> > to a background task. 
> > Having a queue of tasks end executing them one by one should solve the 
> > concurrent access 
> > problem. Check out the book section on scheduler:
> http://web2py.com/books/default/chapter/29/4#Scheduler-%28experimenta...



[web2py] help with eye candy

2012-03-28 Thread weheh
There are two cases where I would like to provide some eye candy in the 
form of a spinning "wait" icon whilst web2py does some heavy processing. In 
one case, I would like to do this while a form is being processed. For 
instance, if someone wants to fill out a contact form, which sends an 
email, it would be nice for the cursor to change to the wait cursor while 
email does its thing. The other case is to start the wait cursor at the 
beginning of an ajax call that I know will take awhile to execute. In both 
cases, the cursor is to restore itself to its former state.

In the ajax case, I've tried 'jQuery(document).css("cursor", "wait");' and 
then changed wait to auto when all is done. That didn't work. I've also 
tried doing it on just the wrapper div of the thing that initiates the 
process. That didn't work either. 

With regards to processing a form, I would need to be able to kick off a 
jQuery(...).css(...) just before form.process().  I don't know how to do 
that, assuming it's at all possible. I imagine rstoring the cursor would be 
done by a similar mechanism just after the controller returns.


[web2py] Re: how to get logout() to launch an ajax call [closed]

2012-03-28 Thread weheh
Thanks, Anthony. I really appreciate your thorough responses. You don't 
just say how to do something, you explain why it works the way it works. 
That kind of response is rare and invaluable. It keeps me from asking the 
same question different ways because I end up understanding how the system 
works under the hood. Please keep up the good work. I would tell your boss 
to give you a raise, but I wouldn't want to get you fired for putting so 
much time into the web2py group! (How ironic, eh?)

On Tuesday, March 27, 2012 10:49:45 PM UTC+8, Anthony wrote:
>
> I want something like this to work, but it doesn't, obviously. 
>>
>> def logout(): 
>> auth.logout() 
>> response.js = 'alert("goodbye world");' 
>> from gluon import HTTP 
>> HTTP(202) 
>> return dict() 
>>
>> I've also tried auth.settings.logout_onlogout = [onlogoutfunction] 
>> but that's not working for me either.
>
>
> auth.logout() does a redirect, so the above won't make it to your 
> HTTP(202) call. Also, response.js only works for Ajax requests for 
> components (i.e., client-side calls to web2py_ajax_page(), which is what 
> the LOAD helper does).
>
> How is the logout request made from the browser? If it is a regular full 
> page request, your controller needs to return a full page (probably via the 
> typical post-logout redirect), and that page then needs to include the 
> relevant JS code (e.g., in a 

[web2py] Re: Modify T() function

2012-03-28 Thread Massimo Di Pierro
I had to look this up in the source myself. I remembered it was there but I 
did not remember the syntax. There is a reason web2py uses its own 
internationalization and not the python one.

On Wednesday, 28 March 2012 09:05:58 UTC-5, Anthony wrote:
>
> On Wednesday, March 28, 2012 9:48:47 AM UTC-4, Massimo Di Pierro wrote:
>>
>> We actually have that already. The way to do is:
>>
>> T(' hello world ## comment')
>>
>
> Another secret feature. Find them all, and you get a prize. :-)
>  
>


[web2py] Re: how to redirect from ajax [closed]

2012-03-28 Thread weheh
I took a look at Angular's page. Looks interesting and might be more 
concise, BUT I can do it all in web2py already. It's mostly a matter of 
sight design -- we all use some jQuery these days, anyway. Retrofitting an 
existing set of pages to reduce them to a 1-pager is exponentially harder 
than designing the site to be a 1-pager to begin with. Now that I have a 
much better idea of how to do it, I think web2py is perfectly acceptable. 
The only inconsistency that I see is with login/out/register/etc. auth 
administration, but it's pretty minor.

On Wednesday, March 28, 2012 11:15:06 PM UTC+8, Anthony wrote:
>
> If you want to build a single-page app, you might also consider options 
> like AngularJS  (supported by Google) and 
> batman.js(by Shopify). They move templating to the 
> client, so your server just 
> delivers the initial "page" (i.e., the whole app, including JS templates) 
> and then takes Ajax requests and returns JSON rather than HTML.
>
> Anthony
>
> On Wednesday, March 28, 2012 10:37:09 AM UTC-4, weheh wrote:
>>
>> P.P.S. As I was saying about compressing the site down to one page ... 
>> the real reason why I was having to do this contortion with redirect is 
>> because I HAVEN'T compressed the site down to one page. It's actually more 
>> like 2 or 3 pages. When I have a little more time, I will compress it down 
>> to 1 and then see how it changes things.
>>
>> @Jonathan -- yes the whole ajax business is headache inducing. Much like 
>> quantum physics. But after awhile, the old way of thinking (Newtonian 
>> viewpoint in the case of physics, or static pages in the case of web stuff) 
>> just seems so limited, and frankly, in the case of physics, insane. Said 
>> differently, just as Newtonian physics (classical mechanics) is a limiting 
>> case of quantum physics, static pages is a limiting case of ajax.
>>
>

[web2py] all-json API [was: how to redirect from ajax]

2012-03-28 Thread Jonathan Lundell
On Mar 28, 2012, at 8:15 AM, Anthony wrote:
> If you want to build a single-page app, you might also consider options like 
> AngularJS (supported by Google) and batman.js (by Shopify). They move 
> templating to the client, so your server just delivers the initial "page" 
> (i.e., the whole app, including JS templates) and then takes Ajax requests 
> and returns JSON rather than HTML.

This relates to another all-json API, namely a JSON (possibly but not 
necessarily JSON-RPC) web service. I use that to serve several iOS apps, and it 
works nicely. There's one problem, though: errors.

If an error occurs before the web2py JSON function is called (typically a 500 
error, such as a Python syntax error in the controller), web2py returns an HTML 
response, and that's awkward for a JSON client to try to handle. 

One thing that slightly complicates matters is that to fix this, web2py would 
need to know that a JSON or JSON-RPC (or for that matter XML-RPC or various 
other formats) request has been made. For most/all 500 errors, we haven't 
gotten to the @service decorator, so we ought to be looking at the requested 
extension or the Accept: header. application/json is what should be there; 
there's no distinction made for JSON-RPC, which is slightly awkward, but 
suggests that we should just return a JSON-RPC error object, perhaps based on 
the content of the request if it parses as JSON.

One thing that's stopped me from proposing a patch is that this really ought to 
be generalized for other non-html services, and perhaps be user-extensible 
(though not necessarily through an application, since we might not have access 
to the application at error time; maybe something in routes.py?). But the 
perfect need not be the enemy of the good-enough, I suppose.

Any interest in working out a definition for this?

Re: [web2py] all-json API [was: how to redirect from ajax]

2012-03-28 Thread Jonathan Lundell
On Mar 28, 2012, at 9:16 AM, Jonathan Lundell wrote:
> On Mar 28, 2012, at 8:15 AM, Anthony wrote:
>> If you want to build a single-page app, you might also consider options like 
>> AngularJS (supported by Google) and batman.js (by Shopify). They move 
>> templating to the client, so your server just delivers the initial "page" 
>> (i.e., the whole app, including JS templates) and then takes Ajax requests 
>> and returns JSON rather than HTML.
> 
> This relates to another all-json API, namely a JSON (possibly but not 
> necessarily JSON-RPC) web service. I use that to serve several iOS apps, and 
> it works nicely. There's one problem, though: errors.
> 
> If an error occurs before the web2py JSON function is called (typically a 500 
> error, such as a Python syntax error in the controller), web2py returns an 
> HTML response, and that's awkward for a JSON client to try to handle. 
> 
> One thing that slightly complicates matters is that to fix this, web2py would 
> need to know that a JSON or JSON-RPC (or for that matter XML-RPC or various 
> other formats) request has been made. For most/all 500 errors, we haven't 
> gotten to the @service decorator, so we ought to be looking at the requested 
> extension or the Accept: header. application/json is what should be there; 
> there's no distinction made for JSON-RPC, which is slightly awkward, but 
> suggests that we should just return a JSON-RPC error object, perhaps based on 
> the content of the request if it parses as JSON.
> 
> One thing that's stopped me from proposing a patch is that this really ought 
> to be generalized for other non-html services, and perhaps be user-extensible 
> (though not necessarily through an application, since we might not have 
> access to the application at error time; maybe something in routes.py?). But 
> the perfect need not be the enemy of the good-enough, I suppose.
> 
> Any interest in working out a definition for this?

Oh, and while we're at it (I'm reminded by Richard's last post): not just error 
handling, but a JSON/JSON-RPC interface to Auth.

[web2py] Re: Using single instance of LibreOffice to convert documents - is this safe?

2012-03-28 Thread Cliff
Most of what I know comes from this:

http://lucasmanual.com/mywiki/OpenOffice

Other points
1.  You can start LibreOffice from a script, but you can't connect to it in 
that same script.  That one cost me half a day.
2.  LibreOffice is gonna crash.  You'll need a cron job to check if 
LibreOffice is still running and restart it if it's died.
3.  It's slow.  If LibreOffice is going to do much work, use the scheduler 
as Wilkus suggests.
4.  Get a version of Python with uno baked in.
5.  ZipFile can unpack an odt document.  Beware on upload, though; don't 
mess with the odt doc until after it is saved.


Here's the code I use to start LibreOffice:

#! /usr/bin/python2.7
import uno, subprocess, shlex, pyuno, os, socket ## prune this import list!
# fire up libreoffice
rgs = '/usr/lib/libreoffice/program/swriter 
-accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" 
-norestore -nofirstwizard -nologo -headless'
args = shlex.split(rgs)
lo = subprocess.Popen(args)


Here's a controller.  
def do_documents(form):
import uno, os, socket, string  ## prune this list
from com.sun.star.beans import PropertyValue
try:
os.mkdir(request.folder + 'temp_pdf')
except OSError:
pass

package_name = db.document_packages[request.args(0)].name
items = {}
# processing a hand made form
# get the doc id, make a list of fields for each
for k,v in form.vars.iteritems():
k_split = k.split('_')
if len(k_split) < 2 or k_split[0][:3] != 'id=':
continue
doc_id = k_split[0][3:]
if doc_id not in items:
items[doc_id] = []
items[doc_id].append((k_split[1], v))
# now attach the the running LibreOffice instance
# still need to implement a check if running and recovery if not
local = uno.getComponentContext()
resolver = 
local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",
 
local)
context = 
resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
desktop = 
context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", 
context)

for k, v in items.iteritems():
rcrd = db.document_templates[k]
path = request.folder + 'uploads/' + rcrd.body
tmplt = desktop.loadComponentFromURL("file:///"+path ,"_blank", 0, 
())
print type(tmplt) # diagnostic

search = tmplt.createSearchDescriptor()
for val in v:
search.SearchString = '{{='+val[0]+'}}'
found = tmplt.findFirst(search)
while found:
found.String = string.replace(found.String, 
unicode('{{='+val[0]+'}}', 'utf-8'), unicode(val[1], 'utf-8'))
found = tmplt.findNext(found.End, search)
## next step is to implement the pdf conversion.  I THINK this code will do 
it
##property = (PropertyValue("FilterName" , 0, "writer_pdf_Export" , 
0 ),) 
##newpath = request.folder + 'temp_pdf/' + os.path.split(path)[1]
##tmplt.storeToURL("file:///" + newpath,property)
##tmplt.dispose()
tmplt.storeAsURL("file:///home/cjk/wtf.odt",()) # not final code
tmplt.dispose()

+




On Wednesday, March 28, 2012 11:17:20 AM UTC-4, DenesL wrote:
>
> Hi Cliff,
>
> could you post more details on your interface to LibreOffice?
>
> Last time I looked at this it did not work properly (UNO bridge with 
> OpenOffice) but from your initial post it sounds like a viable alternative 
> now.
>
> Thanks,
> Denes
>
> On Tuesday, March 27, 2012 7:47:15 AM UTC-4, Cliff wrote:
>>
>> Thanks Wilkus. 
>>
>> Further research this AM says Libre/Open Office does not multi-thread 
>> well. 
>>
>> The scheduler is just what I need. 
>>
>> On Mar 27, 6:33 am, Wikus van de Merwe  
>> wrote: 
>> > If this processing is done after the form submission you can delegate 
>> that 
>> > to a background task. 
>> > Having a queue of tasks end executing them one by one should solve the 
>> > concurrent access 
>> > problem. Check out the book section on scheduler:
>> http://web2py.com/books/default/chapter/29/4#Scheduler-%28experimenta...
>
>

[web2py] Re: how to redirect from ajax [closed]

2012-03-28 Thread Anthony
On Wednesday, March 28, 2012 12:07:35 PM UTC-4, weheh wrote:
>
> I took a look at Angular's page. Looks interesting and might be more 
> concise, BUT I can do it all in web2py already.


Not sure what you mean by "do it all", but certainly web2py alone cannot do 
all of what Angular does (even with jQuery). In particular, it does 
client-side templating, which web2py does not do. It also creates live 
bindings between the DOM and the (client-side) model, so any changes in one 
are immediately reflected in the other. Also, client-side form validation, 
etc.

Anthony


[web2py] Re: How to Save Query in Session

2012-03-28 Thread Cliff
Doesn't db._lastsql return a string?  Can't you just save that in the 
session?

Or is that a naive question?

On Monday, March 26, 2012 10:09:49 PM UTC-4, Limedrop wrote:
>
> Just in case any of you want to do this...I've written a routine that 
> enables you to save a Query/Expression object in the session. 
>
> I have a controller that uses a form to build a relatively complex 
> query and I want other controllers to use that query to generate 
> reports and graphs.  I initially explored saving the query in the 
> session as a string, but it just wasn't working for me so I bit the 
> bullet and wrote a seralization routine that takes a Query object and 
> extracts it into a dictionary strucuture.  There's another function 
> that does the reverse. 
>
> It's all here in this slice: 
> http://www.web2pyslices.com/slice/show/1489/save-query-in-session 
>
> It needs more testing for edge cases (I just don't know enough about 
> the DAL to do all of that).  I've written it as a module, but 
> ultimately it would be nice to have something like it as a method 
> within the gluon.dal.Query class itself?  Better yet, get the 
> framework to automatically invoke it when saving a Query/Expression to 
> session (like it does for rows). 
>


[web2py] Re: how to get logout() to launch an ajax call [closed]

2012-03-28 Thread Anthony
:-D

On Wednesday, March 28, 2012 11:27:03 AM UTC-4, weheh wrote:
>
> Thanks, Anthony. I really appreciate your thorough responses. You don't 
> just say how to do something, you explain why it works the way it works. 
> That kind of response is rare and invaluable. It keeps me from asking the 
> same question different ways because I end up understanding how the system 
> works under the hood. Please keep up the good work. I would tell your boss 
> to give you a raise, but I wouldn't want to get you fired for putting so 
> much time into the web2py group! (How ironic, eh?)
>


[web2py] Re: help with eye candy

2012-03-28 Thread Anthony
I use jQuery BlockUI (http://malsup.com/jquery/block/#overview) for this 
kind of thing. You can block the whole page or just a single page element, 
and you can even set it up so the blocking happens at the start of any Ajax 
request and stops when the Ajax request is complete.

Anthony

On Wednesday, March 28, 2012 11:22:25 AM UTC-4, weheh wrote:
>
> There are two cases where I would like to provide some eye candy in the 
> form of a spinning "wait" icon whilst web2py does some heavy processing. In 
> one case, I would like to do this while a form is being processed. For 
> instance, if someone wants to fill out a contact form, which sends an 
> email, it would be nice for the cursor to change to the wait cursor while 
> email does its thing. The other case is to start the wait cursor at the 
> beginning of an ajax call that I know will take awhile to execute. In both 
> cases, the cursor is to restore itself to its former state.
>
> In the ajax case, I've tried 'jQuery(document).css("cursor", "wait");' and 
> then changed wait to auto when all is done. That didn't work. I've also 
> tried doing it on just the wrapper div of the thing that initiates the 
> process. That didn't work either. 
>
> With regards to processing a form, I would need to be able to kick off a 
> jQuery(...).css(...) just before form.process().  I don't know how to do 
> that, assuming it's at all possible. I imagine rstoring the cursor would be 
> done by a similar mechanism just after the controller returns.
>


[web2py] Re: Using single instance of LibreOffice to convert documents - is this safe?

2012-03-28 Thread Cliff
Oh yeah, I almost forgot.

I've seen a lot of posts about how headless LibreOffice needs X server 
running.  I'm just setting up an Ubuntu server now for test purposes.  I'll 
report back here.

On Wednesday, March 28, 2012 12:53:07 PM UTC-4, Cliff wrote:
>
> Most of what I know comes from this:
>
> http://lucasmanual.com/mywiki/OpenOffice
>
> Other points
> 1.  You can start LibreOffice from a script, but you can't connect to it 
> in that same script.  That one cost me half a day.
> 2.  LibreOffice is gonna crash.  You'll need a cron job to check if 
> LibreOffice is still running and restart it if it's died.
> 3.  It's slow.  If LibreOffice is going to do much work, use the scheduler 
> as Wilkus suggests.
> 4.  Get a version of Python with uno baked in.
> 5.  ZipFile can unpack an odt document.  Beware on upload, though; don't 
> mess with the odt doc until after it is saved.
>
> 
> Here's the code I use to start LibreOffice:
>
> #! /usr/bin/python2.7
> import uno, subprocess, shlex, pyuno, os, socket ## prune this import list!
> # fire up libreoffice
> rgs = '/usr/lib/libreoffice/program/swriter 
> -accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" 
> -norestore -nofirstwizard -nologo -headless'
> args = shlex.split(rgs)
> lo = subprocess.Popen(args)
>
> 
> Here's a controller.  
> def do_documents(form):
> import uno, os, socket, string  ## prune this list
> from com.sun.star.beans import PropertyValue
> try:
> os.mkdir(request.folder + 'temp_pdf')
> except OSError:
> pass
>
> package_name = db.document_packages[request.args(0)].name
> items = {}
> # processing a hand made form
> # get the doc id, make a list of fields for each
> for k,v in form.vars.iteritems():
> k_split = k.split('_')
> if len(k_split) < 2 or k_split[0][:3] != 'id=':
> continue
> doc_id = k_split[0][3:]
> if doc_id not in items:
> items[doc_id] = []
> items[doc_id].append((k_split[1], v))
> # now attach the the running LibreOffice instance
> # still need to implement a check if running and recovery if not
> local = uno.getComponentContext()
> resolver = 
> local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",
>  
> local)
> context = 
> resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
> desktop = 
> context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop",
>  
> context)
>
> for k, v in items.iteritems():
> rcrd = db.document_templates[k]
> path = request.folder + 'uploads/' + rcrd.body
> tmplt = desktop.loadComponentFromURL("file:///"+path ,"_blank", 0, 
> ())
> print type(tmplt) # diagnostic
> 
> search = tmplt.createSearchDescriptor()
> for val in v:
> search.SearchString = '{{='+val[0]+'}}'
> found = tmplt.findFirst(search)
> while found:
> found.String = string.replace(found.String, 
> unicode('{{='+val[0]+'}}', 'utf-8'), unicode(val[1], 'utf-8'))
> found = tmplt.findNext(found.End, search)
> ## next step is to implement the pdf conversion.  I THINK this code will 
> do it
> ##property = (PropertyValue("FilterName" , 0, "writer_pdf_Export" 
> , 0 ),) 
> ##newpath = request.folder + 'temp_pdf/' + os.path.split(path)[1]
> ##tmplt.storeToURL("file:///" + newpath,property)
> ##tmplt.dispose()
> tmplt.storeAsURL("file:///home/cjk/wtf.odt",()) # not final code
> tmplt.dispose()
>
> +
>
>
>
>
> On Wednesday, March 28, 2012 11:17:20 AM UTC-4, DenesL wrote:
>>
>> Hi Cliff,
>>
>> could you post more details on your interface to LibreOffice?
>>
>> Last time I looked at this it did not work properly (UNO bridge with 
>> OpenOffice) but from your initial post it sounds like a viable alternative 
>> now.
>>
>> Thanks,
>> Denes
>>
>> On Tuesday, March 27, 2012 7:47:15 AM UTC-4, Cliff wrote:
>>>
>>> Thanks Wilkus. 
>>>
>>> Further research this AM says Libre/Open Office does not multi-thread 
>>> well. 
>>>
>>> The scheduler is just what I need. 
>>>
>>> On Mar 27, 6:33 am, Wikus van de Merwe  
>>> wrote: 
>>> > If this processing is done after the form submission you can delegate 
>>> that 
>>> > to a background task. 
>>> > Having a queue of tasks end executing them one by one should solve the 
>>> > concurrent access 
>>> > problem. Check out the book section on scheduler:
>>> http://web2py.com/books/default/chapter/29/4#Scheduler-%28experimenta...
>>
>>

[web2py] web2py hosting on VPS server for enterprise

2012-03-28 Thread Omi Chiba
I'm looking for VPS service for our company to running web2py apps.

Requirements
---
OS: Windows2008
Database: MS SQL 2008
RAM: 2GB or higher
Domain: we will get from domain.com
---

I'm pretty interested with kickassvps.com. It looks nice and good pricing 
but not sure if our managment team likes it (including the name) :)

Do you guys know good vps service companies not for personal but more like 
enterprise level with my requirements ?




[web2py] Re: DAL Challenge

2012-03-28 Thread Wikus van de Merwe
First you need to change your model. In relation database you would have:
db.define_table("articles", db.Field("title"), ...)
db.define_table("comments", db.Field("article_id", db.articles), 
db.Field("author"), ...)

But with datastore you want to do the reverse, keep the comment ids in the 
article table:
db.define_table("comments", db.Field("author"), ...)
db.define_table("articles", db.Field("title"), db.Field("comments", 
"list:reference comments"), ...)
or maybe even simply:
db.define_table("articles", db.Field("title"), db.Field("comments", 
"list:integer"), ...)

Then you read all the articles as usual:
articles = db().select(db.articles.ALL)

You go over all articles and store keys for all comments:
from google.appengine.ext import db as gdb
keys = []
for a in articles:
  keys.extend([gdb.Key.from_path("comments", id) for id in a.comments])

And finally you fetch all comments in a single query:
comments = gdb.get(keys)

You will get the comments in a fixed order so it shouldn't be difficult to 
map them to articles in the view.
Simply for the first article where len(articles[0].comments) = 3, it would 
be comments[:3],
for the second article where len(articles[1].comments) = 5, it would be 
comments[3:8].

A dictionary with article ids as you proposed would also work.


Re: [web2py] web2py hosting on VPS server for enterprise

2012-03-28 Thread Bruno Rocha
for windows --> http://www.rackspace.com

On Wed, Mar 28, 2012 at 4:32 PM, Omi Chiba  wrote:

> I'm looking for VPS service for our company to running web2py apps.
>
> Requirements
> ---
> OS: Windows2008
> Database: MS SQL 2008
> RAM: 2GB or higher
> Domain: we will get from domain.com
> ---
>
> I'm pretty interested with kickassvps.com. It looks nice and good pricing
> but not sure if our managment team likes it (including the name) :)
>
> Do you guys know good vps service companies not for personal but more like
> enterprise level with my requirements ?
>
>
>


-- 

Bruno Rocha
[http://rochacbruno.com.br]


[web2py] Re: Problem with rss feed from wiki application in book

2012-03-28 Thread Bill Thayer
Yes, The link in my outlook rss message has the same URL. 
When you click the link 
(http://127.0.0.1:8000/tamoto_dev/default/show.rss/1) , the page retured 
just says: {"errors": {"body": "enter a value"}}

What is the solution?

Thank you,
Bill

On Saturday, October 2, 2010 1:36:15 PM UTC-5, Luther Goh Lu Feng wrote:
>
> Following either 
>
> link = 'http://' + str(request.env.http_host) + URL('show', 
> args=row.id) 
>
> or 
>
> link = "http://127.0.0.1:8000"; + URL('show', args=row.id) 
>
> I get the link in the rss feed to the wiki page as 
>
> http://127.0.0.1:8000/mywiki/default/show.rss/1 
>
> On Sep 26, 7:11 pm, "Martin.Mulone"  wrote: 
> > better way: 
> > 
> > link = 'http://' + str(request.env.http_host) + URL('show', 
> > args=row.id) 
> > 
> > On 26 sep, 06:30, Tom Atkins  wrote: 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > > Thanks for the replies. I worked out what the problem is.  The code in 
> the 
> > > book is incorrect.  The line: 
> > 
> > > link = URL('show', args=row.id) 
> > 
> > > does not produce a full URL.  The RSS service does not like this and 
> fails. 
> > 
> > > If I replace it with: 
> > 
> > > link = "http://127.0.0.1:8000"; + URL('show', args=row.id) 
> > 
> > > then it all works fine.  I'm sure there is a more elegant way to fix 
> this! 
> > 
> > > Please update the example code in the book. 
> > 
> > > Thanks! 
> > 
> > > On 25 September 2010 19:08, mdipierro  
> wrote: 
> > 
> > > > it depends on the model. You must have wiki fields and your action 
> > > > must return record in the format described by the book in chapter 3. 
> > 
> > > > Massimo 
> > 
> > > > On Sep 25, 12:34 pm, Tom Atkins  wrote: 
> > > > > I've just copied and pasted from the online book the wiki 
> application in 
> > > > > chapter 3.  It all works great. 
> > 
> > > > > I've added the function for the rss feed to controller/default.py 
> and if 
> > > > I 
> > > > > go to: 
> > 
> > > > >http://127.0.0.1:8000/mywiki/default/news 
> > 
> > > > > I get a nice page showing the wiki entries. 
> > 
> > > > > However if I go to: 
> > 
> > > > >http://127.0.0.1:8000/mywiki/default/news.rss 
> > 
> > > > > I just get a message saying 'no rss'... 
> > 
> > > > > Am I doing something stupid or is the code in the book wrong / 
> > > > incomplete. 
> > 
> > > > > Thanks for any help.



[web2py] Code submission : Select All checkbox in SQLForm.grid

2012-03-28 Thread Sebastien Stormacq
Dear All,

I recently used a SQLFORM.grid in my app and I wanted 
#1 the possibility to have checkboxes to select multiple row to delete
#2 customize the text of the submit button
#3 have a "select all" checkbox in the table header.

#1 was easy to solve with the help of this mailing list. 
(see https://groups.google.com/d/msg/web2py/lbNf_UoId7s/XvDFLYHQpIsJ)

For #2 and #3 I modified web2py itself (sqlhtml.py - see diff below) - and 
added a few lines of javascript.

Questions :
1. what is the easiest way to active my goal ?
2. is this code contribution worth adding into the trunk ?

Thanks

Seb

***




marsu:gluon sst$ diff -c sqlhtml.py.ORIG sqlhtml.py
*** sqlhtml.py.ORIG Wed Mar 28 22:42:03 2012
--- sqlhtml.py Wed Mar 28 22:42:45 2012
***
*** 1400,1405 
--- 1400,1406 
   editable=True,
   details=True,
   selectable=None,
+  selectable_text=None,
   create=True,
   csv=True,
   links=None,
***
*** 1702,1708 
  
  head = TR(_class=ui.get('header',''))
  if selectable:
! head.append(TH(_class=ui.get('default','')))
  for field in fields:
  if columns and not str(field) in columns: continue
  if not field.readable: continue
--- 1703,1709 
  
  head = TR(_class=ui.get('header',''))
  if selectable:
! head.append(TH(INPUT(_type='checkbox', _name='selectAll', 
_id='selectAll', value='off'), _class=ui.get('default','')))
  for field in fields:
  if columns and not str(field) in columns: continue
  if not field.readable: continue
***
*** 1852,1858 
  htmltable.append(tbody)
  htmltable = DIV(htmltable,_style='width:100%;overflow-x:auto')
  if selectable:
! htmltable = FORM(htmltable,INPUT(_type="submit"))
  if htmltable.process(formname=formname).accepted:#
  htmltable.vars.records = htmltable.vars.records or []
  htmltable.vars.records = htmltable.vars.records if 
type(htmltable.vars.records) == list else [htmltable.vars.records]
--- 1853,1861 
  htmltable.append(tbody)
  htmltable = DIV(htmltable,_style='width:100%;overflow-x:auto')
  if selectable:
! htmltable = FORM(htmltable,INPUT(_type="submit", 
_value=selectable_text if selectable_text else T('Submit')))
! 
htmltable.element(_id='selectAll')['_onClick']="toggleAll(this, 'records');"
  if htmltable.process(formname=formname).accepted:#
  htmltable.vars.records = htmltable.vars.records or []
  htmltable.vars.records = htmltable.vars.records if 
type(htmltable.vars.records) == list else [htmltable.vars.records]


**

//in the view


function toggleAll(source,name) {
  checkboxes = document.getElementsByName(name);
  for(var i in checkboxes)
checkboxes[i].checked = source.checked;
}





[web2py] Re: Primary Key tables in MSSQL. Cannot get them to work

2012-03-28 Thread Derek
Try changing your field1 type to 'id'.
like this:
Field('Field1', 'id'),

On Tuesday, March 27, 2012 10:56:44 PM UTC-7, Andrew wrote:
>
> Hello,
> I posted on this issue some time ago and I'm pretty sure it was working 
> again after a fix from DenesL.
> However I can't get Primary Key tables in MSSQL to work.  They get created 
> OK, but I get errors with a Form in a view.
> I originally made the Key a string, but then switched to integer just to 
> see if it made a difference.  :
>
> *Model:*
> dbSQL = DAL('mssql://)
> # 1 Column PK
> dbSQL.define_table('web2py_int_PK',
> Field('Field1', 'integer'),
> Field('Field2', 'string', length=20),
> format='%(Field1)s',
> primarykey = ['Field1'],
> migrate=True)
>
> *Controller:*
> def web2py_int_PK_form():
> form = SQLFORM(dbSQL.web2py_int_PK)
> if form.process().accepted:
> response.flash = 'form accepted'   
> elif form.errors:   
> response.flash = 'form has errors'   
> else:   
> response.flash = 'please fill out the form'
> return dict(form=form) 
>
> *View:*
> {{extend 'layout.html'}}
> Primary Key Form Test
> {{=form}}
>
> I get this in the ticket:
> File "D:\Mercurial\web2py\gluon\dal.py", line 6912, in __getitem__
> return dict.__getitem__(self, str(key))
> KeyError: '_id'
>
> It looks like it is trying to retrieve the value for "_id" , but looking 
> at the code __init__ for a table, _id never gets set for a table with a 
> Primary Key.  (look at lines 6752, 6762, 6772).
>
> Just wondering if something like line 772 in sqlhtml.py (In the SQLFORM 
> __init__ method).  "self.id_field_name = table._id.name"  could 
> cause the above lookup of the _id key ?  Do Forms work with keyed tables ?
>
> Thanks
> Andrew W
>
>
>

Re: [web2py] web2py hosting on VPS server for enterprise

2012-03-28 Thread Omi Chiba
Burno, 

Thanks ! I just finished chatting with rackspace.com guy and he seems 
helpful guy. Are you running web2py in here for your customers on windows 
environment ?

I'm thinking to appy the following and it's around $160 per month. It's 
pretty good deal.

Cloud Server
-
OS: Windows
DB: SQL 2008 R2 Web Edition
Web server: Apache
RAM: 2GB
--


On Wednesday, March 28, 2012 3:09:49 PM UTC-5, rochacbruno wrote:
>
> for windows --> http://www.rackspace.com
>
> On Wed, Mar 28, 2012 at 4:32 PM, Omi Chiba  wrote:
>
>> I'm looking for VPS service for our company to running web2py apps.
>>
>> Requirements
>> ---
>> OS: Windows2008
>> Database: MS SQL 2008
>> RAM: 2GB or higher
>> Domain: we will get from domain.com
>> ---
>>
>> I'm pretty interested with kickassvps.com. It looks nice and good 
>> pricing but not sure if our managment team likes it (including the name) :)
>>
>> Do you guys know good vps service companies not for personal but more 
>> like enterprise level with my requirements ?
>>
>>
>>
>
>
> -- 
>  
> Bruno Rocha
> [http://rochacbruno.com.br]
>
>
On Wednesday, March 28, 2012 3:09:49 PM UTC-5, rochacbruno wrote:
>
> for windows --> http://www.rackspace.com
>
> On Wed, Mar 28, 2012 at 4:32 PM, Omi Chiba  wrote:
>
>> I'm looking for VPS service for our company to running web2py apps.
>>
>> Requirements
>> ---
>> OS: Windows2008
>> Database: MS SQL 2008
>> RAM: 2GB or higher
>> Domain: we will get from domain.com
>> ---
>>
>> I'm pretty interested with kickassvps.com. It looks nice and good 
>> pricing but not sure if our managment team likes it (including the name) :)
>>
>> Do you guys know good vps service companies not for personal but more 
>> like enterprise level with my requirements ?
>>
>>
>>
>
>
> -- 
>  
> Bruno Rocha
> [http://rochacbruno.com.br]
>
>

[web2py] Re: How to Save Query in Session

2012-03-28 Thread Limedrop
Sometimes that will be sufficient.  The issue is how you turn _lastsql into 
a gluon.dal object that you can further manipulate.  

For example, what if you want to do this:

_lastsql & (db.person.name == 'John') 

See the slice if you need to know how to do it.


On Thursday, March 29, 2012 5:59:23 AM UTC+13, Cliff wrote:
>
> Doesn't db._lastsql return a string?  Can't you just save that in the 
> session?
>
> Or is that a naive question?
>
>
>

Re: [web2py] Re: sqlite to postgres

2012-03-28 Thread Marco Tulio Cicero de M. Porto
That sounds what I need

but:

ubuntu@ip:/home/www-data/web2py$ python scripts/cpdb.py -h
Traceback (most recent call last):
  File "scripts/cpdb.py", line 5, in 
import argparse
ImportError: No module named argparse

then I read somewhere this:


1down vote

The argparse module was added in Python 2.7.
http://docs.python.org/library/argparse.html

Prior to 2.7, the most common way to handle command-line arguments was
probably getopt.http://docs.python.org/library/getopt.html

Of course you can always handle the command-line manually simply by looking
at sys.argv. Howevergetopt is a good abstraction layer, and argparse is
even better.

If you truly need argparse in older environments (debatable), there is a
Google Code project maintaining it, and you can include that in your
project. http://code.google.com/p/argparse/
link |improve this
answer

from:
http://stackoverflow.com/questions/7473609/argparse-python-modules-in-cli

And I'm like:
ubuntu@ip:~$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

wich means it doesn't work because I just don't have it.

someone said this:

up vote3down vote

Well if the only thing you need is argparse (saw that in one of your
comments!) you could just do :

pip install argparse

This is not exactly an answer to the exact question :-) , but indeed if you
are only missing a few feature, many 2.7 features actually come from
independent projects and/or some compatibility packages can be found, eg:


Also from:
http://stackoverflow.com/questions/7473609/argparse-python-modules-in-cli

wich made me think that I'm using 2.6 while there's 2.7 and 3.2 out
there... should I consider upgrading python to a newer version or just get
the missing module?

Thanks in advanced!
Marco Tulio

2012/3/27 nick name 

> On Tuesday, March 27, 2012 11:26:17 AM UTC-4, Marco Tulio wrote:
>
>> How do I get the data that was on my app (on the sqlite database).
>
>
> Web2py comes with scripts/cpdb.py, which copies databases from one
> connection string to another with lots of other goodies.
>
> see
> http://web2py.com/books/default/chapter/29/6#Copy-data-from-one-db-into-another(if
>  it doesn't get you to the right place, look for "cpdb" in the page)
>



-- 
[]'s
Marco Tulio


Re: [web2py] Re: sqlite to postgres

2012-03-28 Thread Marco Tulio Cicero de M. Porto
seems to work, but I still couldn't make it work on my project (worked well
on smaller projects though)

2012/3/27 Anthony 

> http://web2py.com/books/default/chapter/29/6#CSV-(all-tables-at-once)
>
>
> On Tuesday, March 27, 2012 11:26:17 AM UTC-4, Marco Tulio wrote:
>>
>> Hi!
>>
>> I was using sqlite as my database for a few projects, but decided to go
>> to postgres.
>>
>> While to web2py going from one to another is pretty much a connection
>> string that you'll change, there's still one problem remaining.
>>
>> How do I get the data that was on my app (on the sqlite database).
>>
>> On a small application, I managed to do that by exporting a csv file on
>> the old app and importing it on the new one. And that's it.
>>
>> But I have another app that has quite a few tables now... wich means that
>> I'd have to copy several cvs and import them.
>>
>> Question is: isn't there an easier way to do it? (to backup a sqlite
>> database and restore it as postgres in one piece?)
>>
>> If there isn't, that means that worst case scenario, I'll have to
>> export/import csv's corresponding to my tables. I can do that...
>> but there really isn't another way ?
>>
>> Thanks!
>> --
>> []'s
>> Marco Tulio
>>
>>


-- 
[]'s
Marco Tulio


[web2py] 2.6, 2.7, 3.2, PyPy ... wich one to use?

2012-03-28 Thread Marco Tulio Cicero de M. Porto
and that's it...

2.6, 2.7, 3.2, PyPy ... wich one to use (for production on ubuntu linux)?

-- 
[]'s
Marco Tulio


Re: [web2py] 2.6, 2.7, 3.2, PyPy ... wich one to use?

2012-03-28 Thread Jonathan Lundell
On Mar 28, 2012, at 3:53 PM, Marco Tulio Cicero de M. Porto wrote:
> 2.6, 2.7, 3.2, PyPy ... wich one to use (for production on ubuntu linux)?
> 

Latest 2.7. 

[web2py] Re: How to Save Query in Session

2012-03-28 Thread Massimo Di Pierro
Let me know if you have a proposal to imporve the dal to make this easier.

On Wednesday, 28 March 2012 17:29:49 UTC-5, Limedrop wrote:
>
> Sometimes that will be sufficient.  The issue is how you turn _lastsql 
> into a gluon.dal object that you can further manipulate.  
>
> For example, what if you want to do this:
>
> _lastsql & (db.person.name == 'John') 
>
> See the slice if you need to know how to do it.
>
>
> On Thursday, March 29, 2012 5:59:23 AM UTC+13, Cliff wrote:
>>
>> Doesn't db._lastsql return a string?  Can't you just save that in the 
>> session?
>>
>> Or is that a naive question?
>>
>>
>>

Re: [web2py] Re: sqlite to postgres

2012-03-28 Thread Massimo Di Pierro
true. cpdb was rewrtten and requires 2.7. I think it is the only 
module/script that requires 2.7.

On Wednesday, 28 March 2012 17:43:48 UTC-5, Marco Tulio wrote:
>
> That sounds what I need 
>
> but:
>
> ubuntu@ip:/home/www-data/web2py$ python scripts/cpdb.py -h
> Traceback (most recent call last):
>   File "scripts/cpdb.py", line 5, in 
> import argparse
> ImportError: No module named argparse
>
> then I read somewhere this:
>
>   
> 1down vote
>  
> The argparse module was added in Python 2.7. 
> http://docs.python.org/library/argparse.html
>
> Prior to 2.7, the most common way to handle command-line arguments was 
> probably getopt.http://docs.python.org/library/getopt.html
>
> Of course you can always handle the command-line manually simply by 
> looking at sys.argv. Howevergetopt is a good abstraction layer, and 
> argparse is even better.
>
> If you truly need argparse in older environments (debatable), there is a 
> Google Code project maintaining it, and you can include that in your 
> project. http://code.google.com/p/argparse/
>   link |improve this 
> answer
>  
> from: 
> http://stackoverflow.com/questions/7473609/argparse-python-modules-in-cli
>
> And I'm like: 
> ubuntu@ip:~$ python
> Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
> [GCC 4.4.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> 
>
> wich means it doesn't work because I just don't have it.
>
> someone said this:
>
>   up vote3down vote
>  
> Well if the only thing you need is argparse (saw that in one of your 
> comments!) you could just do :
>
> pip install argparse
>
> This is not exactly an answer to the exact question :-) , but indeed if 
> you are only missing a few feature, many 2.7 features actually come from 
> independent projects and/or some compatibility packages can be found, eg:
>
>
> Also from:  
> http://stackoverflow.com/questions/7473609/argparse-python-modules-in-cli
>
> wich made me think that I'm using 2.6 while there's 2.7 and 3.2 out 
> there... should I consider upgrading python to a newer version or just get 
> the missing module?
>
> Thanks in advanced!
> Marco Tulio
>
> 2012/3/27 nick name 
>
>> On Tuesday, March 27, 2012 11:26:17 AM UTC-4, Marco Tulio wrote:
>>
>>> How do I get the data that was on my app (on the sqlite database).
>>
>>
>> Web2py comes with scripts/cpdb.py, which copies databases from one 
>> connection string to another with lots of other goodies.
>>
>> see 
>> http://web2py.com/books/default/chapter/29/6#Copy-data-from-one-db-into-another(if
>>  it doesn't get you to the right place, look for "cpdb" in the page)
>>
>
>
>
> -- 
> []'s
> Marco Tulio
>  


[web2py] Re: Primary Key tables in MSSQL. Cannot get them to work

2012-03-28 Thread Andrew
Thankyou Derek,
I will give it a try , but this was only a simple, cut down, test case to 
get it to work initially.   I originally had a string for the PK, and I 
also wanted to test multi column PKs.  
I am confident the 'id' will work, but it doesn't address the other 
scenarios.   My real goal is to change another base adaptor, but I'm using 
MSSQL as my baseline as it is supposed to work OK.
The next thing I will try is to do some db interaction without forms or 
grids.  I think that might be where the issue is.   
Thanks again.

On Thursday, March 29, 2012 10:50:41 AM UTC+13, Derek wrote:
>
> Try changing your field1 type to 'id'.
> like this:
> Field('Field1', 'id'),
>
> On Tuesday, March 27, 2012 10:56:44 PM UTC-7, Andrew wrote:
>>
>> Hello,
>> I posted on this issue some time ago and I'm pretty sure it was working 
>> again after a fix from DenesL.
>> However I can't get Primary Key tables in MSSQL to work.  They get 
>> created OK, but I get errors with a Form in a view.
>> I originally made the Key a string, but then switched to integer just to 
>> see if it made a difference.  :
>>
>> *Model:*
>> dbSQL = DAL('mssql://)
>> # 1 Column PK
>> dbSQL.define_table('web2py_int_PK',
>> Field('Field1', 'integer'),
>> Field('Field2', 'string', length=20),
>> format='%(Field1)s',
>> primarykey = ['Field1'],
>> migrate=True)
>>
>> *Controller:*
>> def web2py_int_PK_form():
>> form = SQLFORM(dbSQL.web2py_int_PK)
>> if form.process().accepted:
>> response.flash = 'form accepted'   
>> elif form.errors:   
>> response.flash = 'form has errors'   
>> else:   
>> response.flash = 'please fill out the form'
>> return dict(form=form) 
>>
>> *View:*
>> {{extend 'layout.html'}}
>> Primary Key Form Test
>> {{=form}}
>>
>> I get this in the ticket:
>> File "D:\Mercurial\web2py\gluon\dal.py", line 6912, in __getitem__
>> return dict.__getitem__(self, str(key))
>> KeyError: '_id'
>>
>> It looks like it is trying to retrieve the value for "_id" , but looking 
>> at the code __init__ for a table, _id never gets set for a table with a 
>> Primary Key.  (look at lines 6752, 6762, 6772).
>>
>> Just wondering if something like line 772 in sqlhtml.py (In the SQLFORM 
>> __init__ method).  "self.id_field_name = table._id.name"  could 
>> cause the above lookup of the _id key ?  Do Forms work with keyed tables ?
>>
>> Thanks
>> Andrew W
>>
>>
>>

[web2py] Use of return locals()

2012-03-28 Thread Andrew
Hi ,

I've been wondering about the use of return locals() in the Forms chapter 
of the book, particularly with grids
def manage_users(): 
grid = SQLFORM.grid(db.auth_user) 
return locals()

Elsewhere in the book use see something like this for forms return dict(form
=form) 
Would return dict(grid=grid) have given the same result as above?  I know a 
dict is required to automatically use a view with the a/c/f.html naming 
standard, but what does locals() use ?  
I think it would help to clarify this in the book?

Core chapter has:

*Return a dictionary for a view*: 

def index(): return dict(key='value')

*Return all local variables*: 

def index(): return locals()


and also this:

When an action returns a dictionary, web2py looks for a view with the name
  
1.

[controller]/[function].[extension]

and executes it. 
Thanks
Andrew


[web2py] help with IS_IN_DB?

2012-03-28 Thread drayco
I can try to show in form of input and output a dbset, but i want to modify 
prices, because it depends of store

In model

if store.store_id<7:
armazones = db((db.eyewear.observaciones==
'')&(db.eyewear.modelo!='SOLAR'))
elif store.store_id>6:
armazones = db((db.eyewear.observaciones!='2DA JORNADA 2010'))
else:
armazones = db(db.eyewear.id>0)

interes=0.0
if store.store_id==9:
interes=1.25
elif store.store_id>9:
interes=1.10

if interes>0.0:
i=0
for armazon in armazones:

armazones[i].precio=armazon.precio*interes+(armazon.precio*interes)%10
i=i+1

In definition of table

db.define_table("notas",
Field("store_id",db.stores, label='Sucursal',comment='Es a la que se 
encuentra asignado'),
Field('nota', 'integer', default=None, 
writable=False,label='Remisión(Sistema)',comment='Asignado por el sistema'),
Field('armazon1',db.eyewear, 
default=None,requires=IS_NULL_OR(IS_IN_DB(armazones,'eyewear.id','%(marca)s 
%(modelo)s %(color)s %(caract1)s $%(precio)s'))),
Field('modelo1','string', default=None, 
requires=IS_NULL_OR(IS_ALPHANUMERIC(error_message='¡Deben ser caracteres 
alfanumericos, sin espacios en blanco ó ñ!')),label='Modelo armazon1'),
Field('color1','string', default=None, 
requires=IS_NULL_OR(IS_ALPHANUMERIC(error_message='¡Deben ser caracteres 
alfanumericos, sin espacios en blanco ó ñ!')),label='Color(es) armazon1'),
Field('obser1','string', default=None, label='Observaciones 
1',comment='Para el laboratorio'),
Field('lente1',db.lentes, 
default=None,requires=IS_NULL_OR(IS_IN_DB(glases,'lentes.id','%(tecnoGradua)s 
%(material)s %(tipo)s %(tecnoVisual)s %(tratamiento)s $%(promo)s'))),
Field('soloLoC1','string', 
default=None,requires=IS_NULL_OR(IS_IN_SET(soloLoC)), label='Lejos ó Cerca 
1'),
Field('tinte1','string', default=None, 
requires=IS_NULL_OR(IS_IN_SET(tintes))),
Field("total", "double", default=0, writable=False),
Field("descuento", "integer", default=0, 
requires=IS_INT_IN_RANGE(0,41,error_message='Debe ser Numero positivo entre 
0 y 40'), comment='15% maximo permitido'),
Field("anticipo", "double", default=0, 
requires=[IS_NOT_EMPTY(error_message='No puede estar 
vacio'),IS_FLOAT_IN_RANGE(0.0,2.0,error_message='Debe ser un numero 
positivo entre 0 y 2')],comment='35% minimo para descuento'),
Field("pagos", "double", default=0, writable=False),
Field("saldo", "double", default=0, writable=False),
)

db.notas.store_id.represent = lambda value: '%(id)s.- %(store)s' % 
db.stores(value)  if value else ''
db.notas.armazon1.represent = lambda value: '%(marca)s %(modelo)s %(color)s 
%(caract1)s $%(promo)s' % db.eyewear(value) if value else ''
db.notas.lente1.represent = lambda value: '%(tecnoGradua)s %(material)s 
%(tipo)s %(tecnoVisual)s %(tratamiento)s $%(promo)s' % db.lentes(value) if 
value else ''

However, only show data of db not of dbset

Can you help me?
Is it better is_in_set or sqlform.factory?



[web2py] Re: Use of return locals()

2012-03-28 Thread Anthony
locals() returns a dictionary including all the variables in the local 
function, so it is exactly equivalent to dict(grid=grid) in this case. 
See http://docs.python.org/library/functions.html#locals. In general, 
though, you should probably explicitly return just the variables you need 
to pass to the view.

Anthony

On Wednesday, March 28, 2012 8:41:19 PM UTC-4, Andrew wrote:
>
> Hi ,
>
> I've been wondering about the use of return locals() in the Forms chapter 
> of the book, particularly with grids
> def manage_users(): 
> grid = SQLFORM.grid(db.auth_user) 
> return locals()
>
> Elsewhere in the book use see something like this for forms return dict(
> form=form) 
> Would return dict(grid=grid) have given the same result as above?  I know 
> a dict is required to automatically use a view with the a/c/f.html naming 
> standard, but what does locals() use ?  
> I think it would help to clarify this in the book?
>
> Core chapter has:
>
> *Return a dictionary for a view*: 
>
> def index(): return dict(key='value')
>
> *Return all local variables*: 
>
> def index(): return locals()
>
>
> and also this:
>
> When an action returns a dictionary, web2py looks for a view with the name
>   
> 1.
>
> [controller]/[function].[extension]
>
> and executes it. 
> Thanks
> Andrew
>


Re: [web2py] Re: Single error message for radio group

2012-03-28 Thread Limedrop
I've got the same issue (running 1.99.7).  Has anyone solved this?

On Sunday, February 26, 2012 6:12:41 PM UTC+13, Detectedstealth wrote:
>
> Hi Massimo,
>
> Your suggestion doesn't seem to be working: 
> LI(
> H5(self.T('What is your Age?')),
> INPUT( _type='radio', _name='age', _value='1', 
> _id='age1', requires = IS_NOT_EMPTY(error_message=self.T('missing your 
> age')), value=self.request.vars['age']),
> LABEL(SPAN(self.T('Less than 20')), _for='age1'),
> INPUT( _type='radio', _name='age', 
> _value='2',_id='age2', hideerror=True, value=self.request.vars['age']), 
> LABEL(SPAN(self.T('20-35')), _for='age2'),
> INPUT( _type='radio', _name='age', _value='3', 
> _id='age3', hideerror=True, value=self.request.vars['age']), 
> LABEL(SPAN(self.T('35-50')), _for='age3'),
> INPUT( _type='radio', _name='age', _value='4', 
> _id='age4', hideerror=True, value=self.request.vars['age']),
> LABEL(SPAN(self.T('50-65')), _for='age4'),
> INPUT( _type='radio', _name='age', _value='5', 
> _id='age5', hideerror=True, value=self.request.vars['age']), 
> LABEL(SPAN(self.T('65 and never too old')), 
> _for='age5'),
> ),
> I still get an error on all radio fields.
>
> --
> Regards,
> Bruce
> On Sun, Feb 12, 2012 at 6:00 PM, Bruce Wade  wrote:
>
>> Thanks.
>>
>>
>> On Sun, Feb 12, 2012 at 5:57 PM, Massimo Di Pierro <
>> massimo.dipie...@gmail.com> wrote:
>>
>>> INPUT(,hideerror=True)
>>>
>>> On Feb 12, 6:33 pm, Bruce Wade  wrote:
>>> > Hi,
>>> >
>>> > Is it possible to show a single error message for a group of radio 
>>> buttons.
>>> > See screen shot
>>> >
>>> > FORM(
>>> > FIELDSET(
>>> > H4(self.T('Personal Questions')),
>>> > UL(
>>> > LI(
>>> > H5(self.T('What is your Age?')),
>>> > INPUT( _type='radio', _name='age', _value='1',
>>> > _id='age1', requires = IS_NOT_EMPTY(error_message=self.T('missing your
>>> > age'))),
>>> > LABEL(SPAN(self.T('Less than 20')), 
>>> _for='age1'),
>>> > INPUT( _type='radio', _name='age',
>>> > _value='2',_id='age2'),
>>> > LABEL(SPAN(self.T('20-35')), _for='age2'),
>>> > INPUT( _type='radio', _name='age', _value='3',
>>> > _id='age3'),
>>> > LABEL(SPAN(self.T('35-50')), _for='age3'),
>>> > INPUT( _type='radio', _name='age', _value='4',
>>> > _id='age4'), LABEL(SPAN(self.T('50-65')), _for='age4'),
>>> > INPUT( _type='radio', _name='age', _value='5',
>>> > _id='age5'), LABEL(SPAN(self.T('65 and never too old')), _for='age5'),
>>> > ),
>>> >),
>>> >)
>>> > )
>>> >
>>> > --
>>> > --
>>> > Regards,
>>> > Bruce Wadehttp://
>>> ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp://www.warplydesigned.comhttp://www.fitnessfriendsfinder.com
>>> >
>>> >  fit_errors.png
>>> > 371KViewDownload
>>
>>
>>
>>
>> -- 
>> -- 
>> Regards,
>> Bruce Wade
>> http://ca.linkedin.com/in/brucelwade
>> http://www.wadecybertech.com
>> http://www.warplydesigned.com
>> http://www.fitnessfriendsfinder.com
>>
>
>
>
> -- 
> -- 
> Regards,
> Bruce Wade
> http://ca.linkedin.com/in/brucelwade
> http://www.wadecybertech.com
> http://www.warplydesigned.com
> http://www.fitnessfriendsfinder.com
>  


[web2py] Re: Smarttable & SQLFORM.grid

2012-03-28 Thread tomt
You may be thinking of 'powertable'.  This plugin presents a grid that 
includes a typeahead search 
function. It can be found at https://bitbucket.org/rochacbruno/powertable.

- Tom

On Monday, March 26, 2012 2:24:42 PM UTC-6, greenpoise wrote:
>
> What I was looking for was a type-ahead function using SQLFORM.smartgrid 
> instead of typing a word and pressing search.
>
>
>
>
>
>
>
>
> On Thursday, 22 March 2012 16:15:23 UTC-7, Alan Etkin wrote:
>>
>> I think you mean SQLFORM.smartgrid. 
>>
>> Book's 7.8 section (the features are explained there): 
>>
>> "... 
>> A SQLFORM.smartgrid looks a lot like a grid, in fact it contains a 
>> grid but it is 
>> designed to take as input not a query but only one table and to browse 
>> said 
>> table and selected referencing tables. 
>> ..." 
>>
>> On Mar 22, 7:16 pm, greenpoise  wrote: 
>> > Are these two equivalents?? I remember using smartables at some point. 
>> What 
>> > I liked about it was the search feature without having to press any 
>> button 
>> > to search for my text within a table. Does SQLFORM.grid provides 
>> something 
>> > similar?? 
>> > 
>> > Thanks 
>> > 
>> > d
>
>

Re: [web2py] Re: Single error message for radio group

2012-03-28 Thread Massimo Di Pierro
I think there is a bug and I think I just fixed it in trunk. Please check 
it.

On Wednesday, 28 March 2012 20:38:08 UTC-5, Limedrop wrote:
>
> I've got the same issue (running 1.99.7).  Has anyone solved this?
>
> On Sunday, February 26, 2012 6:12:41 PM UTC+13, Detectedstealth wrote:
>>
>> Hi Massimo,
>>
>> Your suggestion doesn't seem to be working: 
>> LI(
>> H5(self.T('What is your Age?')),
>> INPUT( _type='radio', _name='age', _value='1', 
>> _id='age1', requires = IS_NOT_EMPTY(error_message=self.T('missing your 
>> age')), value=self.request.vars['age']),
>> LABEL(SPAN(self.T('Less than 20')), _for='age1'),
>> INPUT( _type='radio', _name='age', 
>> _value='2',_id='age2', hideerror=True, value=self.request.vars['age']), 
>> LABEL(SPAN(self.T('20-35')), _for='age2'),
>> INPUT( _type='radio', _name='age', _value='3', 
>> _id='age3', hideerror=True, value=self.request.vars['age']), 
>> LABEL(SPAN(self.T('35-50')), _for='age3'),
>> INPUT( _type='radio', _name='age', _value='4', 
>> _id='age4', hideerror=True, value=self.request.vars['age']),
>> LABEL(SPAN(self.T('50-65')), _for='age4'),
>> INPUT( _type='radio', _name='age', _value='5', 
>> _id='age5', hideerror=True, value=self.request.vars['age']), 
>> LABEL(SPAN(self.T('65 and never too old')), 
>> _for='age5'),
>> ),
>> I still get an error on all radio fields.
>>
>> --
>> Regards,
>> Bruce
>> On Sun, Feb 12, 2012 at 6:00 PM, Bruce Wade  wrote:
>>
>>> Thanks.
>>>
>>>
>>> On Sun, Feb 12, 2012 at 5:57 PM, Massimo Di Pierro <
>>> massimo.dipie...@gmail.com> wrote:
>>>
 INPUT(,hideerror=True)

 On Feb 12, 6:33 pm, Bruce Wade  wrote:
 > Hi,
 >
 > Is it possible to show a single error message for a group of radio 
 buttons.
 > See screen shot
 >
 > FORM(
 > FIELDSET(
 > H4(self.T('Personal Questions')),
 > UL(
 > LI(
 > H5(self.T('What is your Age?')),
 > INPUT( _type='radio', _name='age', _value='1',
 > _id='age1', requires = IS_NOT_EMPTY(error_message=self.T('missing your
 > age'))),
 > LABEL(SPAN(self.T('Less than 20')), 
 _for='age1'),
 > INPUT( _type='radio', _name='age',
 > _value='2',_id='age2'),
 > LABEL(SPAN(self.T('20-35')), _for='age2'),
 > INPUT( _type='radio', _name='age', _value='3',
 > _id='age3'),
 > LABEL(SPAN(self.T('35-50')), _for='age3'),
 > INPUT( _type='radio', _name='age', _value='4',
 > _id='age4'), LABEL(SPAN(self.T('50-65')), _for='age4'),
 > INPUT( _type='radio', _name='age', _value='5',
 > _id='age5'), LABEL(SPAN(self.T('65 and never too old')), _for='age5'),
 > ),
 >),
 >)
 > )
 >
 > --
 > --
 > Regards,
 > Bruce Wadehttp://
 ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp://www.warplydesigned.comhttp://www.fitnessfriendsfinder.com
 >
 >  fit_errors.png
 > 371KViewDownload
>>>
>>>
>>>
>>>
>>> -- 
>>> -- 
>>> Regards,
>>> Bruce Wade
>>> http://ca.linkedin.com/in/brucelwade
>>> http://www.wadecybertech.com
>>> http://www.warplydesigned.com
>>> http://www.fitnessfriendsfinder.com
>>>
>>
>>
>>
>> -- 
>> -- 
>> Regards,
>> Bruce Wade
>> http://ca.linkedin.com/in/brucelwade
>> http://www.wadecybertech.com
>> http://www.warplydesigned.com
>> http://www.fitnessfriendsfinder.com
>>  
>

Re: [web2py] Re: Single error message for radio group

2012-03-28 Thread Bruce Wade
The solution I made was setting a default value for all my radio groups.

On Wed, Mar 28, 2012 at 7:01 PM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> I think there is a bug and I think I just fixed it in trunk. Please check
> it.
>
>
> On Wednesday, 28 March 2012 20:38:08 UTC-5, Limedrop wrote:
>>
>> I've got the same issue (running 1.99.7).  Has anyone solved this?
>>
>> On Sunday, February 26, 2012 6:12:41 PM UTC+13, Detectedstealth wrote:
>>>
>>> Hi Massimo,
>>>
>>> Your suggestion doesn't seem to be working:
>>> LI(
>>> H5(self.T('What is your Age?')),
>>> INPUT( _type='radio', _name='age', _value='1',
>>> _id='age1', requires = IS_NOT_EMPTY(error_message=**self.T('missing
>>> your age')), value=self.request.vars['age']**),
>>> LABEL(SPAN(self.T('Less than 20')), _for='age1'),
>>> INPUT( _type='radio', _name='age',
>>> _value='2',_id='age2', hideerror=True, value=self.request.vars['age']**
>>> ),
>>> LABEL(SPAN(self.T('20-35')), _for='age2'),
>>> INPUT( _type='radio', _name='age', _value='3',
>>> _id='age3', hideerror=True, value=self.request.vars['age']**),
>>> LABEL(SPAN(self.T('35-50')), _for='age3'),
>>> INPUT( _type='radio', _name='age', _value='4',
>>> _id='age4', hideerror=True, value=self.request.vars['age']**),
>>> LABEL(SPAN(self.T('50-65')), _for='age4'),
>>> INPUT( _type='radio', _name='age', _value='5',
>>> _id='age5', hideerror=True, value=self.request.vars['age']**),
>>> LABEL(SPAN(self.T('65 and never too old')),
>>> _for='age5'),
>>> ),
>>> I still get an error on all radio fields.
>>>
>>> --
>>> Regards,
>>> Bruce
>>> On Sun, Feb 12, 2012 at 6:00 PM, Bruce Wade wrote:
>>>
 Thanks.


 On Sun, Feb 12, 2012 at 5:57 PM, Massimo Di Pierro <
 massimo.dipie...@gmail.com> wrote:

> INPUT(,hideerror=True)
>
> On Feb 12, 6:33 pm, Bruce Wade  wrote:
> > Hi,
> >
> > Is it possible to show a single error message for a group of radio
> buttons.
> > See screen shot
> >
> > FORM(
> > FIELDSET(
> > H4(self.T('Personal Questions')),
> > UL(
> > LI(
> > H5(self.T('What is your Age?')),
> > INPUT( _type='radio', _name='age',
> _value='1',
> > _id='age1', requires = IS_NOT_EMPTY(error_message=**self.T('missing
> your
> > age'))),
> > LABEL(SPAN(self.T('Less than 20')),
> _for='age1'),
> > INPUT( _type='radio', _name='age',
> > _value='2',_id='age2'),
> > LABEL(SPAN(self.T('20-35')), _for='age2'),
> > INPUT( _type='radio', _name='age',
> _value='3',
> > _id='age3'),
> > LABEL(SPAN(self.T('35-50')), _for='age3'),
> > INPUT( _type='radio', _name='age',
> _value='4',
> > _id='age4'), LABEL(SPAN(self.T('50-65')), _for='age4'),
> > INPUT( _type='radio', _name='age',
> _value='5',
> > _id='age5'), LABEL(SPAN(self.T('65 and never too old')),
> _for='age5'),
> > ),
> >),
> >)
> > )
> >
> > --
> > --
> > Regards,
> > Bruce Wadehttp://ca.linkedin.com/in/**brucelwadehttp://www.**
> wadecybertech.comhttp://www.**warplydesigned.comhttp://www.**
> fitnessfriendsfinder.com
> >
> >  fit_errors.png
> > 371KViewDownload




 --
 --
 Regards,
 Bruce Wade
 http://ca.linkedin.com/in/**brucelwade
 http://www.wadecybertech.com
 http://www.warplydesigned.com
 http://www.**fitnessfriendsfinder.com

>>>
>>>
>>>
>>> --
>>> --
>>> Regards,
>>> Bruce Wade
>>> http://ca.linkedin.com/in/**brucelwade
>>> http://www.wadecybertech.com
>>> http://www.warplydesigned.com
>>> http://www.**fitnessfriendsfinder.com
>>>
>>


-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com


Re: [web2py] Re: Single error message for radio group

2012-03-28 Thread Limedrop
Yes, tested and it now works!  Thanks Massimo.

On Thursday, March 29, 2012 3:01:41 PM UTC+13, Massimo Di Pierro wrote:
>
> I think there is a bug and I think I just fixed it in trunk. Please check 
> it.
>
> On Wednesday, 28 March 2012 20:38:08 UTC-5, Limedrop wrote:
>>
>> I've got the same issue (running 1.99.7).  Has anyone solved this?
>>
>> On Sunday, February 26, 2012 6:12:41 PM UTC+13, Detectedstealth wrote:
>>>
>>> Hi Massimo,
>>>
>>> Your suggestion doesn't seem to be working: 
>>> LI(
>>> H5(self.T('What is your Age?')),
>>> INPUT( _type='radio', _name='age', _value='1', 
>>> _id='age1', requires = IS_NOT_EMPTY(error_message=self.T('missing your 
>>> age')), value=self.request.vars['age']),
>>> LABEL(SPAN(self.T('Less than 20')), _for='age1'),
>>> INPUT( _type='radio', _name='age', 
>>> _value='2',_id='age2', hideerror=True, value=self.request.vars['age']), 
>>> LABEL(SPAN(self.T('20-35')), _for='age2'),
>>> INPUT( _type='radio', _name='age', _value='3', 
>>> _id='age3', hideerror=True, value=self.request.vars['age']), 
>>> LABEL(SPAN(self.T('35-50')), _for='age3'),
>>> INPUT( _type='radio', _name='age', _value='4', 
>>> _id='age4', hideerror=True, value=self.request.vars['age']),
>>> LABEL(SPAN(self.T('50-65')), _for='age4'),
>>> INPUT( _type='radio', _name='age', _value='5', 
>>> _id='age5', hideerror=True, value=self.request.vars['age']), 
>>> LABEL(SPAN(self.T('65 and never too old')), 
>>> _for='age5'),
>>> ),
>>> I still get an error on all radio fields.
>>>
>>> --
>>> Regards,
>>> Bruce
>>> On Sun, Feb 12, 2012 at 6:00 PM, Bruce Wade wrote:
>>>
 Thanks.


 On Sun, Feb 12, 2012 at 5:57 PM, Massimo Di Pierro <
 massimo.dipie...@gmail.com> wrote:

> INPUT(,hideerror=True)
>
> On Feb 12, 6:33 pm, Bruce Wade  wrote:
> > Hi,
> >
> > Is it possible to show a single error message for a group of radio 
> buttons.
> > See screen shot
> >
> > FORM(
> > FIELDSET(
> > H4(self.T('Personal Questions')),
> > UL(
> > LI(
> > H5(self.T('What is your Age?')),
> > INPUT( _type='radio', _name='age', 
> _value='1',
> > _id='age1', requires = IS_NOT_EMPTY(error_message=self.T('missing 
> your
> > age'))),
> > LABEL(SPAN(self.T('Less than 20')), 
> _for='age1'),
> > INPUT( _type='radio', _name='age',
> > _value='2',_id='age2'),
> > LABEL(SPAN(self.T('20-35')), _for='age2'),
> > INPUT( _type='radio', _name='age', 
> _value='3',
> > _id='age3'),
> > LABEL(SPAN(self.T('35-50')), _for='age3'),
> > INPUT( _type='radio', _name='age', 
> _value='4',
> > _id='age4'), LABEL(SPAN(self.T('50-65')), _for='age4'),
> > INPUT( _type='radio', _name='age', 
> _value='5',
> > _id='age5'), LABEL(SPAN(self.T('65 and never too old')), 
> _for='age5'),
> > ),
> >),
> >)
> > )
> >
> > --
> > --
> > Regards,
> > Bruce Wadehttp://
> ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp://www.warplydesigned.comhttp://www.fitnessfriendsfinder.com
> >
> >  fit_errors.png
> > 371KViewDownload




 -- 
 -- 
 Regards,
 Bruce Wade
 http://ca.linkedin.com/in/brucelwade
 http://www.wadecybertech.com
 http://www.warplydesigned.com
 http://www.fitnessfriendsfinder.com

>>>
>>>
>>>
>>> -- 
>>> -- 
>>> Regards,
>>> Bruce Wade
>>> http://ca.linkedin.com/in/brucelwade
>>> http://www.wadecybertech.com
>>> http://www.warplydesigned.com
>>> http://www.fitnessfriendsfinder.com
>>>  
>>

Re: [web2py] Re: Single error message for radio group

2012-03-28 Thread Limedrop
Thanks.  In my case default=None (and needs to be), so thankfully Massimo's 
fix does the trick.

On Thursday, March 29, 2012 3:27:40 PM UTC+13, Detectedstealth wrote:
>
> The solution I made was setting a default value for all my radio groups. 
>
>
>

[web2py] SQLFORM.grid not doing what I expect

2012-03-28 Thread Mike Veltman

Gentle people,

I have the following grid:

query = ( (db.lvdisksetup.lvgroupname_id == usedlvdisksetup) & 
(db.lvgroupname.id == usedlvdisksetup) & (db.lvdisksetup.lvdisk_id == 
db.lvdisk.id) )
fields = [db.lvdisksetup.id, db.lvgroupname.lvgroupnamedesc , 
db.lvdisk.lvdiskdesc, db.lvdisksetup.lunid]


form = SQLFORM.grid(query,
fields=fields,
orderby=['lvdisksetup.lunid'],
csv=False,
create = False,
maxtextlength=45
)

I want to manipulate db.lvdisksetup but in stead it manipulates 
db.lvdisk :-)


What causes havoc by deleting essential table data :)



[web2py] SQLFORM.grid not doing what I want :)

2012-03-28 Thread Mike Veltman

Gentle people,

I have the following grid:

query = ( (db.lvdisksetup.lvgroupname_id == usedlvdisksetup) & 
(db.lvgroupname.id == usedlvdisksetup) & (db.lvdisksetup.lvdisk_id == 
db.lvdisk.id) )
fields = [db.lvdisksetup.id, db.lvgroupname.lvgroupnamedesc , 
db.lvdisk.lvdiskdesc, db.lvdisksetup.lunid]


form = SQLFORM.grid(query,
fields=fields,
orderby=['lvdisksetup.lunid'],
csv=False,
create = False,
maxtextlength=45
)

I want to manipulate db.lvdisksetup but in stead it manipulates 
db.lvdisk :-)


What causes havoc by deleting essential table data :)

Part of the db models :)

# All the LV sizes will be collected in here in bytes, like 30GB, 10GB, 
2GB etc

db.define_table('lvsize',

Field('sizename', type='string',
  unique=True,
  label=T('Lun Size')),
Field('size', type='string',
  label=T('LV Size in bytes')),
Field('created_on','datetime',default=request.now,
  label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
  label=T('Modified On'),writable=False,readable=False,
  update=request.now),
migrate=settings.migrate)

# The LV Disk groups
db.define_table('lvgroupname',

Field('lvgroupnamedesc', type='string',
   unique=True,
  label=T('LV Disk Groupname ')),
Field('created_on','datetime',default=request.now,
  label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
  label=T('Modified On'),writable=False,readable=False,
  update=request.now),
migrate=settings.migrate)

# Table rules
db.lvgroupname.lvgroupnamedesc.requires = IS_NOT_EMPTY()

# Logical volume on storage
db.define_table('lvdisk',

Field('lvdiskdesc', type='string',
   unique=True,
  label=T('LV Disk description ')),
Field('lvsize_id', db.lvsize,
  default=2,
  label=T('Size ID')),
Field('created_on','datetime',default=request.now,
  label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
  label=T('Modified On'),writable=False,readable=False,
  update=request.now),
migrate=settings.migrate)

# Table rules
db.lvdisk.lvsize_id.requires = IS_IN_DB(db, 'lvsize.id', 'lvsize.sizename')
db.lvdisk.lvdiskdesc.requires = IS_NOT_EMPTY()


# lvdisksetup
db.define_table('lvdisksetup',

Field('lvdisk_id', db.lvdisk,
  default=1,
  label=T('Logical volume to be added')),
Field('lvgroupname_id', db.lvgroupname,
  default=1,
  label=T('Member of Logical volume group name')),
Field('lunid', type='integer',
  default=2,
  label=T('Lun ID')),
Field('created_on','datetime',default=request.now,
  label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
  label=T('Modified On'),writable=False,readable=False,
  update=request.now),
migrate=settings.migrate)

# Table rules
db.lvdisksetup.lvdisk_id.requires = IS_IN_DB(db, 'lvdisk.id', 
'lvdisk.lvdiskdesc')
db.lvdisksetup.lvgroupname_id.requires = IS_IN_DB(db, 'lvgroupname.id', 
'lvgroupname.lvgroupnamedesc')



# hbahostgroupsetup (to add the right disks to a hba or a hostgroup)
db.define_table('hbahostgroupsetup',

Field('hbahgdesc', type='string',
  label=T('LV Disk setup Description ')),
Field('lvgroupname_id', db.lvgroupname,
  default=1,
  label=T('LV Disk')),
Field('mapping_id', db.storagemap,
  default=1,
  label=T('HBA or Hostgroup mapping')),
Field('created_on','datetime',default=request.now,
  label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
  label=T('Modified On'),writable=False,readable=False,
  update=request.now),
migrate=settings.migrate)

# Table rules
db.hbahostgroupsetup.lvgroupname_id.requires = IS_IN_DB(db, 
'lvgroupname.id', 'lvdisk.lvgroupnamedesc')
db.hbahostgroupsetup.mapping_id.requires = IS_IN_DB(db, 'storagemap.id', 
'storagemap.mapping')

db.hbahostgroupsetup.hbahgdesc.requires = IS_NOT_EMPTY()

# disksetupname (to make it possible to have the same lv setup for 
different class setups)

db.define_table('disksetupname',

Field('disksetupnamedesc', type='string',
  label=T('LV Disk group selection description ')),
Field('created_on','datetime',default=request.now,
  label=T('Created On'),writable=False,readable=False),
Field('modified_on','datetime',default=request.now,
  label=T('Modified On'),writable=False,readable=False,
  update=request.now),
migrate=settings.migrate)

# Table rules
db.disksetupname.disksetupnamedesc.requires = IS_NOT_EMPTY()

# hbahggroup
db.define_table('hbahggroup',

Field('hbahostgroupsetup_id', db.hbahostgroupsetup,
  

[web2py] Re: Use of return locals()

2012-03-28 Thread Andrew
Thanks Anthony !

On Thursday, March 29, 2012 2:31:02 PM UTC+13, Anthony wrote:
>
> locals() returns a dictionary including all the variables in the local 
> function, so it is exactly equivalent to dict(grid=grid) in this case. See 
> http://docs.python.org/library/functions.html#locals. In general, though, 
> you should probably explicitly return just the variables you need to pass 
> to the view.
>
> Anthony
>
> On Wednesday, March 28, 2012 8:41:19 PM UTC-4, Andrew wrote:
>>
>> Hi ,
>>
>> I've been wondering about the use of return locals() in the Forms chapter 
>> of the book, particularly with grids
>> def manage_users(): 
>> grid = SQLFORM.grid(db.auth_user) 
>> return locals()
>>
>> Elsewhere in the book use see something like this for forms return dict(
>> form=form) 
>> Would return dict(grid=grid) have given the same result as above?  I know 
>> a dict is required to automatically use a view with the a/c/f.html naming 
>> standard, but what does locals() use ?  
>> I think it would help to clarify this in the book?
>>
>> Core chapter has:
>>
>> *Return a dictionary for a view*: 
>>
>> def index(): return dict(key='value')
>>
>> *Return all local variables*: 
>>
>> def index(): return locals()
>>
>>
>> and also this:
>>
>> When an action returns a dictionary, web2py looks for a view with the name
>>   
>> 1.
>>
>> [controller]/[function].[extension]
>>
>> and executes it. 
>> Thanks
>> Andrew
>>
>

[web2py] Facing Trouble in Cascading drop-down with ajax

2012-03-28 Thread Sanjeet Kumar
I am using the three cascading drop-down menu with the help of slices i am 
able to show the value in the second drop-down filtered on the first one 
but i am not be able to shown the value in the third 
drop-down filtration on the second via ajax so please help me.