pylons

Debug Pylons application through Eclipse

我的梦境 提交于 2019-11-29 23:18:50
I have Eclipse setup with PyDev and love being able to debug my scripts/apps. I've just started playing around with Pylons and was wondering if there is a way to start up the paster server through Eclipse so I can debug my webapp? Create a new launch configuration (Python Run) Main tab Use paster-script.py as main module (you can find it in the Scripts sub-directory in your python installation directory) Don't forget to add the root folder of your application in the PYTHONPATH zone Arguments Set the base directory to the root folder also. As Program Arguments use "serve development.ini" (or

Stream a file to the HTTP response in Pylons

ぃ、小莉子 提交于 2019-11-29 20:58:40
问题 I have a Pylons controller action that needs to return a file to the client. (The file is outside the web root, so I can't just link directly to it.) The simplest way is, of course, this: with open(filepath, 'rb') as f: response.write(f.read()) That works, but it's obviously inefficient for large files. What's the best way to do this? I haven't been able to find any convenient methods in Pylons to stream the contents of the file. Do I really have to write the code to read a chunk at a time

SQLAlchemy printing raw SQL from create()

点点圈 提交于 2019-11-29 20:37:21
I am giving Pylons a try with SQLAlchemy, and I love it, there is just one thing, is it possible to print out the raw SQL CREATE TABLE data generated from Table().create() before it's executed? Antoine Leclair from sqlalchemy.schema import CreateTable print(CreateTable(table)) If you are using declarative syntax: print(CreateTable(Model.__table__)) Update: Since I have the accepted answer and there is important information in klenwell answer , I'll also add it here. You can get the SQL for your specific database (MySQL, Postgresql, etc.) by compiling with your engine. print(CreateTable(Model._

How to efficiently manage frequent schema changes using sqlalchemy?

喜欢而已 提交于 2019-11-29 19:05:17
I'm programming a web application using sqlalchemy. Everything was smooth during the first phase of development when the site was not in production. I could easily change the database schema by simply deleting the old sqlite database and creating a new one from scratch. Now the site is in production and I need to preserve the data, but I still want to keep my original development speed by easily converting the database to the new schema. So let's say that I have model.py at revision 50 and model.py a revision 75, describing the schema of the database. Between those two schema most changes are

A simple Python deployment problem - a whole world of pain

我们两清 提交于 2019-11-29 18:46:14
We have several Python 2.6 applications running on Linux. Some of them are Pylons web applications, others are simply long-running processes that we run from the command line using nohup . We're also using virtualenv , both in development and in production. What is the best way to deploy these applications to a production server? In development we simply get the source tree into any directory, set up a virtualenv and run - easy enough. We could do the same in production and perhaps that really is the most practical solution, but it just feels a bit wrong to run svn update in production. We've

Mark string as safe in Mako

拜拜、爱过 提交于 2019-11-29 18:43:07
问题 I'm using Pylons with Mako templates and I want to avoid typing this all the time: ${ h.some_function_that_outputs_html() | n } I want to somehow mark the function, or a variable as safe (you can do that in Django) so I don't have to pipe-en all the time. Any ideas? 回答1: I just found out that if you put a html method in your class, then Mako will just call that method and output whatever it returns in the template. So I did: def __html__(self): return unicode(self) That's basically what h

Check if a user has a permission in pyramid (pylons 2)?

和自甴很熟 提交于 2019-11-29 11:38:17
How do i check if a user has a permission in pyramid. For example, I want to show some HTML only if a user has some permission, but have the view available for everybody. The usual method is: from pyramid.security import has_permission has_permission('view', someresource, request) See also http://docs.pylonsproject.org/projects/pyramid/1.0/narr/security.html#debugging-imperative-authorization-failures and http://docs.pylonsproject.org/projects/pyramid/1.0/api/security.html#pyramid.security.has_permission 来源: https://stackoverflow.com/questions/4916127/check-if-a-user-has-a-permission-in

Proper way to set object instance variables

◇◆丶佛笑我妖孽 提交于 2019-11-29 11:31:44
问题 I'm writing a class to insert users into a database, and before I get too far in, I just want to make sure that my OO approach is clean: class User(object): def setName(self,name): #Do sanity checks on name self._name = name def setPassword(self,password): #Check password length > 6 characters #Encrypt to md5 self._password = password def commit(self): #Commit to database >>u = User() >>u.setName('Jason Martinez') >>u.setPassword('linebreak') >>u.commit() Is this the right approach? Should I

Full text search engine for Python

女生的网名这么多〃 提交于 2019-11-29 09:43:05
问题 I'm searching for a Python full text search engine. I took a look at PyLucense, but I think that using a Java-based library in a Python project is not good. As I understand, Sphinx does not have a Python API. Any ideas ? 回答1: Have you looked at Whoosh? It's pure Python. 回答2: "Sphinx does not have a Python API" is not true. Download the release and look at sphinx/api/sphinxapi.py I use it myself and I'm pretty happy with it. The documentation is for PHP only but the Python API uses the exact

SQLAlchemy declarative syntax with autoload (reflection) in Pylons

廉价感情. 提交于 2019-11-29 04:04:38
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__ = 'events' __table_args__ = {'schema': 'events', 'autoload': True} Unfortunately, this way I get: