pyramid

Pyramid: multiple resource factories — how to

对着背影说爱祢 提交于 2019-12-22 09:15:27
问题 I have a simple root resource factory: class Root: __acl__ = [ (Allow, Authenticated, 'edit') ] Now for some "special" routes, I need to create another resource factory config.add_route('special', '/special/test', factory=SpecialFactory) class SpecialFactory: __acl__ = [ (Allow, Authenticated, 'special_edit') ] Now, I want to make Root the parent of SpecialFactory -- how should I do it? Is this the right way... class SpecialFactory: def __init__(self, request): self.request = request self._

How do I restrict permissions based on the single page ID in the URL?

时间秒杀一切 提交于 2019-12-22 05:24:09
问题 I'm trying to implement Pyramid's Security features in my website but I'm having some trouble figuring out how to use it. I've been reading over this tutorial and this example, as well as the Pyramid docs, and I can't figure out how to implement an authorization policy for single page IDs. For example, I have the following URL scheme: /pages /pages/12 /pages obviously lists the available pages and /pages/:id is where you can read/comment on the page. The documentation/examples I've read have

Python pyramid - How to use checkboxes and radio buttons

痞子三分冷 提交于 2019-12-21 23:24:04
问题 I've been trying to make a form with checkboxes and radio button using Pyramid framework but I can't figure out how to do it properly. I'm using the pyramid_simpleform . So far I've been able to put my checkboxes on the form using a for loop but I can't make any checkbox checked even if I specify checked=True . % for item in groups: ${form.checkbox(name="groups",label=item, value=item, checked=True)} % endfor I know there's a better way of doing this. Is there any examples I could look at.

Rolling back database transactions in SQLAlchemy tests with PostgreSQL

本小妞迷上赌 提交于 2019-12-21 23:03:12
问题 I am building a Pyramid web application which is built on the top of SQLAlchemy and solely relies PostgreSQL as its database backend. What would be a way to have the unit tests structure so that To speed up tests, database transactions are rolled back at the teardown() , or other clean up hook of the test suite Other tricks to speed up tests could be used, e.g. if SQLAlchemy and PostgreSQL has anything corresponding SQLite's :in:memory: database It is possible to choose a custom test runner á

How flexible is Pyramids auth system?

人走茶凉 提交于 2019-12-21 19:50:34
问题 I am getting my feet wet working with the Pyramid framework (great framework), and I've come to the point of user authorization. I want to take advantage of the ACL to block users who are already logged in from visiting the registration page. Obviously, I could do this other ways, but I was wondering if there was any way to do this using tools in pyramid. I know that by adding permissions to a view, users who do not meet the criteria are shown a forbidden view. In my case, I simply want to re

Having tests in multiple files

吃可爱长大的小学妹 提交于 2019-12-21 18:31:23
问题 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? 回答1: First, you need to make sure tests is not just a

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

北战南征 提交于 2019-12-21 17:32:30
问题 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

Deform/Colander validator that has access to all nodes?

限于喜欢 提交于 2019-12-21 10:32:10
问题 How do you define a custom validator in Deform/Colander that has access to all node values. I need to access the values from two fields in order to decide if a particular value is valid or not? 回答1: Here is an example of interfield validation. http://deformdemo.repoze.org/interfield/ 回答2: To place a validator for all colander fields we can simply do this validator method: def user_DoesExist(node,appstruct): if DBSession.query(User).filter_by(username=appstruct['username']).count() > 0: raise

Non-ASCII character '\x90' executing pserve on windows inside virtualenv

六月ゝ 毕业季﹏ 提交于 2019-12-21 04:25:13
问题 Question: How can i solve no-ascii character error executing pserve on virtualenv in windows? Description: I'm trying to execute pserve (pyllons/pyramid development web server) inside a virtualenv on windows. It's a fresh install, so maybe it is related to versions. Problem: With the virtualenv activated, execute pserve config.ini throw error: SyntaxError: Non-ASCII character '\x90' in file C:\PATH_TO_MY_ENV_HOME\env\Scripts\pserve.exe on line 1, but no encoding declared; see http://python

Preparing a pyramid app for production

混江龙づ霸主 提交于 2019-12-21 02:53:20
问题 So as I near the production phase of my web project, I've been wondering how exactly to deploy a pyramid app. In the docs, it says to use ../bin/python setup.py develop to put the app in development mode . Is there another mode that is designed for production. Or do I just use ../bin/python setup.py install . 回答1: Well the big difference between python setup.py develop and python setup.py install . Is that install will install the package in your site-packages directory. While develop will