Skip to content
Browse files

Merge pull request #9 from virhilo/master

Some small updates for lastest pyramid
  • Loading branch information...
2 parents 5ad8e92 + f87197d commit be1d81bdce018a4c66904fd7170ba660897f878d @mcdonc mcdonc committed Mar 24, 2012
Showing with 43 additions and 13 deletions.
  1. +5 −0 .gitignore
  2. +3 −1 README.rst
  3. +4 −3 setup.py
  4. +2 −2 shootout/__init__.py
  5. +2 −7 shootout/models.py
  6. +1 −0 shootout/scripts/__init__.py
  7. +26 −0 shootout/scripts/initializedb.py
View
5 .gitignore
@@ -9,6 +9,11 @@
*.txt.py
*.swp
.coverage
+.project
+.pydevproject
+shootout/.project
+shootout/.pydevproject
+shootout/.settings/
env26/
env24/
env27/
View
4 README.rst
@@ -36,5 +36,7 @@ Installing and Running
- python setup.py develop
-- paster serve development.ini
+- initialize_shootout_db
+
+- pserve development.ini
View
7 setup.py
@@ -9,7 +9,7 @@
requires = [
'setuptools',
- 'pyramid>=1.2',
+ 'pyramid>=1.3',
'SQLAlchemy',
'transaction',
'pyramid_tm',
@@ -27,7 +27,7 @@
raise RuntimeError('This application requires Python 2.6+')
setup(name='shootout',
- version='0.2.2',
+ version='0.2.3',
description='A generic idea discussion and rating app (Pyramid sample)',
long_description=README + '\n\n' + CHANGES,
classifiers=[
@@ -53,7 +53,8 @@
entry_points="""\
[paste.app_factory]
main = shootout:main
+ [console_scripts]
+ initialize_shootout_db = shootout.scripts.initializedb:main
""",
- paster_plugins=['pyramid'],
)
View
4 shootout/__init__.py
@@ -6,14 +6,14 @@
from sqlalchemy import engine_from_config
-from shootout.models import initialize_sql
+from shootout.models import DBSession
def main(global_config, **settings): # pragma: no cover
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
- initialize_sql(engine)
+ DBSession.configure(bind=engine)
session_factory = session_factory_from_settings(settings)
View
9 shootout/models.py
@@ -176,7 +176,8 @@ def get_by_tagname(cls, tag_name, with_joinedload=True):
@classmethod
def ideas_bunch(cls, order_by, how_many=10, with_joinedload=True):
query = cls.get_query(with_joinedload).join('author')
- return query.filter(cls.target == None).order_by(order_by)[:how_many]
+ query = query.filter(cls.target == None).order_by(order_by)
+ return query.limit(how_many)
def user_voted(self, username):
return bool(self.voted_users.filter_by(username=username).first())
@@ -203,9 +204,3 @@ class RootFactory(object):
def __init__(self, request):
pass # pragma: no cover
-
-def initialize_sql(engine): # pragma: no cover
- DBSession.configure(bind=engine)
- Base.metadata.bind = engine
- Base.metadata.create_all(engine)
-
View
1 shootout/scripts/__init__.py
@@ -0,0 +1 @@
+#package
View
26 shootout/scripts/initializedb.py
@@ -0,0 +1,26 @@
+import os
+import sys
+import transaction
+
+from sqlalchemy import engine_from_config
+
+from pyramid.paster import get_appsettings, setup_logging
+
+from shootout.models import DBSession, Base
+
+def usage(argv):
+ cmd = os.path.basename(argv[0])
+ print('usage: %s <config_uri>\n'
+ '(example: "%s development.ini")' % (cmd, cmd))
+ sys.exit(1)
+
+def main(argv=sys.argv):
+ if len(argv) != 2:
+ usage(argv)
+ config_uri = argv[1]
+ setup_logging(config_uri)
+ settings = get_appsettings(config_uri)
+ engine = engine_from_config(settings, 'sqlalchemy.')
+ DBSession.configure(bind=engine)
+ Base.metadata.create_all(engine)
+

0 comments on commit be1d81b

Please sign in to comment.
Something went wrong with that request. Please try again.