synch up source code in tests step
1 files deleted
5 files added
10 files modified
New file |
| | |
| | | *.egg |
| | | *.egg-info |
| | | *.pyc |
| | | *$py.class |
| | | *~ |
| | | .coverage |
| | | coverage.xml |
| | | build/ |
| | | dist/ |
| | | .tox/ |
| | | nosetests.xml |
| | | env*/ |
| | | tmp/ |
| | | Data.fs* |
| | | *.sublime-project |
| | | *.sublime-workspace |
| | | .*.sw? |
| | | .sw? |
| | | .DS_Store |
| | | coverage |
| | | test |
| | |
| | | |
| | | env/bin/pip install -e ".[testing]" |
| | | |
| | | - Configure the database. |
| | | - Initialize and upgrade the database using Alembic. |
| | | |
| | | - Generate your first revision. |
| | | |
| | | env/bin/alembic -c development.ini revision --autogenerate -m "init" |
| | | |
| | | - Upgrade to that revision. |
| | | |
| | | env/bin/alembic -c development.ini upgrade head |
| | | |
| | | - Load default data into the database using a script. |
| | | |
| | | env/bin/initialize_tutorial_db development.ini |
| | | |
| | |
| | | # wsgi server configuration |
| | | ### |
| | | |
| | | [alembic] |
| | | # path to migration scripts |
| | | script_location = tutorial/alembic |
| | | file_template = %%(year)d%%(month).2d%%(day).2d_%%(rev)s |
| | | # file_template = %%(rev)s_%%(slug)s |
| | | |
| | | [server:main] |
| | | use = egg:waitress#main |
| | | listen = localhost:6543 |
| | |
| | | # wsgi server configuration |
| | | ### |
| | | |
| | | [alembic] |
| | | # path to migration scripts |
| | | script_location = tutorial/alembic |
| | | file_template = %%(year)d%%(month).2d%%(day).2d_%%(rev)s |
| | | # file_template = %%(rev)s_%%(slug)s |
| | | |
| | | [server:main] |
| | | use = egg:waitress#main |
| | | listen = *:6543 |
| | |
| | | [pytest] |
| | | testpaths = tutorial |
| | | python_files = *.py |
| | | python_files = test*.py |
| | |
| | | CHANGES = f.read() |
| | | |
| | | requires = [ |
| | | 'alembic', |
| | | 'bcrypt', |
| | | 'docutils', |
| | | 'plaster_pastedeploy', |
| | | 'pyramid >= 1.9a', |
| | | 'pyramid >= 1.9', |
| | | 'pyramid_debugtoolbar', |
| | | 'pyramid_jinja2', |
| | | 'pyramid_retry', |
| | |
| | | 'main = tutorial:main', |
| | | ], |
| | | 'console_scripts': [ |
| | | 'initialize_tutorial_db = tutorial.scripts.initializedb:main', |
| | | 'initialize_tutorial_db = tutorial.scripts.initialize_db:main', |
| | | ], |
| | | }, |
| | | ) |
New file |
| | |
| | | """Pyramid bootstrap environment. """ |
| | | from alembic import context |
| | | from pyramid.paster import get_appsettings, setup_logging |
| | | from sqlalchemy import engine_from_config |
| | | |
| | | from tutorial.models.meta import Base |
| | | |
| | | config = context.config |
| | | |
| | | setup_logging(config.config_file_name) |
| | | |
| | | settings = get_appsettings(config.config_file_name) |
| | | target_metadata = Base.metadata |
| | | |
| | | |
| | | def run_migrations_offline(): |
| | | """Run migrations in 'offline' mode. |
| | | |
| | | This configures the context with just a URL |
| | | and not an Engine, though an Engine is acceptable |
| | | here as well. By skipping the Engine creation |
| | | we don't even need a DBAPI to be available. |
| | | |
| | | Calls to context.execute() here emit the given string to the |
| | | script output. |
| | | |
| | | """ |
| | | context.configure(url=settings['sqlalchemy.url']) |
| | | with context.begin_transaction(): |
| | | context.run_migrations() |
| | | |
| | | |
| | | def run_migrations_online(): |
| | | """Run migrations in 'online' mode. |
| | | |
| | | In this scenario we need to create an Engine |
| | | and associate a connection with the context. |
| | | |
| | | """ |
| | | engine = engine_from_config(settings, prefix='sqlalchemy.') |
| | | |
| | | connection = engine.connect() |
| | | context.configure( |
| | | connection=connection, |
| | | target_metadata=target_metadata |
| | | ) |
| | | |
| | | try: |
| | | with context.begin_transaction(): |
| | | context.run_migrations() |
| | | finally: |
| | | connection.close() |
| | | |
| | | |
| | | if context.is_offline_mode(): |
| | | run_migrations_offline() |
| | | else: |
| | | run_migrations_online() |
New file |
| | |
| | | """${message} |
| | | |
| | | Revision ID: ${up_revision} |
| | | Revises: ${down_revision | comma,n} |
| | | Create Date: ${create_date} |
| | | |
| | | """ |
| | | from alembic import op |
| | | import sqlalchemy as sa |
| | | ${imports if imports else ""} |
| | | |
| | | # revision identifiers, used by Alembic. |
| | | revision = ${repr(up_revision)} |
| | | down_revision = ${repr(down_revision)} |
| | | branch_labels = ${repr(branch_labels)} |
| | | depends_on = ${repr(depends_on)} |
| | | |
| | | |
| | | def upgrade(): |
| | | ${upgrades if upgrades else "pass"} |
| | | |
| | | |
| | | def downgrade(): |
| | | ${downgrades if downgrades else "pass"} |
New file |
| | |
| | | Placeholder for alembic versions |
| | |
| | | |
| | | # import or define all models here to ensure they are attached to the |
| | | # Base.metadata prior to any initialization routines |
| | | from .page import Page # noqa |
| | | from .user import User # noqa |
| | | from .page import Page # flake8: noqa |
| | | from .user import User # flake8: noqa |
| | | |
| | | # run configure_mappers after defining all of the models to ensure |
| | | # all relationships can be setup |
| | |
| | | Everyone, |
| | | ) |
| | | |
| | | from .models import Page |
| | | from . import models |
| | | |
| | | def includeme(config): |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | |
| | | |
| | | def new_page_factory(request): |
| | | pagename = request.matchdict['pagename'] |
| | | if request.dbsession.query(Page).filter_by(name=pagename).count() > 0: |
| | | if request.dbsession.query(models.Page).filter_by(name=pagename).count() > 0: |
| | | next_url = request.route_url('edit_page', pagename=pagename) |
| | | raise HTTPFound(location=next_url) |
| | | return NewPage(pagename) |
| | |
| | | |
| | | def page_factory(request): |
| | | pagename = request.matchdict['pagename'] |
| | | page = request.dbsession.query(Page).filter_by(name=pagename).first() |
| | | page = request.dbsession.query(models.Page).filter_by(name=pagename).first() |
| | | if page is None: |
| | | raise HTTPNotFound |
| | | return PageResource(page) |
New file |
| | |
| | | import os |
| | | import sys |
| | | |
| | | from pyramid.paster import bootstrap, setup_logging |
| | | from sqlalchemy.exc import OperationalError |
| | | |
| | | from .. import models |
| | | |
| | | |
| | | def setup_models(dbsession): |
| | | editor = models.User(name='editor', role='editor') |
| | | editor.set_password('editor') |
| | | dbsession.add(editor) |
| | | |
| | | basic = models.User(name='basic', role='basic') |
| | | basic.set_password('basic') |
| | | dbsession.add(basic) |
| | | |
| | | page = models.Page( |
| | | name='FrontPage', |
| | | creator=editor, |
| | | data='This is the front page', |
| | | ) |
| | | dbsession.add(page) |
| | | |
| | | |
| | | 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) |
| | | env = bootstrap(config_uri) |
| | | |
| | | try: |
| | | with env['request'].tm: |
| | | dbsession = env['request'].dbsession |
| | | setup_models(dbsession) |
| | | except OperationalError: |
| | | print(''' |
| | | Pyramid is having a problem using your SQL database. The problem |
| | | might be caused by one of the following things: |
| | | |
| | | 1. You may need to initialize your database tables with `alembic`. |
| | | Check your README.txt for description 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. |
| | | ''') |
| | |
| | | Everyone, |
| | | ) |
| | | |
| | | from .models import User |
| | | from . import models |
| | | |
| | | |
| | | class MyAuthenticationPolicy(AuthTktAuthenticationPolicy): |
| | |
| | | def get_user(request): |
| | | user_id = request.unauthenticated_userid |
| | | if user_id is not None: |
| | | user = request.dbsession.query(User).get(user_id) |
| | | user = request.dbsession.query(models.User).get(user_id) |
| | | return user |
| | | |
| | | def includeme(config): |
| | |
| | | <!-- Custom styles for this scaffold --> |
| | | <link href="{{request.static_url('tutorial:static/theme.css')}}" rel="stylesheet"> |
| | | |
| | | <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --> |
| | | <!-- HTML5 shiv and Respond.js IE8 support of HTML5 elements and media queries --> |
| | | <!--[if lt IE 9]> |
| | | <script src="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js" integrity="sha384-0s5Pv64cNZJieYFkXYOTId2HMA2Lfb6q2nAcx2n0RTLUnCAoTTsS0nKEO27XyKcY" crossorigin="anonymous"></script> |
| | | <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js" integrity="sha384-ZoaMbDF+4LeFxg6WdScQ9nnR1QC2MIRxA1O9KWEXQwns1G8UNyIEZIQidzb0T1fo" crossorigin="anonymous"></script> |
| | |
| | | <div class="container"> |
| | | <div class="row"> |
| | | <div class="col-md-2"> |
| | | <img class="logo img-responsive" src="{{request.static_url('tutorial:static/pyramid.png')}}" alt="pyramid web framework"> |
| | | <img class="logo img-responsive" src="{{request.static_url('tutorial:static/pyramid.png') }}" alt="pyramid web framework"> |
| | | </div> |
| | | <div class="col-md-10"> |
| | | <div class="content"> |
| | |
| | | from pyramid.httpexceptions import HTTPFound |
| | | from pyramid.view import view_config |
| | | |
| | | from ..models import Page |
| | | from .. import models |
| | | |
| | | # regular expression used to find WikiWords |
| | | wikiwords = re.compile(r"\b([A-Z]\w+[A-Z]+\w+)") |
| | |
| | | |
| | | def add_link(match): |
| | | word = match.group(1) |
| | | exists = request.dbsession.query(Page).filter_by(name=word).all() |
| | | exists = request.dbsession.query(models.Page).filter_by(name=word).all() |
| | | if exists: |
| | | view_url = request.route_url('view_page', pagename=word) |
| | | return '<a href="%s">%s</a>' % (view_url, escape(word)) |
| | |
| | | pagename = request.context.pagename |
| | | if 'form.submitted' in request.params: |
| | | body = request.params['body'] |
| | | page = Page(name=pagename, data=body) |
| | | page = models.Page(name=pagename, data=body) |
| | | page.creator = request.user |
| | | request.dbsession.add(page) |
| | | next_url = request.route_url('view_page', pagename=pagename) |