From d4bd291fd5ca51bbbeec487f2011476706a5952f Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Fri, 9 Aug 2013 11:37:48 -0400 Subject: Lots of updates, move more code out of code-blocks into working package code. About to tackle cool Pyramid stuff. --- docs/getting_started/databases.rst | 17 + docs/getting_started/index.rst | 7 + docs/getting_started/pserve.rst | 18 + docs/getting_started/quick_glance.rst | 306 ++++++++--------- .../quick_glance/hello_sqlalchemy/CHANGES.txt | 4 - .../quick_glance/hello_sqlalchemy/MANIFEST.in | 2 - .../quick_glance/hello_sqlalchemy/README.txt | 14 - .../quick_glance/hello_sqlalchemy/development.ini | 71 ---- .../hello_sqlalchemy/hello_sqlalchemy.sqlite | Bin 3072 -> 0 bytes .../hello_sqlalchemy/hello_sqlalchemy/__init__.py | 20 -- .../hello_sqlalchemy/hello_sqlalchemy/models.py | 28 -- .../hello_sqlalchemy/scripts/__init__.py | 1 - .../hello_sqlalchemy/scripts/initializedb.py | 37 -- .../hello_sqlalchemy/static/favicon.ico | Bin 1406 -> 0 bytes .../hello_sqlalchemy/static/footerbg.png | Bin 333 -> 0 bytes .../hello_sqlalchemy/static/headerbg.png | Bin 203 -> 0 bytes .../hello_sqlalchemy/static/ie6.css | 8 - .../hello_sqlalchemy/static/middlebg.png | Bin 2797 -> 0 bytes .../hello_sqlalchemy/static/pylons.css | 372 --------------------- .../hello_sqlalchemy/static/pyramid-small.png | Bin 7044 -> 0 bytes .../hello_sqlalchemy/static/pyramid.png | Bin 33055 -> 0 bytes .../hello_sqlalchemy/static/transparent.gif | Bin 49 -> 0 bytes .../hello_sqlalchemy/templates/mytemplate.pt | 76 ----- .../hello_sqlalchemy/hello_sqlalchemy/tests.py | 33 -- .../hello_sqlalchemy/hello_sqlalchemy/views.py | 44 --- .../quick_glance/hello_sqlalchemy/production.ini | 62 ---- .../quick_glance/hello_sqlalchemy/setup.cfg | 27 -- .../quick_glance/hello_sqlalchemy/setup.py | 44 --- .../quick_glance/package/development.ini | 13 +- .../quick_glance/package/hello_world/__init__.py | 13 +- .../hello_world/templates/mytemplate.jinja2 | 5 +- .../quick_glance/package/hello_world/tests.py | 1 - .../quick_glance/package/hello_world/views.py | 18 +- docs/getting_started/quick_glance/package/setup.py | 2 + .../quick_glance/sqla_demo/CHANGES.txt | 4 + .../quick_glance/sqla_demo/MANIFEST.in | 2 + .../quick_glance/sqla_demo/README.txt | 14 + .../quick_glance/sqla_demo/development.ini | 71 ++++ .../quick_glance/sqla_demo/production.ini | 62 ++++ .../quick_glance/sqla_demo/setup.cfg | 27 ++ .../quick_glance/sqla_demo/setup.py | 44 +++ .../quick_glance/sqla_demo/sqla_demo.sqlite | Bin 0 -> 3072 bytes .../quick_glance/sqla_demo/sqla_demo/__init__.py | 20 ++ .../quick_glance/sqla_demo/sqla_demo/models.py | 29 ++ .../sqla_demo/sqla_demo/scripts/__init__.py | 1 + .../sqla_demo/sqla_demo/scripts/initializedb.py | 37 ++ .../sqla_demo/sqla_demo/static/favicon.ico | Bin 0 -> 1406 bytes .../sqla_demo/sqla_demo/static/footerbg.png | Bin 0 -> 333 bytes .../sqla_demo/sqla_demo/static/headerbg.png | Bin 0 -> 203 bytes .../sqla_demo/sqla_demo/static/ie6.css | 8 + .../sqla_demo/sqla_demo/static/middlebg.png | Bin 0 -> 2797 bytes .../sqla_demo/sqla_demo/static/pylons.css | 372 +++++++++++++++++++++ .../sqla_demo/sqla_demo/static/pyramid-small.png | Bin 0 -> 7044 bytes .../sqla_demo/sqla_demo/static/pyramid.png | Bin 0 -> 33055 bytes .../sqla_demo/sqla_demo/static/transparent.gif | Bin 0 -> 49 bytes .../sqla_demo/sqla_demo/templates/mytemplate.pt | 76 +++++ .../quick_glance/sqla_demo/sqla_demo/tests.py | 33 ++ .../quick_glance/sqla_demo/sqla_demo/views.py | 37 ++ docs/getting_started/top_ten.rst | 33 +- docs/getting_started/views.rst | 10 - 60 files changed, 1101 insertions(+), 1022 deletions(-) create mode 100644 docs/getting_started/pserve.rst delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/CHANGES.txt delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/MANIFEST.in delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/README.txt delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/development.ini delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy.sqlite delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/__init__.py delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/models.py delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/scripts/__init__.py delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/scripts/initializedb.py delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/favicon.ico delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/footerbg.png delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/headerbg.png delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/ie6.css delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/middlebg.png delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/pylons.css delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/pyramid-small.png delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/pyramid.png delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/transparent.gif delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/templates/mytemplate.pt delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/tests.py delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/views.py delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/production.ini delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/setup.cfg delete mode 100644 docs/getting_started/quick_glance/hello_sqlalchemy/setup.py create mode 100644 docs/getting_started/quick_glance/sqla_demo/CHANGES.txt create mode 100644 docs/getting_started/quick_glance/sqla_demo/MANIFEST.in create mode 100644 docs/getting_started/quick_glance/sqla_demo/README.txt create mode 100644 docs/getting_started/quick_glance/sqla_demo/development.ini create mode 100644 docs/getting_started/quick_glance/sqla_demo/production.ini create mode 100644 docs/getting_started/quick_glance/sqla_demo/setup.cfg create mode 100644 docs/getting_started/quick_glance/sqla_demo/setup.py create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo.sqlite create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/__init__.py create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/models.py create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/scripts/__init__.py create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/scripts/initializedb.py create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/favicon.ico create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/footerbg.png create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/headerbg.png create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/ie6.css create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/middlebg.png create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pylons.css create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pyramid-small.png create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pyramid.png create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/transparent.gif create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/templates/mytemplate.pt create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/tests.py create mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/views.py (limited to 'docs') diff --git a/docs/getting_started/databases.rst b/docs/getting_started/databases.rst index f982643af..c415ed2db 100644 --- a/docs/getting_started/databases.rst +++ b/docs/getting_started/databases.rst @@ -2,3 +2,20 @@ Databases With SQLAlchemy ========================= +We can now visit our sample at +`http://localhost:6543/ `_. Some choices that +the scaffold helped us with: + +- A ``setup.py`` with appropriate dependencies + +- Connection strings and integration in our ``development.ini`` file + +- A console script which we ran above to initialize the database + +- The SQLAlchemy engine integrated into the ``Configurator`` on + application startup + +- Python modules for the SQLAlchemy models and the Pyramid views that + go with them + +- Some unit tests...yummy! diff --git a/docs/getting_started/index.rst b/docs/getting_started/index.rst index 06baf20ca..b7ab3c7bb 100644 --- a/docs/getting_started/index.rst +++ b/docs/getting_started/index.rst @@ -29,6 +29,12 @@ Notes - Cover static urls and asset specifications, resolving, replacing +.. toctree:: + :maxdepth: 1 + + gettingstarted + + Contents ======== @@ -42,6 +48,7 @@ Contents views templates static_assets + pserve testing forms databases diff --git a/docs/getting_started/pserve.rst b/docs/getting_started/pserve.rst new file mode 100644 index 000000000..a7f8ba62c --- /dev/null +++ b/docs/getting_started/pserve.rst @@ -0,0 +1,18 @@ +=================================== +Application Running With ``pserve`` +=================================== + + +Three Cool Things About ``pserve`` +---------------------------------- + +1. *Multiple .ini files*. You might have some settings in + development mode or some in production mode. Maybe you are writing an + add-on that needs to be wired-up by other people. + +2. *Choice of WSGI server*. ``pserve`` itself isn't a WSGI server. + Instead, it loads the server you want from the configuration file. + +3. *Friends of pserve*. With the ``pserve``/``.ini`` approach you + also get other commands that help during development: ``pshell``, + ``proutes``, ``pviews``, ``prequest``, etc. diff --git a/docs/getting_started/quick_glance.rst b/docs/getting_started/quick_glance.rst index 7189a0d13..f9a60c0eb 100644 --- a/docs/getting_started/quick_glance.rst +++ b/docs/getting_started/quick_glance.rst @@ -270,7 +270,7 @@ The only change in our view...point the renderer at the ``.jinja2`` file: Our Jinja2 template is very similar to our previous template: .. literalinclude:: quick_glance/jinja2/hello_world.jinja2 - :language: html + :language: jinja Pyramid's templating add-ons register a new kind of renderer into your application. The renderer registration maps to different kinds of @@ -432,9 +432,15 @@ Let's look at ``pserve`` and configuration in more depth. Application Running with ``pserve`` =================================== -When you install Pyramid, a small command program called ``pserve`` is -written to your ``bin`` directory. This program is an executable Python -module. It's very small, getting most of its brains via import. +Prior to scaffolds, our project mixed a number of operations details +into our code. Why should my main code care with HTTP server I want and +what port number to run on? + +``pserve`` is Pyramid's application runner, separating operational +details from your code. When you install Pyramid, a small command +program called ``pserve`` is written to your ``bin`` directory. This +program is an executable Python module. It's very small, getting most +of its brains via import. You can run ``pserve`` with ``--help`` to see some of its options. Doing so reveals that you can ask ``pserve`` to watch your development @@ -444,35 +450,22 @@ files and reload the server when they change: $ pserve development.ini --reload -By design, ``pserve`` itself isn't all that interesting. Instead, -its brains from your project's wiring, as expressed in the -configuration file you supply it. - -.. seealso:: See Also: :ref:`what_is_this_pserve_thing` - -Three Cool Things About ``pserve`` ----------------------------------- - -1. *Multiple .ini files*. You might have some settings in - development mode or some in production mode. Maybe you are writing an - add-on that needs to be wired-up by other people. - -2. *Choice of WSGI server*. ``pserve`` itself isn't a WSGI server. - Instead, it loads the server you want from the configuration file. - -3. *Friends of pserve*. With the ``pserve``/``.ini`` approach you - also get other commands that help during development: ``pshell``, - ``proutes``, ``pviews``, ``prequest``, etc. +The ``pserve`` command has a number of other options and operations. +Most of the work, though, comes from your project's wiring, as +expressed in the configuration file you supply to ``pserve``. Let's +take a look at this configuration file. Configuration with ``.ini`` Files ================================= Earlier in *Quick Glance* we first met Pyramid's configuration system. -At that point we did all configuration in Python code, -aka *imperatively*. For example, the port number chosen for our HTTP -server was right there in Python code. Our scaffold has moved this -decision, and more, into *declarative* configuration in the -``development.ini`` file. +At that point we did all configuration in Python code. For example, +the port number chosen for our HTTP server was right there in Python +code. Our scaffold has moved this decision, and more, into the +``development.ini`` file: + +.. literalinclude:: quick_glance/package/development.ini + :language: ini Let's take a quick high-level look. First, the ``.ini`` file is divided into sections: @@ -485,7 +478,7 @@ into sections: - Various sections afterwards configure our Python logging system -Let's look at a few decisions made in this configuration: +We have a few decisions made for us in this configuration: #. *Choice of web server*. The ``use = egg:pyramid#wsgiref`` tell ``pserve`` to the ``wsgiref`` server that is wrapped in the Pyramid @@ -520,9 +513,9 @@ illustrates several points about configuration. First, change your ``setup.py`` to say: -.. code-block:: python - - requires=['pyramid>=1.0.2', 'pyramid_jinja2'] +.. literalinclude:: quick_glance/package/setup.py + :start-after: Start Requires + :end-before: End Requires ...and re-run your setup: @@ -530,26 +523,31 @@ First, change your ``setup.py`` to say: $ python ./setup.py develop -The Python package was now installed into our environment but we -haven't told our web app to use it. We can do so imperatively in code: +The Python package was now installed into our environment. The package +is a Pyramid add-on, which means we need to include its configuration +into our web application. We could do this with imperative +configuration, as we did above for the ``pyramid_jinja2`` add-on: -.. code-block:: python - - config.include('pyramid_debugtoolbar') +.. literalinclude:: quick_glance/package/hello_world/__init__.py + :start-after: Start Include + :end-before: End Include -Instead, let's do it in configuration by modifying our +Now that we have a configuration file, we can use the +``pyramid.includes`` facility and place this in our ``development.ini`` instead: -.. code-block:: ini - - [app:hello_world] - pyramid.includes = pyramid_debugtoolbar +.. literalinclude:: quick_glance/package/development.ini + :language: ini + :start-after: Start Includes + :end-before: End Includes -That is, add ``pyramid.includes = pyramid_debugtoolbar`` anywhere in the -``[app:hello_world]`` section. You'll now see an attractive (and -collapsible) menu in the right of your browser giving you introspective +You'll now see an attractive (and +collapsible) menu in the right of your browser, providing introspective access to debugging information. Even better, if your web application -generates an error, you will see a nice traceback on the screen. +generates an error, you will see a nice traceback on the screen. When +you want to disable this toolbar, no need to change code: you can +remove it from ``pyramid.includes`` in the relevant ``.ini`` +configuration file. Unit Tests and ``nose`` ======================= @@ -577,7 +575,8 @@ We changed ``setup.py`` which means we need to re-run .. code-block:: bash - $ nosetests + $ cd hello_world + $ nosetests . . Name Stmts Miss Cover Missing --------------------------------------------------- @@ -594,25 +593,7 @@ We changed ``setup.py`` which means we need to re-run Our unit test passed. What did our test look like? -.. code-block:: python - - import unittest - from pyramid import testing - - - class ViewTests(unittest.TestCase): - def setUp(self): - testing.setUp() - - def tearDown(self): - testing.tearDown() - - def test_my_view(self): - from hello_world.views import my_view - - request = testing.DummyRequest() - response = my_view(request) - self.assertEqual(response['project'], 'hello_world') +.. literalinclude:: quick_glance/package/hello_world/tests.py Pyramid supplies helpers for test writing, which we use in the test setup and teardown. Our one test imports the view, @@ -634,65 +615,75 @@ messages sent by Pyramid (for example, when a new request comes in.) Maybe you would like to log messages in your code? In your Python module, import and setup the logging: -.. code-block:: python - - import logging - log = logging.getLogger(__name__) +.. literalinclude:: quick_glance/package/hello_world/views.py + :start-after: Start Logging 1 + :end-before: End Logging 1 You can now, in your code, log messages: -.. code-block:: python - - log.debug('Some Message') +.. literalinclude:: quick_glance/package/hello_world/views.py + :start-after: Start Logging 2 + :end-before: End Logging 2 This will log ``Some Message`` at a ``debug`` log level, to the application-configured logger in your ``development.ini``. What controls that? These sections in the configuration file: -.. code-block:: ini - - [loggers] - keys = root, hello_world - - [logger_hello_world] - level = DEBUG - handlers = - qualname = hello_world +.. literalinclude:: quick_glance/package/development.ini + :language: ini + :start-after: Start Sphinx Include + :end-before: End Sphinx Include Our application, a package named ``hello_world``, is setup as a logger -and configured to log messages at a ``DEBUG`` or higher level. +and configured to log messages at a ``DEBUG`` or higher level. When you +visit ``http://localhost:6543`` your console will now show:: + + 2013-08-09 10:42:42,968 DEBUG [hello_world.views][MainThread] Some Message Sessions ======== When people use your web application, they frequently perform a task -that requires semi-permanent data to be saved. For example,a shopping -cart. These are frequently called *sessions*. +that requires semi-permanent data to be saved. For example, a shopping +cart. This is called a :term:`session`. Pyramid has basic built-in support for sessions, with add-ons such as *Beaker* (or your own custom sessioning engine) that provide richer -session support. For the built-in session support, you first import -the "factory" which provides the sessioning: +session support. Let's take a look at the +:doc:`built-in sessioning support <../narr/sessions>`. In our +``__init__.py`` we first import the kind of sessioning we want: -.. code-block:: python +.. literalinclude:: quick_glance/package/hello_world/__init__.py + :start-after: Start Sphinx Include 1 + :end-before: End Sphinx Include 1 - from pyramid.session import UnencryptedCookieSessionFactoryConfig - my_session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet') +.. warning:: -We tell the configuration system that this is the source of our -sessioning support when setting up the ``Configurator``: + As noted in the session docs, this example implementation is + not intended for use in settings with security implications. -.. code-block:: python +Now make a "factory" and pass it to the :term:`configurator`'s +``session_factory`` argument: - config = Configurator(session_factory = my_session_factory) +.. literalinclude:: quick_glance/package/hello_world/__init__.py + :start-after: Start Sphinx Include 2 + :end-before: End Sphinx Include 2 -This now lets us use the session in our application code: +Pyramid's :term:`request` object now has a ``session`` attribute +that we can use in our view code: -.. code-block:: python +.. literalinclude:: quick_glance/package/hello_world/views.py + :start-after: Start Sphinx Include 1 + :end-before: End Sphinx Include 1 + +With this, each reload will increase the counter displayed in our +Jinja2 template: + +.. literalinclude:: quick_glance/package/hello_world/templates/mytemplate.jinja2 + :language: jinja + :start-after: Start Sphinx Include 1 + :end-before: End Sphinx Include 1 - session = request.session - if 'abc' in session: - session['fred'] = 'yes' Databases ========= @@ -708,8 +699,8 @@ scaffold! .. code-block:: bash - $ pcreate --scaffold alchemy hello_sqlalchemy - $ cd hello_sqlalchemy + $ pcreate --scaffold alchemy sqla_demo + $ cd sqla_demo $ python setup.py develop We now have a working sample SQLAlchemy application with all @@ -719,80 +710,97 @@ the application: .. code-block:: bash - $ initialize_hello_sqlalchemy_db development.ini + $ initialize_sqla_demo_db development.ini $ pserve development.ini -We can now visit our sample at -`http://localhost:6543/ `_. Some choices that -the scaffold helped us with: - -- A ``setup.py`` with appropriate dependencies +The ORM eases the mapping of database structures into a programming +language. SQLAlchemy uses "models" for this mapping. The scaffold +generated a sample model: -- Connection strings and integration in our ``development.ini`` file +.. literalinclude:: quick_glance/sqla_demo/sqla_demo/models.py + :start-after: Start Sphinx Include + :end-before: End Sphinx Include -- A console script which we ran above to initialize the database +View code, which mediates the logic between web requests and the rest +of the system, can then easily get at the data thanks to SQLAlchemy: -- The SQLAlchemy engine integrated into the ``Configurator`` on - application startup +.. literalinclude:: quick_glance/sqla_demo/sqla_demo/views.py + :start-after: Start Sphinx Include + :end-before: End Sphinx Include -- Python modules for the SQLAlchemy models and the Pyramid views that - go with them +Forms +===== -- Some unit tests...yummy! +Developers have lots of opinions about web forms, and thus there are many +form libraries for Python. Pyramid doesn't directly bundle a form +library, but *Deform* is a popular choice for forms, +along with its related *Colander* schema system. -As mentioned above, an ORM is software that eases the mapping of -database structures into a programming language. SQLAlchemy uses models -for this, and its scaffold generated a sample model: +As an example, imagine we want a form that edits a wiki page. The form +should have two fields on it, one of them a required title and the +other a rich text editor for the body. With Deform we can express this +as a Colander schema: .. code-block:: python - class MyModel(Base): - __tablename__ = 'models' - id = Column(Integer, primary_key=True) - name = Column(Text, unique=True) - value = Column(Integer) + class WikiPage(colander.MappingSchema): + title = colander.SchemaNode(colander.String()) + body = colander.SchemaNode( + colander.String(), + widget=deform.widget.RichTextWidget() + ) - def __init__(self, name, value): - self.name = name - self.value = value - -The Python module also includes this: +With this in place, we can render the HTML for a form, +perhaps with form data from an existing page: .. code-block:: python - from zope.sqlalchemy import ZopeTransactionExtension - -The generated application includes the optional support for -``pyramid_tm``, a unique transaction monitor that integrates your -database transactions with your code for transparent rollback and commit. + form = self.wiki_form.render() -View code, which mediates the logic between web requests and the rest -of the system, can then easily get at the data: +We'd like to handle form submission, validation, and saving: .. code-block:: python - one = DBSession.query(MyModel).filter(MyModel.name == 'one').first() - - -Forms -===== + # Get the form data that was posted + controls = self.request.POST.items() + try: + # Validate and either raise a validation error + # or return deserialized data from widgets + appstruct = wiki_form.validate(controls) + except deform.ValidationFailure as e: + # Bail out and render form with errors + return dict(title=title, page=page, form=e.render()) -Developers have lots of opinions about forms, and thus there are many -form libraries for Python. Pyramid doesn't directly bundle a form -library, but *Deform* is a popular choice. Let's see it in action. -First we install it: + # Change the content and redirect to the view + page['title'] = appstruct['title'] + page['body'] = appstruct['body'] -.. code-block:: bash +Deform and Colander provide a very flexible combination for forms, +widgets, schemas, and validation. Recent versions of Deform also +include a +`retail mode `_ +for gaining Deform +features on custom forms. - $ pip-3.3 install deform +Also, the ``deform_bootstrap`` Pyramid add-on restyles the stock Deform +widgets using attractive CSS from Bootstrap and more powerful widgets +from Chosen. +Awesome Pyramid Features +======================== +For the most part this *Quick Glance* has covered concepts that are +common in Python web frameworks. Pyramid has a unique niche, +though. It helps you start with a small project that grows into a +larger project. Let's look at some of the unique facilities that help. -Authentication -============== -Authorization -============= +Conclusion +========== +This *Quick Glance* was a little about a lot. We introduced a long list +of concepts in Pyramid, many of which are expanded on more fully later +in *Getting Started* and certainly in the Pyramid developer docs. \ No newline at end of file diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/CHANGES.txt b/docs/getting_started/quick_glance/hello_sqlalchemy/CHANGES.txt deleted file mode 100644 index 35a34f332..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/CHANGES.txt +++ /dev/null @@ -1,4 +0,0 @@ -0.0 ---- - -- Initial version diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/MANIFEST.in b/docs/getting_started/quick_glance/hello_sqlalchemy/MANIFEST.in deleted file mode 100644 index 2a06ba607..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -include *.txt *.ini *.cfg *.rst -recursive-include hello_sqlalchemy *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/README.txt b/docs/getting_started/quick_glance/hello_sqlalchemy/README.txt deleted file mode 100644 index b7a6612a0..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/README.txt +++ /dev/null @@ -1,14 +0,0 @@ -hello_sqlalchemy README -================== - -Getting Started ---------------- - -- cd - -- $venv/bin/python setup.py develop - -- $venv/bin/initialize_hello_sqlalchemy_db development.ini - -- $venv/bin/pserve development.ini - diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/development.ini b/docs/getting_started/quick_glance/hello_sqlalchemy/development.ini deleted file mode 100644 index 59ae96568..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/development.ini +++ /dev/null @@ -1,71 +0,0 @@ -### -# app configuration -# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html -### - -[app:main] -use = egg:hello_sqlalchemy - -pyramid.reload_templates = true -pyramid.debug_authorization = false -pyramid.debug_notfound = false -pyramid.debug_routematch = false -pyramid.default_locale_name = en -pyramid.includes = - pyramid_debugtoolbar - pyramid_tm - -sqlalchemy.url = sqlite:///%(here)s/hello_sqlalchemy.sqlite - -# By default, the toolbar only appears for clients from IP addresses -# '127.0.0.1' and '::1'. -# debugtoolbar.hosts = 127.0.0.1 ::1 - -### -# wsgi server configuration -### - -[server:main] -use = egg:waitress#main -host = 0.0.0.0 -port = 6543 - -### -# logging configuration -# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html -### - -[loggers] -keys = root, hello_sqlalchemy, sqlalchemy - -[handlers] -keys = console - -[formatters] -keys = generic - -[logger_root] -level = INFO -handlers = console - -[logger_hello_sqlalchemy] -level = DEBUG -handlers = -qualname = hello_sqlalchemy - -[logger_sqlalchemy] -level = INFO -handlers = -qualname = sqlalchemy.engine -# "level = INFO" logs SQL queries. -# "level = DEBUG" logs SQL queries and results. -# "level = WARN" logs neither. (Recommended for production systems.) - -[handler_console] -class = StreamHandler -args = (sys.stderr,) -level = NOTSET -formatter = generic - -[formatter_generic] -format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy.sqlite b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy.sqlite deleted file mode 100644 index fa6adb104..000000000 Binary files a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy.sqlite and /dev/null differ diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/__init__.py b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/__init__.py deleted file mode 100644 index aac7c5e69..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -from pyramid.config import Configurator -from sqlalchemy import engine_from_config - -from .models import ( - DBSession, - Base, - ) - - -def main(global_config, **settings): - """ This function returns a Pyramid WSGI application. - """ - engine = engine_from_config(settings, 'sqlalchemy.') - DBSession.configure(bind=engine) - Base.metadata.bind = engine - config = Configurator(settings=settings) - config.add_static_view('static', 'static', cache_max_age=3600) - config.add_route('home', '/') - config.scan() - return config.make_wsgi_app() diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/models.py b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/models.py deleted file mode 100644 index aeeb9df64..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/models.py +++ /dev/null @@ -1,28 +0,0 @@ -from sqlalchemy import ( - Column, - Integer, - Text, - ) - -from sqlalchemy.ext.declarative import declarative_base - -from sqlalchemy.orm import ( - scoped_session, - sessionmaker, - ) - -from zope.sqlalchemy import ZopeTransactionExtension - -DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension())) -Base = declarative_base() - - -class MyModel(Base): - __tablename__ = 'models' - id = Column(Integer, primary_key=True) - name = Column(Text, unique=True) - value = Column(Integer) - - def __init__(self, name, value): - self.name = name - self.value = value diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/scripts/__init__.py b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/scripts/__init__.py deleted file mode 100644 index 5bb534f79..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/scripts/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# package diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/scripts/initializedb.py b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/scripts/initializedb.py deleted file mode 100644 index 66feb3008..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/scripts/initializedb.py +++ /dev/null @@ -1,37 +0,0 @@ -import os -import sys -import transaction - -from sqlalchemy import engine_from_config - -from pyramid.paster import ( - get_appsettings, - setup_logging, - ) - -from ..models import ( - DBSession, - MyModel, - Base, - ) - - -def usage(argv): - cmd = os.path.basename(argv[0]) - print('usage: %s \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) - with transaction.manager: - model = MyModel(name='one', value=1) - DBSession.add(model) diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/favicon.ico b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/favicon.ico deleted file mode 100644 index 71f837c9e..000000000 Binary files a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/favicon.ico and /dev/null differ diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/footerbg.png b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/footerbg.png deleted file mode 100644 index 1fbc873da..000000000 Binary files a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/footerbg.png and /dev/null differ diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/headerbg.png b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/headerbg.png deleted file mode 100644 index 0596f2020..000000000 Binary files a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/headerbg.png and /dev/null differ diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/ie6.css b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/ie6.css deleted file mode 100644 index b7c8493d8..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/ie6.css +++ /dev/null @@ -1,8 +0,0 @@ -* html img, -* html .png{position:relative;behavior:expression((this.runtimeStyle.behavior="none")&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none", -this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "',sizingMethod='image')", -this.src = "static/transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''), -this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "',sizingMethod='crop')", -this.runtimeStyle.backgroundImage = "none")),this.pngSet=true) -);} -#wrap{display:table;height:100%} diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/middlebg.png b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/middlebg.png deleted file mode 100644 index 2369cfb7d..000000000 Binary files a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/middlebg.png and /dev/null differ diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/pylons.css b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/pylons.css deleted file mode 100644 index 4b1c017cd..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/pylons.css +++ /dev/null @@ -1,372 +0,0 @@ -html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td -{ - margin: 0; - padding: 0; - border: 0; - outline: 0; - font-size: 100%; /* 16px */ - vertical-align: baseline; - background: transparent; -} - -body -{ - line-height: 1; -} - -ol, ul -{ - list-style: none; -} - -blockquote, q -{ - quotes: none; -} - -blockquote:before, blockquote:after, q:before, q:after -{ - content: ''; - content: none; -} - -:focus -{ - outline: 0; -} - -ins -{ - text-decoration: none; -} - -del -{ - text-decoration: line-through; -} - -table -{ - border-collapse: collapse; - border-spacing: 0; -} - -sub -{ - vertical-align: sub; - font-size: smaller; - line-height: normal; -} - -sup -{ - vertical-align: super; - font-size: smaller; - line-height: normal; -} - -ul, menu, dir -{ - display: block; - list-style-type: disc; - margin: 1em 0; - padding-left: 40px; -} - -ol -{ - display: block; - list-style-type: decimal-leading-zero; - margin: 1em 0; - padding-left: 40px; -} - -li -{ - display: list-item; -} - -ul ul, ul ol, ul dir, ul menu, ul dl, ol ul, ol ol, ol dir, ol menu, ol dl, dir ul, dir ol, dir dir, dir menu, dir dl, menu ul, menu ol, menu dir, menu menu, menu dl, dl ul, dl ol, dl dir, dl menu, dl dl -{ - margin-top: 0; - margin-bottom: 0; -} - -ol ul, ul ul, menu ul, dir ul, ol menu, ul menu, menu menu, dir menu, ol dir, ul dir, menu dir, dir dir -{ - list-style-type: circle; -} - -ol ol ul, ol ul ul, ol menu ul, ol dir ul, ol ol menu, ol ul menu, ol menu menu, ol dir menu, ol ol dir, ol ul dir, ol menu dir, ol dir dir, ul ol ul, ul ul ul, ul menu ul, ul dir ul, ul ol menu, ul ul menu, ul menu menu, ul dir menu, ul ol dir, ul ul dir, ul menu dir, ul dir dir, menu ol ul, menu ul ul, menu menu ul, menu dir ul, menu ol menu, menu ul menu, menu menu menu, menu dir menu, menu ol dir, menu ul dir, menu menu dir, menu dir dir, dir ol ul, dir ul ul, dir menu ul, dir dir ul, dir ol menu, dir ul menu, dir menu menu, dir dir menu, dir ol dir, dir ul dir, dir menu dir, dir dir dir -{ - list-style-type: square; -} - -.hidden -{ - display: none; -} - -p -{ - line-height: 1.5em; -} - -h1 -{ - font-size: 1.75em; - line-height: 1.7em; - font-family: helvetica, verdana; -} - -h2 -{ - font-size: 1.5em; - line-height: 1.7em; - font-family: helvetica, verdana; -} - -h3 -{ - font-size: 1.25em; - line-height: 1.7em; - font-family: helvetica, verdana; -} - -h4 -{ - font-size: 1em; - line-height: 1.7em; - font-family: helvetica, verdana; -} - -html, body -{ - width: 100%; - height: 100%; -} - -body -{ - margin: 0; - padding: 0; - background-color: #fff; - position: relative; - font: 16px/24px NobileRegular, "Lucida Grande", Lucida, Verdana, sans-serif; -} - -a -{ - color: #1b61d6; - text-decoration: none; -} - -a:hover -{ - color: #e88f00; - text-decoration: underline; -} - -body h1, body h2, body h3, body h4, body h5, body h6 -{ - font-family: NeutonRegular, "Lucida Grande", Lucida, Verdana, sans-serif; - font-weight: 400; - color: #373839; - font-style: normal; -} - -#wrap -{ - min-height: 100%; -} - -#header, #footer -{ - width: 100%; - color: #fff; - height: 40px; - position: absolute; - text-align: center; - line-height: 40px; - overflow: hidden; - font-size: 12px; - vertical-align: middle; -} - -#header -{ - background: #000; - top: 0; - font-size: 14px; -} - -#footer -{ - bottom: 0; - background: #000 url(footerbg.png) repeat-x 0 top; - position: relative; - margin-top: -40px; - clear: both; -} - -.header, .footer -{ - width: 750px; - margin-right: auto; - margin-left: auto; -} - -.wrapper -{ - width: 100%; -} - -#top, #top-small, #bottom -{ - width: 100%; -} - -#top -{ - color: #000; - height: 230px; - background: #fff url(headerbg.png) repeat-x 0 top; - position: relative; -} - -#top-small -{ - color: #000; - height: 60px; - background: #fff url(headerbg.png) repeat-x 0 top; - position: relative; -} - -#bottom -{ - color: #222; - background-color: #fff; -} - -.top, .top-small, .middle, .bottom -{ - width: 750px; - margin-right: auto; - margin-left: auto; -} - -.top -{ - padding-top: 40px; -} - -.top-small -{ - padding-top: 10px; -} - -#middle -{ - width: 100%; - height: 100px; - background: url(middlebg.png) repeat-x; - border-top: 2px solid #fff; - border-bottom: 2px solid #b2b2b2; -} - -.app-welcome -{ - margin-top: 25px; -} - -.app-name -{ - color: #000; - font-weight: 700; -} - -.bottom -{ - padding-top: 50px; -} - -#left -{ - width: 350px; - float: left; - padding-right: 25px; -} - -#right -{ - width: 350px; - float: right; - padding-left: 25px; -} - -.align-left -{ - text-align: left; -} - -.align-right -{ - text-align: right; -} - -.align-center -{ - text-align: center; -} - -ul.links -{ - margin: 0; - padding: 0; -} - -ul.links li -{ - list-style-type: none; - font-size: 14px; -} - -form -{ - border-style: none; -} - -fieldset -{ - border-style: none; -} - -input -{ - color: #222; - border: 1px solid #ccc; - font-family: sans-serif; - font-size: 12px; - line-height: 16px; -} - -input[type=text], input[type=password] -{ - width: 205px; -} - -input[type=submit] -{ - background-color: #ddd; - font-weight: 700; -} - -/*Opera Fix*/ -body:before -{ - content: ""; - height: 100%; - float: left; - width: 0; - margin-top: -32767px; -} diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/pyramid-small.png b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/pyramid-small.png deleted file mode 100644 index a5bc0ade7..000000000 Binary files a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/pyramid-small.png and /dev/null differ diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/pyramid.png b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/pyramid.png deleted file mode 100644 index 347e05549..000000000 Binary files a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/pyramid.png and /dev/null differ diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/transparent.gif b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/transparent.gif deleted file mode 100644 index 0341802e5..000000000 Binary files a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/static/transparent.gif and /dev/null differ diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/templates/mytemplate.pt b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/templates/mytemplate.pt deleted file mode 100644 index 2de66d4c9..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/templates/mytemplate.pt +++ /dev/null @@ -1,76 +0,0 @@ - - - - The Pyramid Web Framework - - - - - - - - - - -
-
-
-
pyramid
-
-
-
-
-

- Welcome to ${project}, an application generated by
- the Pyramid Web Framework. -

-
-
-
-
-
-

Search documentation

-
- - -
-
- -
-
-
- - - diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/tests.py b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/tests.py deleted file mode 100644 index e2789665b..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/tests.py +++ /dev/null @@ -1,33 +0,0 @@ -import unittest -import transaction - -from pyramid import testing - -from .models import DBSession - - -class TestMyView(unittest.TestCase): - def setUp(self): - self.config = testing.setUp() - from sqlalchemy import create_engine - engine = create_engine('sqlite://') - from .models import ( - Base, - MyModel, - ) - DBSession.configure(bind=engine) - Base.metadata.create_all(engine) - with transaction.manager: - model = MyModel(name='one', value=55) - DBSession.add(model) - - def tearDown(self): - DBSession.remove() - testing.tearDown() - - def test_it(self): - from .views import my_view - request = testing.DummyRequest() - info = my_view(request) - self.assertEqual(info['one'].name, 'one') - self.assertEqual(info['project'], 'hello_sqlalchemy') diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/views.py b/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/views.py deleted file mode 100644 index 796acf738..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/hello_sqlalchemy/views.py +++ /dev/null @@ -1,44 +0,0 @@ -from pyramid.response import Response -from pyramid.view import view_config - -import colander -import deform - -from sqlalchemy.exc import DBAPIError - -from .models import ( - DBSession, - MyModel, - ) - -class MyForm(colander.MappingSchema): - title = colander.SchemaNode(colander.String()) - body = colander.SchemaNode( - colander.String(), - widget=deform.widget.RichTextWidget() - ) - -@view_config(route_name='home', renderer='templates/mytemplate.pt') -def my_view(request): - try: - 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': 'hello_sqlalchemy'} - -conn_err_msg = """\ -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 run the "initialize_hello_sqlalchemy_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. -""" - diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/production.ini b/docs/getting_started/quick_glance/hello_sqlalchemy/production.ini deleted file mode 100644 index 3257d0067..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/production.ini +++ /dev/null @@ -1,62 +0,0 @@ -### -# app configuration -# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html -### - -[app:main] -use = egg:hello_sqlalchemy - -pyramid.reload_templates = false -pyramid.debug_authorization = false -pyramid.debug_notfound = false -pyramid.debug_routematch = false -pyramid.default_locale_name = en -pyramid.includes = - pyramid_tm - -sqlalchemy.url = sqlite:///%(here)s/hello_sqlalchemy.sqlite - -[server:main] -use = egg:waitress#main -host = 0.0.0.0 -port = 6543 - -### -# logging configuration -# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html -### - -[loggers] -keys = root, hello_sqlalchemy, sqlalchemy - -[handlers] -keys = console - -[formatters] -keys = generic - -[logger_root] -level = WARN -handlers = console - -[logger_hello_sqlalchemy] -level = WARN -handlers = -qualname = hello_sqlalchemy - -[logger_sqlalchemy] -level = WARN -handlers = -qualname = sqlalchemy.engine -# "level = INFO" logs SQL queries. -# "level = DEBUG" logs SQL queries and results. -# "level = WARN" logs neither. (Recommended for production systems.) - -[handler_console] -class = StreamHandler -args = (sys.stderr,) -level = NOTSET -formatter = generic - -[formatter_generic] -format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/setup.cfg b/docs/getting_started/quick_glance/hello_sqlalchemy/setup.cfg deleted file mode 100644 index d08bf9c9b..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/setup.cfg +++ /dev/null @@ -1,27 +0,0 @@ -[nosetests] -match=^test -nocapture=1 -cover-package=hello_sqlalchemy -with-coverage=1 -cover-erase=1 - -[compile_catalog] -directory = hello_sqlalchemy/locale -domain = hello_sqlalchemy -statistics = true - -[extract_messages] -add_comments = TRANSLATORS: -output_file = hello_sqlalchemy/locale/hello_sqlalchemy.pot -width = 80 - -[init_catalog] -domain = hello_sqlalchemy -input_file = hello_sqlalchemy/locale/hello_sqlalchemy.pot -output_dir = hello_sqlalchemy/locale - -[update_catalog] -domain = hello_sqlalchemy -input_file = hello_sqlalchemy/locale/hello_sqlalchemy.pot -output_dir = hello_sqlalchemy/locale -previous = true diff --git a/docs/getting_started/quick_glance/hello_sqlalchemy/setup.py b/docs/getting_started/quick_glance/hello_sqlalchemy/setup.py deleted file mode 100644 index f4e1f48c0..000000000 --- a/docs/getting_started/quick_glance/hello_sqlalchemy/setup.py +++ /dev/null @@ -1,44 +0,0 @@ -import os - -from setuptools import setup, find_packages - -here = os.path.abspath(os.path.dirname(__file__)) -README = open(os.path.join(here, 'README.txt')).read() -CHANGES = open(os.path.join(here, 'CHANGES.txt')).read() - -requires = [ - 'pyramid', - 'SQLAlchemy', - 'transaction', - 'pyramid_tm', - 'pyramid_debugtoolbar', - 'zope.sqlalchemy', - 'waitress', - ] - -setup(name='hello_sqlalchemy', - version='0.0', - description='hello_sqlalchemy', - long_description=README + '\n\n' + CHANGES, - classifiers=[ - "Programming Language :: Python", - "Framework :: Pyramid", - "Topic :: Internet :: WWW/HTTP", - "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", - ], - author='', - author_email='', - url='', - keywords='web wsgi bfg pylons pyramid', - packages=find_packages(), - include_package_data=True, - zip_safe=False, - test_suite='hello_sqlalchemy', - install_requires=requires, - entry_points="""\ - [paste.app_factory] - main = hello_sqlalchemy:main - [console_scripts] - initialize_hello_sqlalchemy_db = hello_sqlalchemy.scripts.initializedb:main - """, - ) diff --git a/docs/getting_started/quick_glance/package/development.ini b/docs/getting_started/quick_glance/package/development.ini index 9aa5f40cf..a751ff903 100644 --- a/docs/getting_started/quick_glance/package/development.ini +++ b/docs/getting_started/quick_glance/package/development.ini @@ -1,5 +1,7 @@ +# Start Includes [app:hello_world] pyramid.includes = pyramid_debugtoolbar +# End Includes use = egg:hello_world reload_templates = true debug_authorization = false @@ -22,9 +24,16 @@ port = 6543 # Begin logging configuration +# Start Sphinx Include [loggers] keys = root, hello_world +[logger_hello_world] +level = DEBUG +handlers = +qualname = hello_world +# End Sphinx Include + [handlers] keys = console @@ -35,10 +44,6 @@ keys = generic level = INFO handlers = console -[logger_hello_world] -level = DEBUG -handlers = -qualname = hello_world [handler_console] class = StreamHandler diff --git a/docs/getting_started/quick_glance/package/hello_world/__init__.py b/docs/getting_started/quick_glance/package/hello_world/__init__.py index 9b5753c26..6e66bf40a 100644 --- a/docs/getting_started/quick_glance/package/hello_world/__init__.py +++ b/docs/getting_started/quick_glance/package/hello_world/__init__.py @@ -1,5 +1,9 @@ from pyramid.config import Configurator from pyramid_jinja2 import renderer_factory +# Start Sphinx Include 1 +from pyramid.session import UnencryptedCookieSessionFactoryConfig +# End Sphinx Include 1 + from hello_world.models import get_root def main(global_config, **settings): @@ -11,9 +15,16 @@ def main(global_config, **settings): settings = dict(settings) settings.setdefault('jinja2.i18n.domain', 'hello_world') - config = Configurator(root_factory=get_root, settings=settings) + # Start Sphinx Include 2 + my_session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet') + config = Configurator(root_factory=get_root, settings=settings, + session_factory=my_session_factory) + # End Sphinx Include 2 config.add_translation_dirs('locale/') + # Start Include config.include('pyramid_jinja2') + # End Include + config.add_static_view('static', 'static') config.add_view('hello_world.views.my_view', diff --git a/docs/getting_started/quick_glance/package/hello_world/templates/mytemplate.jinja2 b/docs/getting_started/quick_glance/package/hello_world/templates/mytemplate.jinja2 index 998edfe12..25a28ed7a 100644 --- a/docs/getting_started/quick_glance/package/hello_world/templates/mytemplate.jinja2 +++ b/docs/getting_started/quick_glance/package/hello_world/templates/mytemplate.jinja2 @@ -35,7 +35,10 @@

{% trans %}Hello!{% endtrans %}

-

Request performed with {{ request.locale_name }} locale.

+ +

Counter: {{ request.session.counter }}

+ +

Request performed with {{ request.locale_name }} locale.

diff --git a/docs/getting_started/quick_glance/package/hello_world/tests.py b/docs/getting_started/quick_glance/package/hello_world/tests.py index a81c29eb0..ccec14f70 100644 --- a/docs/getting_started/quick_glance/package/hello_world/tests.py +++ b/docs/getting_started/quick_glance/package/hello_world/tests.py @@ -18,4 +18,3 @@ class ViewTests(unittest.TestCase): request = testing.DummyRequest() response = my_view(request) self.assertEqual(response['project'], 'hello_world') - diff --git a/docs/getting_started/quick_glance/package/hello_world/views.py b/docs/getting_started/quick_glance/package/hello_world/views.py index c271d45dd..109c260ad 100644 --- a/docs/getting_started/quick_glance/package/hello_world/views.py +++ b/docs/getting_started/quick_glance/package/hello_world/views.py @@ -1,6 +1,22 @@ +# Start Logging 1 +import logging +log = logging.getLogger(__name__) +# End Logging 1 + from pyramid.i18n import TranslationStringFactory _ = TranslationStringFactory('hello_world') + def my_view(request): - return {'project':'hello_world'} + # Start Logging 2 + log.debug('Some Message') + # End Logging 2 + # Start Sphinx Include 1 + session = request.session + if 'counter' in session: + session['counter'] += 1 + else: + session['counter'] = 0 + # End Sphinx Include 1 + return {'project': 'hello_world'} diff --git a/docs/getting_started/quick_glance/package/setup.py b/docs/getting_started/quick_glance/package/setup.py index 6269accf1..f118ed5fb 100644 --- a/docs/getting_started/quick_glance/package/setup.py +++ b/docs/getting_started/quick_glance/package/setup.py @@ -6,7 +6,9 @@ here = os.path.abspath(os.path.dirname(__file__)) README = open(os.path.join(here, 'README.txt')).read() CHANGES = open(os.path.join(here, 'CHANGES.txt')).read() +# Start Requires requires = ['pyramid>=1.0.2', 'pyramid_jinja2', 'pyramid_debugtoolbar'] +# End Requires setup(name='hello_world', version='0.0', diff --git a/docs/getting_started/quick_glance/sqla_demo/CHANGES.txt b/docs/getting_started/quick_glance/sqla_demo/CHANGES.txt new file mode 100644 index 000000000..35a34f332 --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/CHANGES.txt @@ -0,0 +1,4 @@ +0.0 +--- + +- Initial version diff --git a/docs/getting_started/quick_glance/sqla_demo/MANIFEST.in b/docs/getting_started/quick_glance/sqla_demo/MANIFEST.in new file mode 100644 index 000000000..a432577e9 --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/MANIFEST.in @@ -0,0 +1,2 @@ +include *.txt *.ini *.cfg *.rst +recursive-include sqla_demo *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml diff --git a/docs/getting_started/quick_glance/sqla_demo/README.txt b/docs/getting_started/quick_glance/sqla_demo/README.txt new file mode 100644 index 000000000..f35d3aec5 --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/README.txt @@ -0,0 +1,14 @@ +sqla_demo README +================== + +Getting Started +--------------- + +- cd + +- $venv/bin/python setup.py develop + +- $venv/bin/initialize_sqla_demo_db development.ini + +- $venv/bin/pserve development.ini + diff --git a/docs/getting_started/quick_glance/sqla_demo/development.ini b/docs/getting_started/quick_glance/sqla_demo/development.ini new file mode 100644 index 000000000..174468abf --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/development.ini @@ -0,0 +1,71 @@ +### +# app configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html +### + +[app:main] +use = egg:sqla_demo + +pyramid.reload_templates = true +pyramid.debug_authorization = false +pyramid.debug_notfound = false +pyramid.debug_routematch = false +pyramid.default_locale_name = en +pyramid.includes = + pyramid_debugtoolbar + pyramid_tm + +sqlalchemy.url = sqlite:///%(here)s/sqla_demo.sqlite + +# By default, the toolbar only appears for clients from IP addresses +# '127.0.0.1' and '::1'. +# debugtoolbar.hosts = 127.0.0.1 ::1 + +### +# wsgi server configuration +### + +[server:main] +use = egg:waitress#main +host = 0.0.0.0 +port = 6543 + +### +# logging configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html +### + +[loggers] +keys = root, sqla_demo, sqlalchemy + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = INFO +handlers = console + +[logger_sqla_demo] +level = DEBUG +handlers = +qualname = sqla_demo + +[logger_sqlalchemy] +level = INFO +handlers = +qualname = sqlalchemy.engine +# "level = INFO" logs SQL queries. +# "level = DEBUG" logs SQL queries and results. +# "level = WARN" logs neither. (Recommended for production systems.) + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s diff --git a/docs/getting_started/quick_glance/sqla_demo/production.ini b/docs/getting_started/quick_glance/sqla_demo/production.ini new file mode 100644 index 000000000..dc0ba304f --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/production.ini @@ -0,0 +1,62 @@ +### +# app configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html +### + +[app:main] +use = egg:sqla_demo + +pyramid.reload_templates = false +pyramid.debug_authorization = false +pyramid.debug_notfound = false +pyramid.debug_routematch = false +pyramid.default_locale_name = en +pyramid.includes = + pyramid_tm + +sqlalchemy.url = sqlite:///%(here)s/sqla_demo.sqlite + +[server:main] +use = egg:waitress#main +host = 0.0.0.0 +port = 6543 + +### +# logging configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html +### + +[loggers] +keys = root, sqla_demo, sqlalchemy + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console + +[logger_sqla_demo] +level = WARN +handlers = +qualname = sqla_demo + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine +# "level = INFO" logs SQL queries. +# "level = DEBUG" logs SQL queries and results. +# "level = WARN" logs neither. (Recommended for production systems.) + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s diff --git a/docs/getting_started/quick_glance/sqla_demo/setup.cfg b/docs/getting_started/quick_glance/sqla_demo/setup.cfg new file mode 100644 index 000000000..9f91cd122 --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/setup.cfg @@ -0,0 +1,27 @@ +[nosetests] +match=^test +nocapture=1 +cover-package=sqla_demo +with-coverage=1 +cover-erase=1 + +[compile_catalog] +directory = sqla_demo/locale +domain = sqla_demo +statistics = true + +[extract_messages] +add_comments = TRANSLATORS: +output_file = sqla_demo/locale/sqla_demo.pot +width = 80 + +[init_catalog] +domain = sqla_demo +input_file = sqla_demo/locale/sqla_demo.pot +output_dir = sqla_demo/locale + +[update_catalog] +domain = sqla_demo +input_file = sqla_demo/locale/sqla_demo.pot +output_dir = sqla_demo/locale +previous = true diff --git a/docs/getting_started/quick_glance/sqla_demo/setup.py b/docs/getting_started/quick_glance/sqla_demo/setup.py new file mode 100644 index 000000000..ac2eed035 --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/setup.py @@ -0,0 +1,44 @@ +import os + +from setuptools import setup, find_packages + +here = os.path.abspath(os.path.dirname(__file__)) +README = open(os.path.join(here, 'README.txt')).read() +CHANGES = open(os.path.join(here, 'CHANGES.txt')).read() + +requires = [ + 'pyramid', + 'SQLAlchemy', + 'transaction', + 'pyramid_tm', + 'pyramid_debugtoolbar', + 'zope.sqlalchemy', + 'waitress', + ] + +setup(name='sqla_demo', + version='0.0', + description='sqla_demo', + long_description=README + '\n\n' + CHANGES, + classifiers=[ + "Programming Language :: Python", + "Framework :: Pyramid", + "Topic :: Internet :: WWW/HTTP", + "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", + ], + author='', + author_email='', + url='', + keywords='web wsgi bfg pylons pyramid', + packages=find_packages(), + include_package_data=True, + zip_safe=False, + test_suite='sqla_demo', + install_requires=requires, + entry_points="""\ + [paste.app_factory] + main = sqla_demo:main + [console_scripts] + initialize_sqla_demo_db = sqla_demo.scripts.initializedb:main + """, + ) diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo.sqlite b/docs/getting_started/quick_glance/sqla_demo/sqla_demo.sqlite new file mode 100644 index 000000000..fa6adb104 Binary files /dev/null and b/docs/getting_started/quick_glance/sqla_demo/sqla_demo.sqlite differ diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/__init__.py b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/__init__.py new file mode 100644 index 000000000..aac7c5e69 --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/__init__.py @@ -0,0 +1,20 @@ +from pyramid.config import Configurator +from sqlalchemy import engine_from_config + +from .models import ( + DBSession, + Base, + ) + + +def main(global_config, **settings): + """ This function returns a Pyramid WSGI application. + """ + engine = engine_from_config(settings, 'sqlalchemy.') + DBSession.configure(bind=engine) + Base.metadata.bind = engine + config = Configurator(settings=settings) + config.add_static_view('static', 'static', cache_max_age=3600) + config.add_route('home', '/') + config.scan() + return config.make_wsgi_app() diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/models.py b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/models.py new file mode 100644 index 000000000..3dfb40e58 --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/models.py @@ -0,0 +1,29 @@ +from sqlalchemy import ( + Column, + Integer, + Text, + ) + +from sqlalchemy.ext.declarative import declarative_base + +from sqlalchemy.orm import ( + scoped_session, + sessionmaker, + ) + +from zope.sqlalchemy import ZopeTransactionExtension + +DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension())) +Base = declarative_base() + +# Start Sphinx Include +class MyModel(Base): + __tablename__ = 'models' + id = Column(Integer, primary_key=True) + name = Column(Text, unique=True) + value = Column(Integer) + + def __init__(self, name, value): + self.name = name + self.value = value + # End Sphinx Include diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/scripts/__init__.py b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/scripts/__init__.py new file mode 100644 index 000000000..5bb534f79 --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/scripts/__init__.py @@ -0,0 +1 @@ +# package diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/scripts/initializedb.py b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/scripts/initializedb.py new file mode 100644 index 000000000..66feb3008 --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/scripts/initializedb.py @@ -0,0 +1,37 @@ +import os +import sys +import transaction + +from sqlalchemy import engine_from_config + +from pyramid.paster import ( + get_appsettings, + setup_logging, + ) + +from ..models import ( + DBSession, + MyModel, + Base, + ) + + +def usage(argv): + cmd = os.path.basename(argv[0]) + print('usage: %s \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) + with transaction.manager: + model = MyModel(name='one', value=1) + DBSession.add(model) diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/favicon.ico b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/favicon.ico new file mode 100644 index 000000000..71f837c9e Binary files /dev/null and b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/favicon.ico differ diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/footerbg.png b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/footerbg.png new file mode 100644 index 000000000..1fbc873da Binary files /dev/null and b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/footerbg.png differ diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/headerbg.png b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/headerbg.png new file mode 100644 index 000000000..0596f2020 Binary files /dev/null and b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/headerbg.png differ diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/ie6.css b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/ie6.css new file mode 100644 index 000000000..b7c8493d8 --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/ie6.css @@ -0,0 +1,8 @@ +* html img, +* html .png{position:relative;behavior:expression((this.runtimeStyle.behavior="none")&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none", +this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "',sizingMethod='image')", +this.src = "static/transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''), +this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "',sizingMethod='crop')", +this.runtimeStyle.backgroundImage = "none")),this.pngSet=true) +);} +#wrap{display:table;height:100%} diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/middlebg.png b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/middlebg.png new file mode 100644 index 000000000..2369cfb7d Binary files /dev/null and b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/middlebg.png differ diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pylons.css b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pylons.css new file mode 100644 index 000000000..4b1c017cd --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pylons.css @@ -0,0 +1,372 @@ +html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td +{ + margin: 0; + padding: 0; + border: 0; + outline: 0; + font-size: 100%; /* 16px */ + vertical-align: baseline; + background: transparent; +} + +body +{ + line-height: 1; +} + +ol, ul +{ + list-style: none; +} + +blockquote, q +{ + quotes: none; +} + +blockquote:before, blockquote:after, q:before, q:after +{ + content: ''; + content: none; +} + +:focus +{ + outline: 0; +} + +ins +{ + text-decoration: none; +} + +del +{ + text-decoration: line-through; +} + +table +{ + border-collapse: collapse; + border-spacing: 0; +} + +sub +{ + vertical-align: sub; + font-size: smaller; + line-height: normal; +} + +sup +{ + vertical-align: super; + font-size: smaller; + line-height: normal; +} + +ul, menu, dir +{ + display: block; + list-style-type: disc; + margin: 1em 0; + padding-left: 40px; +} + +ol +{ + display: block; + list-style-type: decimal-leading-zero; + margin: 1em 0; + padding-left: 40px; +} + +li +{ + display: list-item; +} + +ul ul, ul ol, ul dir, ul menu, ul dl, ol ul, ol ol, ol dir, ol menu, ol dl, dir ul, dir ol, dir dir, dir menu, dir dl, menu ul, menu ol, menu dir, menu menu, menu dl, dl ul, dl ol, dl dir, dl menu, dl dl +{ + margin-top: 0; + margin-bottom: 0; +} + +ol ul, ul ul, menu ul, dir ul, ol menu, ul menu, menu menu, dir menu, ol dir, ul dir, menu dir, dir dir +{ + list-style-type: circle; +} + +ol ol ul, ol ul ul, ol menu ul, ol dir ul, ol ol menu, ol ul menu, ol menu menu, ol dir menu, ol ol dir, ol ul dir, ol menu dir, ol dir dir, ul ol ul, ul ul ul, ul menu ul, ul dir ul, ul ol menu, ul ul menu, ul menu menu, ul dir menu, ul ol dir, ul ul dir, ul menu dir, ul dir dir, menu ol ul, menu ul ul, menu menu ul, menu dir ul, menu ol menu, menu ul menu, menu menu menu, menu dir menu, menu ol dir, menu ul dir, menu menu dir, menu dir dir, dir ol ul, dir ul ul, dir menu ul, dir dir ul, dir ol menu, dir ul menu, dir menu menu, dir dir menu, dir ol dir, dir ul dir, dir menu dir, dir dir dir +{ + list-style-type: square; +} + +.hidden +{ + display: none; +} + +p +{ + line-height: 1.5em; +} + +h1 +{ + font-size: 1.75em; + line-height: 1.7em; + font-family: helvetica, verdana; +} + +h2 +{ + font-size: 1.5em; + line-height: 1.7em; + font-family: helvetica, verdana; +} + +h3 +{ + font-size: 1.25em; + line-height: 1.7em; + font-family: helvetica, verdana; +} + +h4 +{ + font-size: 1em; + line-height: 1.7em; + font-family: helvetica, verdana; +} + +html, body +{ + width: 100%; + height: 100%; +} + +body +{ + margin: 0; + padding: 0; + background-color: #fff; + position: relative; + font: 16px/24px NobileRegular, "Lucida Grande", Lucida, Verdana, sans-serif; +} + +a +{ + color: #1b61d6; + text-decoration: none; +} + +a:hover +{ + color: #e88f00; + text-decoration: underline; +} + +body h1, body h2, body h3, body h4, body h5, body h6 +{ + font-family: NeutonRegular, "Lucida Grande", Lucida, Verdana, sans-serif; + font-weight: 400; + color: #373839; + font-style: normal; +} + +#wrap +{ + min-height: 100%; +} + +#header, #footer +{ + width: 100%; + color: #fff; + height: 40px; + position: absolute; + text-align: center; + line-height: 40px; + overflow: hidden; + font-size: 12px; + vertical-align: middle; +} + +#header +{ + background: #000; + top: 0; + font-size: 14px; +} + +#footer +{ + bottom: 0; + background: #000 url(footerbg.png) repeat-x 0 top; + position: relative; + margin-top: -40px; + clear: both; +} + +.header, .footer +{ + width: 750px; + margin-right: auto; + margin-left: auto; +} + +.wrapper +{ + width: 100%; +} + +#top, #top-small, #bottom +{ + width: 100%; +} + +#top +{ + color: #000; + height: 230px; + background: #fff url(headerbg.png) repeat-x 0 top; + position: relative; +} + +#top-small +{ + color: #000; + height: 60px; + background: #fff url(headerbg.png) repeat-x 0 top; + position: relative; +} + +#bottom +{ + color: #222; + background-color: #fff; +} + +.top, .top-small, .middle, .bottom +{ + width: 750px; + margin-right: auto; + margin-left: auto; +} + +.top +{ + padding-top: 40px; +} + +.top-small +{ + padding-top: 10px; +} + +#middle +{ + width: 100%; + height: 100px; + background: url(middlebg.png) repeat-x; + border-top: 2px solid #fff; + border-bottom: 2px solid #b2b2b2; +} + +.app-welcome +{ + margin-top: 25px; +} + +.app-name +{ + color: #000; + font-weight: 700; +} + +.bottom +{ + padding-top: 50px; +} + +#left +{ + width: 350px; + float: left; + padding-right: 25px; +} + +#right +{ + width: 350px; + float: right; + padding-left: 25px; +} + +.align-left +{ + text-align: left; +} + +.align-right +{ + text-align: right; +} + +.align-center +{ + text-align: center; +} + +ul.links +{ + margin: 0; + padding: 0; +} + +ul.links li +{ + list-style-type: none; + font-size: 14px; +} + +form +{ + border-style: none; +} + +fieldset +{ + border-style: none; +} + +input +{ + color: #222; + border: 1px solid #ccc; + font-family: sans-serif; + font-size: 12px; + line-height: 16px; +} + +input[type=text], input[type=password] +{ + width: 205px; +} + +input[type=submit] +{ + background-color: #ddd; + font-weight: 700; +} + +/*Opera Fix*/ +body:before +{ + content: ""; + height: 100%; + float: left; + width: 0; + margin-top: -32767px; +} diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pyramid-small.png b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pyramid-small.png new file mode 100644 index 000000000..a5bc0ade7 Binary files /dev/null and b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pyramid-small.png differ diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pyramid.png b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pyramid.png new file mode 100644 index 000000000..347e05549 Binary files /dev/null and b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pyramid.png differ diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/transparent.gif b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/transparent.gif new file mode 100644 index 000000000..0341802e5 Binary files /dev/null and b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/transparent.gif differ diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/templates/mytemplate.pt b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/templates/mytemplate.pt new file mode 100644 index 000000000..e0ac9d440 --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/templates/mytemplate.pt @@ -0,0 +1,76 @@ + + + + The Pyramid Web Application Development Framework + + + + + + + + + + +
+
+
+
pyramid
+
+
+
+
+

+ Welcome to ${project}, an application generated by
+ the Pyramid web application development framework. +

+
+
+
+
+
+

Search documentation

+
+ + +
+
+ +
+
+
+ + + diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/tests.py b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/tests.py new file mode 100644 index 000000000..6fef6d695 --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/tests.py @@ -0,0 +1,33 @@ +import unittest +import transaction + +from pyramid import testing + +from .models import DBSession + + +class TestMyView(unittest.TestCase): + def setUp(self): + self.config = testing.setUp() + from sqlalchemy import create_engine + engine = create_engine('sqlite://') + from .models import ( + Base, + MyModel, + ) + DBSession.configure(bind=engine) + Base.metadata.create_all(engine) + with transaction.manager: + model = MyModel(name='one', value=55) + DBSession.add(model) + + def tearDown(self): + DBSession.remove() + testing.tearDown() + + def test_it(self): + from .views import my_view + request = testing.DummyRequest() + info = my_view(request) + self.assertEqual(info['one'].name, 'one') + self.assertEqual(info['project'], 'sqla_demo') diff --git a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/views.py b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/views.py new file mode 100644 index 000000000..768a7e42e --- /dev/null +++ b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/views.py @@ -0,0 +1,37 @@ +from pyramid.response import Response +from pyramid.view import view_config + +from sqlalchemy.exc import DBAPIError + +from .models import ( + DBSession, + MyModel, + ) + + +@view_config(route_name='home', renderer='templates/mytemplate.pt') +def my_view(request): + try: + # Start Sphinx Include + one = DBSession.query(MyModel).filter(MyModel.name == 'one').first() + # End Sphinx Include + except DBAPIError: + return Response(conn_err_msg, content_type='text/plain', status_int=500) + return {'one': one, 'project': 'sqla_demo'} + +conn_err_msg = """\ +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 run the "initialize_sqla_demo_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. +""" + diff --git a/docs/getting_started/top_ten.rst b/docs/getting_started/top_ten.rst index a11d2898c..e207f4ce1 100644 --- a/docs/getting_started/top_ten.rst +++ b/docs/getting_started/top_ten.rst @@ -2,31 +2,40 @@ Top Killer Features In Pyramid ============================== -"Making your own framework" - -- Transactions +As a regular developer - Configuration - - config.include +- Route factories and contexts -- Advanced views and view predicates +- Advanced view configuration -Custom views -============ +- Route prefixes -- Corneice does this +- Asset specifications - Events -- Ordered routes - - Custom renderers - Tweens -- Asset specifications +- Transactions - Traversal -- Transactions \ No newline at end of file +- Custom directives + +- config.include + +- Extensible applications + + - Overridable views, routes, and assets + + - config.include + + - Events + + - Distributing an add-on + + - "Making your own framework", Extensibility diff --git a/docs/getting_started/views.rst b/docs/getting_started/views.rst index 827778a66..f30caea8a 100644 --- a/docs/getting_started/views.rst +++ b/docs/getting_started/views.rst @@ -17,22 +17,12 @@ person, then editing that person or perhaps deleting that person. They might logically belong together. We could do these as independent functions, but let's do them together as a view class: -.. literalinclude:: quick_glance/view_classes/views.py - :start-after: Start View 1 - :end-before: End View 1 ...and some routes that wire up the views to URLs: -.. literalinclude:: quick_glance/view_classes/app.py - :start-after: Start Routes 1 - :end-before: End Routes 1 ...and a form in ``hello_world.jinja2`` that submits to the second view: -.. literalinclude:: quick_glance/view_classes/hello_world.jinja2 - :language: html - :start-after: Start Form 1 - :end-before: End Form 1 Just to review: -- cgit v1.2.3