Massimo,

The old T2/T3 was "too narrow and too tall" for me: I have too many
use cases that just plainly don't  fit. That's why I was glad that you
isolated crud and auth, both of them "broad and flat" utitility
layers.

So while I understand that the "rest of T2" needs to be redone, I have
more interest in documenting and expanding what is now in tools.py
than what was left out of it. ;-)

Cheers,
-Peter

On Feb 9, 12:47 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> Peter,
>
> if you and some others (Fran? Ceej?) want to take over T2 and move it
> on top of tools.py please go ahead.
>
> the source of t2.pdf is on launchpad together with the rest of the
> code.
>
> Massimo
>
> On Feb 8, 5:32 pm, Peter <peter.kleyn...@gmail.com> wrote:
>
> > Chris, this is something I was working on, based on the t2.pdf
> > example... See if it is of any use to you. The indentation will be
> > screwed up pretty badly, I'm afraid...
>
> > These instructions replicate the puppy example in the
> > T2.PDF docs, pages 7-11, for the new tools.py
> > environment in web2py 1.56
>
> > 0. From the admin interface, add new app 'puppy'
>
> > 1. Define table 'puppy' and create a crud instance
>
> > # db.py:
>
> > db.define_table('puppy',
> >     SQLField('name'),
> >     SQLField('image','upload') )
> > db.puppy.name.requires=IS_NOT_EMPTY()
>
> > from gluon.tools import Mail, Auth, Crud
> > crud=Crud(globals(),db)
>
> > 2. Enable a RESTful interface through crud
>
> > # controllers/default.py:
>
> > def data():
> >     return dict(form=crud())
>
> > def download():
> >     return response.download(request,db)
>
> > 3. Go tohttp://localhost:8000/puppy/default/data/create/puppy
> > to see a 'create puppy' form and play around with the default CRUD
> > interface
>
> > 4. Create a template for the CRUD pages
>
> > # views/default/data.html
>
> > {{extend 'layout.html'}}
> > {{=form}}
> > <p>You are now using the data.html template.</p>
>
> > ...and retry the CRUD URLs; the nice admin/session/etc buttons showed
> > earlier should be missing now...
>
> > 5. Define a combo page that shows items + a create form
>
> > # views/default/customcreate.html
> > {{extend 'layout.html'}}
>
> > <div class="frame">
> > <h2>Post the image of a Puppy</h2>
> > {{=form}}
> > </div>
> > <div class="frame">
> > <h2>Puppies</h2>
> > {{=items}}
> > </div>
> > <p>You are now using the customcreate.html template.</p>
>
> > # controllers/default.py
> > def customcreate():
> >     form = crud.create('puppy')
> >     items = crud.select('puppy', linkto=URL(r=request,f='data',args=
> > ['read']))
> >     return dict(form=form, items=items)
>
> > 6. Optionally include the "search" widget from t2.py?
> > (see t2.pdf, page 9)
> > (the high-level stuff such as search, comments, etc has gracefully
> > been split out of tools.py)
>
> > 7. Add authentication
>
> > # in models/db.py:
> > # define your own auth_user table so you can extend it later...
> > # you can also set auth.settings.table_user later, but you may lose
> > users already registered (?)
> > db.define_table('auth_user',
> >     SQLField('first_name',length=32,default=''),
> >     SQLField('last_name',length=50,default=''),
> >     SQLField('email',requires=IS_EMAIL()),
> >     SQLField('password','password',requires=CRYPT()),
> >     SQLField('registration_key',length=64),
> >     SQLField('pic','upload',default=''))    # and add any field you
> > want...
>
> > auth=Auth(globals(),db)
> > auth.settings.table_user=db.auth_user
> > auth.define_tables()
>
> > # in controllers/default.py:
> > def user(): return dict(form=auth())
>
> > # and add a menu so we can see state
> > if auth.user: response.menu=[
> >     ['logout',False,URL(r=request,f='user',args=['logout'])]]
> > else: response.menu=[
> >     ['login',False,URL(r=request,f='user',args=['login'])],
> >     ['register',False,URL(r=request,f='user',args=['register'])]]
>
> > Go tohttp://localhost:8000/puppy/default/user/registertoregister as
> > a user.
> > Go tohttp://localhost:8000/puppy/default/user/logintolog in.
>
> > 8. Now restrict access to these puppies to logged in users
>
> > # in controllers/default.py:
>
> > @auth.requires_login()
> > def data():
> >     return dict(form=crud())
>
> > @auth.requires_login()
> > def download():
> >     return response.download(request,db)
>
> > @auth.requires_login()
> > def customcreate():
> >     form = crud.create('puppy')
> >     items = crud.select('puppy', linkto=URL(r=request,f='data',args=
> > ['read']))
> >     return dict(form=form, items=items)
>
> > (Note: the T2 requires_login had the option of specifying a 'next'
> > function which
> > was passed in the vars._destination... This is missing in tools for
> > now, AFAICT)
>
> > ---
>
> > I don't use the authorization stuff yet, powerful as it is, so I'll
> > leave this to someone else.
> > For myself, the next stop is subclassing Auth... one reason being to
> > adapt email registration.
>
> > Cheers,
> > -Peter
>
> > On Feb 8, 6:04 pm, murray3 <ch...@murraypost.net> wrote:
>
> > > Massimo,
> > > having trouble getting email registration to work on localhost with
> > > the T2 Puppies app. What needs to be set up?
>
> > > Also how do you get the puppies app to run on GAE SDK, I keep getting
> > > internal error, is it supposed to work?
>
> > > regards
> > > chris
>
> > > On Feb 8, 1:31 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > asap. We need to rewrite T2 to use tools first. if anybody can help
> > > > please raise your hand.
>
> > > > Massimo
>
> > > > On Feb 7, 6:58 pm, murray3 <ch...@murraypost.net> wrote:
>
> > > > > Could any of you guy's run through the T2 "puppy" example using the
> > > > > new gluon.tools syntax.
> > > > > I am missing something (porting my T2 based code) and I'm sure this
> > > > > would get me restarted.
>
> > > > > thanks
> > > > > chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to