pyramid

SQLAlchemy: Knowing the field names and values of a model object?

走远了吗. 提交于 2019-12-04 10:29:26
I'm trying to keep to SOLID object oriented programming principles, stay DRY, etc, but my newness to Python/SQLAlchemy/Pyramid is making it very hard. I'm trying to take what I now know to be a SQLAlchemy model used to create a simple Pyramid Framework object and use what I know to be "reflection" in C#, it may be called something different in Python (Introspection? Not sure as this is only my second week with python but I have lots of experience in other languages (C/C++/C#,Java, etc) so the trouble seems to be mapping my knowledge to the vocabulary of python, sorry), to find out the field

Having tests in multiple files

℡╲_俬逩灬. 提交于 2019-12-04 10:02:16
I am using pyramids framework for large project and I find it messy to have all my tests in one tests.py file. So I have decided to create directory that would contain files with my tests. Problem is, I have no idea, how to tell pyramids, to run my tests from this directory. I am running the tests using python setup.py test -q . But this of course do not work, after I have moved my tests into tests directory. What to do, to make it work? First, you need to make sure tests is not just a directory, but a Python package by creating an __init__.py in it. You also need to make sure you name the

How to set the content type header in response for a particular file type in Pyramid web framework

痴心易碎 提交于 2019-12-04 09:37:28
I am using pyramid web framework to build a website. I keep getting this warning in chrome console: Resource interpreted as Font but transferred with MIME type application/octet-stream: "http:static/images/fonts/font.woff". How do I get rid of this warning message? I have configured static files to be served using add_static_view I can think of a way to do this by adding a subscriber function for responses that checks if the path ends in .woff and setting the response header to application/x-font-woff . But it does not look like a clean solution. Is there a way to tell Pyramid to do it through

mod_wsgi error - class.__dict__ not accessible in restricted mode

给你一囗甜甜゛ 提交于 2019-12-04 09:31:14
问题 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):

When should I be calling flush() on SQLAlchemy?

為{幸葍}努か 提交于 2019-12-04 09:01:29
问题 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

Pyramid view class inheritance with @view_defaults and @view_config decorators

痴心易碎 提交于 2019-12-04 08:26:03
I have written up a view class that has multiple @view_config's with predicates set for a single route. I then have a subclass that overwrites a couple of the sub-functions, which affects how the view is made. Below is something similar, but with simplified code. When visiting the view_a route, everything works fine. When visiting the view_b route, it shows "404 Not Found The resource could not be found". It seems the @view_configs aren't 'inherited' and linked to the new @view_default. Is there a simple way to fix this, or will I have to switch to manually doing config.add_view() ? @view

Pyramid and FormAlchemy admin interface

◇◆丶佛笑我妖孽 提交于 2019-12-04 07:34:52
I have a pyramid project using the formalchemy admin interface. I added the basic ACL authentication and the pyramid_formalchemy plugin always denys even though I am authenticated. Any thoughts on how only allow authenticated users to use the pyramid_formalchemy admin interface? The authorization policy was add like this: authn_policy = AuthTktAuthenticationPolicy('MYhiddenSECRET', callback=groupfinder) authz_policy = ACLAuthorizationPolicy() config = Configurator( settings=settings, root_factory='package.auth.RootFactory', authentication_policy=authn_policy, authorization_policy=authz_policy

PyCharm SQLAlchemy autocomplete

情到浓时终转凉″ 提交于 2019-12-04 07:32:25
I started evaluating PyCharm 3 professional edition because I will be working on several Pyramid + SQLAlchemy projects. One of the things I would really love to have is SQLAlchemy autocomplete. I'll explain my scenario. I created a new starter project with the alchemy scaffold, I followed the instructions here http://docs.pylonsproject.org/projects/pyramid_tutorials/en/latest/pycharm/index.html . I also installed the SQLAlchemy package for the interpreter and virtual environment I am using for this project. Also, when I created a new pycharm project for this code, the IDE suggested me to

File writing permission denied in mod_wsgi deployed app

孤人 提交于 2019-12-04 06:33:16
I'm trying to deploy a Pyramid app using mod_wsgi on Apache. I get IOError: [Errno 13] Permission denied on templates folder, where mako caches his templates, even if I grant write permissions to anybody . If I remove template caching from my ini file the site runs flawlessly. I also tried running Apache as the user owning the folder instead of www-data with no luck. Any clue? neurino It's an Apache permission issue, I had to change owner of folder to www-data user and set permissions to 775 chown -R www-data:www-data ~/data chmod -R 775 ~/data Also see here but note for Mako 664 permissions

Dynamic user based authorization in Pyramid

妖精的绣舞 提交于 2019-12-04 05:24:50
I'm following security guidelines found on Pyramid docs along with wiki tutorial Adding Authorization Now I need to add restrictions based un single user rather than groups. Let's say for example that, if any blog editor can have permission to review all comments, only post author can edit the post itself . For the first task I will have in my Root ACL like this: __acl__ = [ (Allow, Everyone, 'view'), (Allow, Authenticated, 'view_profile'), (Allow, 'groups:editor', 'edit_comment') ] but whay about for edit_post ? I've read this answer but seems overkill to me for my needs since I don't need to