Skip to content

Commit edab595

Browse files
committed
Initial commit, pyramid alchemy scaffold
0 parents  commit edab595

17 files changed

+598
-0
lines changed

CHANGES.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
0.0
2+
---
3+
4+
- Initial version

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include *.txt *.ini *.cfg *.rst
2+
recursive-include tilaushallinta *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml

README.txt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tilaushallinta README
2+
==================
3+
4+
Getting Started
5+
---------------
6+
7+
- cd <directory containing this file>
8+
9+
- $VENV/bin/python setup.py develop
10+
11+
- $VENV/bin/initialize_tilaushallinta_db development.ini
12+
13+
- $VENV/bin/pserve development.ini
14+

development.ini

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
###
2+
# app configuration
3+
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
4+
###
5+
6+
[app:main]
7+
use = egg:tilaushallinta
8+
9+
pyramid.reload_templates = true
10+
pyramid.debug_authorization = false
11+
pyramid.debug_notfound = false
12+
pyramid.debug_routematch = false
13+
pyramid.default_locale_name = en
14+
pyramid.includes =
15+
pyramid_debugtoolbar
16+
pyramid_tm
17+
18+
sqlalchemy.url = sqlite:///%(here)s/tilaushallinta.sqlite
19+
20+
# By default, the toolbar only appears for clients from IP addresses
21+
# '127.0.0.1' and '::1'.
22+
# debugtoolbar.hosts = 127.0.0.1 ::1
23+
24+
###
25+
# wsgi server configuration
26+
###
27+
28+
[server:main]
29+
use = egg:waitress#main
30+
host = 0.0.0.0
31+
port = 6543
32+
33+
###
34+
# logging configuration
35+
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
36+
###
37+
38+
[loggers]
39+
keys = root, tilaushallinta, sqlalchemy
40+
41+
[handlers]
42+
keys = console
43+
44+
[formatters]
45+
keys = generic
46+
47+
[logger_root]
48+
level = INFO
49+
handlers = console
50+
51+
[logger_tilaushallinta]
52+
level = DEBUG
53+
handlers =
54+
qualname = tilaushallinta
55+
56+
[logger_sqlalchemy]
57+
level = INFO
58+
handlers =
59+
qualname = sqlalchemy.engine
60+
# "level = INFO" logs SQL queries.
61+
# "level = DEBUG" logs SQL queries and results.
62+
# "level = WARN" logs neither. (Recommended for production systems.)
63+
64+
[handler_console]
65+
class = StreamHandler
66+
args = (sys.stderr,)
67+
level = NOTSET
68+
formatter = generic
69+
70+
[formatter_generic]
71+
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

production.ini

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
###
2+
# app configuration
3+
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
4+
###
5+
6+
[app:main]
7+
use = egg:tilaushallinta
8+
9+
pyramid.reload_templates = false
10+
pyramid.debug_authorization = false
11+
pyramid.debug_notfound = false
12+
pyramid.debug_routematch = false
13+
pyramid.default_locale_name = en
14+
pyramid.includes =
15+
pyramid_tm
16+
17+
sqlalchemy.url = sqlite:///%(here)s/tilaushallinta.sqlite
18+
19+
[server:main]
20+
use = egg:waitress#main
21+
host = 0.0.0.0
22+
port = 6543
23+
24+
###
25+
# logging configuration
26+
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
27+
###
28+
29+
[loggers]
30+
keys = root, tilaushallinta, sqlalchemy
31+
32+
[handlers]
33+
keys = console
34+
35+
[formatters]
36+
keys = generic
37+
38+
[logger_root]
39+
level = WARN
40+
handlers = console
41+
42+
[logger_tilaushallinta]
43+
level = WARN
44+
handlers =
45+
qualname = tilaushallinta
46+
47+
[logger_sqlalchemy]
48+
level = WARN
49+
handlers =
50+
qualname = sqlalchemy.engine
51+
# "level = INFO" logs SQL queries.
52+
# "level = DEBUG" logs SQL queries and results.
53+
# "level = WARN" logs neither. (Recommended for production systems.)
54+
55+
[handler_console]
56+
class = StreamHandler
57+
args = (sys.stderr,)
58+
level = NOTSET
59+
formatter = generic
60+
61+
[formatter_generic]
62+
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

setup.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
3+
from setuptools import setup, find_packages
4+
5+
here = os.path.abspath(os.path.dirname(__file__))
6+
with open(os.path.join(here, 'README.txt')) as f:
7+
README = f.read()
8+
with open(os.path.join(here, 'CHANGES.txt')) as f:
9+
CHANGES = f.read()
10+
11+
requires = [
12+
'pyramid',
13+
'pyramid_chameleon',
14+
'pyramid_debugtoolbar',
15+
'pyramid_tm',
16+
'SQLAlchemy',
17+
'transaction',
18+
'zope.sqlalchemy',
19+
'waitress',
20+
]
21+
22+
setup(name='tilaushallinta',
23+
version='0.0',
24+
description='tilaushallinta',
25+
long_description=README + '\n\n' + CHANGES,
26+
classifiers=[
27+
"Programming Language :: Python",
28+
"Framework :: Pyramid",
29+
"Topic :: Internet :: WWW/HTTP",
30+
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
31+
],
32+
author='',
33+
author_email='',
34+
url='',
35+
keywords='web wsgi bfg pylons pyramid',
36+
packages=find_packages(),
37+
include_package_data=True,
38+
zip_safe=False,
39+
test_suite='tilaushallinta',
40+
install_requires=requires,
41+
entry_points="""\
42+
[paste.app_factory]
43+
main = tilaushallinta:main
44+
[console_scripts]
45+
initialize_tilaushallinta_db = tilaushallinta.scripts.initializedb:main
46+
""",
47+
)

tilaushallinta/__init__.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from pyramid.config import Configurator
2+
from sqlalchemy import engine_from_config
3+
4+
from .models import (
5+
DBSession,
6+
Base,
7+
)
8+
9+
10+
def main(global_config, **settings):
11+
""" This function returns a Pyramid WSGI application.
12+
"""
13+
engine = engine_from_config(settings, 'sqlalchemy.')
14+
DBSession.configure(bind=engine)
15+
Base.metadata.bind = engine
16+
config = Configurator(settings=settings)
17+
config.include('pyramid_chameleon')
18+
config.add_static_view('static', 'static', cache_max_age=3600)
19+
config.add_route('home', '/')
20+
config.scan()
21+
return config.make_wsgi_app()

tilaushallinta/models.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from sqlalchemy import (
2+
Column,
3+
Index,
4+
Integer,
5+
Text,
6+
)
7+
8+
from sqlalchemy.ext.declarative import declarative_base
9+
10+
from sqlalchemy.orm import (
11+
scoped_session,
12+
sessionmaker,
13+
)
14+
15+
from zope.sqlalchemy import ZopeTransactionExtension
16+
17+
DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
18+
Base = declarative_base()
19+
20+
21+
class MyModel(Base):
22+
__tablename__ = 'models'
23+
id = Column(Integer, primary_key=True)
24+
name = Column(Text)
25+
value = Column(Integer)
26+
27+
Index('my_index', MyModel.name, unique=True, mysql_length=255)

tilaushallinta/scripts/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# package
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import os
2+
import sys
3+
import transaction
4+
5+
from sqlalchemy import engine_from_config
6+
7+
from pyramid.paster import (
8+
get_appsettings,
9+
setup_logging,
10+
)
11+
12+
from pyramid.scripts.common import parse_vars
13+
14+
from ..models import (
15+
DBSession,
16+
MyModel,
17+
Base,
18+
)
19+
20+
21+
def usage(argv):
22+
cmd = os.path.basename(argv[0])
23+
print('usage: %s <config_uri> [var=value]\n'
24+
'(example: "%s development.ini")' % (cmd, cmd))
25+
sys.exit(1)
26+
27+
28+
def main(argv=sys.argv):
29+
if len(argv) < 2:
30+
usage(argv)
31+
config_uri = argv[1]
32+
options = parse_vars(argv[2:])
33+
setup_logging(config_uri)
34+
settings = get_appsettings(config_uri, options=options)
35+
engine = engine_from_config(settings, 'sqlalchemy.')
36+
DBSession.configure(bind=engine)
37+
Base.metadata.create_all(engine)
38+
with transaction.manager:
39+
model = MyModel(name='one', value=1)
40+
DBSession.add(model)
1.29 KB
Loading

tilaushallinta/static/pyramid.png

12.6 KB
Loading

0 commit comments

Comments
 (0)