Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
P
Pyramid CRUD
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jørn Åne de Jong
Pyramid CRUD
Commits
91ca258f
Commit
91ca258f
authored
Nov 14, 2014
by
yorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Install pyramid_crud
parent
cd29d00a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
24 deletions
+23
-24
crud/__init__.py
crud/__init__.py
+14
-1
crud/views.py
crud/views.py
+8
-23
development.ini
development.ini
+1
-0
No files found.
crud/__init__.py
View file @
91ca258f
from
pyramid.config
import
Configurator
from
pyramid.config
import
Configurator
from
sqlalchemy
import
engine_from_config
from
sqlalchemy
import
engine_from_config
from
pyramid.session
import
SignedCookieSessionFactory
from
pyramid.events
import
subscriber
,
NewRequest
from
.models
import
(
from
.models
import
(
DBSession
,
DBSession
,
Base
,
Base
,
)
)
COOKIE_SECRET
=
'ThV1DNsNLgU7viLKmwe3Gg8qTcnbGuaN'
@
subscriber
(
NewRequest
)
def
new_request
(
event
):
request
=
event
.
request
request
.
dbsession
=
DBSession
def
main
(
global_config
,
**
settings
):
def
main
(
global_config
,
**
settings
):
""" This function returns a Pyramid WSGI application.
""" This function returns a Pyramid WSGI application.
"""
"""
engine
=
engine_from_config
(
settings
,
'sqlalchemy.'
)
engine
=
engine_from_config
(
settings
,
'sqlalchemy.'
)
DBSession
.
configure
(
bind
=
engine
)
DBSession
.
configure
(
bind
=
engine
)
my_session_factory
=
SignedCookieSessionFactory
(
COOKIE_SECRET
,
cookie_name
=
'crud'
,
timeout
=
28800
)
Base
.
metadata
.
bind
=
engine
Base
.
metadata
.
bind
=
engine
config
=
Configurator
(
settings
=
settings
)
config
=
Configurator
(
settings
=
settings
,
session_factory
=
my_session_factory
)
config
.
include
(
'pyramid_chameleon'
)
config
.
include
(
'pyramid_chameleon'
)
config
.
add_static_view
(
'static'
,
'static'
,
cache_max_age
=
3600
)
config
.
add_static_view
(
'static'
,
'static'
,
cache_max_age
=
3600
)
config
.
add_route
(
'home'
,
'/'
)
config
.
add_route
(
'home'
,
'/'
)
...
...
crud/views.py
View file @
91ca258f
from
pyramid.response
import
Response
from
pyramid.response
import
Response
from
pyramid.view
import
view_config
from
pyramid.view
import
view_config
from
pyramid_crud.forms
import
CSRFModelForm
from
pyramid_crud.views
import
CRUDView
from
sqlalchemy.exc
import
DBAPIError
from
sqlalchemy.exc
import
DBAPIError
...
@@ -9,28 +11,11 @@ from .models import (
...
@@ -9,28 +11,11 @@ from .models import (
)
)
@
view_config
(
route_name
=
'home'
,
renderer
=
'templates/mytemplate.pt'
)
class
MyModelForm
(
CSRFModelForm
):
def
my_view
(
request
):
class
Meta
:
try
:
model
=
MyModel
one
=
DBSession
.
query
(
MyModel
).
filter
(
MyModel
.
name
==
'one'
).
first
()
except
DBAPIError
:
return
Response
(
conn_err_msg
,
content_type
=
'text/plain'
,
status_int
=
500
)
return
{
'one'
:
one
,
'project'
:
'crud'
}
class
MyModelView
(
CRUDView
):
conn_err_msg
=
"""
\
Form
=
MyModelForm
Pyramid is having a problem using your SQL database. The problem
url_path
=
'/mymodel'
might be caused by one of the following things:
1. You may need to run the "initialize_crud_db" script
to initialize your database tables. Check your virtual
environment's "bin" directory for this script and try to run it.
2. Your database server may not be running. Check that the
database server referred to by the "sqlalchemy.url" setting in
your "development.ini" file is running.
After you fix the problem, please restart the Pyramid application to
try it again.
"""
development.ini
View file @
91ca258f
...
@@ -14,6 +14,7 @@ pyramid.default_locale_name = en
...
@@ -14,6 +14,7 @@ pyramid.default_locale_name = en
pyramid.includes
=
pyramid.includes
=
pyramid_debugtoolbar
pyramid_debugtoolbar
pyramid_tm
pyramid_tm
pyramid_crud
sqlalchemy.url
=
sqlite:///%(here)s/crud.sqlite
sqlalchemy.url
=
sqlite:///%(here)s/crud.sqlite
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment