pyramid

using Mysql and SqlAlchemy in Pyramid Framework

北城余情 提交于 2019-12-06 05:35:33
Pyramid Framework comes with a sample tutorial of sql alchemy that uses sqlite. The problem is that i want to use mysql so i change this sqlalchemy.url = sqlite:///%(here)s/tutorial.db Into this sqlalchemy.url = mysql://root:22password@localhost/alchemy when i try to run ../bin/pserve development.ini --reload It gives me the following error File "build/bdist.linux-i686/egg/sqlalchemy/connectors/mysqldb.py", line 52, in dbapi ImportError: No module named MySQLdb I understand that i should include the dependecies of my app in setup.py but i don't know what to include right now some help please

How to generate URL to view when using Traversal?

喜欢而已 提交于 2019-12-06 05:16:23
问题 When URL Dispatch is used, we can easily generate a URL to a view because every view has a distinct route_name like: login.py: @view_config(route_name='login') index.pt: <a href="${request.route_url('login')}">Login</a> But how to do this in traversal? Since there is no instance of resources 'Login' available, I don't know how to generate URL to view login. 回答1: In traversal you are required to know the structure of your tree, and you must be able to load context objects on demand. The URLs

How do I get the number of rows affected with SQL Alchemy?

怎甘沉沦 提交于 2019-12-06 04:22:36
问题 How do I get the number of rows affected for an update statement with sqlalchemy? (I am using mysql and python/pyramid): from sqlalchemy.engine.base import ResultProxy @classmethod def myupdate(cls, id, myvalue): DBSession.query(cls).filter(cls.id == id).update({'mycolumn': myvalue}) if ResultProxy.rowcount == 1: return True else: return False Note: I saw this post but according to the docs: "The ‘rowcount’ reports the number of rows matched by the WHERE criterion of an UPDATE or DELETE

passing **settings info to unittest from nose

我怕爱的太早我们不能终老 提交于 2019-12-06 04:18:36
问题 I'm running my unit tests using nose. I have .ini files such as production.ini, development.ini, local.ini. Finally, I have a test.ini file which looks like: [app:main] use = config:local.ini # Add additional test specific configuration options as necessary. sqlalchemy.url = sqlite:///%(here)s/tests.db In my test class I want to setup the database as I would in my app server code. Something like: engine = engine_from_config(settings) initialize_sql(engine) dbfixture = SQLAlchemyFixture( env

Pyramid and FormAlchemy admin interface

ⅰ亾dé卋堺 提交于 2019-12-06 03:25:17
问题 I have a pyramid project using the formalchemy admin interface. I added the basic ACL authentication and the pyramid_formalchemy plugin always denys even though I am authenticated. Any thoughts on how only allow authenticated users to use the pyramid_formalchemy admin interface? The authorization policy was add like this: authn_policy = AuthTktAuthenticationPolicy('MYhiddenSECRET', callback=groupfinder) authz_policy = ACLAuthorizationPolicy() config = Configurator( settings=settings, root

Pyramid view class inheritance with @view_defaults and @view_config decorators

妖精的绣舞 提交于 2019-12-06 03:17:53
问题 I have written up a view class that has multiple @view_config's with predicates set for a single route. I then have a subclass that overwrites a couple of the sub-functions, which affects how the view is made. Below is something similar, but with simplified code. When visiting the view_a route, everything works fine. When visiting the view_b route, it shows "404 Not Found The resource could not be found". It seems the @view_configs aren't 'inherited' and linked to the new @view_default. Is

Pyramid with memcached: how to make it work? Error - MissingCacheParameter: url is required

梦想与她 提交于 2019-12-06 03:02:45
I have site on Pyramid framework and want to cache with memcached. For testing reasons I've used memory type caching and everything was OK. I'm using pyramid_beaker package. Here is my previous code (working version). In .ini file cache.regions = day, hour, minute, second cache.type = memory cache.second.expire = 1 cache.minute.expire = 60 cache.hour.expire = 3600 cache.day.expire = 86400 In views.py: from beaker.cache import cache_region @cache_region('hour') def get_popular_users(): #some code to work with db return some_dict The only .ini settings I've found in docs were about working with

Is there a way to share common configuration using Paste Deploy?

别等时光非礼了梦想. 提交于 2019-12-06 02:22:05
This is a pretty simple idea conceptually. In terms of specifics, I'm working with a pretty generic Kotti installation, where I'm customizing some pages / templates. Much of my configuration is shared between a production and development server. Currently, these settings are included in two separate ini files. It would be nice to DRY this configuration, with common settings in one place. I'm quite open to this happening in python or an an ini file / section (or perhaps a third, yet-to-be-considered place). I think it's equivalent to use a [DEFAULT] section, or pass dictionaries to loadapp via

Dynamic user based authorization in Pyramid

雨燕双飞 提交于 2019-12-06 01:37:33
问题 I'm following security guidelines found on Pyramid docs along with wiki tutorial Adding Authorization Now I need to add restrictions based un single user rather than groups. Let's say for example that, if any blog editor can have permission to review all comments, only post author can edit the post itself . For the first task I will have in my Root ACL like this: __acl__ = [ (Allow, Everyone, 'view'), (Allow, Authenticated, 'view_profile'), (Allow, 'groups:editor', 'edit_comment') ] but whay

File writing permission denied in mod_wsgi deployed app

吃可爱长大的小学妹 提交于 2019-12-06 00:59:01
问题 I'm trying to deploy a Pyramid app using mod_wsgi on Apache. I get IOError: [Errno 13] Permission denied on templates folder, where mako caches his templates, even if I grant write permissions to anybody . If I remove template caching from my ini file the site runs flawlessly. I also tried running Apache as the user owning the folder instead of www-data with no luck. Any clue? 回答1: It's an Apache permission issue, I had to change owner of folder to www-data user and set permissions to 775