Ok Moritz, let's try CrudRestController...
Yes, it works!
thanks a lot.

j

Moritz Schlarb wrote:
Have you thought about using CrudRestController from tgext.crud ?
Using it would save you some hassle, and it's very configurable though.

Am Donnerstag, 20. Dezember 2012 08:27:23 UTC+1 schrieb jo:

    Hi all,

    I'm new to tg2 and I'm trying sprox, I followed the tutorial at:
    http://sprox.org/tutorials/table.html
    <http://sprox.org/tutorials/table.html> and
    http://sprox.org/tutorials/form.html
    <http://sprox.org/tutorials/form.html>

    and I created the model, templates and controller
    I can insert new rows into the table movies
    and the table grid shows the rows I inserted
    but when I try to edit or delete a row
    I get the 404 error like this:

    edit: http://myserverdev:8080/movies/3/edit
    <http://myserverdev:8080/movies/3/edit> ERROR 404
    delete: http://myserverdev:8080/movies/3
    <http://myserverdev:8080/movies/3> ERROR 404

    here is my controller, what's wrong with it?
    -------------------------------------------------------

    from formencode.validators import DateValidator, String
    from sprox.formbase import Field, CalendarDatePicker, AddRecordForm,
    EditableForm
    from sprox.tablebase import TableBase
    from sprox.fillerbase import TableFiller, EditFormFiller
    from tg.controllers import RestController, redirect
    from tg import expose, tmpl_context, validate
    from vir.model import DBSession
    from vir.model.movies import Movie, Genre, Director
    import transaction

    class MovieTableFiller(TableFiller):
    __model__ = Movie
    def directors(self, obj):
    directors = ', '.join(['<a
    href="/directors/'+str(d.director_id)+'">'+d.name
    <http://d.name>+'</a>'
    for d in obj.directors])
    return directors.join(('<div>', '</div>'))

    class MovieTable(TableBase):
    __model__ = Movie
    __omit_fields__ = ['movie_id', 'genre_id']
    __xml_fields__ = ['directors']

    class NewMovieForm(AddRecordForm):
    __model__ = Movie
    release_date = Field(DateValidator)
    title = Field(String(min=4))
    __require_fields__ = ['release_date','description']

    class MovieEditForm(EditableForm):
    __model__ = Movie
    __omit_fields__ = ['genre_id', 'movie_id']

    movie_table = MovieTable(DBSession);
    movie_filler = MovieTableFiller(DBSession)
    new_movie_form = NewMovieForm(DBSession)
    edit_movie_form = MovieEditForm(DBSession)


    class SproxMovieController(RestController):
    @expose('vir.templates.movies')
    def get_all(self):
    tmpl_context.widget = movie_table
    value = movie_filler.get_value()
    return dict(value=value)

    @expose('vir.templates.movies_new')
    def new(self, **kw):
    tmpl_context.widget = new_movie_form
    return dict(value=kw)

    @expose('vir.templates.movies_add')
    @validate(new_movie_form, error_handler=new)
    def add_movie(self, **kw):
    record = Movie(
    title = kw.get('title') ,
    description = kw.get('description') ,
    genre_id = kw.get('genre') ,
    release_date = kw.get('release_date')
    )
    DBSession.add(record)
    DBSession.flush()
    transaction.commit()
    redirect('/movies')

    @expose('vir.templates.movies_edit')
    def edit(self, **kw):
    tmpl_context.widget = edit_movie_form
    return dict(value=kw)
    --------------------------------------------------
    thanks for any help
    j

--
You received this message because you are subscribed to the Google Groups "TurboGears" group. To view this discussion on the web visit https://groups.google.com/d/msg/turbogears/-/oiMX0zaiGvwJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.


--
Jose Soares Da Silva                     _/_/
Sferacarta Net
Via Bazzanese 69                       _/_/    _/_/_/
40033 Casalecchio di Reno             _/_/  _/_/  _/_/
Bologna - Italy                      _/_/  _/_/  _/_/
Ph  +39051591054              _/_/  _/_/  _/_/  _/_/
fax +390516131537            _/_/  _/_/  _/_/  _/_/
web:www.sferacarta.com        _/_/_/      _/_/_/

Le informazioni contenute nella presente mail ed in ogni eventuale file 
allegato sono riservate e, comunque, destinate esclusivamente alla persona o 
ente sopraindicati, ai sensi del decreto legislativo 30 giugno 2003, n. 196. La 
diffusione, distribuzione e/o copiatura della mail trasmessa, da parte di 
qualsiasi soggetto diverso dal destinatario, sono vietate. La correttezza, 
l’integrità e la sicurezza della presente mail non possono essere garantite. Se 
avete ricevuto questa mail per errore, Vi preghiamo di contattarci 
immediatamente e di eliminarla. Grazie.

This communication is intended only for use by the addressee, pursuant to 
legislative decree 30 June 2003, n. 196. It may contain confidential or 
privileged information. You should not copy or use it to disclose its contents 
to any other person. Transmission cannot be guaranteed to be error-free, 
complete and secure. If you are not the intended recipient and receive this 
communication unintentionally, please inform us immediately and then delete 
this message from your system. Thank you.

--
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to