pyramid

Pyramid.security questions: Double cookies? Insecure cookies? Expiration?

ⅰ亾dé卋堺 提交于 2019-12-05 03:45:48
I'm taking my first foray into the Pyramid security module. I'm using this login code to set the auth_tkt: @view_config(route_name='LoginForm', request_method='POST', renderer='string') class LoginForm(SimpleObject): def __call__(self): emailAddress = self.request.params.get('emailAddress') password = self.request.params.get('password') if emailAddress != 'testemail@gmail.com' or password != 'testpassword': errorDictionary = { 'message' : "Either the email address or password is wrong." } self.request.response.status = 400 return json.dumps( errorDictionary, default=json_util.default)

Multiple permissions in view_config decorator?

谁都会走 提交于 2019-12-05 02:43:51
I am configuring access control for a web application based on the Pyramid framework. I am setting up permissions for my view callables using the @view_config decorator. I have two permissions, namely 'read' and 'write' . Now, I want certain views to require both permissions. I was unable to figure out how to do this with view_config - am I missing something, or is there maybe another way to do this? Make a readwrite permission. Each view gets one and only one permission but each principal can be mapped to many permissions. 来源: https://stackoverflow.com/questions/15055029/multiple-permissions

how can i get the ini data in pyramid?

一曲冷凌霜 提交于 2019-12-04 23:19:42
There is a development.ini or production.ini in a pyramid project. I add my own config data in the ini files like: [thrift] host = 0.0.0.0 port = 8080 and I want to use the config data in one of py files in the project. How can I get the data without the request object? (I've seen a solution which uses request.) You can access the settings at request.registry.settings or pyramid.threadlocal.get_current_registry().settings . It behaves like dictionary. If you want to use the second one, that is getting the settings without having the request, I have to warn you. According to the doc : This

Routes with trailing slashes in Pyramid

拥有回忆 提交于 2019-12-04 22:24:39
问题 Let's say I have a route '/foo/bar/baz'. I would also like to have another view corresponding to '/foo' or '/foo/'. But I don't want to systematically append trailing slashes for other routes, only for /foo and a few others (/buz but not /biz) From what I saw I cannot simply define two routes with the same route_name. I currently do this: config.add_route('foo', '/foo') config.add_route('foo_slash', '/foo/') config.add_view(lambda _,__: HTTPFound('/foo'), route_name='foo_slash') Is there

Password not getting encrypted when I update

戏子无情 提交于 2019-12-04 22:01:43
Being a newb to python I am not quite sure why I am getting inconsistent results. I register a user and the password in my table ends up being the hashed version. When the user updates his password, the password in the table ends up being the unhashed version. Obviously, I want the hashed version. What am I doing wrong? (I am using SQLAlchemy and mysql if that matters.) I have the following: def hash_password(password): blah, blah, blah # hash my password here return hashed_password class User(Base): __tablename__ = 'mytable' email = Column('email') _password = Column('password') def _get

Why is SQLAlchemy execute Update not working

佐手、 提交于 2019-12-04 18:54:10
I have the following: @periodic_task(run_every=crontab(minute="*/1")) def PeriodicUpdateAgentLastRica(): query = """update agents inner join (select sims.consignment_agents_id as agents_id, MAX(sims.rica_current_stamp) as last_rica_stamp from sims where sims.rica_current_stamp > DATE_SUB(now(), INTERVAL 3 MONTH) and sims.consignment_agents_id is not NULL group by sims.consignment_agents_id) as dt on dt.agents_id = agents.id set agents.last_rica_stamp = dt.last_rica_stamp""" res = Session.execute(query) print res if res.rowcount: log.info("Updated %s agents" % res.rowcount) #transaction.commit(

Python pyramid - How to use checkboxes and radio buttons

北慕城南 提交于 2019-12-04 18:36:51
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. All the examples in pyramid's documentation are simple text fields. I didn't find any radio button or

Pyramids route_url with additional query arguments

和自甴很熟 提交于 2019-12-04 16:51:19
问题 In Pyramids framework, functions route_path and route_url are used to generate urls from routes configuration. So, if I have route: config.add_route('idea', 'ideas/{idea}') I am able to generate the url for it using request.route_url('idea', idea="great"); However, sometimes I may want to add additional get parameters to generate url like: idea/great?sort=asc How to do this? I have tried request.route_url('idea', idea='great', sort='asc') But that didn't work. 回答1: You can add additional

How to Integrate Pyramid 1.1 and Mongo DB - as few lines as possible

谁说我不能喝 提交于 2019-12-04 16:24:01
Goal : I try to integrate Mongo DB with Pyramid 1.1 basic application. Background : Appliation is created by the book (https://docs.pylonsproject.org/projects/pyramid/1.1/narr/project.html#creating-the-project) using basic command "paste create -t pyramid_starter" I followed this cookbook article: https://docs.pylonsproject.org/projects/pyramid_cookbook/dev/mongo.html Problem : It seems that when ever I add MongoDB connection into request I got "Internal Server Error" with I have tried several articles and it seems that I must start debug system more? Has anybody found easy solution for this?

Rolling back database transactions in SQLAlchemy tests with PostgreSQL

天大地大妈咪最大 提交于 2019-12-04 15:49:45
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 á la py.test if a specific features outside the standard library unittest framework makes it easier to