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.
There is a follow up somewhere on this list (sorry, too lazy to track
it down) that notes that Elixir has its own session context, and as
far as I can tell, you have to use that one instead of creating one
through pylons.database. Instead of:
from pylons.database import session_context
do this:
import elixir
session_context = elixir.objectstore.context
There is probably a way to use a different session context, but this
seems to work well enough for me for now (in production even).
On a related note, you might be interested in this:
http://code.google.com/p/restler/.
If you scroll all the way down to the bottom of
http://restler.googlecode.com/svn/trunk/restler/base.py to the
`init_model` function, you can see an example setup. Note that even
though it tries to get a `session_context` from the model before using
Elixir's builtin one, for now I never create a `session_context` in
my model, so I always end up using Elixir's.
HTH,
__wyatt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---