pyramid

How can I select 2 different random rows from a table?

懵懂的女人 提交于 2019-12-13 16:44:02
问题 right now I have row=session.query(Item).order_by(func.random()).limit(2) name1=row[0].name name2=row[1].name Which gives me the first column(name) of each entry. The problem is, I get multiples (it will select the same random row twice. I want it to always be different. Is there a way to do this without an if, then statement? if its useful, when I print row, it gives me something like this: SELECT items.id AS items_id, items.name AS items_name, items.data AS items_data FROM items ORDER BY

pyramid pserve in different root path than /

夙愿已清 提交于 2019-12-13 07:18:32
问题 When pserve starts by default it runs the pyramid application in http://0.0.0.0:6543 however how can I changed it to http://0.0.0.0:6543 /myapp In the settings I can change the port but I haven't found elsewhere where to change the root path 回答1: In any WSGI application the environ['SCRIPT_NAME'] is very important here. It defines the root path for all urls in the app. The full path is environ['SCRIPT_NAME'] + environ['PATH_INFO'] . Assuming you have done things properly in your app (for

Pyramid, Python3, SQLAlchemy and MySQL

梦想与她 提交于 2019-12-13 02:30:03
问题 I want Pyramid, Python3, SQLAlchemy and MySQL to play nice on a single machine. This question has been asked before, but it was a long enough time ago that I'm hoping the answer has changed... Questions: What driver works for getting a Python 3 Pyramid app to talk nicely to MySQL via SQLAalchemy? Is this even possible? I've gotten quite far in this project thinking it would be a simple thing to switch out databases, now I'm a bit stuck and downgrading to Python 2.7 is not something I want to

Writing doctests for pyramid web app which depend on settings in ini file

走远了吗. 提交于 2019-12-13 02:08:44
问题 I would like to write doctests for my pyramid web app, using the webtest module. I tried it like this: from my_webapp import main from webtest import TestApp app = TestApp(main({})) result = app.get('/') This raises a KeyError (because some.url is not known) when my code reaches this line: url = request.registry.settings['some.url'] The value of some.url is specified in the paster ini file of my application. Is there a simple way to use my development.ini when running my test code? I did not

Pyramid pserve.exe syntax error

雨燕双飞 提交于 2019-12-12 22:23:42
问题 I have created a pyramid application using pcreate, now when I try to run it using pserve with --reload, I get following error SyntaxError: Non-ASCII character '\x90' in file <path>\pserve.exe on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details Interestingly this error shows up only when I use --reload, if I remove reload it starts fine. After debugging, I see another file pserve-script.py at the same location of pserve.exe and this python script is

SQLAlchemy Attempting to Twice Delete Many to Many Secondary Relationship

℡╲_俬逩灬. 提交于 2019-12-12 16:20:16
问题 I have a product model with a many to many relationship to product_categories as described below: class Product(Base): """ The SQLAlchemy declarative model class for a Product object. """ __tablename__ = 'products' id = Column(Integer, primary_key=True) part_number = Column(String(10), nullable=False, unique=True) name = Column(String(80), nullable=False, unique=True) description = Column(String(2000), nullable=False) categories = relationship('Category', secondary=product_categories, backref

How to create a “type-agnostic” SchemaNode in colander

放肆的年华 提交于 2019-12-12 14:11:05
问题 I'm trying to use colander to define a SchemaNode that could have any type. I'd like it to just take whatever was deserialized from the JSON and pass it along. Is that possible? class Foo(colander.MappingSchema): name = colander.SchemaNode(colander.String(), validator=colander.Length(max=80)) value = colander.SchemaNode(??) # should accept int, float, string... 回答1: Those Colander types derive from SchemaType and implement the methods that actually do the serialisation and deserialisation.

using base layout templates in chameleon

怎甘沉沦 提交于 2019-12-12 13:16:40
问题 In the pyramid docs there is a nice tutorial on UX stuff here: http://docs.pylonsproject.org/projects/pyramid_tutorials/en/latest/humans/creatingux/step07/index.html One thing I noticed though is in the tutorial they are setting up and passing around the 'global layout' explicitly in the code (see below). I thought this was unusual and unnecessary because I've always just used the 'load' command as shown in the docs here: http://chameleon.repoze.org/docs/latest/ Is this just a personal

How to turn off MySQL query cache while using SQLAlchemy?

白昼怎懂夜的黑 提交于 2019-12-12 10:42:59
问题 I am working with a fairly large MySQL database via the SQLAlchemy library, and I'd love to turn off MySQL's query caching to debug performance issues on a per-session basis. It's difficult to debug slow queries when repeating them results in much faster execution. With the CLI MySQL client, I can execute SET SESSION query_cache_type = OFF; to achieve the result I'm looking for, and I would like to run this on every SQLAlchemy session (when I'm debugging). But I can't figure out how to

How to commit model instances and remove them from working memory a few at a time

随声附和 提交于 2019-12-12 10:16:39
问题 I have a pyramid view that is used for loading data from a large file into a database. For each line in the file it does a little processing then creates some model instances and adds them to the session. This works fine except when the files are big. For large files the view slowly eats up all my ram until everything effectively grinds to a halt. So my idea is to process each line individually with a function that creates a session, creates the necessary model instances and adds them to the