pyramid

onupdate based on another field with sqlalchemy declarative base

若如初见. 提交于 2020-01-24 13:33:06
问题 I use sqlalchemy with the pyramid framework, and i want to link a person to his geographical department using his postcode. So i try to use the onupdate argument when defining the department_id column define the department_id. see fallowing code: from datetime import date from emailing.models import Base, DBSession from sqlalchemy import Column, Integer, Unicode, Text, DateTime, Sequence, Boolean, Date, UnicodeText, UniqueConstraint, Table, ForeignKey from sqlalchemy.orm import scoped_session

onupdate based on another field with sqlalchemy declarative base

天涯浪子 提交于 2020-01-24 13:33:05
问题 I use sqlalchemy with the pyramid framework, and i want to link a person to his geographical department using his postcode. So i try to use the onupdate argument when defining the department_id column define the department_id. see fallowing code: from datetime import date from emailing.models import Base, DBSession from sqlalchemy import Column, Integer, Unicode, Text, DateTime, Sequence, Boolean, Date, UnicodeText, UniqueConstraint, Table, ForeignKey from sqlalchemy.orm import scoped_session

SQLAlchemy won't update my database

最后都变了- 提交于 2020-01-21 01:34:54
问题 I'm making a Pyramid app using SQLAlchemy-0.7.8. I'm using 64bit Python3.2. The question is, why does the following function not commit anything to the database? def create_card(sText,sCard): """ create a wildcard instance if all is well (ie,sCard match in sText) return oCard, dCard otherwise return False,False """ oMatch = re.search(sCard,sText) if oMatch: oCard = WildCard() #set up some stuff about the WildCard DBSession.add(oCard) DBSession.flush() dCard = { 'id' : oCard.id, 'span' :

Pyramid Replacing Double Forward-Slash in URL Matchdict

半城伤御伤魂 提交于 2020-01-20 08:42:28
问题 Essentially, I'm just building an API redirection route inside of Pyramid to process cross-domain AJAX requests without using JSONP. I've added a route, like so: config.add_route("api","/api/{url:.*}") with which I want to capture URLs like so: http://domain.com/api/http://location.of/other/api However, when grabbing the captured URL suffix out of the Request matchdict, I get the following: http:/location.of/other/api I'm guessing some escaping has been done during URL processing/matching?

How can I separate this into two strings?

泪湿孤枕 提交于 2020-01-17 04:47:20
问题 I am new to Python, I am not sure what should I be looking for but I assure you I have done my research and still came up with a rather ugly 20 lines long block of code for this simple issue. I am processing a traversal URL with my app based on Pyramid framework. Now, the URL can be these: (url = None) url = "" url = "/" url = "/block_1" url = "/block_1/" url = "/block_1/block_2" url = "/block_1/block_2/" The url can contain nothing. In this case, I want my function to return False, None, or

How to do a while ( x < y ) in jinja2

醉酒当歌 提交于 2020-01-13 09:16:10
问题 How should I do a while ( x < y ) in jinja2? I've seen the jinja2 docs, it seems like they only support for loop for a declared variable of array and while() is not supported at all. 回答1: I think your closest alternative with Jinja2 would be to use a for with range : {% range number from 3 to 6 %} {{ number }} (...) {% endrange %} And you can pass the variables from your program to use them in the loop. 来源: https://stackoverflow.com/questions/13668025/how-to-do-a-while-x-y-in-jinja2

SQLAlchemy StaleDataError on deleting items inserted via ORM sqlalchemy.orm.exc.StaleDataError

别说谁变了你拦得住时间么 提交于 2020-01-13 07:54:08
问题 I'm having an issue where I get a an error such as this one: "MyPyramidApplication Error"<class 'sqlalchemy.orm.exc.StaleDataError'>: DELETE statement on table 'page_view' expected to delete 6 row(s); Only 0 were matched. So, I have a good idea what is causing the issue but I have been unable to solve it. I have a page_view model, that has a foreign key on page_id and a user_id . Here's what the model looks like: page_view_table = sa.Table( 'page_view', metadata, sa.Column('id', sa.Integer,

Creating databases in SQLAlchemy tests with PostgreSQL

ぐ巨炮叔叔 提交于 2020-01-12 05:24:29
问题 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

Creating databases in SQLAlchemy tests with PostgreSQL

拜拜、爱过 提交于 2020-01-12 05:24:06
问题 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

Trying to catch integrity error with SQLAlchemy

给你一囗甜甜゛ 提交于 2020-01-10 17:43:23
问题 I'm having problems with trying to catch an error. I'm using Pyramid/SQLAlchemy and made a sign up form with email as the primary key. The problem is when a duplicate email is entered it raises a IntegrityError, so I'm trying to catch that error and provide a message but no matter what I do I can't catch it, the error keeps appearing. try: new_user = Users(email, firstname, lastname, password) DBSession.add(new_user) return HTTPFound(location = request.route_url('new')) except IntegrityError: