[web2py] Re: Readonly elements (select and date field) respond to clicks, allow for changes and can be submitted?

2014-06-23 Thread Massimo Di Pierro
That s what readonly means. readonly is an HTML attribute and has nothing 
to do with form processing. If you do not want them to appear in forms you 
have to tell the model:

db.owner.own_end_date.writable = False # not writable
db.owner.own_end_date.readable = False # do not show is at all!

Massimo

On Monday, 23 June 2014 00:00:05 UTC-5, 98u...@gmail.com wrote:

 Why readonly elements (select and date field) of a form respond to clicks 
 and allow for changes and can be submitted? They look grayed out as if 
 readonly but when I click on date field the date picker appears and works 
 as it shoud also the select option is grayed out but it offers a list to 
 choose an option and the form can be submitted with these changed values 
 even though this is not intended.
 #this is the model

 db.define_table('owner',
 Field('own_cust_fk','reference customer',label='Customer'),
 Field('own_veh_fk','reference vehicle',label='Vehicle'),
 Field('own_plate','string',label='Plate'),
 Field('own_comment','string',label='Comment'),
 Field('own_start_date','date',default=now,label='Start 
 date'),
 
 Field('own_end_date','date',default=None,label='Terminated'),
 migrate='owner.table',format='%(own_plate)s 
 %(own_cust_fk)s',
 plural='Owner'
 )


 def index():

 ...
 ...

 form = SQLFORM.smartgrid(db.owner,
  fields=fields,
  headers=headers,
  paginate=all,
  details=True,
  editable=True,
  deletable=False,
  create=False,
  showbuttontext=False,
  maxtextlength=40,
  maxtextlengths=maxtextlengths,
  buttons_placement = 'left',
  )
 ...
 ...

 if ((len(request.args)1) and (request.args(1)=='edit')):
 form.element('select',_name='own_cust_fk')['_readonly']='True'
 form.element('input',_name='own_end_date')['_readonly']='True'
 ...
 ...
 return dict(form=form)



 Any help would be appreciated!
 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: Undesired redirect to other page after submitting a form

2014-06-23 Thread Tom Clerckx
Anyone has observed this as well?
Is this expected behavior?

I understood the importance of giving a formname when you're dealing with 
two grids on one single  page.

This however concerns one single grid per page in which case I believe the 
formname is not required. 
It looks however that the link associated to the redirect after submitting 
a form is influenced by using the browser's back-button in the case when no 
formname paramater is used in the grid.

Best regards,
Tom.

On Thursday, June 19, 2014 9:46:06 AM UTC+2, Tom Clerckx wrote:

 Hi,

 I have some undesired behavior in my app that I was able to resolve, but I 
 would like to understand what goes wrong.
 I could easily reproduce the problem with a simple test-application, 
 containing two pages and two forms (I'm skipping the boilerplate code that 
 is created when making a new application):

 menu.py
 response.menu = [
 (T('Home'), False, URL('default', 'index'), []),
 (T('Secondpage'), False, URL('default', 'secondpage'), []),
 ]

 controller
 def index():
 form = SQLFORM.grid(db.contact, create=True, user_signature=False, )
 return dict(form=form)

 def secondpage():
 form = SQLFORM.grid(db.activity, create=True, user_signature=False, )
 return dict(form=form)

 index.html
 {{extend 'layout.html'}}
 h1Index page/h1
 {{=form}}

 secondpage.html
 {{extend 'layout.html'}}
 h1Welcome to the 2nd page/h1
 {{=form}}

 db.py
 contact = db.define_table('contact',
   Field('first_name', 'string'),
   Field('last_name', 'string'),
   )
 
 activity = db.define_table('activity',
 Field('what_you_plan_to_do', 'string'),
 )

 The problem occurs as follows:

 * I go to the index page
 * I press the add button opening up the contacts form (which I don't fill 
 in at this point)
 * In the menu I now press the link to the secondpage
 * When the secondpage is loaded I press the browser's back-button
 * Now I see the contacts form again which I fill in
 * When I now press the Submit button, I am redirected to the secondpage as 
 opposed to staying on the index page, which is not the desired outcome.

 I could resolve this by giving the forms a formname, but I would like to 
 understand why this behavior occurs.
 In this specific example the undesired behavior is not critical, but it 
 was really a problem in my app as the redirect went to a .load page that 
 did not contain any css styling.


 Updated controller resolving the problem
 def index():
 form = SQLFORM.grid(db.contact, create=True, user_signature=False, 
 formname='contact')
 return dict(form=form)

 def secondpage():
 form = SQLFORM.grid(db.activity, create=True, user_signature=False, 
 formname='activity')
 return dict(form=form)


 web2py version info
 2.8.2-stable+timestamp.2013.11.28.13.54.07
 (Running on Rocket 1.2.6, Python 2.7.5)


 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: web2py password encryption/decryption

2014-06-23 Thread Massimo Di Pierro
Hello Farmy,

The code you posted helps and this examples the PHP algorithm:
http://pythonhosted.org/passlib/lib/passlib.hash.phpass.html

I recorded this in Python:

import random, hashlib

class PHPHash(object):
CHARS = '0123456789abcdefghijklmoqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
def __init__(self,secret,rounds=10):
self.secret = secret
self.rounds = rounds
def hash(self,password, salt=None):
if salt is None:
salt = ''.join(random.choice(self.CHARS) for i in range(8))
checksum = hashlib.md5(salt+self.secret).hexdigest()
for k in range(2**self.rounds):
checksum = hashlib.md5(checksum+password).hexdigest()
hashed = '$P$%s%s%s' % (chr(self.rounds+ord('0')-5),salt,checksum)
return hashed

p = PHPHash('mysecret', rounds=13)
print p.hash('mypassword')

Please check it an make sure you can reproduce the PHP passwords. Once 
that's done we can try implement a custom validator, based on CRYPT that 
will work with them.





Massimo






On Sunday, 22 June 2014 15:40:32 UTC-5, farmy zdrowia wrote:

 I did kind of investigation by myself. 
 I can see CB uses new Joomla Portable PHP password hashing framework 
 functionality to crypt password. I noticed CB run on joomla 3.2.1, 
 while my other site is on Joomla 2

 Anyway at the end of pasword cryption chain there is a function 
 hashPassword and verifyPassword in libraries/joomla/user/helper.php

 abstract class JUserHelper
 public static function hashPassword($password)
 {
 // Use PHPass's portable hashes with a cost of 10.
 $phpass = new PasswordHash(10, true);

 return $phpass-HashPassword($password);
 }


 public static function verifyPassword($password, $hash, $user_id = 
 0)
 {
 $rehash = false;
 $match = false;

 // If we are using phpass
 if (strpos($hash, '$P$') === 0)
 {
 // Use PHPass's portable hashes with a cost of 10.
 $phpass = new PasswordHash(10, true);

 $match = $phpass-CheckPassword($password, $hash);

 $rehash = false;
 }
 

 Indeed all my passwords starts with $P$

 Whole algorithm to crypt CB/Joomla3.2.1 password is in file   
 libraries/phpass/PasswordHash.php



 Question now is how to transform it to web2py CUSTOMER validator. I'll 
 need your help




  



-- 
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 install facebookpython sdk in web2py

2014-06-23 Thread Massimo Di Pierro
talking about this: 
https://github.com/pythonforfacebook/facebook-sdk

1) install web2py from source
2) install git
3) git clone https://github.com/pythonforfacebook/facebook-sdk.git
4) cd facebook-sdk
5) sudo python setup.py install
6) done, you should be able to import facebook from web2py.


On Sunday, 22 June 2014 16:02:44 UTC-5, Denis wrote:

 Same thing. I cannot find any piece of documentation on how to get needed 
 facebook module.
 Thank you in advance

 On Saturday, June 21, 2014 1:19:31 PM UTC+3, greed wrote:

 can please any one tell me how to install the facebook python sdk in 
 web2py.



-- 
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: Trying to use the LOAD helper, if a button is clicked

2014-06-23 Thread Tomeu Roig
Thanks Brian

El lunes, 23 de junio de 2014 03:56:32 UTC+2, Brian M escribió:

 Tomeu,

 At the moment I'm just letting datatables.net enhance a plain html table 
 for me. One of these days I'll probably get around to giving it a json 
 datasource but so far it hasn't been a priority for my usage.

 As a bonus, here's some of how to update the datatables.net display after 
 using the edit dialog. (So just the edited record's row in the datatable 
 gets updated rather than a full page refresh)

 In controller
 #after you'd done the necessary DB updates...

 #tell browser to close the jqueryui dialog
 response.js =XML( '$(#edit_dialog).dialog(close);')

 #prepare for display update 
 edit_icon = IMG(_src=URL(c=static,f=images/page_white_edit.png), 
 _alt=Click 
 to edit)

 #prep javascript code for datatables.net to update the existing row's 
 display
 #basically just a json list of td values
 row_update = simplejson.dumps([updated_record.table.first_name, 
 updated_record.table.last_name, updated_record.table2.name, 
 str(A(edit_icon, _href=URL(r=request,f='edit_loader', args=[
 updated_record.table.record_id, mode]), _class=updateDialog)), 
 updated_record.table.email, updated_record.table.someother_id])

 #using the tr#id method to update table is unreliable (the TR won't have 
 an id if it was added dynamically
 #instead use the row index provided by datatables.net itself (we passed 
 it in via ajax vars)
 #essentially fnUpdate(new td values, which row)
 response.js += '$(#your_table_selector).dataTable().fnUpdate( '+
 row_update+', '+request.vars['datatable_row_index']+',0, false );'

 #also using jGrowl to give an acknowledgement
 message = T(%s updated) % (updated_record.table.first_name)
 response.js += '$.jGrowl('+message+');'


 And as the second bonus, how to insert a brand new row in the datatable. 
 (Below my datatable.net is another always visible LOAD()ed form for 
 creating a new record. Upon submission the new record is inserted into the 
 existing datatable via javascript returned in web2py's response)

 In controller:
 #do the database insert then
 #prepare for display update 
 edit_icon = IMG(_src=URL(c=static,f=images/page_white_edit.png), 
 _alt=Click 
 to edit)

 table_update = simplejson.dumps([new_record.table.first_name, new_record.
 table.last_name, 
 new_record.table2.name, str(A(edit_icon, _href=URL(r=request,f=
 'edit_loader', 
 args=[new_record.table.record_id, form.vars.mode]), _class=
 updateDialog)), 
 new_record.table.email, new_record.table.foreign_id])
 
 #issue command for adding new row to datatable
 response.js = 'vol_table.fnAddData('+table_update+');'

 Good luck

 ~Brian


 On Sunday, June 22, 2014 4:44:33 PM UTC-5, Tomeu Roig wrote:

 Thanks Brian, nice think to get a full href for pass to the 
 $web2py.component.

 I see that you use datatables.net. Do you use some plugin o directly you 
 pass json from controller?

 I want use in a new project but i have doubts have to implement. Can you 
 give me some idea?



-- 
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: upgraded and lost + - in string:list

2014-06-23 Thread Niphlod
np. Glad that the issue was located and fixed ^_^

On Monday, June 23, 2014 3:00:12 AM UTC+2, LoveWeb2py wrote:

 Issue resolved. Copied the web2py.js from the welcome app which had all 
 the right lines. Very very weird! Thank you so much for your help, Niphlod. 
 I didn't even think to check the git branch.


-- 
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: web2py and self-submission/postbacks - a newcomer asks

2014-06-23 Thread Graham Ranson
Anthony abastardi@... writes:

 If your going to use the web2py FORM or SQLFORM functionality, then the 
same code both defines and processes the form, so self submission makes 
sense. If you would rather build all of your form creation and processing 
code from scratch, then sure, do whatever you want. Anthony

That's the issue really - whether my design lends itself to self-submisson 
and if not whether not using those features of web2py that are built around 
self-submission rather reduce the benefits of using web2py at all.
It's not that I cannot see a way to use self-submission but there are then 
oddities - well they seem so to me - I notice that the book says:

Pre-populating the form

It is always possible to pre-populate a form using the syntax:
form.vars.name = 'fieldvalue'

Statements like the one above must be inserted after the form declaration 
and before the form is accepted, whether or not the field (name in the 
example) is explicitly visualized in the form.

and to use the example from a few lines earlier:

def display_form():
   record = db.person(request.args(0)) or redirect(URL('index'))
   url = URL('download')
   link = URL('list_records', args='db')
   form = SQLFORM(db.person, record, deletable=True,
  upload=url, linkto=link)

# pre-population would go here ?!

   if form.process().accepted:
   response.flash = 'form accepted'
   elif form.errors:
   response.flash = 'form has errors'
   return dict(form=form)

in the example that I was thinking about that would involve a couple of DB 
reads followed by the form.vars... assignments. Now if the same code is 
then executed after submission how do these statements get handled ? I can 
only suppose that re-executing the form=SQLFORM(...) has some magic in it, 
but presumably not in the DB access and the form... assignments.
How does it deal with those ?

I've been otherwise occupied in the past few days and still haven't 
actually done any work wit web2py yet...

graham




-- 
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: web2py and self-submission/postbacks - a newcomer asks

2014-06-23 Thread Jim Steil
I would handle setting defaults in the above example by setting the default
value on the fields before the SQLFORM call like this:

db.person.name.default = 'fieldvalue'

-Jim


On Mon, Jun 23, 2014 at 8:01 AM, Graham Ranson g73...@gishpuppy.com wrote:

 Anthony abastardi@... writes:

  If your going to use the web2py FORM or SQLFORM functionality, then the
 same code both defines and processes the form, so self submission makes
 sense. If you would rather build all of your form creation and processing
 code from scratch, then sure, do whatever you want. Anthony

 That's the issue really - whether my design lends itself to self-submisson
 and if not whether not using those features of web2py that are built around
 self-submission rather reduce the benefits of using web2py at all.
 It's not that I cannot see a way to use self-submission but there are then
 oddities - well they seem so to me - I notice that the book says:

 Pre-populating the form

 It is always possible to pre-populate a form using the syntax:
 form.vars.name = 'fieldvalue'

 Statements like the one above must be inserted after the form declaration
 and before the form is accepted, whether or not the field (name in the
 example) is explicitly visualized in the form.

 and to use the example from a few lines earlier:

 def display_form():
record = db.person(request.args(0)) or redirect(URL('index'))
url = URL('download')
link = URL('list_records', args='db')
form = SQLFORM(db.person, record, deletable=True,
   upload=url, linkto=link)

 # pre-population would go here ?!

if form.process().accepted:
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
return dict(form=form)

 in the example that I was thinking about that would involve a couple of DB
 reads followed by the form.vars... assignments. Now if the same code is
 then executed after submission how do these statements get handled ? I can
 only suppose that re-executing the form=SQLFORM(...) has some magic in it,
 but presumably not in the DB access and the form... assignments.
 How does it deal with those ?

 I've been otherwise occupied in the past few days and still haven't
 actually done any work wit web2py yet...

 graham




 --
 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 a topic in the
 Google Groups web2py-users group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/web2py/wbei89YDwL0/unsubscribe.
 To unsubscribe from this group and all its topics, 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] Re: web2py and self-submission/postbacks - a newcomer asks

2014-06-23 Thread Anthony
It would probably help if you show some code, or at least explain in more 
detail an example where self submission is not possible or overly 
difficult. Note, your code can always distinguish between a form creation 
request and a form submission request by checking whether request.post_vars 
is None or whether request.env.http_method == POST. 

As Jim suggested, if you are using SQLFORM, the easiest way to pre-populate 
is by setting field default values *before* form creation.

Anthony

On Monday, June 23, 2014 9:02:13 AM UTC-4, Graham Ranson wrote:

 Anthony abastardi@... writes: 

  If your going to use the web2py FORM or SQLFORM functionality, then the 
 same code both defines and processes the form, so self submission makes 
 sense. If you would rather build all of your form creation and processing 
 code from scratch, then sure, do whatever you want. Anthony 

 That's the issue really - whether my design lends itself to self-submisson 
 and if not whether not using those features of web2py that are built 
 around 
 self-submission rather reduce the benefits of using web2py at all. 
 It's not that I cannot see a way to use self-submission but there are then 
 oddities - well they seem so to me - I notice that the book says: 

 Pre-populating the form 

 It is always possible to pre-populate a form using the syntax: 
 form.vars.name = 'fieldvalue' 

 Statements like the one above must be inserted after the form declaration 
 and before the form is accepted, whether or not the field (name in the 
 example) is explicitly visualized in the form. 

 and to use the example from a few lines earlier: 

 def display_form(): 
record = db.person(request.args(0)) or redirect(URL('index')) 
url = URL('download') 
link = URL('list_records', args='db') 
form = SQLFORM(db.person, record, deletable=True, 
   upload=url, linkto=link) 

 # pre-population would go here ?! 

if form.process().accepted: 
response.flash = 'form accepted' 
elif form.errors: 
response.flash = 'form has errors' 
return dict(form=form) 

 in the example that I was thinking about that would involve a couple of DB 
 reads followed by the form.vars... assignments. Now if the same code is 
 then executed after submission how do these statements get handled ? I can 
 only suppose that re-executing the form=SQLFORM(...) has some magic in it, 
 but presumably not in the DB access and the form... assignments. 
 How does it deal with those ? 

 I've been otherwise occupied in the past few days and still haven't 
 actually done any work wit web2py yet... 

 graham 






-- 
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: Hypermedia API and Collection+JSON in web2py

2014-06-23 Thread samuel bonill
Thanks massimo, this is the point, generate many2many relations, with one
request get all the information relations to a resource.  I'm developing a
plugin to generate great RESTful API based in many2many relations. inspired
by the  Instagram API
http://instagram.com/developer/endpoints/users/#get_users.

for example :


GET: http://example.com/default/index/posts/1.json


{
data: [{
id: 1,
title: web2py,
text: testing ...,
picture: http://web2py.s3.amazonaws.com/post/my_s3_file.jpg;,
coments: [{
id: 1,
text: my coment,
author: {id:3685, name: Lebron james ...},
   }, ... ]
}]
 }

I'm trying do this possible, this is my implementation :



2014-06-23 0:14 GMT-05:00 Massimo Di Pierro massimo.dipie...@gmail.com:

 Let me add that Collection+JSON is a standard but that does not make it
 perfect. I find many limitations. I managed to overcome some but utilizing
 extensions.
 https://github.com/mamund/collection-json/tree/master/extensions
 I also made some of my own extensions. Extensions are allowed and
 compatible.

 Yet it needs more extensions. I did not push this too much because I did
 not want to depart too much much from the standard.

 Collection+JSON is also very verbose. I made a Collection(compact=True)
 option that makes it much less verbose but will break the specs.



 On Monday, 23 June 2014 00:01:27 UTC-5, Massimo Di Pierro wrote:

 This is a automatic in Colleciton+JSON. For example:

 # assume a model that described things and their attributes
 db.define_table('thing',Field('name'))
 db.define_table('attr',Field('thing','reference thing'),Field('name'))

 and you expose both:

 def api():
 from gluon.contrib.hypermedia import Collection
 rules = {
 'thing': {
 'GET':{'query':None,'fields':['id', 'name']},
 'POST':{'query':None,'fields':['name']},
 'PUT':{'query':None,'fields':['name']},
 'DELETE':{'query':None},
 },
 'attr': {
 'GET':{'query':None,'fields':['id', 'name', 'thing']},
 'POST':{'query':None,'fields':['name', 'thing']},
 'PUT':{'query':None,'fields':['name', 'thing']},
 'DELETE':{'query':None},
 },
 }
 return Collection(db).process(request,response,rules)

 $ curl http://127.0.0.1:8000/super/collections/api/thing/1
 {collection: {version: 1.0, href: /super/collections/api/thing,
 items: [{href: http://127.0.0.1:8000/super/
 collections/api/thing/1/chair, data: [{prompt: Id, name: id,
 value: 1}, {prompt: Name, name: name, value: Chair}],
 links: [{href: http://127.0.0.1:8000/super/
 collections/api/attr?thing=1,.

 The links field tells you how to get the attributes of the thing Chair.

 For many2many and links to images you have to do a little bit more
 programming. For example:

 Given:
 db.define_table('thing',Field('name'),Field('image','upload'))

 You can define:
 rules = {'thing':{'GET':{'query':None, 'fields':None,
 'links':{'picture':lambda row: URL('download',args=row.image,
 scheme=True)

 Problem is that collection+JSON does not say anything about image uploads
 (POST) and does not say anything about many2many relations.

 Massimo




 On Sunday, 22 June 2014 18:20:36 UTC-5, samuel bonill wrote:

 it's good, I use db.parse_as_rest for generate the representation of
 resources, Collection+JSON help much.

 other thing, I would like generate a resource with relationship  for
 example


 patterns = [ (posts/{post.id}, {coments: {author: auth_user}}]
 # My implementation
 
 parser = db.parse_as_rest(patterns, args, kwargs)

 GET: http://example.com/default/index/posts/1.json

 {
 content: [{
 id: 1,
 title: web2py,
 text: testing ...,
 picture: http://web2py.s3.amazonaws.com/post/my_s3_file.jpg;,
 coments: [{
 id: 1,
 text: my coment,
 author: {id:3685, name: Lebron james ...},
}, ... ]
 }]
  }

 the problem with the traditional RESTful apps on web2py is that for get the 
 information
 of our restful example planted before, you need do three request to the 
 api, like this case.

 patterns = [ post/{post.id},
  post/{post.id}/coments[coments]/{coments.id},
  
 post/{post.id}/coments[coments]/{coments.id}/author[auth_user]
]
 
 parser = db.parse_as_rest(patterns, args, kwargs)

 #1 GET: http://example.com/default/index/post/1.json

 #2 GET: http://example.com/default/index/post/1/coments/1.json
 #3 GET: http://example.com/default/index/post/1/coments/1/author.json

 sorry my english... regards



 El domingo, 22 de junio de 2014 15:45:06 UTC-5, Massimo Di Pierro
 escribió:

 I added Hypermedia API support to web2py using Collection+JSON.
 Experimental.
 Collection+JSON is a standard for self documenting RESTful API.
 Read more: http://amundsen.com/media-types/collection/

 

Re: [web2py] Re: Hypermedia API and Collection+JSON in web2py

2014-06-23 Thread samuel bonill
patterns = [ (posts/{post.id}, {coments: {author: auth_user}}]
 # My implementation

parser = Rest.generate(patterns, args, kwargs)

This automatically generate, the post with comments associate and user
associated to a comment...

What do you think about my idea ?



2014-06-23 9:50 GMT-05:00 samuel bonill pythonn...@gmail.com:

 Thanks massimo, this is the point, generate many2many relations, with one
 request get all the information relations to a resource.  I'm developing a
 plugin to generate great RESTful API based in many2many relations. inspired
 by the  Instagram API
 http://instagram.com/developer/endpoints/users/#get_users.

 for example :


 GET: http://example.com/default/index/posts/1.json


 {
 data: [{

 id: 1,
 title: web2py,
 text: testing ...,
 picture: http://web2py.s3.amazonaws.com/post/my_s3_file.jpg;,
 coments: [{
 id: 1,
 text: my coment,
 author: {id:3685, name: Lebron james ...},
}, ... ]

 }]

 }

 I'm trying do this possible, this is my implementation :



 2014-06-23 0:14 GMT-05:00 Massimo Di Pierro massimo.dipie...@gmail.com:

 Let me add that Collection+JSON is a standard but that does not make it
 perfect. I find many limitations. I managed to overcome some but utilizing
 extensions.
 https://github.com/mamund/collection-json/tree/master/extensions
 I also made some of my own extensions. Extensions are allowed and
 compatible.

 Yet it needs more extensions. I did not push this too much because I did
 not want to depart too much much from the standard.

 Collection+JSON is also very verbose. I made a Collection(compact=True)
 option that makes it much less verbose but will break the specs.



 On Monday, 23 June 2014 00:01:27 UTC-5, Massimo Di Pierro wrote:

 This is a automatic in Colleciton+JSON. For example:

 # assume a model that described things and their attributes
 db.define_table('thing',Field('name'))
 db.define_table('attr',Field('thing','reference thing'),Field('name'))

 and you expose both:

 def api():
 from gluon.contrib.hypermedia import Collection
 rules = {
 'thing': {
 'GET':{'query':None,'fields':['id', 'name']},
 'POST':{'query':None,'fields':['name']},
 'PUT':{'query':None,'fields':['name']},
 'DELETE':{'query':None},
 },
 'attr': {
 'GET':{'query':None,'fields':['id', 'name', 'thing']},
 'POST':{'query':None,'fields':['name', 'thing']},
 'PUT':{'query':None,'fields':['name', 'thing']},
 'DELETE':{'query':None},
 },
 }
 return Collection(db).process(request,response,rules)

 $ curl http://127.0.0.1:8000/super/collections/api/thing/1
 {collection: {version: 1.0, href: /super/collections/api/thing,
 items: [{href: http://127.0.0.1:8000/super/
 collections/api/thing/1/chair, data: [{prompt: Id, name: id,
 value: 1}, {prompt: Name, name: name, value: Chair}],
 links: [{href: http://127.0.0.1:8000/super/
 collections/api/attr?thing=1,.

 The links field tells you how to get the attributes of the thing Chair.

 For many2many and links to images you have to do a little bit more
 programming. For example:

 Given:
 db.define_table('thing',Field('name'),Field('image','upload'))

 You can define:
 rules = {'thing':{'GET':{'query':None, 'fields':None,
 'links':{'picture':lambda row: URL('download',args=row.image,
 scheme=True)

 Problem is that collection+JSON does not say anything about image
 uploads (POST) and does not say anything about many2many relations.

 Massimo




 On Sunday, 22 June 2014 18:20:36 UTC-5, samuel bonill wrote:

 it's good, I use db.parse_as_rest for generate the representation of
 resources, Collection+JSON help much.

 other thing, I would like generate a resource with relationship 
 for example


 patterns = [ (posts/{post.id}, {coments: {author:
 auth_user}}]  # My implementation
 
 parser = db.parse_as_rest(patterns, args, kwargs)

 GET: http://example.com/default/index/posts/1.json

 {
 content: [{
 id: 1,
 title: web2py,
 text: testing ...,
 picture: http://web2py.s3.amazonaws.com/post/my_s3_file.jpg;,
 coments: [{
 id: 1,
 text: my coment,
 author: {id:3685, name: Lebron james ...},
}, ... ]

 }]
  }

 the problem with the traditional RESTful apps on web2py is that for get 
 the information
 of our restful example planted before, you need do three request to the 
 api, like this case.

 patterns = [ post/{post.id},
  post/{post.id}/coments[coments]/{coments.id},

  
 post/{post.id}/coments[coments]/{coments.id}/author[auth_user]

]
 
 parser = db.parse_as_rest(patterns, args, kwargs)

 #1 GET: http://example.com/default/index/post/1.json

 #2 GET: http://example.com/default/index/post/1/coments/1.json
 #3 GET: 

[web2py] /default/user/login not honoring _next anymore?

2014-06-23 Thread Wei Wang
In the current head branch in github (Version 
2.9.5-trunk+timestamp.2014.06.19.17.16.40), it seems that the 
/default/user/login form does not use the _next variable specified in the 
URL.

For example,

The myapp/default/view is decorated with @auth.requires_login(), so when I 
am not logged in, it triggers web2py's login form with this URL:


https://server-name:4443/myapp/default/user/login?_next=/myapp/default/view%3Fapp%3Dnextapp

However, the variable _next in the form is always:

input type=hidden value=/myapp/default/index name=_next

I would expect it to be:

input type=hidden value=/myapp/default/view?app=nextapp 
name=_next

Is this a potential bug or is this an expected change?

Thanks,
-- 
Wei Wang

-- 
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] which web2py version contains the hypermedia api in gluon contrib?

2014-06-23 Thread greaneym
Hello,

I am interested in testing the hypermedia collectionjs combination in 
web2py. I downloaded 2.9.5-trunk+timestamp.2014.03.29.21.54.41 but it's not 
in the gluon/contrib.

which version should I download to test please?

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: Readonly elements (select and date field) respond to clicks, allow for changes and can be submitted?

2014-06-23 Thread 98ujko9
I did what you suggested but the calls to:

db.owner.own_end_date.writable = False # not writable
db.owner.own_end_date.readable = False # do not show is at all!

are effective only if executed before the call to form = 
SQLFORM.smartgrid(db.owner, ...
When executed after, have no effect.
I want to make db.owner.own_end_date not writeable conditionally:
   ...
   ...
   if ((len(request.args)1) and (request.args(1)=='edit')):
if (form.element('input',_name='own_end_date')['_value']!=''):
db.owner.own_end_date.writable=False # - no effect
...
...

If the edited record contains a date value in that field then user must not 
change it. How can I make that field not writeable in such a case?
Thanks

On Monday, June 23, 2014 1:00:05 AM UTC-4, 98u...@gmail.com wrote:

 Why readonly elements (select and date field) of a form respond to clicks 
 and allow for changes and can be submitted? They look grayed out as if 
 readonly but when I click on date field the date picker appears and works 
 as it shoud also the select option is grayed out but it offers a list to 
 choose an option and the form can be submitted with these changed values 
 even though this is not intended.
 #this is the model

 db.define_table('owner',
 Field('own_cust_fk','reference customer',label='Customer'),
 Field('own_veh_fk','reference vehicle',label='Vehicle'),
 Field('own_plate','string',label='Plate'),
 Field('own_comment','string',label='Comment'),
 Field('own_start_date','date',default=now,label='Start 
 date'),
 
 Field('own_end_date','date',default=None,label='Terminated'),
 migrate='owner.table',format='%(own_plate)s 
 %(own_cust_fk)s',
 plural='Owner'
 )


 def index():

 ...
 ...

 form = SQLFORM.smartgrid(db.owner,
  fields=fields,
  headers=headers,
  paginate=all,
  details=True,
  editable=True,
  deletable=False,
  create=False,
  showbuttontext=False,
  maxtextlength=40,
  maxtextlengths=maxtextlengths,
  buttons_placement = 'left',
  )
 ...
 ...

 if ((len(request.args)1) and (request.args(1)=='edit')):
 form.element('select',_name='own_cust_fk')['_readonly']='True'
 form.element('input',_name='own_end_date')['_readonly']='True'
 ...
 ...
 return dict(form=form)



 Any help would be appreciated!
 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] IS_IN_SET options list separator

2014-06-23 Thread Carlos Correia
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi,

Is there a way to introduce a separator in IS_IN_SET options widget, so that
from code like:

IS_IN_SET( ('1', 'First'), (seperator?), ('2', 'Second'),'3', 'Third') )

it produces something like this?

select
option value=1First/option
option disabled_/option
option value=2Second/option
option value=3Third/option
/select

Thanks,
- -- 
Com os melhores cumprimentos,

Carlos Correia
=
MEMÓRIA PERSISTENTE
Tel.: 219 291 591 - GSM:  917 157 146 / 967 511 762
e-mail: ge...@memoriapersistente.pt - URL: http://www.memoriapersistente.pt
Jabber: m...@jabber.org
GnuPG: wwwkeys.eu.pgp.net
URL Suporte: https://t5.m16e.com/gps
-BEGIN PGP SIGNATURE-
Version: GnuPG v1
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlOoaJMACgkQ90uzwjA1SJULhACgl/tHifyri+2PIRchIHEgZ54X
xQ4AmwQC8Tvr2icSr1cDAd0pilAe2XyK
=cv7J
-END PGP SIGNATURE-

-- 
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: which web2py version contains the hypermedia api in gluon contrib?

2014-06-23 Thread greaneym
Hi,

Never mind, I found the version on github.  Thanks (  There should probably 
be a pointer from the downloads page on the main web2py site to github ).

Margaret

On Monday, June 23, 2014 10:42:32 AM UTC-5, greaneym wrote:

 Hello,

 I am interested in testing the hypermedia collectionjs combination in 
 web2py. I downloaded 2.9.5-trunk+timestamp.2014.03.29.21.54.41 but it's 
 not in the gluon/contrib.

 which version should I download to test please?

 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: which web2py version contains the hypermedia api in gluon contrib?

2014-06-23 Thread LightDot
What's a bigger pointer than a big red button called Git repository or 
Mercurial repository..? They are right there, on the downloads page... :)

Regards

On Monday, June 23, 2014 10:43:46 PM UTC+2, greaneym wrote:

 Hi,

 Never mind, I found the version on github.  Thanks (  There should 
 probably be a pointer from the downloads page on the main web2py site to 
 github ).

 Margaret

 On Monday, June 23, 2014 10:42:32 AM UTC-5, greaneym wrote:

 Hello,

 I am interested in testing the hypermedia collectionjs combination in 
 web2py. I downloaded 2.9.5-trunk+timestamp.2014.03.29.21.54.41 but it's 
 not in the gluon/contrib.

 which version should I download to test please?

 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: Trying to use the LOAD helper, if a button is clicked

2014-06-23 Thread Brian M
Looks like the new datatables.net v1.10 has a new API so there are now 
probably better ways to do this than I showed.

On Monday, June 23, 2014 4:51:53 AM UTC-5, Tomeu Roig wrote:

 Thanks Brian

 El lunes, 23 de junio de 2014 03:56:32 UTC+2, Brian M escribió:

 Tomeu,

 At the moment I'm just letting datatables.net enhance a plain html table 
 for me. One of these days I'll probably get around to giving it a json 
 datasource but so far it hasn't been a priority for my usage.

 As a bonus, here's some of how to update the datatables.net display 
 after using the edit dialog. (So just the edited record's row in the 
 datatable gets updated rather than a full page refresh)

 In controller
 #after you'd done the necessary DB updates...

 #tell browser to close the jqueryui dialog
 response.js =XML( '$(#edit_dialog).dialog(close);')

 #prepare for display update 
 edit_icon = IMG(_src=URL(c=static,f=images/page_white_edit.png), _alt
 =Click to edit)

 #prep javascript code for datatables.net to update the existing row's 
 display
 #basically just a json list of td values
 row_update = simplejson.dumps([updated_record.table.first_name, 
 updated_record.table.last_name, updated_record.table2.name, 
 str(A(edit_icon, _href=URL(r=request,f='edit_loader', args=[
 updated_record.table.record_id, mode]), _class=updateDialog)), 
 updated_record.table.email, updated_record.table.someother_id])

 #using the tr#id method to update table is unreliable (the TR won't have 
 an id if it was added dynamically
 #instead use the row index provided by datatables.net itself (we passed 
 it in via ajax vars)
 #essentially fnUpdate(new td values, which row)
 response.js += '$(#your_table_selector).dataTable().fnUpdate( '+
 row_update+', '+request.vars['datatable_row_index']+',0, false );'

 #also using jGrowl to give an acknowledgement
 message = T(%s updated) % (updated_record.table.first_name)
 response.js += '$.jGrowl('+message+');'


 And as the second bonus, how to insert a brand new row in the datatable. 
 (Below my datatable.net is another always visible LOAD()ed form for 
 creating a new record. Upon submission the new record is inserted into the 
 existing datatable via javascript returned in web2py's response)

 In controller:
 #do the database insert then
 #prepare for display update 
 edit_icon = IMG(_src=URL(c=static,f=images/page_white_edit.png), _alt
 =Click to edit)

 table_update = simplejson.dumps([new_record.table.first_name, new_record.
 table.last_name, 
 new_record.table2.name, str(A(edit_icon, _href=URL(r=request,f=
 'edit_loader', 
 args=[new_record.table.record_id, form.vars.mode]), _class=
 updateDialog)), 
 new_record.table.email, new_record.table.foreign_id])
 
 #issue command for adding new row to datatable
 response.js = 'vol_table.fnAddData('+table_update+');'

 Good luck

 ~Brian


 On Sunday, June 22, 2014 4:44:33 PM UTC-5, Tomeu Roig wrote:

 Thanks Brian, nice think to get a full href for pass to the 
 $web2py.component.

 I see that you use datatables.net. Do you use some plugin o directly 
 you pass json from controller?

 I want use in a new project but i have doubts have to implement. Can you 
 give me some idea?



-- 
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.