pylons

Pylons & Beaker: JSON Encoded Sessions

淺唱寂寞╮ 提交于 2019-12-11 11:43:30
问题 Need to read Pylons session data (just read, not write to) in node.js Once I decode the base64, I'm left with a string containing a serialized Python object which, is a pain to parse in node.js How can I get Beaker to serialize to JSON instead? For it is far easier for node.js to handle. 回答1: i had to look inside beaker to find what you call "Python serialized strings" are python pickles. i don't think it would be more than a few lines to change it get it to use json to store the dict. here

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

How to determine if an HTTP request is asynchronous in Python or Pylons

 ̄綄美尐妖づ 提交于 2019-12-11 03:43:12
问题 I can't help but think that this is a duplicate, but if it is, I can't seem to find the doppelganger. I'm just starting to learn Python (focusing on Pylons) and I'd like to know if there is a way to determine if a call to a controller is done asynchronously or not. In PHP it would look something like this: function isAjax() { return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; } Is there one that works well for all of Python, or is there

Is there a way to have SQLAlchemy NOT wrap SQL writes within a BEGIN and COMMIT?

邮差的信 提交于 2019-12-11 03:06:43
问题 I'm using SQLAlchemy 0.6.4 on the Pylons 1.0 framework. I've tried every permutation of setting autoflush and autocommit to True and False, but I've found that SQLAlchemy wants to wrap all SQL sessions or writes with a BEGIN/COMMIT. I've configured the scoped_session in models/meta.py as below: """SQLAlchemy Metadata and Session object""" from sqlalchemy import MetaData from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import scoped_session, sessionmaker __all__ = [

ckan.plugins.core.PluginNotFoundException: pages

你离开我真会死。 提交于 2019-12-11 02:49:18
问题 I'm using CKAN as my open data portal. It's written in Python using Pylons framework. I just want to add a new page similar to about page to display the terms and conditions to the users. About page comes built in. So I installed ckanext-pages using pip command. What I did was below 1. # Activate your CKAN virtual environment . /usr/lib/ckan/default/bin/activate 2. # Install the pages extension. pip install -e 'git+https://github.com/ckan/ckanext-pages.git#egg=ckanext-pages' But now I end up

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

Pylons: How to write a custom 404 page?

廉价感情. 提交于 2019-12-11 01:17:36
问题 So this question has been asked before, but not answered in great detail. I want to override the default Pylons error page to make a nicer, custom one. I've got as far as overwriting the controller in error.py , as follows: def document(self): """Render the error document""" resp = request.environ.get('pylons.original_response') content = literal(resp.body) or cgi.escape(request.GET.get('message', '')) custom_error_template = literal("""\ # some brief HTML here """) page = custom_error

Content-Length header not returned from Pylons response

大城市里の小女人 提交于 2019-12-11 00:56:10
问题 I'm still struggling to Stream a file to the HTTP response in Pylons. In addition to the original problem, I'm finding that I cannot return the Content-Length header, so that for large files the client cannot estimate how long the download will take. I've tried response.content_length = 12345 and I've tried response.headers['Content-Length'] = 12345 In both cases the HTTP response (viewed in Fiddler) simply does not contain the Content-Length header. How do I get Pylons to return this header?

Multiple database connections with Python + Pylons + SQLAlchemy

北慕城南 提交于 2019-12-10 23:08:34
问题 I'm trying to implement the proper architecture for multiple databases under Python + Pylons. I can't put everything in the config files since one of the database connections requires the connection info from a previous database connection (sharding). What's the best way to implement such an infrastructure? 回答1: Pylons's template configures the database in config/environment.py , probably with the engine_from_config method. It finds all the config settings with a particular prefix and passes