On May 12, 3:55 pm, Antipin Aleksei <[EMAIL PROTECTED]> wrote:
> Hi
>
> I posted this qeustion to sqlalchemy maillist but it seems to be a
> Pylons problem. This is the original question
>
>
>
> > I implemented simple form to edit user table. Suppose we have user2,
> > u...
> > <http://groups.google.com/groups/unlock?msg=bc1bbcd3e09b6ab9&_done=/gr...>@email.com.
> > Change name to user222 and click submit. Pgamin shows that
> > now we have user222 as expected. But if I visit 'users/edit/2' many
> > times I see sometimes old value 'user2' and another time new value
> > 'user222'.
>
> > Now I configure models in this way:
>
> > #models/__init__.py
> > from pylons.database import session_context
> > from elixir import metadata
> > from sqlalchemy import Table, BoundMetaData
> > engine = session_context.current.bind_to
>
> > import pyoner.models.user
>
> > #base.py
> > class BaseController(WSGIController):
> >         def __call__(self, environ, start_response):
> >                 del model.session_context.current
> >                 model.metadata.connect(model.engine)
>
> >                 return WSGIController.__call__(self, environ,
> > start_response)
>
> > My users.py controller:
> > from pyoner.lib.base import *
> > from pyoner.models.user import *
>
> > class UsersController(BaseController):
> >         def index(self):
> >                 c.users = User.select()
> >                 return render_response('/user_list.html')
>
> >         def edit(self, id):
> >                 c.user = User.get_by(id=id)
> >                 print(c.user.name)
> >                 return render_response('/user_edit.html')
>
> >         def apply(self, id):
> >                 user = User.get(id)
> >                 user.name = request.params.get('username', '').strip()
> >                 user.email = request.params.get('email', '').strip()
> >                 objectstore.flush()
> >                 redirect_to(controller='users', action='index')
>
> > and models/user.py:
> > from elixir import *
> > from sqlalchemy import *
> > from datetime import datetime
>
> > #from pyoner.models import UserEntity
> > class User(Entity):
> >         has_field('id', Integer, primary_key=True)
> >         has_field('name', Unicode(50), unique=True)
> >         has_field('email', Unicode(255), unique=True)
> >         has_field('password', Unicode(40))
> >         has_field('created', DateTime, default=datetime.now)
> >         using_options(tablename='user')
>
> > [app:main]
> > sqlalchemy.dburi = postgres://user:[EMAIL PROTECTED]:5432/pyoner
> > sqlalchemy.echo = false
>
> > Is there any error in my config of SQLAlchemy?
>
> For now I tried variants suggested 
> onhttp://bel-epa.com/wiki/UsingElixirWithPylons.
> Every method gives me the error:
> after updating username, going to users/index or users/edit/id several
> times results in strange behavior- user.name can show any of old values.

Also, starting in Elixir 0.3.0, by default you don't need to connect
`metadata` on every request. You only need to connect it once. You can
remove this from `from BaseController.__call__`:

    model.metadata.connect(model.engine)

 and add this to model.py:

    metadata.connect(engine)

Also, you could (maybe even should) create your `engine` like this in
model.py:

    from pylons.database import create_engine
    engine = create_engine()

__wyatt


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

Reply via email to