pyramid

how do I json encode this view?

蓝咒 提交于 2019-12-11 04:24:35
问题 New to python and Pyramid. I have a view that does pagination. How do I json encode it? I get an error "object at 0x2d16d90> is not JSON serializable" when I try this: @view_config(route_name="paginate") def paginate(request): query = DBSession.query(MyTable) page_url = paginate.PageURL_WebOb(request) customers = paginate.Page(query, page=int(request.params.get("page", 1)), items_per_page=25, url=page_url) if "partial" in request.params: # Render the partial list page return render_to

Database Connection Manager for Pyramid using minimal SQLAlchemy

徘徊边缘 提交于 2019-12-11 03:57:43
问题 I made a starter (pcreate -s starter myproject) project in Pyramid. How do I make database connection available to my application when needed I looked here: Subscribing Database Conenction. Below is the code: @subscriber(NewRequest) def new_request_subscriber(event): request = event.request settings = request.registry.settings request.db = sqlite3.connect(settings['db']) request.add_finished_callback(close_db_connection) def close_db_connection(request): request.db.close() I am worried about

Python unittest (using SQLAlchemy) does not write/update database?

≡放荡痞女 提交于 2019-12-11 03:17:04
问题 I am puzzled at why my Python unittest runs perfectly fine without actually updating the database. I can even see the SQL statements from SQLAlchemy and step through the newly created user object's email -- ...INFO sqlalchemy.engine.base.Engine.0x...954c INSERT INTO users (user_id, user_name, email, ...) VALUES (%(user_id)s, %(user_name)s, %(email)s, ...) ...INFO sqlalchemy.engine.base.Engine.0x...954c {'user_id': u'4cfdafe3f46544e1b4ad0c7fccdbe24a', 'email': u'test@example.com', ...} > ...

Pyramid TranslationString not working on json renderer

江枫思渺然 提交于 2019-12-11 02:38:46
问题 In a test I am doing in a pyramid application, I am trying to send a translatable text via JSON, but the translation is not working. At the beginning of the file I am importing the translation string function: from pyramid.i18n import TranslationString as _ Then consider the following code: @view_config(route_name='transtest', renderer='json') def transtest_view(request): return { 'myvar': _('temp-test', default='Temporary test', domain='myapp') } But what I get is: {"myvar": "temp-test"}

Long running tasks in Pyramid web app

China☆狼群 提交于 2019-12-11 02:38:34
问题 I need to run some tasks in background of web app (checking the code out, etc) without blocking the views. The twist in typical Queue / Celery scenario is that I have to ensure that the tasks will complete, surviving even web app crash or restart until those tasks complete, whatever their final result. I was thinking about recording parameters for multiprocessing.Pool in a database and starting all the incomplete tasks at webapp restart. It's doable, but I'm wondering if there's a simpler or

Pyramid debug toolbar serving static content over HTTP instead of HTTPS

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 02:12:06
问题 On our test servers, we're using the Pyramid debug toolbar, however, it generates http:// links to static content (like its CSS and JavaScript files), while the rest of the content is served over HTTPS. This causes mixed content warnings, and it breaks all functionality. Is there a way to force it to generate HTTPS links? I know it's possible to enable mixed content in Chrome, and this works, but it's not a feasible solution for the entire QA team. 回答1: There might be better/simpler ways to

Are there any side effects from calling SQLAlchemy flush() within code?

耗尽温柔 提交于 2019-12-11 01:55:36
问题 A bit of background: I am using pyramid framework with SQLAlchemy . My db session is handled by pyramid_tm and ZTE DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension())) I have a very complicated database design with lots of model classes, foreign keys, and complex relationships between my models. So while doing some very complicated logic on my Models and deleting, updating , inserting, and moving around objects from relationships in different models I used to get

Pyramid mongodb scaffold failing on Python 3 due to Paste

帅比萌擦擦* 提交于 2019-12-10 20:33:25
问题 Environment: Python 3.2.3 (using virtualenv) Pyramid 1.4 pyramid_mongodb scaffold After installing myproject using pyramid_mongodb scaffold I ran python setup.py test -q and it's failing with below errors. running build_ext Traceback (most recent call last): File "setup.py", line 33, in <module> """, File "/usr/lib/python3.2/distutils/core.py", line 148, in setup dist.run_commands() File "/usr/lib/python3.2/distutils/dist.py", line 917, in run_commands self.run_command(cmd) File "/usr/lib

All addresses to go to a single page (catch-all route to a single view) in Python Pyramid

一世执手 提交于 2019-12-10 17:02:16
问题 I am trying to alter the Pyramid hello world example so that any request to the Pyramid server serves the same page. i.e. all routes point to the same view. This is what iv got so far: from wsgiref.simple_server import make_server from pyramid.config import Configurator from pyramid.response import Response def hello_world(request): return Response('Hello %(name)s!' % request.matchdict) if __name__ == '__main__': config = Configurator() config.add_route('hello', '/*') config.add_view(hello

Serve up pdf as a download with Pyramid, ningx, X-Accel-Redirect Header

穿精又带淫゛_ 提交于 2019-12-10 15:13:43
问题 I want a user to be able to click a link like this: <a href="/download?file=123">download</a> Have a Pyramid 1.2.7 app handle the view like this @view_config(route_name='download') def download(request): file_id = request.GET['file'] filename = get_filename(file_id) headers = request.response.headers headers['Content-Description'] = 'File Transfer' headers['Content-Type'] = 'application/force-download' headers['Accept-Ranges'] = 'bytes' headers['X-Accel-Redirect'] = ("/path/" + filename + "