pyramid

ArgumentError: relationship expects a class or mapper argument

ぐ巨炮叔叔 提交于 2019-12-03 09:43:41
I am getting this strange error, and I'm saying strange because I made a change to an unrelated table. I am trying to query my tDevice table which looks like this: class TDevice(Base): __tablename__ = 'tDevice' ixDevice = Column(Integer, primary_key=True) ixDeviceType = Column(Integer, ForeignKey('tDeviceType.ixDeviceType'), nullable=False) ixSubStation = Column(Integer, ForeignKey('tSubStation.ixSubStation'), nullable=False) ixModel = Column(Integer, ForeignKey('tModel.ixModel'), nullable=True) ixParentDevice = Column(Integer, ForeignKey('tDevice.ixDevice'), nullable=True) sDeviceName =

The best way to store a python list to a database?

核能气质少年 提交于 2019-12-03 08:55:48
What would be the best way of storing a python list of numbers (such as [4, 7, 10, 39, 91]) to a database? I am using the Pyramid framework with SQLAlchemy to communicate to a database. Thanks! Well conceptually you can store a list as a bunch of rows in a table using a one-to-many relation, or you can focus on how to store a list in a particular database backend. For example postgres can store an array in a particular cell using the sqlalchemy.dialects.postgres.ARRAY data type which can serialize a python array into a postgres array column. You can use json to save your arrays in db as stings

How can I redirect after POST in Pyramid?

拥有回忆 提交于 2019-12-03 08:40:53
问题 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)

Calling another view in Pyramid

北城以北 提交于 2019-12-03 08:11:08
问题 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:

Want to prompt browser to save csv

丶灬走出姿态 提交于 2019-12-03 08:10:06
Want to prompt browser to save csv using pyramid.response.Response searched for clues and found here's a link Django answer but i can't use it with Pyramid wsgi my code looks like this: from pyramid.response import Response def get_list_names_emails(request): session, env = request.db, request.client_env response = Response(content_type='text/csv') output = StringIO() writer = csv.writer(output) writer.writerow(['SomeName', 'SomeEmail', 'CompanyName]) csv_output = output.getvalue() return csv_output Marco Mariani As a cleaner way to do that, you can register a renderer. In your configuration

Setup uWSGI as webserver with pyramid (no NGINX)

点点圈 提交于 2019-12-03 08:01:38
Most of the available tutorials show how to set up uWSGI with an upstream HTTP server (like NGINX). But uWSGI alone can act beautifully as router/proxy/load-balancer - refer this For my project, I didn't want to setup NGINX at this moment so I started off exploring the option of serving webpages through uWSGI. The answer here shows how to set it up with Pyramid . Dev Maha I am using pyramid_mongodb scaffold, which I have modified to get it working on python3. See here for details. Assuming that we have a Pyramid project (created with pcreate -s pyramid_mongodb MyProject ). Here are the uWSGI

SelectField in wtforms and added <option> via javascript

*爱你&永不变心* 提交于 2019-12-03 07:30:11
I'm currently work on some project in pyramid and have problem with wtforms SelectField. I have a 3 SelectField fields: car_make (e.g., "audi") car_model (e.g., "audi 80") car_version (e.g., "AUDI 80 B4"). The car_make choices I can load in the view. The choices for rest of SelectFields (car_model, car_version) I will load on the client side via AJAX/javascript (I can choose car_model when car_make is selected and so on). The problem is that when I submit the form, car_model and car_version raise 'Not valid choice' because (in SelectField.pre_validation line 431) self.choices is empty. How can

Creating databases in SQLAlchemy tests with PostgreSQL

一曲冷凌霜 提交于 2019-12-03 07:15:17
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 Database is built once per test run - not on every test setUp() as this is too slow for a complex application Database tables are (re)created as they would be created in production (e.g. run migrations from Alembic). Any unclean databases are destroyed at the start of the test run. It is possible to choose a custom test runner á la py.test if a specific features outside the standard library unittest

Using pyramid authentication with pyramid

懵懂的女人 提交于 2019-12-03 06:13:50
问题 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=

Determine the user language in Pyramid

风格不统一 提交于 2019-12-03 05:38:55
I want to make internationalization for my project. I followed how it is described in official documentation, but localization still doesn't work. Here is how I try get user locale: def get_locale_name(request): """ Return the :term:`locale name` associated with the current request (possibly cached).""" locale_name = getattr(request, 'locale_name', None) if locale_name is None: locale_name = negotiate_locale_name(request) request.locale_name = locale_name return locale_name But request doesn't have attr "local_name", but it has "Accept-Language" and so when function get_local_name doesn't find