pylons

SQLAlchemy declarative syntax with autoload (reflection) in Pylons

*爱你&永不变心* 提交于 2019-11-27 18:19:48
问题 I would like to use autoload to use an existings database. I know how to do it without declarative syntax (model/_ init _.py): def init_model(engine): """Call me before using any of the tables or classes in the model""" t_events = Table('events', Base.metadata, schema='events', autoload=True, autoload_with=engine) orm.mapper(Event, t_events) Session.configure(bind=engine) class Event(object): pass This works fine, but I would like to use declarative syntax: class Event(Base): __tablename__ =

Best Practices for Python UnicodeDecodeError

≡放荡痞女 提交于 2019-11-27 15:36:39
问题 I use Pylons framework, Mako template for a web based application. I wasn't really bother too deep into the way Python handles the unicode strings. I had tense moment when I did see my site crash when the page is rendered and later I came to know that it was related to UnicodeDecodeError. After seeing the error, I started mesh around my Python code adding encode, decode calls for string with 'ignore' option but still I could not see the errors gone sometime. Finally I used to decode to ascii

With sqlalchemy how to dynamically bind to database engine on a per-request basis

被刻印的时光 ゝ 提交于 2019-11-27 11:00:43
问题 I have a Pylons-based web application which connects via Sqlalchemy (v0.5) to a Postgres database. For security, rather than follow the typical pattern of simple web apps (as seen in just about all tutorials), I'm not using a generic Postgres user (e.g. "webapp") but am requiring that users enter their own Postgres userid and password, and am using that to establish the connection. That means we get the full benefit of Postgres security. Complicating things still further, there are two

Handle mysql restart in SQLAlchemy

放肆的年华 提交于 2019-11-27 10:11:44
问题 My Pylons app uses local MySQL server via SQLAlchemy and python-MySQLdb. When the server is restarted, open pooled connections are apparently closed, but the application doesn't know about this and apparently when it tries to use such connection it receives "MySQL server has gone away": File '/usr/lib/pymodules/python2.6/sqlalchemy/engine/default.py', line 277 in do_execute cursor.execute(statement, parameters) File '/usr/lib/pymodules/python2.6/MySQLdb/cursors.py', line 166 in execute self

SQLAlchemy, clear database content but don't drop the schema

孤街醉人 提交于 2019-11-27 10:06:44
问题 I'm developing a Pylons app which is based on exisitng database, so I'm using reflection. I have an SQL file with the schema that I used to create my test database. That's why I can't simply use drop_all and create_all . I would like to write some unit tests and I faced the problem of clearing the database content after each test. I just want to erase all the data but leave the tables intact. Is this possible? The application uses Postgres and this is what has to be used also for the tests.

python list to newline separated value

天涯浪子 提交于 2019-11-27 07:20:32
问题 Im trying to get data in pylon to use in jquery autocomplete, the librarary i'm using for autocomplete it requires this format abc pqr xyz and in python i have data in this format [["abc"], ["pqr"],["xyz"] How do i convert this list to the above one. Edit: I trying to use these for a autocompete and i'm using pylons, in which the query to the server return list in this format [["abc"], ["pqr"],["xyz"] http://jquery.bassistance.de/autocomplete/demo/ this library except remote call in abc pqr

sqlalchemy existing database query

a 夏天 提交于 2019-11-27 01:02:57
问题 I am using SQLAlchemy as ORM for a python project. I have created few models/schema and it is working fine. Now I need to query a existing MySQL database, no insert/update just the select statement. How can I create a wrapper around the tables of this existing database? I have briefly gone through the sqlalchemy docs and SO but couldn't find anything relevant. All suggest execute method, where I need to write the raw sql queries, while I want to use the SQLAlchemy query method in same way as

UnicodeEncodeError: 'latin-1' codec can't encode character

流过昼夜 提交于 2019-11-26 18:22:41
What could be causing this error when I try to insert a foreign character into the database? >>UnicodeEncodeError: 'latin-1' codec can't encode character u'\u201c' in position 0: ordinal not in range(256) And how do I resolve it? Thanks! Character U+201C Left Double Quotation Mark is not present in the Latin-1 (ISO-8859-1) encoding. It is present in code page 1252 (Western European). This is a Windows-specific encoding that is based on ISO-8859-1 but which puts extra characters into the range 0x80-0x9F. Code page 1252 is often confused with ISO-8859-1, and it's an annoying but now-standard web