pyramid

mod_wsgi error - class.__dict__ not accessible in restricted mode

亡梦爱人 提交于 2019-12-03 03:09:20
This started biting our ass on our production server really hard. We saw this occasionally (for 1 request per week). Back then we found out it is because of mod_wsgi doing some funky stuff in some configs. As we could not track the reason for the bug, we decided that it did not require instant attention. However today, on 1 of our production servers this really occurred for 10 % of all server requests; that is 10 % of all server requests failed with this very same error: mod_wsgi (pid=1718): Target WSGI script '/installation/dir/our-program/prod-dispatch.wsgi' cannot be loaded as Python module

SQLAlchemy session issues with celery

谁说我不能喝 提交于 2019-12-03 03:09:20
I have scheduled a few recurring tasks with celery beat for our web app The app itself is build using pyramid web framework. Using the zopetransaction extension to manage session In celery, I am using the app as a library. I am redefining session in models with a function. It works well but once in a while, it raises InvalidRequestError: This session is in 'prepared' state; no further SQL can be emitted within this transaction I am not sure what is wrong and why it issues these warnings. Sample code: in tasks.py def initialize_async_session(): import sqlalchemy from webapp.models import Base,

User Authentication in Pyramid

半腔热情 提交于 2019-12-03 02:12:53
问题 I'm building a webapp and needed to choose between Django and Pyramid. I decided to go with Pyramid. I understand Pyramid comes with its own authentication/authorization framework which looks nice. But I haven't seen anywhere in Pyramid where users/groups/permissions are defined. In Django these things come for free. I'm using SQLAlchemy and was wondering if there are similar users/groups/permissions already built that I can import. I'd rather not define these objects/mappings and hash

When should I be calling flush() on SQLAlchemy?

一世执手 提交于 2019-12-03 01:49:15
I'm new to SQLAlchemy and have inherited a somewhat messy codebase without access to the original author. The code is litered with calls to DBSession.flush() , seemingly any time the author wanted to make sure data was being saved. At first I was just following patterns I saw in this code, but as I'm reading docs, it seems this is unnecessary - that autoflushing should be in place. Additionally, I've gotten into a few cases with AJAX calls that generate the error "InvalidRequestError: Session is already flushing". Under what scenarios would I legitimately want to keep a call to flush()? This

Jinja2 Inheritance with Blocks and Includes

做~自己de王妃 提交于 2019-12-03 01:41:37
I can't figure out how to modify blocks from included templates using Jinja2. Here's an example where I use three files. base.html: <html>{% include "content.html" %}</html> content.html: <h1>{% block title %}Title{% endblock title%}</h1> <div>{% block content_body %}Content Body{% endblock content_body%}</div> story.html {% extends "base.html" %} {% block title %}story.title{% endblock title %} {% block content_body %}story.description{% endblock content_body %} When rendering story.html, I'll get: <html> <h1>Title</h1> <div>Content Body</div> </html> How would I render with the expected

Using a different schema for the same declarative Base in sqlalchemy

泪湿孤枕 提交于 2019-12-02 23:49:19
I am new to both Pyramid and SQLAlchemy. I am working on a Python Pyramid project with SQLAlchemy. I have a simple model set up below. How would I go about being able to use this with different schemas at run-time? This will be a PostgreSQL database backend. Right now, "public" is hard-coded into the declarative base model. I would need the ability to use this same model with different schema. What is the best approach? Unless I missed it, the documentation at SQLAlchemy seemed unclear to me. from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, BigInteger _

How can I redirect after POST in Pyramid?

核能气质少年 提交于 2019-12-02 22:29:23
I'm trying to have my form submit to a route which will validate the data then redirect back to the original route. For example: User loads the page website.com/post Form POSTs the data to website.com/post-save User gets redirected back to website.com/post Pyramid is giving me some troubles doing this. Here's my slimmed down views.py def _get_link_form(post_data): """ Returns the initialised form object """ return LinkForm(post_data) def home_page(request): form = _get_link_form(request.POST) return {'form' : form} def save_post(request): """ form data is submitted here """" form = _get_link

How to get column names from SQLAlchemy result (declarative syntax)

风格不统一 提交于 2019-12-02 21:54:59
I am working in a pyramid project and I've the table in SQLAlchemy in declarative syntax """models.py""" class Projects(Base): __tablename__ = 'projects' __table_args__ = {'autoload': True} I get the results by using """"views.py""" session = DBSession() row_data = session.query(Projects).filter_by(id=1).one() How can I get the column names from this result. PS: I am unable to use this method since I am using the declarative syntax. zzzeek The difference is between ORM and non-ORM, not declarative, which is just a helper for the ORM. Query has a method column_descriptions() that was added for

Calling another view in Pyramid

佐手、 提交于 2019-12-02 20:51:17
My goal: In Pyramid, to call another view-callable, and to get a Response object back without knowing any details about that view-callable. In my Pyramid application, say I have a view "foo" which is defined using a view_config decorator: @view_config(route_name="foo", renderer="foo.jinja2") def foo_view(request): return {"whereami" : "foo!"} Now say that I want to route "bar" to a view that does the same thing for the time being, so it internally calls foo_view and returns its Response: @view_config(route_name="bar") def bar_view(request): return foo_view(request) ...but wait! That doesn't

Using pyramid authentication with pyramid

扶醉桌前 提交于 2019-12-02 20:50:31
In the pyramid documentation, the Sqlalchemy Dispatch Tutorial uses dummy data in security.py . I needed to use mysql data so I implemented it like this: My Login Code @view_config(route_name='login', renderer='json',permission='view') def user_login(request): session = DBSession username = request.params['username'] password = request.params['password'] sha = hashlib.md5() sha.update(password) password = sha.digest().encode('hex') user = session.query(Users).filter(and_(Users.username==username,Users.password ==password)).count() if(user != 0): headers = remember(request, username) return