[web2py] Google Datastore

2014-03-30 Thread Massimo Di Pierro
A number of recent of events had let me to take a second look at the Google 
Datastore. It has improved a lot since the early days and it is a great 
tool to build scalable applications.
Web2py supported it form the earliest times. Web2py also supports NDB, an 
interface to the datastore that uses memcache to speed-up searches.

Now it is easier then ever:

1) setup web2py for GAE

$ web2py.py -G config  
   Your GAE app name: test1

   optional: edit app.yaml

2) run the local development server
   
   $ dev_appserver.py --port 8080 ./
   (this comes with the GAE SDK)

3) in your models use

   db = DAL('google:datastore+ndb')




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


[web2py] Re: handbook, Configuring layout

2014-03-30 Thread ureal frank
yes! :) thanks Marco.

(someone with write permissions can fix the handbook? kthxbye)

On Sunday, March 30, 2014, Marco Mansilla  wrote:

> El Sat, 29 Mar 2014 17:59:19 +
> Frank > escribió:
>
> > Hi,
> >
> > I’m too newbie to know if this is a typo or an error but,
> > here
> http://web2py.com/books/default/chapter/29/03/overview#Configuring-the-layout
> > when Massimo writes “(…) In fact, the "static/base.css" stylesheet is
> > well documented and described in Chapter 5 (…), I can’t find
> > any reference to this ‘static/base.css’ file under chapter 5 or under
> > the
> > official repo
> https://github.com/web2py/web2py/tree/master/applications/welcome/static/css
> >
> > Maybe I am missing something or this ‘static/base.css’ file should be
> > another one?
> >
> > Cheers,
> > --
> > Frank
> >
>
> I guess you're looking for web2py.css in static/css/
>
> Marco.
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [web2py] Re: Dynamically Creating a Form

2014-03-30 Thread Anthony
Yes, that will do it. form.vars (as well as request.vars and many other 
web2py objects) is a gluon.storage.Storage object, which is much like a 
dictionary and allows dictionary-like syntax for accessing items. Similar 
syntax works with DAL Table and Row objects.

Anthony

On Monday, March 31, 2014 12:49:37 AM UTC-4, mweissen wrote:

> Try form.vars['color'] or take a variable v
> v="color"
> form.vars[v]
>
>
>
>
> 2014-03-31 2:32 GMT+02:00 horridohobbyist :
>
>> But if I create a name such as, for example, "color", I'd need to access 
>> the form variable thusly:  form.vars.color. Since the name was created on 
>> the fly, how can I actually say "form.vars.color"?? If the name was created 
>> and stored in a variable, say, x, I can't say "form.vars.x". I guess I 
>> don't quite understand Python's capabilities.
>>
>>
>> On Sunday, 30 March 2014 20:00:56 UTC-4, Anthony wrote:
>>>
>>> Well, you need some way to dynamically create names for your fields as 
>>> well. Figure something out based on whatever you are using to construct the 
>>> fields themselves.
>>>
>>> On Sunday, March 30, 2014 7:45:56 PM UTC-4, horridohobbyist wrote:

 Treating a form like a Python list works like a charm. However, having 
 dynamically added SELECT fields, I don't know how to extract the form.vars 
 for these fields. I don't know how to assign _name in a way that I can 
 reference it after the form has been accepted. For example,

 elements = []
 for b in a:
 sel = []
 for c, val in a[b].iteritems():
 sel.append(string.capitalize(c)+':'+str(val))
 sel.sort()
 elements.append(TR(T(string.capitalize(b)),SELECT(sel,_
 name=???)))

 After a form.accepts, I need to access form.vars.??? to get the field 
 selection. But how do I know what the variable name is??


 On Saturday, 29 March 2014 09:21:59 UTC-4, Tim Richardson wrote:
>
> FORMs are just HTML helpers, so you manipulate them after creating 
> them.
> You can therefore just treat them like python lists, but there is 
> functionality which may be more helpful:
>
> http://web2py.com/books/default/chapter/29/05/the-
> views#Server-side-DOM-and-parsing
>
>
>
> On Sunday, 30 March 2014 00:11:27 UTC+11, horridohobbyist wrote:
>>
>> Is there a way for me to dynamically add form elements, such as INPUT 
>> fields or SELECT fields, to a form? I'm not sure how to do this. I'd 
>> like 
>> to add these elements only under certain conditions.
>>
>> Thanks.
>>
>>  -- 
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to web2py+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>  

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


Re: [web2py] Re: Dynamically Creating a Form

2014-03-30 Thread Martin Weissenboeck
Try form.vars['color'] or take a variable v
v="color"
form.vars[v]




2014-03-31 2:32 GMT+02:00 horridohobbyist :

> But if I create a name such as, for example, "color", I'd need to access
> the form variable thusly:  form.vars.color. Since the name was created on
> the fly, how can I actually say "form.vars.color"?? If the name was created
> and stored in a variable, say, x, I can't say "form.vars.x". I guess I
> don't quite understand Python's capabilities.
>
>
> On Sunday, 30 March 2014 20:00:56 UTC-4, Anthony wrote:
>>
>> Well, you need some way to dynamically create names for your fields as
>> well. Figure something out based on whatever you are using to construct the
>> fields themselves.
>>
>> On Sunday, March 30, 2014 7:45:56 PM UTC-4, horridohobbyist wrote:
>>>
>>> Treating a form like a Python list works like a charm. However, having
>>> dynamically added SELECT fields, I don't know how to extract the form.vars
>>> for these fields. I don't know how to assign _name in a way that I can
>>> reference it after the form has been accepted. For example,
>>>
>>> elements = []
>>> for b in a:
>>> sel = []
>>> for c, val in a[b].iteritems():
>>> sel.append(string.capitalize(c)+':'+str(val))
>>> sel.sort()
>>> elements.append(TR(T(string.capitalize(b)),SELECT(sel,_
>>> name=???)))
>>>
>>> After a form.accepts, I need to access form.vars.??? to get the field
>>> selection. But how do I know what the variable name is??
>>>
>>>
>>> On Saturday, 29 March 2014 09:21:59 UTC-4, Tim Richardson wrote:

 FORMs are just HTML helpers, so you manipulate them after creating them.
 You can therefore just treat them like python lists, but there is
 functionality which may be more helpful:

 http://web2py.com/books/default/chapter/29/05/the-
 views#Server-side-DOM-and-parsing



 On Sunday, 30 March 2014 00:11:27 UTC+11, horridohobbyist wrote:
>
> Is there a way for me to dynamically add form elements, such as INPUT
> fields or SELECT fields, to a form? I'm not sure how to do this. I'd like
> to add these elements only under certain conditions.
>
> Thanks.
>
>  --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


[web2py] web2py form submit does not take custom widget with x-editable fields

2014-03-30 Thread Yufei Li


I am trying to use x-editable fields rather than plain INPUT in my model as 
in:

def string_editable_widget(field, value):return A('', _href='#', _class="%s 
myeditable" % field.type, _name=field.name, \
  _id="%s_%s" % (field._tablename, field.name), _value=value, \
  requires=field.requires, **{'_data-type': 'text'})

db.define_table('person',Field('name', 'string', widget=string_editable_widget))

The fields are displayed on the form as expected, however when I submit, it 
shows "Errors in form". Digging deeper, I noticed, when I use plain INPUT, 
the post request contains:

Content-Disposition: form-data; name="name"

Some name

Yet, with the custom widget, the post request does not contain the above at 
all, which means the form is not grabbing inputs from the x-editable fields.

Please help on how to connect these two.

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


[web2py] Re: Dynamically Creating a Form

2014-03-30 Thread horridohobbyist
But if I create a name such as, for example, "color", I'd need to access 
the form variable thusly:  form.vars.color. Since the name was created on 
the fly, how can I actually say "form.vars.color"?? If the name was created 
and stored in a variable, say, x, I can't say "form.vars.x". I guess I 
don't quite understand Python's capabilities.


On Sunday, 30 March 2014 20:00:56 UTC-4, Anthony wrote:
>
> Well, you need some way to dynamically create names for your fields as 
> well. Figure something out based on whatever you are using to construct the 
> fields themselves.
>
> On Sunday, March 30, 2014 7:45:56 PM UTC-4, horridohobbyist wrote:
>>
>> Treating a form like a Python list works like a charm. However, having 
>> dynamically added SELECT fields, I don't know how to extract the form.vars 
>> for these fields. I don't know how to assign _name in a way that I can 
>> reference it after the form has been accepted. For example,
>>
>> elements = []
>> for b in a:
>> sel = []
>> for c, val in a[b].iteritems():
>> sel.append(string.capitalize(c)+':'+str(val))
>> sel.sort()
>> 
>> elements.append(TR(T(string.capitalize(b)),SELECT(sel,_name=???)))
>>
>> After a form.accepts, I need to access form.vars.??? to get the field 
>> selection. But how do I know what the variable name is??
>>
>>
>> On Saturday, 29 March 2014 09:21:59 UTC-4, Tim Richardson wrote:
>>>
>>> FORMs are just HTML helpers, so you manipulate them after creating them.
>>> You can therefore just treat them like python lists, but there is 
>>> functionality which may be more helpful:
>>>
>>>
>>> http://web2py.com/books/default/chapter/29/05/the-views#Server-side-DOM-and-parsing
>>>
>>>
>>>
>>> On Sunday, 30 March 2014 00:11:27 UTC+11, horridohobbyist wrote:

 Is there a way for me to dynamically add form elements, such as INPUT 
 fields or SELECT fields, to a form? I'm not sure how to do this. I'd like 
 to add these elements only under certain conditions.

 Thanks.



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


[web2py] Re: Dynamically Creating a Form

2014-03-30 Thread Anthony
Well, you need some way to dynamically create names for your fields as 
well. Figure something out based on whatever you are using to construct the 
fields themselves.

On Sunday, March 30, 2014 7:45:56 PM UTC-4, horridohobbyist wrote:
>
> Treating a form like a Python list works like a charm. However, having 
> dynamically added SELECT fields, I don't know how to extract the form.vars 
> for these fields. I don't know how to assign _name in a way that I can 
> reference it after the form has been accepted. For example,
>
> elements = []
> for b in a:
> sel = []
> for c, val in a[b].iteritems():
> sel.append(string.capitalize(c)+':'+str(val))
> sel.sort()
> 
> elements.append(TR(T(string.capitalize(b)),SELECT(sel,_name=???)))
>
> After a form.accepts, I need to access form.vars.??? to get the field 
> selection. But how do I know what the variable name is??
>
>
> On Saturday, 29 March 2014 09:21:59 UTC-4, Tim Richardson wrote:
>>
>> FORMs are just HTML helpers, so you manipulate them after creating them.
>> You can therefore just treat them like python lists, but there is 
>> functionality which may be more helpful:
>>
>>
>> http://web2py.com/books/default/chapter/29/05/the-views#Server-side-DOM-and-parsing
>>
>>
>>
>> On Sunday, 30 March 2014 00:11:27 UTC+11, horridohobbyist wrote:
>>>
>>> Is there a way for me to dynamically add form elements, such as INPUT 
>>> fields or SELECT fields, to a form? I'm not sure how to do this. I'd like 
>>> to add these elements only under certain conditions.
>>>
>>> Thanks.
>>>
>>>

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


[web2py] Re: Dynamically Creating a Form

2014-03-30 Thread horridohobbyist
Treating a form like a Python list works like a charm. However, having 
dynamically added SELECT fields, I don't know how to extract the form.vars 
for these fields. I don't know how to assign _name in a way that I can 
reference it after the form has been accepted. For example,

elements = []
for b in a:
sel = []
for c, val in a[b].iteritems():
sel.append(string.capitalize(c)+':'+str(val))
sel.sort()

elements.append(TR(T(string.capitalize(b)),SELECT(sel,_name=???)))

After a form.accepts, I need to access form.vars.??? to get the field 
selection. But how do I know what the variable name is??


On Saturday, 29 March 2014 09:21:59 UTC-4, Tim Richardson wrote:
>
> FORMs are just HTML helpers, so you manipulate them after creating them.
> You can therefore just treat them like python lists, but there is 
> functionality which may be more helpful:
>
>
> http://web2py.com/books/default/chapter/29/05/the-views#Server-side-DOM-and-parsing
>
>
>
> On Sunday, 30 March 2014 00:11:27 UTC+11, horridohobbyist wrote:
>>
>> Is there a way for me to dynamically add form elements, such as INPUT 
>> fields or SELECT fields, to a form? I'm not sure how to do this. I'd like 
>> to add these elements only under certain conditions.
>>
>> Thanks.
>>
>>

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


[web2py] Re: How to use AJAX within a SQLFORM.grid 'add' form

2014-03-30 Thread Anthony
First, take grid out of BEAUTIFY -- not necessary.

Does db.t_dogs happen to have a field called "name"? If so, change the name 
of your extra input element to something other than "name".

Also, when typing in your input field, open the browser developer tools and 
see if (a) you get any JavaScript errors in the console and (b) an Ajax 
request gets sent to the server.

Anthony

On Sunday, March 30, 2014 4:43:34 PM UTC-4, backseat wrote:

> On Sunday, 30 March 2014 14:08:38 UTC+1, Anthony wrote:
>>
>> Would help to see the controller code.
>>
>
> Here's the code from a test app I've put together to simplify:
>
> def index():
> grid = SQLFORM.grid(db.t_dogs,
> create=True,
> csv=False,
> deletable=False,
> details=False,
> editable=True,
> paginate=100,
> searchable=False,
> )
> return locals()
>
>
> def echo():
> print "in echo()"
> #from gluon.debug import dbg
> #dbg.set_trace()
> return request.vars.name
>
>
> What is "form", and why are "grid" and "form" inside BEAUTIFY?
>>
>
> Here's the simplified view:
>
> {{extend 'layout.html'}}
>
> Target
> 
> 
> 
>
> 
>
> DOGS
> {{=BEAUTIFY(grid)}}
>
>
> They're inside BEAUTIFY to keep it simple for now: that is how they are 
> after the application wizard has run.
>  
>
>> What are you really trying to do?
>>
>
> Ultimately, I want the Add from from a SQLFORM.grid to have a dropdown 
> combo and a text area (amongst other things). I want the text area to be 
> populated with default text when the dropdown changes, and I was going to 
> do this with AJAX.
>
> The simplified application shown above demonstrates the problem. When the 
> grid is displayed, the AJAX call works as expected. When the grid "Add" 
> form is displayed and characters are typed in the input area, the echo() 
> function is not called.
>

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


[web2py] Re: How to use AJAX within a SQLFORM.grid 'add' form

2014-03-30 Thread backseat
On Sunday, 30 March 2014 14:08:38 UTC+1, Anthony wrote:
>
> Would help to see the controller code.
>

Here's the code from a test app I've put together to simplify:

def index():
grid = SQLFORM.grid(db.t_dogs,
create=True,
csv=False,
deletable=False,
details=False,
editable=True,
paginate=100,
searchable=False,
)
return locals()


def echo():
print "in echo()"
#from gluon.debug import dbg
#dbg.set_trace()
return request.vars.name


What is "form", and why are "grid" and "form" inside BEAUTIFY?
>

Here's the simplified view:

{{extend 'layout.html'}}

Target



   


DOGS
{{=BEAUTIFY(grid)}}


They're inside BEAUTIFY to keep it simple for now: that is how they are 
after the application wizard has run.
 

> What are you really trying to do?
>

Ultimately, I want the Add from from a SQLFORM.grid to have a dropdown 
combo and a text area (amongst other things). I want the text area to be 
populated with default text when the dropdown changes, and I was going to 
do this with AJAX.

The simplified application shown above demonstrates the problem. When the 
grid is displayed, the AJAX call works as expected. When the grid "Add" 
form is displayed and characters are typed in the input area, the echo() 
function is not called.

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


[web2py] Re: json and URL

2014-03-30 Thread Niphlod
json is unicode by default...

https://docs.python.org/2/library/json.html#encoders-and-decoders

web is full of examples and even web2py's core deals with it :P

https://github.com/web2py/web2py/blob/master/gluon/scheduler.py#L171

On Sunday, March 30, 2014 8:54:16 PM UTC+2, mweissen wrote:
>
> Validator: only a typo, I have used IS_JSON()
>
> Without json.dumps / json.loads: same results.
> In my emails I have shown a simplified code. This is a part of the real 
> code:
>
> ---
> *db.py:*
>
> db.define_table("antworten",
> 
> Field('nn','json', requires=IS_JSON()),
> )
>
> ---
> *This function writes to the database:*
>
> def testantworten0():
> d={"f":"testantworten2", "vars":dict(x=3)}
> print str(d),* type(d["f"])*
>  v=db.antworten.insert( nn=d, )
> return dict(form=v)
>
> The result of the print statement:
> {'vars': {'x': 3}, 'f': 'testantworten2'}* *
>
> ---
> *This function reads from the database:*
>
> def antwortAuswerten(typ, antwort, absender='%', doNext=False):
> q=db((db.antworten.typ==typ) & db.antworten.absender.like(absender))
> for res in q.select():
> print res.nn, type(res.nn)
> print res.nn['f'],* type(res.nn['f'])*  
>
> And it prints:
>
> {u'vars': {u'x': 3}, u'f': u'testantworten2'} 
> testantworten2* *
>
> ---
>
> I put a dict with a *str* into my table and I get back a *unicode.*
> Is this the expected behavior?
>
>   
>
>
> 2014-03-30 20:02 GMT+02:00 Anthony >:
>
>> First, you don't need to explicitly specify the validator, but if you do, 
>> it should be IS_JSON(). Second, once you select a record, you do not need 
>> to pass the resulting value to json.loads() -- web2py will automatically 
>> convert the stored JSON value to a Python object (that's the point of the 
>> JSON field type).
>>
>> Anthony
>>
>>
>> On Sunday, March 30, 2014 12:59:11 PM UTC-4, mweissen wrote:
>>
>>> Sorry, I did not test all cases.
>>> E.g.:
>>>
>>> Field ('url', 'json', requires=IS_JSON) 
>>> ...
>>> res = db(db.mydb.id==1).select().first()
>>> print json.loads(res.url)
>>>
>>>
>>> Again res.url is something like 
>>>  {'u'f : u'testfunction' ... }
>>>
>>> and URL(**res.url) fails.
>>>
>>>
>>>
>>> 2014-03-30 18:21 GMT+02:00 Martin Weissenboeck 
>>> 
>>> >:
>>>
 That's the answer! I have forgotten the "json" type parameter, I had 
 only  requires=IS_JSON()
 I have tried it again and now it works. Thank you!




 2014-03-30 15:10 GMT+02:00 Anthony >:

 Have you tried:
>
> Field('url', 'json')
>
> Anthony
>
> On Saturday, March 29, 2014 7:11:34 PM UTC-4, mweissen wrote:
>
>> Let's say I have 
>> URL(f="myfunction", vars=dict(x=1))
>> or
>> v = {"f":"myfunction", "vars":{"x":1}}
>> URL(**v)
>>
>> That works fine.
>>
>> Now I do
>> j = json.dumps(v)
>>
>> I store j in
>> Field("url", requires=IS_JSON())
>>
>> Now I read this field and call URL(**fieldvalue). I get an error:
>>
>>  when calling URL, function or 
>> function name required
>>
>> The fieldvalue I get is
>> {'u'f : u'festfunction' ... }
>>
>> The key is a unicode string and not utf-8 coded.
>>
>> What is wrong? How can I get an utf-8 string?
>>
>> Regards, Martin
>>
>>  


>  

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


[web2py] Re: json and URL

2014-03-30 Thread Martin Weissenboeck
Validator: only a typo, I have used IS_JSON()

Without json.dumps / json.loads: same results.
In my emails I have shown a simplified code. This is a part of the real
code:

---
*db.py:*

db.define_table("antworten",

Field('nn','json', requires=IS_JSON()),
)

---
*This function writes to the database:*

def testantworten0():
d={"f":"testantworten2", "vars":dict(x=3)}
print str(d),* type(d["f"])*
v=db.antworten.insert( nn=d, )
return dict(form=v)

The result of the print statement:
{'vars': {'x': 3}, 'f': 'testantworten2'}* *

---
*This function reads from the database:*

def antwortAuswerten(typ, antwort, absender='%', doNext=False):
q=db((db.antworten.typ==typ) & db.antworten.absender.like(absender))
for res in q.select():
print res.nn, type(res.nn)
print res.nn['f'],* type(res.nn['f'])*

And it prints:

{u'vars': {u'x': 3}, u'f': u'testantworten2'} 
testantworten2* *

---

I put a dict with a *str* into my table and I get back a *unicode.*
Is this the expected behavior?




2014-03-30 20:02 GMT+02:00 Anthony :

> First, you don't need to explicitly specify the validator, but if you do,
> it should be IS_JSON(). Second, once you select a record, you do not need
> to pass the resulting value to json.loads() -- web2py will automatically
> convert the stored JSON value to a Python object (that's the point of the
> JSON field type).
>
> Anthony
>
>
> On Sunday, March 30, 2014 12:59:11 PM UTC-4, mweissen wrote:
>
>> Sorry, I did not test all cases.
>> E.g.:
>>
>> Field ('url', 'json', requires=IS_JSON)
>> ...
>> res = db(db.mydb.id==1).select().first()
>> print json.loads(res.url)
>>
>>
>> Again res.url is something like
>>  {'u'f : u'testfunction' ... }
>>
>> and URL(**res.url) fails.
>>
>>
>>
>> 2014-03-30 18:21 GMT+02:00 Martin Weissenboeck :
>>
>>> That's the answer! I have forgotten the "json" type parameter, I had
>>> only  requires=IS_JSON()
>>> I have tried it again and now it works. Thank you!
>>>
>>>
>>>
>>>
>>> 2014-03-30 15:10 GMT+02:00 Anthony :
>>>
>>> Have you tried:

 Field('url', 'json')

 Anthony

 On Saturday, March 29, 2014 7:11:34 PM UTC-4, mweissen wrote:

> Let's say I have
> URL(f="myfunction", vars=dict(x=1))
> or
> v = {"f":"myfunction", "vars":{"x":1}}
> URL(**v)
>
> That works fine.
>
> Now I do
> j = json.dumps(v)
>
> I store j in
> Field("url", requires=IS_JSON())
>
> Now I read this field and call URL(**fieldvalue). I get an error:
>
>  when calling URL, function or function
> name required
>
> The fieldvalue I get is
> {'u'f : u'festfunction' ... }
>
> The key is a unicode string and not utf-8 coded.
>
> What is wrong? How can I get an utf-8 string?
>
> Regards, Martin
>
>
>>>
>>>

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


[web2py] Re: json and URL

2014-03-30 Thread Anthony
First, you don't need to explicitly specify the validator, but if you do, 
it should be IS_JSON(). Second, once you select a record, you do not need 
to pass the resulting value to json.loads() -- web2py will automatically 
convert the stored JSON value to a Python object (that's the point of the 
JSON field type).

Anthony

On Sunday, March 30, 2014 12:59:11 PM UTC-4, mweissen wrote:

> Sorry, I did not test all cases.
> E.g.:
>
> Field ('url', 'json', requires=IS_JSON) 
> ...
> res = db(db.mydb.id==1).select().first()
> print json.loads(res.url)
>
>
> Again res.url is something like 
>  {'u'f : u'testfunction' ... }
>
> and URL(**res.url) fails.
>
>
>
> 2014-03-30 18:21 GMT+02:00 Martin Weissenboeck :
>
>> That's the answer! I have forgotten the "json" type parameter, I had only 
>>  requires=IS_JSON()
>> I have tried it again and now it works. Thank you!
>>
>>
>>
>>
>> 2014-03-30 15:10 GMT+02:00 Anthony :
>>
>> Have you tried:
>>>
>>> Field('url', 'json')
>>>
>>> Anthony
>>>
>>> On Saturday, March 29, 2014 7:11:34 PM UTC-4, mweissen wrote:
>>>
 Let's say I have 
 URL(f="myfunction", vars=dict(x=1))
 or
 v = {"f":"myfunction", "vars":{"x":1}}
 URL(**v)

 That works fine.

 Now I do
 j = json.dumps(v)

 I store j in
 Field("url", requires=IS_JSON())

 Now I read this field and call URL(**fieldvalue). I get an error:

  when calling URL, function or function 
 name required

 The fieldvalue I get is
 {'u'f : u'festfunction' ... }

 The key is a unicode string and not utf-8 coded.

 What is wrong? How can I get an utf-8 string?

 Regards, Martin

  
>>
>>
>>  

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


[web2py] Re: json and URL

2014-03-30 Thread Martin Weissenboeck
Sorry, I did not test all cases.
E.g.:

Field ('url', 'json', requires=IS_JSON)
...
res = db(db.mydb.id==1).select().first()
print json.loads(res.url)


Again res.url is something like
 {'u'f : u'testfunction' ... }

and URL(**res.url) fails.



2014-03-30 18:21 GMT+02:00 Martin Weissenboeck :

> That's the answer! I have forgotten the "json" type parameter, I had only
>  requires=IS_JSON()
> I have tried it again and now it works. Thank you!
>
>
>
>
> 2014-03-30 15:10 GMT+02:00 Anthony :
>
> Have you tried:
>>
>> Field('url', 'json')
>>
>> Anthony
>>
>> On Saturday, March 29, 2014 7:11:34 PM UTC-4, mweissen wrote:
>>
>>> Let's say I have
>>> URL(f="myfunction", vars=dict(x=1))
>>> or
>>> v = {"f":"myfunction", "vars":{"x":1}}
>>> URL(**v)
>>>
>>> That works fine.
>>>
>>> Now I do
>>> j = json.dumps(v)
>>>
>>> I store j in
>>> Field("url", requires=IS_JSON())
>>>
>>> Now I read this field and call URL(**fieldvalue). I get an error:
>>>
>>>  when calling URL, function or function
>>> name required
>>>
>>> The fieldvalue I get is
>>> {'u'f : u'festfunction' ... }
>>>
>>> The key is a unicode string and not utf-8 coded.
>>>
>>> What is wrong? How can I get an utf-8 string?
>>>
>>> Regards, Martin
>>>
>>>
>
>
>

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


[web2py] Re: json and URL

2014-03-30 Thread Anthony
Have you tried:

Field('url', 'json')

Anthony

On Saturday, March 29, 2014 7:11:34 PM UTC-4, mweissen wrote:

> Let's say I have 
> URL(f="myfunction", vars=dict(x=1))
> or
> v = {"f":"myfunction", "vars":{"x":1}}
> URL(**v)
>
> That works fine.
>
> Now I do
> j = json.dumps(v)
>
> I store j in
> Field("url", requires=IS_JSON())
>
> Now I read this field and call URL(**fieldvalue). I get an error:
>
>  when calling URL, function or function 
> name required
>
> The fieldvalue I get is
> {'u'f : u'festfunction' ... }
>
> The key is a unicode string and not utf-8 coded.
>
> What is wrong? How can I get an utf-8 string?
>
> Regards, Martin
>
>  

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


[web2py] Re: How to use AJAX within a SQLFORM.grid 'add' form

2014-03-30 Thread Anthony
Would help to see the controller code. What is "form", and why are "grid" 
and "form" inside BEAUTIFY? What are you really trying to do?

On Sunday, March 30, 2014 5:39:21 AM UTC-4, backseat wrote:
>
> Hi All
>
> Am I doing something wrong on this group?
>
> I've highlighted what looks like a bug to me, but I've had no response. Is 
> this the wrong place to discuss what looks like a bug?
>
> Thanks
> Keith
>

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


[web2py] Re: How to use AJAX within a SQLFORM.grid 'add' form

2014-03-30 Thread backseat
Hi All

Am I doing something wrong on this group?

I've highlighted what looks like a bug to me, but I've had no response. Is 
this the wrong place to discuss what looks like a bug?

Thanks
Keith

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


[web2py] Re: json and URL

2014-03-30 Thread Martin Weissenboeck
Solved.

I have found an answer from Massimo:
https://groups.google.com/forum/#!topic/web2py/aqECpxiPTqw

A code like
Field('data','text',filter_in=(lambda x: pickle.dumps(x)),filter_out=(lambda
s: s and pickle.loads(s)),default=None)
works fine.

But why is it not possible to use json?




2014-03-30 0:11 GMT+01:00 Martin Weissenboeck :

> Let's say I have
> URL(f="myfunction", vars=dict(x=1))
> or
> v = {"f":"myfunction", "vars":{"x":1}}
> URL(**v)
>
> That works fine.
>
> Now I do
> j = json.dumps(v)
>
> I store j in
> Field("url", requires=IS_JSON())
>
> Now I read this field and call URL(**fieldvalue). I get an error:
>
>  when calling URL, function or function
> name required
>
> The fieldvalue I get is
> {'u'f : u'festfunction' ... }
>
> The key is a unicode string and not utf-8 coded.
>
> What is wrong? How can I get an utf-8 string?
>
> Regards, Martin
>
>

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