[web2py] RESTful json:api

2016-04-17 Thread Raphael Lechner
Hi,

I'm trying to build an application with ember.js as frontend and web2py as 
backend. Ember requires a valid json:api (http://jsonapi.org/) interface.
I tried to use the generic json view but the output is different.

Example output from generic json view:
{"data": [{
"name": "100",
"filename": 
"pictures.picture_file.8dd3626ec0b3a290.494d475f32303135303532365f3130353432342e6a7067_print.jpg",
"id": 1
  },
  {
"name": "101",
"filename": 
"pictures.picture_file.8e48a177244f1ea9.494d475f32303135303532365f3130353435302e6a7067_print.jpg",
"id": 2}
  ]}

Valid json:api output:
{"data": [{
"id": "100",
"type": "picture",
"attributes": {
  "name": "100",
  "filename": 
"pictures.picture_file.8dd3626ec0b3a290.494d475f32303135303532365f3130353432342e6a7067_print.jpg",
}
  },
  {
"id": "101",
"type": "picture",
"attributes": {
  "name": "101",
  "filename": 
"pictures.picture_file.8dd3626ec0b3a290.494d475f32303135303532365f3130353432342e6a7067_print.jpg",
}
  }
  ]}

Is there a way to change the schema of the json output?

Thanks!
Raphael

-- 
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] testcase for all menu items with py.test after a logon

2015-09-10 Thread Raphael Lechner
Hi,

I'm trying to write a test to verify that all menu items are working. I 
copied the Example from https://github.com/viniciusban/web2py.test to write 
the first test.
The problem is that most of the menu items are only visible after a login. 
Therefore I tried to login with auth.login_bare but it seems that something 
is still missing.
The login works but after calling the menu.py with execfile I don't get all 
menu items.

Any idea?

*models/menu.py:*
if not auth.is_logged_in():
response.menu = [
 (T('Support'), False, URL('default', 'support'), [])
 ]
else:
if auth.has_membership('manager'):
 response.menu += [...


*tests/controllers/test_example.py*
from gluon import * 
def test_menu_links(client, web2py):
db = web2py.db
auth = Auth(db)

password = db.auth_user.password.requires[0]('manager')[0]
user = auth.get_or_create_user({
'username': 'manager',
'password': password
})
# create group
group_id = db.auth_group.insert(**{
 'role': 'manager'
})

auth.add_membership(group_id=group_id, user_id=user.id)
db.commit()

out = auth.login_bare('manager','manager')
g=copy(current.globalenv)

# Returns True
print auth.is_logged_in()
# Returns True
print auth.has_membership('manager')

execfile('applications/app_under_test/models/menu.py', g)

links = set()
for i in current.response.menu:
topmenu = i
top_links = topmenu[2]
links.add(top_links)
submenu = topmenu[3]
for subitem in submenu:
links.add(subitem[2])
print links
# returns only menu items without auth

Thanks!!!
Raphael

-- 
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: Customizing SQLFORM.grid create, edit and update forms

2015-08-21 Thread Raphael Lechner
Hi,

I have the same issue. I added a checkbox to the form, but I can't get the 
value after submitting.

if request.args(0) == 'new':
my_extra_element = DIV(LABEL('Create Remote SSH 
Key',_class=control-label 
col-sm-3),INPUT(_name='create_key',_type='checkbox'), _class=form-group)
form[1].insert(0,my_extra_element)

on_validation - form.vars - create_key is missing

Have you found a solution for that? 
Is there a better approach for adding a checkbox to a grid-form?

Thanks!
Raphael

On Wednesday, February 26, 2014 at 1:38:30 PM UTC+1, Maciej S wrote:

 Hi!

 I've created SQLFORM.grid like whowhywhat did. New elements have been 
 added to the form, but there is one drawback, if I submit, all data from 
 new fields is lost. What should I do to keep it during callbacks?

 Here is  my code:
 def users():   
 grid = SQLFORM.grid(db.auth_user)
 
 if  len(request.args)1 and request.args[-2]=='new' and grid.
 create_form:
 grid.create_form[0].insert(-1,TR( LABEL('User type:', _id=
 'auth_user_user_type'), INPUT(_type=radio, _name=radio_user_type, 
 _value=normal) + LABEL('Normal user', _id=auth_user_normal_user)))
 grid.create_form[0].insert(-1,TR('', INPUT(_type=radio, _name=
 radio_user_type, _value=service) + LABEL('Service user', _id=
 auth_user_service_user)))
 grid.create_form[0].insert(-1,TR('', INPUT(_type=radio, _name=
 radio_user_type, _value=producer) + LABEL('Producer user', _id=
 auth_user_producer_user)))

 return grid

 Maciej

 W dniu piątek, 16 grudnia 2011 17:03:55 UTC+1 użytkownik whowhywhat 
 napisał:

 wow .. it works! :) ...

 i just added the following in the controller (after calling SQLFORM.grid):

 #check if form is a create form
 if  len(request.args)1 and request.args[-2]=='new' and form.create_form:
 my_extra_element = 
 TR(LABEL('Married'),INPUT(_name='married',value=False,_type='checkbox'))
 form.create_form[0].insert(-1,my_extra_element)

 now i need to add some jquery in the view (again after checking if the 
 view is for a create or edit form).. this is so cool :D ..
 thanks a lot Anthony!

 will post a full example later..



-- 
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] view without newline

2015-08-19 Thread Raphael Lechner
Hi,

I have created a small application that will try to lookup for a name from 
a phonenumber. My problem is that FreeSWITCH(the telephone software) 
requires that the answer don't contains newlines.
I have tried with a view that contains only a single line {{=name}} but the 
answer always contains a newline.
Is there a way I can suppress the newline?

Thanks,
Raphael

-- 
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: view without newline

2015-08-19 Thread Raphael Lechner
OK I found a very simple solution. I created the view file like

echo -n {{=name}}  lookup.html

On Wednesday, August 19, 2015 at 10:04:52 AM UTC+2, Raphael Lechner wrote:

 Hi,

 I have created a small application that will try to lookup for a name from 
 a phonenumber. My problem is that FreeSWITCH(the telephone software) 
 requires that the answer don't contains newlines.
 I have tried with a view that contains only a single line {{=name}} but 
 the answer always contains a newline.
 Is there a way I can suppress the newline?

 Thanks,
 Raphael


-- 
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: IMPORTANT - WEB2PY CONSULTING

2015-08-04 Thread Raphael Lechner
Hi Massimo,

Please add me to the list:
Raphael Lechner - GeekOnDemand (Italy) http://www.geekondemand.it/

Thanks!

On Sunday, February 15, 2015 at 11:21:36 PM UTC+1, Massimo Di Pierro wrote:

 We need to update the list of companies that provide web2py consulting.
 This list is obsolete:

 http://web2py.com/init/default/support

 Some links are broke. Most pages do not even mention web2py. Some of them 
 have a design that is simply not acceptable for a web development company.

 That list will be eliminated. IF YOU WANT TO BE LISTED please update your 
 page to have a decent design and MENTION WEB2PY on the main site. Then 
 respond to this thread by providing an updated link and the country were 
 you incorporated. If you have a self-employed individual list your country 
 of residence.



-- 
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: create xml

2013-11-29 Thread Raphael Lechner
Thank you Massimo for the example. I tried your example code but I get now 
this error:
type 'exceptions.NameError' name 'content' is not defined

any idea?

thank you,
Raphael

On Saturday, November 16, 2013 6:38:57 PM UTC+1, Massimo Di Pierro wrote:

 Using generic.xml creates a fixed structure. Like in the case of 
 generic.html, you may need your own view.

 So if you have:

 def index():
 return dict(phonebook = [dict(content=dict(phone=123)), 
 dict(content=dict(phone=234))])

 Make an index.xml with

 {{=TAG.phonebook(*[tag.content(tag.phone(c['phone'])) for c in content])}}



 On Saturday, 16 November 2013 04:29:14 UTC-6, mweissen wrote:

 I want to use the xml-rendering to create something like
  
 phonebook
content
phone123/phone
 /content
content
phone234/phone
/content
 /phonebook
  
 I have tried the following data structure
  
 [dict(content=dict(phone=123)), dict(content=dict(phone=234))]
  
 but the list creates an additional tag item
  
 Any ideas?
 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/groups/opt_out.