From ae901436a61563968cc31cc636f1fbeb5e85b528 Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Sun, 11 Aug 2013 09:53:00 -0400 Subject: Per discussion with Chris, just wrap up "getting started" as the Quick Tour. Still need to do more linking and perhaps add a section on root factories, authorization, authentication. --- docs/getting_started/configuration.rst | 4 - docs/getting_started/databases.rst | 21 - docs/getting_started/forms.rst | 3 - docs/getting_started/gettingstarted.rst | 84 --- docs/getting_started/index.rst | 60 -- docs/getting_started/internationalization.rst | 3 - docs/getting_started/json.rst | 4 - docs/getting_started/pserve.rst | 18 - docs/getting_started/quick_glance.rst | 806 --------------------- .../quick_glance/hello_world/app.py | 16 - docs/getting_started/quick_glance/jinja2/app.py | 11 - .../quick_glance/jinja2/hello_world.jinja2 | 8 - docs/getting_started/quick_glance/jinja2/views.py | 8 - docs/getting_started/quick_glance/json/app.py | 15 - .../quick_glance/json/hello_world.jinja2 | 10 - .../quick_glance/json/hello_world.pt | 17 - docs/getting_started/quick_glance/json/views.py | 13 - .../quick_glance/package/CHANGES.txt | 4 - .../quick_glance/package/MANIFEST.in | 2 - .../quick_glance/package/README.txt | 4 - .../quick_glance/package/development.ini | 57 -- .../quick_glance/package/hello_world/__init__.py | 34 - .../locale/de/LC_MESSAGES/hello_world.mo | Bin 460 -> 0 bytes .../locale/de/LC_MESSAGES/hello_world.po | 21 - .../locale/fr/LC_MESSAGES/hello_world.mo | Bin 461 -> 0 bytes .../locale/fr/LC_MESSAGES/hello_world.po | 21 - .../package/hello_world/locale/hello_world.pot | 21 - .../quick_glance/package/hello_world/models.py | 8 - .../package/hello_world/static/favicon.ico | Bin 1406 -> 0 bytes .../package/hello_world/static/logo.png | Bin 6641 -> 0 bytes .../package/hello_world/static/pylons.css | 73 -- .../hello_world/templates/mytemplate.jinja2 | 90 --- .../quick_glance/package/hello_world/tests.py | 20 - .../quick_glance/package/hello_world/views.py | 22 - .../quick_glance/package/message-extraction.ini | 3 - .../getting_started/quick_glance/package/setup.cfg | 28 - docs/getting_started/quick_glance/package/setup.py | 41 -- docs/getting_started/quick_glance/requests/app.py | 24 - docs/getting_started/quick_glance/routing/app.py | 12 - docs/getting_started/quick_glance/routing/views.py | 10 - .../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 3072 -> 0 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 1406 -> 0 bytes .../sqla_demo/sqla_demo/static/footerbg.png | Bin 333 -> 0 bytes .../sqla_demo/sqla_demo/static/headerbg.png | Bin 203 -> 0 bytes .../sqla_demo/sqla_demo/static/ie6.css | 8 - .../sqla_demo/sqla_demo/static/middlebg.png | Bin 2797 -> 0 bytes .../sqla_demo/sqla_demo/static/pylons.css | 372 ---------- .../sqla_demo/sqla_demo/static/pyramid-small.png | Bin 7044 -> 0 bytes .../sqla_demo/sqla_demo/static/pyramid.png | Bin 33055 -> 0 bytes .../sqla_demo/sqla_demo/static/transparent.gif | Bin 49 -> 0 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 - .../quick_glance/static_assets/app.py | 14 - .../quick_glance/static_assets/hello_world.jinja2 | 10 - .../quick_glance/static_assets/hello_world.pt | 16 - .../quick_glance/static_assets/static/app.css | 4 - .../quick_glance/static_assets/views.py | 6 - .../getting_started/quick_glance/templating/app.py | 10 - .../quick_glance/templating/hello_world.pt | 9 - .../quick_glance/templating/views.py | 8 - .../quick_glance/view_classes/app.py | 13 - .../quick_glance/view_classes/delete.jinja2 | 9 - .../quick_glance/view_classes/edit.jinja2 | 9 - .../quick_glance/view_classes/hello.jinja2 | 17 - .../quick_glance/view_classes/views.py | 32 - docs/getting_started/quick_glance/views/app.py | 13 - docs/getting_started/quick_glance/views/views.py | 29 - docs/getting_started/routes.rst | 3 - docs/getting_started/scaffolds.rst | 110 --- docs/getting_started/security.rst | 3 - docs/getting_started/sessions.rst | 3 - docs/getting_started/special_views.rst | 3 - docs/getting_started/static_assets.rst | 4 - docs/getting_started/templates.rst | 4 - docs/getting_started/testing.rst | 4 - docs/getting_started/top_ten.rst | 41 -- docs/getting_started/views.rst | 30 - docs/index.rst | 42 +- docs/quick_tour.rst | 789 ++++++++++++++++++++ 91 files changed, 810 insertions(+), 2858 deletions(-) delete mode 100644 docs/getting_started/configuration.rst delete mode 100644 docs/getting_started/databases.rst delete mode 100644 docs/getting_started/forms.rst delete mode 100644 docs/getting_started/gettingstarted.rst delete mode 100644 docs/getting_started/index.rst delete mode 100644 docs/getting_started/internationalization.rst delete mode 100644 docs/getting_started/json.rst delete mode 100644 docs/getting_started/pserve.rst delete mode 100644 docs/getting_started/quick_glance.rst delete mode 100644 docs/getting_started/quick_glance/hello_world/app.py delete mode 100644 docs/getting_started/quick_glance/jinja2/app.py delete mode 100644 docs/getting_started/quick_glance/jinja2/hello_world.jinja2 delete mode 100644 docs/getting_started/quick_glance/jinja2/views.py delete mode 100644 docs/getting_started/quick_glance/json/app.py delete mode 100644 docs/getting_started/quick_glance/json/hello_world.jinja2 delete mode 100644 docs/getting_started/quick_glance/json/hello_world.pt delete mode 100644 docs/getting_started/quick_glance/json/views.py delete mode 100644 docs/getting_started/quick_glance/package/CHANGES.txt delete mode 100644 docs/getting_started/quick_glance/package/MANIFEST.in delete mode 100644 docs/getting_started/quick_glance/package/README.txt delete mode 100644 docs/getting_started/quick_glance/package/development.ini delete mode 100644 docs/getting_started/quick_glance/package/hello_world/__init__.py delete mode 100644 docs/getting_started/quick_glance/package/hello_world/locale/de/LC_MESSAGES/hello_world.mo delete mode 100644 docs/getting_started/quick_glance/package/hello_world/locale/de/LC_MESSAGES/hello_world.po delete mode 100644 docs/getting_started/quick_glance/package/hello_world/locale/fr/LC_MESSAGES/hello_world.mo delete mode 100644 docs/getting_started/quick_glance/package/hello_world/locale/fr/LC_MESSAGES/hello_world.po delete mode 100644 docs/getting_started/quick_glance/package/hello_world/locale/hello_world.pot delete mode 100644 docs/getting_started/quick_glance/package/hello_world/models.py delete mode 100644 docs/getting_started/quick_glance/package/hello_world/static/favicon.ico delete mode 100644 docs/getting_started/quick_glance/package/hello_world/static/logo.png delete mode 100644 docs/getting_started/quick_glance/package/hello_world/static/pylons.css delete mode 100644 docs/getting_started/quick_glance/package/hello_world/templates/mytemplate.jinja2 delete mode 100644 docs/getting_started/quick_glance/package/hello_world/tests.py delete mode 100644 docs/getting_started/quick_glance/package/hello_world/views.py delete mode 100644 docs/getting_started/quick_glance/package/message-extraction.ini delete mode 100644 docs/getting_started/quick_glance/package/setup.cfg delete mode 100644 docs/getting_started/quick_glance/package/setup.py delete mode 100644 docs/getting_started/quick_glance/requests/app.py delete mode 100644 docs/getting_started/quick_glance/routing/app.py delete mode 100644 docs/getting_started/quick_glance/routing/views.py delete mode 100644 docs/getting_started/quick_glance/sqla_demo/CHANGES.txt delete mode 100644 docs/getting_started/quick_glance/sqla_demo/MANIFEST.in delete mode 100644 docs/getting_started/quick_glance/sqla_demo/README.txt delete mode 100644 docs/getting_started/quick_glance/sqla_demo/development.ini delete mode 100644 docs/getting_started/quick_glance/sqla_demo/production.ini delete mode 100644 docs/getting_started/quick_glance/sqla_demo/setup.cfg delete mode 100644 docs/getting_started/quick_glance/sqla_demo/setup.py delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo.sqlite delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/__init__.py delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/models.py delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/scripts/__init__.py delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/scripts/initializedb.py delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/favicon.ico delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/footerbg.png delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/headerbg.png delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/ie6.css delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/middlebg.png delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pylons.css delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pyramid-small.png delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pyramid.png delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/transparent.gif delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/templates/mytemplate.pt delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/tests.py delete mode 100644 docs/getting_started/quick_glance/sqla_demo/sqla_demo/views.py delete mode 100644 docs/getting_started/quick_glance/static_assets/app.py delete mode 100644 docs/getting_started/quick_glance/static_assets/hello_world.jinja2 delete mode 100644 docs/getting_started/quick_glance/static_assets/hello_world.pt delete mode 100644 docs/getting_started/quick_glance/static_assets/static/app.css delete mode 100644 docs/getting_started/quick_glance/static_assets/views.py delete mode 100644 docs/getting_started/quick_glance/templating/app.py delete mode 100644 docs/getting_started/quick_glance/templating/hello_world.pt delete mode 100644 docs/getting_started/quick_glance/templating/views.py delete mode 100644 docs/getting_started/quick_glance/view_classes/app.py delete mode 100644 docs/getting_started/quick_glance/view_classes/delete.jinja2 delete mode 100644 docs/getting_started/quick_glance/view_classes/edit.jinja2 delete mode 100644 docs/getting_started/quick_glance/view_classes/hello.jinja2 delete mode 100644 docs/getting_started/quick_glance/view_classes/views.py delete mode 100644 docs/getting_started/quick_glance/views/app.py delete mode 100644 docs/getting_started/quick_glance/views/views.py delete mode 100644 docs/getting_started/routes.rst delete mode 100644 docs/getting_started/scaffolds.rst delete mode 100644 docs/getting_started/security.rst delete mode 100644 docs/getting_started/sessions.rst delete mode 100644 docs/getting_started/special_views.rst delete mode 100644 docs/getting_started/static_assets.rst delete mode 100644 docs/getting_started/templates.rst delete mode 100644 docs/getting_started/testing.rst delete mode 100644 docs/getting_started/top_ten.rst delete mode 100644 docs/getting_started/views.rst create mode 100644 docs/quick_tour.rst (limited to 'docs') diff --git a/docs/getting_started/configuration.rst b/docs/getting_started/configuration.rst deleted file mode 100644 index 30280c7e1..000000000 --- a/docs/getting_started/configuration.rst +++ /dev/null @@ -1,4 +0,0 @@ -============================================ -Managing Project Settings With Configuration -============================================ - diff --git a/docs/getting_started/databases.rst b/docs/getting_started/databases.rst deleted file mode 100644 index c415ed2db..000000000 --- a/docs/getting_started/databases.rst +++ /dev/null @@ -1,21 +0,0 @@ -========================= -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/forms.rst b/docs/getting_started/forms.rst deleted file mode 100644 index 039bfbce4..000000000 --- a/docs/getting_started/forms.rst +++ /dev/null @@ -1,3 +0,0 @@ -================================ -Forms and Validation With Deform -================================ diff --git a/docs/getting_started/gettingstarted.rst b/docs/getting_started/gettingstarted.rst deleted file mode 100644 index 191a6a090..000000000 --- a/docs/getting_started/gettingstarted.rst +++ /dev/null @@ -1,84 +0,0 @@ -=============== -Getting Started -=============== - -What is Pyramid? ----------------- - -Pyramid is a web application development framework. Pyramid is lean, fast, -stable, well-tested, and thoroughly documented. Pyramid is written in Python, -and is open source software released under a `BSD-like license -`_. - -Pyramid helps you "start small, finish big". You can create a simple web -application using Pyramid with only basic knowledge. As you become more -familiar with Pyramid, you'll find there is plenty of room to grow. Code you -started with early on can be re-used in mature, large, powerful applications. - -Pyramid has dozens of features — URL generation, authentication and -authorization, [one or two more?] — just like any other web application -framework. Several features are unique and make Pyramid stand out from the -crowd. - -* Traversal -* Python 3 compatibility -* Tweens -* Debug Toolbar - -Installation Guide ------------------- -The Installation Guide describes how to install everything needed to get -started with Pyramid. It also offers practical advice on working with -projects. Whether you're new to Pyramid, Python, programming, or web -application development, the Installation Guide will help you get your first -Pyramid application up and running and deployed into production. - -Developer Guide ---------------- -The Developer Guide describes Pyramid in depth. Formerly called "narrative -documentation", the Developer Guide uses technical terms more familiar to the -seasoned web application developer. Beginners may be challenged, to put it -mildly, but it's a challenge worth accepting. Developers who have already -installed Pyramid, worked through a few tutorials, and are ready to write their -own applications will find that this guide offers a comprehensive understanding -of Pyramid. - -API Guide ---------- -The API Guide is a comprehensive reference for every public application -programming interface (API) exposed by Pyramid. The API Guide lists each item, -its arguments, definition, narrative description, its inner workings, and the -values and objects it returns in great detail. - -Tutorials and Screencasts -------------------------- -There are several tutorials and screencasts that give beginners and new-comers -to Pyramid hands-on experience with writing Pyramid applications. - -http://docs.pylonsproject.org/projects/pyramid_tutorials/en/latest/ - -Add-ons -------- -Pyramid is extensible through add-ons. - -http://docs.pylonsproject.org/en/latest/docs/pyramid.html#pyramid-add-on-documentation - -Support -------- -https://github.com/Pylons/pylonsrtd/blob/master/index.rst#support - -Pylons-discuss Google group/mail list - -'#pyramid' IRC channel on irc.freenode.net - -issue tracker on GitHub http://github.com/Pylons/pyramid/issues - -Contributing ------------- -Guidelines for contributing to Pyramid are available at the following URL. - -https://github.com/Pylons/pylonsrtd/tree/master/community - -Community ---------- -http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/ diff --git a/docs/getting_started/index.rst b/docs/getting_started/index.rst deleted file mode 100644 index b7ab3c7bb..000000000 --- a/docs/getting_started/index.rst +++ /dev/null @@ -1,60 +0,0 @@ -============================ -Getting Started With Pyramid -============================ - -Welcome to Pyramid, the Python web framework that lets you start small -and finish big. Whether you are new to Python web development or you're -an experienced developer wanting a quick look at the major -features, this guide provides a convenient entry point with independent -chapters for each topic. - -About This Guide -================ - -Evaluators want to jump right into a particular topic. This *Getting -Started* guide is structured with chapter titles that focuses on a -particular aspect of web development. Each chapter is autonomous and -you don't have to follow from beginning to end. - -By definition, each topic is covered at a high level. To make it easy -to get to in-depth treatment, the chapters provide interlinking with -the full treatment in the :ref:`html_narrative_documentation`. - -This guide is part of the official documentation. If you find a bug, -you can report it using the same facilities as the described in the -software's :ref:`support-and-development`. - -Notes -===== - -- Cover static urls and asset specifications, resolving, replacing - -.. toctree:: - :maxdepth: 1 - - gettingstarted - - -Contents -======== - -.. toctree:: - :maxdepth: 2 - - quick_glance - scaffolds - configuration - routes - views - templates - static_assets - pserve - testing - forms - databases - security - json - sessions - internationalization - special_views - top_ten \ No newline at end of file diff --git a/docs/getting_started/internationalization.rst b/docs/getting_started/internationalization.rst deleted file mode 100644 index cc93406b1..000000000 --- a/docs/getting_started/internationalization.rst +++ /dev/null @@ -1,3 +0,0 @@ -============================================= -Multiple Languages Using Internationalization -============================================= diff --git a/docs/getting_started/json.rst b/docs/getting_started/json.rst deleted file mode 100644 index 006b44fc3..000000000 --- a/docs/getting_started/json.rst +++ /dev/null @@ -1,4 +0,0 @@ -================================= -Modern Web Development Using JSON -================================= - diff --git a/docs/getting_started/pserve.rst b/docs/getting_started/pserve.rst deleted file mode 100644 index a7f8ba62c..000000000 --- a/docs/getting_started/pserve.rst +++ /dev/null @@ -1,18 +0,0 @@ -=================================== -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 deleted file mode 100644 index f9a60c0eb..000000000 --- a/docs/getting_started/quick_glance.rst +++ /dev/null @@ -1,806 +0,0 @@ -============ -Quick Glance -============ - -Pyramid lets you start small and finish big. This :doc:`index` guide -walks you through many of Pyramid's key features. Let's put the -emphasis on *start* by doing a quick tour through Pyramid, with -snippets of code to illustrate major concepts. - -.. note:: - - Like the rest of Getting Started, we're using Python 3 in - our samples. Pyramid was one of the first (October 2011) web - frameworks to fully support Python 3. You can use Python 3 - as well for this guide, but you can also use Python 2.7. - -Python Setup -============ - -First things first: we need our Python environment in ship-shape. -Pyramid encourages standard Python development practices (virtual -environments, packaging tools, logging, etc.) so let's get our working -area in place. For Python 3.3: - -.. code-block:: bash - - $ pyvenv-3.3 env33 - $ source env33/bin/activate - $ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python - $ easy_install-3.3 pip - -We make a :term:`virtualenv` then activate it. We then get Python -packaging tools installed so we can use the popular ``pip`` tool for -installing packages. Normal first steps for any Python project. - -Pyramid Installation -==================== - -We now have a standard starting point for Python. Getting Pyramid -installed is easy: - -.. code-block:: bash - - $ pip install pyramid - -Our virtual environment now has the Pyramid software available to its -Python. - -Hello World -=========== - -Microframeworks have shown that learning starts best from a very small -first step. Here's a tiny application in Pyramid: - -.. literalinclude:: quick_glance/hello_world/app.py - :linenos: - -This simple example is easy to run. Save this as ``app.py`` and run it: - -.. code-block:: bash - - $ python ./app.py - -Next, open `http://localhost:6543/ `_ in a -browser and you will see the ``Hello World!`` message. - -New to Python web programming? If so, some lines in module merit -explanation: - -#. *Line 10*. The ``if __name__ == '__main__':`` is Python's way of - saying "Start here when running from the command line". - -#. *Lines 11-13*. Use Pyramid's :term:`configurator` to connect - :term:`view` code to particular URL :term:`route`. - -#. *Lines 6-7*. Implement the view code that generates the - :term:`response`. - -#. *Lines 14-16*. Publish a :term:`WSGI` app using an HTTP server. - -As shown in this example, the :term:`configurator` plays a central role -in Pyramid development. Building an application from loosely-coupled -parts via :doc:`../narr/configuration` is a central idea in Pyramid, -one that we will revisit regurlarly in this *Getting Started* document. - -Handling Web Requests and Responses -=================================== - -Developing for the web means processing web requests. As this is a -critical part of a web application, web developers need a robust, -mature set of software for web requests. - -Pyramid has always fit nicely into the existing world of Python web -development (virtual environments, packaging, scaffolding, -first to embrace Python 3, etc.) For request handling, Pyramid turned -to the well-regarded :term:`WebOb` Python library for request and -response handling. In our example -above, Pyramid hands ``hello_world`` a ``request`` that is -:ref:`based on WebOb `. - -Let's see some features of requests and responses in action: - -.. literalinclude:: quick_glance/requests/app.py - :pyobject: hello_world - -In this Pyramid view, we get the URL being visited from ``request.url``. -Also, if you visited ``http://localhost:6543/?name=alice``, -the name is included in the body of the response:: - - URL http://localhost:6543/?name=alice with name: alice - -Finally, we set the response's content type and return the Response. - -Views -===== - -For the examples above, the ``hello_world`` function is a "view". In -Pyramid, views are the primary way to accept web requests and return -responses. - -So far our examples place everything in one file: - -- the view function - -- its registration with the configurator - -- the route to map it to a URL - -- the WSGI application launcher - -Let's move the views out to their own ``views.py`` module and change -the ``app.py`` to scan that module, looking for decorators that setup -the views. First, our revised ``app.py``: - -.. literalinclude:: quick_glance/views/app.py - :linenos: - -We added some more routes, but we also removed the view code. -Our views, and their registrations (via decorators) are now in a module -``views.py`` which is scanned via ``config.scan('views')``. - -We now have a ``views.py`` module that is focused on handling requests -and responses: - -.. literalinclude:: quick_glance/views/views.py - :linenos: - -We have 4 views, each leading to the other. If you start at -``http://localhost:6543/``, you get a response with a link to the next -view. The ``hello_view`` (available at the URL ``/howdy``) has a link -to the ``redirect_view``, which shows issuing a redirect to the final -view. - -Earlier we saw ``config.add_view`` as one way to configure a view. This -section introduces ``@view_config``. Pyramid's configuration supports -:term:`imperative configuration`, such as the ``config.add_view`` in -the previous example. You can also use :term:`declarative -configuration`, in which a Python :term:`decorator` is placed on the -line above the view. Both approaches result in the same final -configuration, thus usually, it is simply a matter of taste. - -.. note:: - - We're focusing on one topic at a time, thus we are leaving out - handling errors, logging, restarting, etc. These will be covered in - sections of the *Getting Started* guide. - - -Routing -======= - -Writing web applications usually means sophisticated URL design. We -just saw some Pyramid machinery for requests and views. Let's look at -features that help in routing. - -Above we saw the basics of routing URLs to views in Pyramid: - -- Your project's "setup" code registers a route name to be used when - matching part of the URL - -- Elsewhere, a view is configured to be called for that route name - -.. note:: - - Why do this twice? Other systems don't make us repeat this! As - illustrated in :ref:`routes_need_ordering`, multiple routes might - match the same URL pattern. Rather than provide ways to help guess, - Pyramid lets you be explicit in ordering. Pyramid also gives - facilities to avoid the problem. - -What if we want part of the URL to be available as data in my view? This -route declaration: - -.. literalinclude:: quick_glance/routing/app.py - :start-after: Start Route 1 - :end-before: End Route 1 - -With this, URLs such as ``/howdy/amy/smith`` will assign ``amy`` to -``first`` and ``smith`` to ``last``. We can then use this data in our -view: - -.. literalinclude:: quick_glance/routing/views.py - :start-after: Start Route 1 - :end-before: End Route 1 - -``request.matchdict`` contains values from the URL that match the -"replacement patterns" (the curly braces) in the route declaration. -This information can then be used in your view. - -As you might imagine, Pyramid provides -:doc:`many more features in routing <../narr/urldispatch>` -(route factories, custom predicates, security statements, -etc.) We will see more features later in *Geting Started*. - -Templating -========== - -Ouch. We have been making our own ``Response`` and filling the response -body with HTML. You usually won't embed an HTML string directly in -Python, but instead, will use a templating language. - -Pyramid doesn't mandate a particular database system, form library, -etc. It encourages replaceability. This applies equally to templating, -which is fortunate: developers have strong views about template -languages. That said, Pyramid bundles Chameleon and Mako, -so in this step, let's use Chameleon as an example: - -.. literalinclude:: quick_glance/templating/views.py - :start-after: Start View 1 - :end-before: End View 1 - -Ahh, that looks better. We have a view that is focused on Python code. -Our ``@view_config`` decorator specifies a :term:`renderer` that points -our template file. Our view then simply returns data which is then -supplied to our template: - -.. literalinclude:: quick_glance/templating/hello_world.pt - :language: html - -Since our view returned ``dict(name=request.matchdict['name'])``, -we can use ``name`` as a variable in our template via -``${name}``. - -Templating With ``jinja2`` -========================== - -We just said Pyramid doesn't prefer one templating language over -another. Time to prove it. Jinja2 is a popular templating system, -modelled after Django's templates. Let's add ``pyramid_jinja2``, -a Pyramid :term:`add-on` which enables Jinja2 as a :term:`renderer` in -our Pyramid applications: - -.. code-block:: bash - - $ pip install pyramid_jinja2 - -With the package installed, we can include the template bindings into -our configuration: - -.. code-block:: python - - config.include('pyramid_jinja2') - -The only change in our view...point the renderer at the ``.jinja2`` file: - -.. literalinclude:: quick_glance/jinja2/views.py - :start-after: Start View 1 - :end-before: End View 1 - -Our Jinja2 template is very similar to our previous template: - -.. literalinclude:: quick_glance/jinja2/hello_world.jinja2 - :language: jinja - -Pyramid's templating add-ons register a new kind of renderer into your -application. The renderer registration maps to different kinds of -filename extensions. In this case, changing the extension from ``.pt`` -to ``.jinja2`` passed the view response through the ``pyramid_jinja2`` -renderer. - -.. note:: - - At the time of this writing, Jinja2 had not released a version - compatible with Python 3.3. - - -Static Assets -============= - -Of course the Web is more than just markup. You need static assets: -CSS, JS, and images. Let's point our web app at a directory where -Pyramid will serve some static assets. First, another call to the -:term:`configurator`: - -.. literalinclude:: quick_glance/static_assets/app.py - :start-after: Start Static 1 - :end-before: End Static 1 - -This tells our WSGI application to map requests under -``http://localhost:6543/static/`` to files and directories inside a -``static`` directory alongside our Python module. - -Next, make a directory ``static`` and place ``app.css`` inside: - -.. literalinclude:: quick_glance/static_assets/static/app.css - :language: css - -All we need to do now is point to it in the ```` of our Jinja2 -template: - -.. literalinclude:: quick_glance/static_assets/hello_world.pt - :language: html - :start-after: Start Link 1 - :end-before: End Link 1 - -This link presumes that our CSS is at a URL starting with ``/static/``. -What if the site is later moved under ``/somesite/static/``? Or perhaps -web developer changes the arrangement on disk? Pyramid gives a helper -that provides flexibility on URL generation: - -.. literalinclude:: quick_glance/static_assets/hello_world.pt - :language: html - :start-after: Start Link 2 - :end-before: End Link 2 - -By using ``request.static_url`` to generate the full URL to the static -assets, you both ensure you stay in sync with the configuration and -gain refactoring flexibility later. - -Returning JSON -============== - -Modern web apps are more than rendered HTML. Dynamic pages now use -JavaScript to update the UI in the browser by requesting server data as -JSON. Pyramid supports this with a JSON renderer: - -.. literalinclude:: quick_glance/json/views.py - :start-after: Start View 1 - :end-before: End View 2 - -This wires up a view that returns some data through the JSON -:term:`renderer`, which calls Python's JSON support to serialize the data -into JSON and set the appropriate HTTP headers. - -View Classes -============ - -So far our views have been simple, free-standing functions. Many times -your views are related: different ways to look at or work on the same -data or a REST API that handles multiple operations. Grouping these -together as a -:ref:`view class ` makes sense: - -- Group views - -- Centralize some repetitive defaults - -- Share some state and helpers - -The following shows a "Hello World" example with three operations: view -a form, save a change, or press the delete button: - -.. literalinclude:: quick_glance/view_classes/views.py - :start-after: Start View 1 - :end-before: End View 1 - -As you can see, the three views are logically grouped together. -Specifically: - -- The first view is returned when you go to ``/howdy/amy``. This URL is - mapped to the ``hello`` route that we centrally set using the optional - ``@view_defaults``. - -- The second view is returned when the form data contains a field with - ``form.edit``, such as clicking on - ````. This rule - is specified in the ``@view_config`` for that view. - -- The third view is returned when clicking on a button such - as ````. - -Only one route needed, stated in one place atop the view class. Also, -the assignment of the ``name`` is done in the ``__init__``. Our -templates can then use ``{{ view.name }}``. - -Quick Project Startup with Scaffolds -==================================== - -So far we have done all of our *Quick Glance* as a single Python file. -No Python packages, no structure. Most Pyramid projects, though, -aren't developed this way. - -To ease the process of getting started, Pyramid provides *scaffolds* -that generate sample projects from templates in Pyramid and Pyramid -add-ons. Pyramid's ``pcreate`` command can list the available scaffolds: - -.. code-block:: bash - - $ pcreate --list - Available scaffolds: - alchemy: Pyramid SQLAlchemy project using url dispatch - pyramid_jinja2_starter: pyramid jinja2 starter project - starter: Pyramid starter project - zodb: Pyramid ZODB project using traversal - -The ``pyramid_jinja2`` add-on gave us a scaffold that we can use. From -the parent directory of where we want our Python package to be generated, -let's use that scaffold to make our project: - -.. code-block:: bash - - $ pcreate --scaffold pyramid_jinja2_starter hello_world - -We next use the normal Python development to setup our package for -development: - -.. code-block:: bash - - $ cd hello_world - $ python ./setup.py develop - -We are moving in the direction of a full-featured Pyramid project, -with a proper setup for Python standards (packaging) and Pyramid -configuration. This includes a new way of running your application: - -.. code-block:: bash - - $ pserve development.ini - -Let's look at ``pserve`` and configuration in more depth. - -Application Running with ``pserve`` -=================================== - -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 -files and reload the server when they change: - -.. code-block:: bash - - $ pserve development.ini --reload - -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. 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: - -- ``[app:hello_world]`` configures our WSGI app - -- ``[pipeline:main]`` sets up our WSGI "pipeline" - -- ``[server:main]`` holds our WSGI server settings - -- Various sections afterwards configure our Python logging system - -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 - package. - -#. *Port number*. ``port = 6543`` tells ``wsgiref`` to listen on port - 6543. - -#. *WSGI app*. What package has our WSGI application in it? - ``use = egg:hello_world`` in the app section tells the - configuration what application to load. - -#. *Easier development by automatic template reloading*. In development - mode, you shouldn't have to restart the server when editing a Jinja2 - template. ``reload_templates = true`` sets this policy, - which might be different in production. - -Additionally, the ``development.ini`` generated by this scaffold wired -up Python's standard logging. We'll now see in the console, for example, -a log on every request that comes in, as well traceback information. - -Easier Development with ``debugtoolbar`` -======================================== - -As we introduce the basics we also want to show how to be productive in -development and debugging. For example, we just discussed template -reloading and earlier we showed ``--reload`` for application reloading. - -``pyramid_debugtoolbar`` is a popular Pyramid add-on which makes -several tools available in your browser. Adding it to your project -illustrates several points about configuration. - -First, change your ``setup.py`` to say: - -.. literalinclude:: quick_glance/package/setup.py - :start-after: Start Requires - :end-before: End Requires - -...and re-run your setup: - -.. code-block:: bash - - $ python ./setup.py develop - -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: - -.. literalinclude:: quick_glance/package/hello_world/__init__.py - :start-after: Start Include - :end-before: End Include - -Now that we have a configuration file, we can use the -``pyramid.includes`` facility and place this in our -``development.ini`` instead: - -.. literalinclude:: quick_glance/package/development.ini - :language: ini - :start-after: Start Includes - :end-before: End Includes - -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. 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`` -======================= - -Yikes! We got this far and we haven't yet discussed tests. Particularly -egregious, as Pyramid has had a deep commitment to full test coverage -since before it was released. - -Our ``pyramid_jinja2_starter`` scaffold generated a ``tests.py`` module -with one unit test in it. To run it, let's install the handy ``nose`` -test runner by editing ``setup.py``. While we're at it, we'll throw in -the ``coverage`` tool which yells at us for code that isn't tested: - -.. code-block:: python - - setup(name='hello_world', - # Some lines removed... - extras_require={ - 'testing': ['nose', 'coverage'], - } - ) - -We changed ``setup.py`` which means we need to re-run -``python ./setup.py develop``. We can now run all our tests: - -.. code-block:: bash - - $ cd hello_world - $ nosetests . - . - Name Stmts Miss Cover Missing - --------------------------------------------------- - hello_world 12 8 33% 11-23 - hello_world.models 5 1 80% 8 - hello_world.tests 14 0 100% - hello_world.views 4 0 100% - --------------------------------------------------- - TOTAL 35 9 74% - ---------------------------------------------------------------------- - Ran 1 test in 0.931s - - OK - -Our unit test passed. What did our test look like? - -.. 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, -makes a dummy request, and sees if the view returns what we expected. - -Logging -======= - -It's important to know what is going on inside our web application. -In development we might need to collect some output. In production, -we might need to detect situations when other people use the site. We -need *logging*. - -Fortunately Pyramid uses the normal Python approach to logging. The -scaffold generated, in your ``development.ini``, a number of lines that -configure the logging for you to some reasonable defaults. You then see -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: - -.. 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: - -.. 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: - -.. 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. 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. 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. 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: - -.. literalinclude:: quick_glance/package/hello_world/__init__.py - :start-after: Start Sphinx Include 1 - :end-before: End Sphinx Include 1 - -.. warning:: - - As noted in the session docs, this example implementation is - not intended for use in settings with security implications. - -Now make a "factory" and pass it to the :term:`configurator`'s -``session_factory`` argument: - -.. literalinclude:: quick_glance/package/hello_world/__init__.py - :start-after: Start Sphinx Include 2 - :end-before: End Sphinx Include 2 - -Pyramid's :term:`request` object now has a ``session`` attribute -that we can use in our view code: - -.. 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 - - -Databases -========= - -Web applications mean data. Data means databases. Frequently SQL -databases. SQL Databases frequently mean an "ORM" -(object-relational mapper.) In Python, ORM usually leads to the -mega-quality *SQLAlchemy*, a Python package that greatly eases working -with databases. - -Pyramid and SQLAlchemy are great friends. That friendship includes a -scaffold! - -.. code-block:: bash - - $ pcreate --scaffold alchemy sqla_demo - $ cd sqla_demo - $ python setup.py develop - -We now have a working sample SQLAlchemy application with all -dependencies installed. The sample project provides a console script to -initialize a SQLite database with tables. Let's run it and then start -the application: - -.. code-block:: bash - - $ initialize_sqla_demo_db development.ini - $ pserve development.ini - -The ORM eases the mapping of database structures into a programming -language. SQLAlchemy uses "models" for this mapping. The scaffold -generated a sample model: - -.. literalinclude:: quick_glance/sqla_demo/sqla_demo/models.py - :start-after: Start Sphinx Include - :end-before: End Sphinx Include - -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: - -.. literalinclude:: quick_glance/sqla_demo/sqla_demo/views.py - :start-after: Start Sphinx Include - :end-before: End Sphinx Include - -Forms -===== - -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 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 WikiPage(colander.MappingSchema): - title = colander.SchemaNode(colander.String()) - body = colander.SchemaNode( - colander.String(), - widget=deform.widget.RichTextWidget() - ) - -With this in place, we can render the HTML for a form, -perhaps with form data from an existing page: - -.. code-block:: python - - form = self.wiki_form.render() - -We'd like to handle form submission, validation, and saving: - -.. code-block:: python - - # 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()) - - # Change the content and redirect to the view - page['title'] = appstruct['title'] - page['body'] = appstruct['body'] - -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. - -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. - - - - -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_world/app.py b/docs/getting_started/quick_glance/hello_world/app.py deleted file mode 100644 index df5a6cf18..000000000 --- a/docs/getting_started/quick_glance/hello_world/app.py +++ /dev/null @@ -1,16 +0,0 @@ -from wsgiref.simple_server import make_server -from pyramid.config import Configurator -from pyramid.response import Response - - -def hello_world(request): - return Response('

Hello World!

') - - -if __name__ == '__main__': - config = Configurator() - config.add_route('hello', '/') - config.add_view(hello_world, route_name='hello') - app = config.make_wsgi_app() - server = make_server('0.0.0.0', 6543, app) - server.serve_forever() \ No newline at end of file diff --git a/docs/getting_started/quick_glance/jinja2/app.py b/docs/getting_started/quick_glance/jinja2/app.py deleted file mode 100644 index 83af219db..000000000 --- a/docs/getting_started/quick_glance/jinja2/app.py +++ /dev/null @@ -1,11 +0,0 @@ -from wsgiref.simple_server import make_server -from pyramid.config import Configurator - -if __name__ == '__main__': - config = Configurator() - config.add_route('hello', '/howdy/{name}') - config.include('pyramid_jinja2') - config.scan('views') - app = config.make_wsgi_app() - server = make_server('0.0.0.0', 6543, app) - server.serve_forever() \ No newline at end of file diff --git a/docs/getting_started/quick_glance/jinja2/hello_world.jinja2 b/docs/getting_started/quick_glance/jinja2/hello_world.jinja2 deleted file mode 100644 index e177744b5..000000000 --- a/docs/getting_started/quick_glance/jinja2/hello_world.jinja2 +++ /dev/null @@ -1,8 +0,0 @@ - - - Hello World - - -

Hello {{ name }}!

- - \ No newline at end of file diff --git a/docs/getting_started/quick_glance/jinja2/views.py b/docs/getting_started/quick_glance/jinja2/views.py deleted file mode 100644 index 916cdc720..000000000 --- a/docs/getting_started/quick_glance/jinja2/views.py +++ /dev/null @@ -1,8 +0,0 @@ -from pyramid.view import view_config - - -# Start View 1 -@view_config(route_name='hello', renderer='hello_world.jinja2') -# End View 1 -def hello_world(request): - return dict(name=request.matchdict['name']) diff --git a/docs/getting_started/quick_glance/json/app.py b/docs/getting_started/quick_glance/json/app.py deleted file mode 100644 index 950cb478f..000000000 --- a/docs/getting_started/quick_glance/json/app.py +++ /dev/null @@ -1,15 +0,0 @@ -from wsgiref.simple_server import make_server - -from pyramid.config import Configurator - - -if __name__ == '__main__': - config = Configurator() - config.add_route('hello', '/howdy/{name}') - config.add_route('hello_json', 'hello.json') - config.add_static_view(name='static', path='static') - config.include('pyramid_jinja2') - config.scan('views') - app = config.make_wsgi_app() - server = make_server('0.0.0.0', 6543, app) - server.serve_forever() \ No newline at end of file diff --git a/docs/getting_started/quick_glance/json/hello_world.jinja2 b/docs/getting_started/quick_glance/json/hello_world.jinja2 deleted file mode 100644 index f6862e618..000000000 --- a/docs/getting_started/quick_glance/json/hello_world.jinja2 +++ /dev/null @@ -1,10 +0,0 @@ - - - - Quick Glance - - - -

Hello {{ name }}!

- - \ No newline at end of file diff --git a/docs/getting_started/quick_glance/json/hello_world.pt b/docs/getting_started/quick_glance/json/hello_world.pt deleted file mode 100644 index 711054aa9..000000000 --- a/docs/getting_started/quick_glance/json/hello_world.pt +++ /dev/null @@ -1,17 +0,0 @@ - - - - Quick Glance - - - - - - - - -

Hello ${name}!

- - \ No newline at end of file diff --git a/docs/getting_started/quick_glance/json/views.py b/docs/getting_started/quick_glance/json/views.py deleted file mode 100644 index 583e220c7..000000000 --- a/docs/getting_started/quick_glance/json/views.py +++ /dev/null @@ -1,13 +0,0 @@ -from pyramid.view import view_config - - -@view_config(route_name='hello', renderer='hello_world.pt') -def hello_world(request): - return dict(name=request.matchdict['name']) - - -# Start View 1 -@view_config(route_name='hello_json', renderer='json') -def hello_json(request): - return [1, 2, 3] - # End View 1 \ No newline at end of file diff --git a/docs/getting_started/quick_glance/package/CHANGES.txt b/docs/getting_started/quick_glance/package/CHANGES.txt deleted file mode 100644 index ffa255da8..000000000 --- a/docs/getting_started/quick_glance/package/CHANGES.txt +++ /dev/null @@ -1,4 +0,0 @@ -0.0 ---- - -- Initial version diff --git a/docs/getting_started/quick_glance/package/MANIFEST.in b/docs/getting_started/quick_glance/package/MANIFEST.in deleted file mode 100644 index 18fbd855c..000000000 --- a/docs/getting_started/quick_glance/package/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -include *.txt *.ini *.cfg *.rst -recursive-include hello_world *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml diff --git a/docs/getting_started/quick_glance/package/README.txt b/docs/getting_started/quick_glance/package/README.txt deleted file mode 100644 index 63aaf6fbd..000000000 --- a/docs/getting_started/quick_glance/package/README.txt +++ /dev/null @@ -1,4 +0,0 @@ -hello_world README - - - diff --git a/docs/getting_started/quick_glance/package/development.ini b/docs/getting_started/quick_glance/package/development.ini deleted file mode 100644 index a751ff903..000000000 --- a/docs/getting_started/quick_glance/package/development.ini +++ /dev/null @@ -1,57 +0,0 @@ -# Start Includes -[app:hello_world] -pyramid.includes = pyramid_debugtoolbar -# End Includes -use = egg:hello_world -reload_templates = true -debug_authorization = false -debug_notfound = false -debug_routematch = false -debug_templates = true -default_locale_name = en -jinja2.directories = hello_world:templates - - - -[pipeline:main] -pipeline = - hello_world - -[server:main] -use = egg:pyramid#wsgiref -host = 0.0.0.0 -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 - -[formatters] -keys = generic - -[logger_root] -level = INFO -handlers = console - - -[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 - -# End logging configuration diff --git a/docs/getting_started/quick_glance/package/hello_world/__init__.py b/docs/getting_started/quick_glance/package/hello_world/__init__.py deleted file mode 100644 index 6e66bf40a..000000000 --- a/docs/getting_started/quick_glance/package/hello_world/__init__.py +++ /dev/null @@ -1,34 +0,0 @@ -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): - """ This function returns a WSGI application. - - It is usually called by the PasteDeploy framework during - ``paster serve``. - """ - settings = dict(settings) - settings.setdefault('jinja2.i18n.domain', 'hello_world') - - # 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', - context='hello_world.models.MyModel', - renderer="mytemplate.jinja2") - - return config.make_wsgi_app() diff --git a/docs/getting_started/quick_glance/package/hello_world/locale/de/LC_MESSAGES/hello_world.mo b/docs/getting_started/quick_glance/package/hello_world/locale/de/LC_MESSAGES/hello_world.mo deleted file mode 100644 index 40bf0c271..000000000 Binary files a/docs/getting_started/quick_glance/package/hello_world/locale/de/LC_MESSAGES/hello_world.mo and /dev/null differ diff --git a/docs/getting_started/quick_glance/package/hello_world/locale/de/LC_MESSAGES/hello_world.po b/docs/getting_started/quick_glance/package/hello_world/locale/de/LC_MESSAGES/hello_world.po deleted file mode 100644 index 0df243dba..000000000 --- a/docs/getting_started/quick_glance/package/hello_world/locale/de/LC_MESSAGES/hello_world.po +++ /dev/null @@ -1,21 +0,0 @@ -# Translations template for PROJECT. -# Copyright (C) 2011 ORGANIZATION -# This file is distributed under the same license as the PROJECT project. -# FIRST AUTHOR , 2011. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PROJECT VERSION\n" -"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2011-05-12 09:14-0330\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 0.9.6\n" - -msgid "Hello!" -msgstr "Hallo!" diff --git a/docs/getting_started/quick_glance/package/hello_world/locale/fr/LC_MESSAGES/hello_world.mo b/docs/getting_started/quick_glance/package/hello_world/locale/fr/LC_MESSAGES/hello_world.mo deleted file mode 100644 index 4fc438bfe..000000000 Binary files a/docs/getting_started/quick_glance/package/hello_world/locale/fr/LC_MESSAGES/hello_world.mo and /dev/null differ diff --git a/docs/getting_started/quick_glance/package/hello_world/locale/fr/LC_MESSAGES/hello_world.po b/docs/getting_started/quick_glance/package/hello_world/locale/fr/LC_MESSAGES/hello_world.po deleted file mode 100644 index dc0aae5d7..000000000 --- a/docs/getting_started/quick_glance/package/hello_world/locale/fr/LC_MESSAGES/hello_world.po +++ /dev/null @@ -1,21 +0,0 @@ -# Translations template for PROJECT. -# Copyright (C) 2011 ORGANIZATION -# This file is distributed under the same license as the PROJECT project. -# FIRST AUTHOR , 2011. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PROJECT VERSION\n" -"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2011-05-12 09:14-0330\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 0.9.6\n" - -msgid "Hello!" -msgstr "Bonjour!" diff --git a/docs/getting_started/quick_glance/package/hello_world/locale/hello_world.pot b/docs/getting_started/quick_glance/package/hello_world/locale/hello_world.pot deleted file mode 100644 index 9c9460cb2..000000000 --- a/docs/getting_started/quick_glance/package/hello_world/locale/hello_world.pot +++ /dev/null @@ -1,21 +0,0 @@ -# Translations template for PROJECT. -# Copyright (C) 2011 ORGANIZATION -# This file is distributed under the same license as the PROJECT project. -# FIRST AUTHOR , 2011. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PROJECT VERSION\n" -"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2011-05-12 09:14-0330\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 0.9.6\n" - -msgid "Hello!" -msgstr "" diff --git a/docs/getting_started/quick_glance/package/hello_world/models.py b/docs/getting_started/quick_glance/package/hello_world/models.py deleted file mode 100644 index edd361c9c..000000000 --- a/docs/getting_started/quick_glance/package/hello_world/models.py +++ /dev/null @@ -1,8 +0,0 @@ -class MyModel(object): - pass - -root = MyModel() - - -def get_root(request): - return root diff --git a/docs/getting_started/quick_glance/package/hello_world/static/favicon.ico b/docs/getting_started/quick_glance/package/hello_world/static/favicon.ico deleted file mode 100644 index 71f837c9e..000000000 Binary files a/docs/getting_started/quick_glance/package/hello_world/static/favicon.ico and /dev/null differ diff --git a/docs/getting_started/quick_glance/package/hello_world/static/logo.png b/docs/getting_started/quick_glance/package/hello_world/static/logo.png deleted file mode 100644 index 88f5d9865..000000000 Binary files a/docs/getting_started/quick_glance/package/hello_world/static/logo.png and /dev/null differ diff --git a/docs/getting_started/quick_glance/package/hello_world/static/pylons.css b/docs/getting_started/quick_glance/package/hello_world/static/pylons.css deleted file mode 100644 index 42e2e320e..000000000 --- a/docs/getting_started/quick_glance/package/hello_world/static/pylons.css +++ /dev/null @@ -1,73 +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;} -/* remember to define focus styles! */ -:focus{outline:0;} -/* remember to highlight inserts somehow! */ -ins{text-decoration:none;} -del{text-decoration:line-through;} -/* tables still need 'cellspacing="0"' in the markup */ -table{border-collapse:collapse;border-spacing:0;} -/* restyling */ -sub{vertical-align:sub;font-size:smaller;line-height:normal;} -sup{vertical-align:super;font-size:smaller;line-height:normal;} -/* lists */ -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;} -/* nested lists have no top/bottom margins */ -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;} -/* 2 deep unordered lists use a circle */ -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;} -/* 3 deep (or more) unordered lists use a square */ -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;/* 28px */ -line-height:1.7em;font-family:helvetica,verdana;} -h2{font-size:1.5em;/* 24px */ -line-height:1.7em;font-family:helvetica,verdana;} -h3{font-size:1.25em;/* 20px */ -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:#ffffff;position:relative;font:16px/24px "Nobile","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:"Nobile","Lucida Grande",Lucida,Verdana,sans-serif;font-weight:normal;color:#144fb2;font-style:normal;} -#wrap {min-height: 100%;} -#header,#footer{width:100%;color:#ffffff;height:40px;position:absolute;text-align:center;line-height:40px;overflow:hidden;font-size:12px;} -#header{background-color:#e88f00;top:0;font-size:14px;} -#footer{background-color:#000000;bottom:0;position: relative;margin-top:-40px;clear:both;} -.header,.footer{width:700px;margin-right:auto;margin-left:auto;} -.wrapper{width:100%} -#top,#bottom{width:100%;} -#top{color:#888;background-color:#eee;height:300px;border-bottom:2px solid #ddd;} -#bottom{color:#222;background-color:#ffffff;overflow:auto;padding-bottom:80px;} -.top,.bottom{width:700px;margin-right:auto;margin-left:auto;} -.top{padding-top:100px;} -.app-welcome{margin-top:25px;} -.app-name{color:#000000;font-weight:bold;} -.bottom{padding-top:50px;} -#left{width:325px;float:left;padding-right:25px;} -#right{width:325px;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=submit]{background-color:#ddd;font-weight:bold;} -/*Opera Fix*/ -body:before {content:"";height:100%;float:left;width:0;margin-top:-32767px;} 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 deleted file mode 100644 index 25a28ed7a..000000000 --- a/docs/getting_started/quick_glance/package/hello_world/templates/mytemplate.jinja2 +++ /dev/null @@ -1,90 +0,0 @@ - - - - The Pyramid Web Framework - - - - - - - - - - -
- -
-
- Logo -

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

-
-
-
-
-

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

- -

Counter: {{ request.session.counter }}

- -

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

-
-
-
-

Search Pyramid documentation

-
- - -
-
- -
-
-
- - - diff --git a/docs/getting_started/quick_glance/package/hello_world/tests.py b/docs/getting_started/quick_glance/package/hello_world/tests.py deleted file mode 100644 index ccec14f70..000000000 --- a/docs/getting_started/quick_glance/package/hello_world/tests.py +++ /dev/null @@ -1,20 +0,0 @@ -import unittest -from pyramid import testing -from pyramid.i18n import TranslationStringFactory - -_ = TranslationStringFactory('hello_world') - - -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') diff --git a/docs/getting_started/quick_glance/package/hello_world/views.py b/docs/getting_started/quick_glance/package/hello_world/views.py deleted file mode 100644 index 109c260ad..000000000 --- a/docs/getting_started/quick_glance/package/hello_world/views.py +++ /dev/null @@ -1,22 +0,0 @@ -# Start Logging 1 -import logging -log = logging.getLogger(__name__) -# End Logging 1 - -from pyramid.i18n import TranslationStringFactory - -_ = TranslationStringFactory('hello_world') - - -def my_view(request): - # 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/message-extraction.ini b/docs/getting_started/quick_glance/package/message-extraction.ini deleted file mode 100644 index 0c3d54bc1..000000000 --- a/docs/getting_started/quick_glance/package/message-extraction.ini +++ /dev/null @@ -1,3 +0,0 @@ -[python: **.py] -[jinja2: **.jinja2] -encoding = utf-8 diff --git a/docs/getting_started/quick_glance/package/setup.cfg b/docs/getting_started/quick_glance/package/setup.cfg deleted file mode 100644 index 186e796fc..000000000 --- a/docs/getting_started/quick_glance/package/setup.cfg +++ /dev/null @@ -1,28 +0,0 @@ -[nosetests] -match = ^test -nocapture = 1 -cover-package = hello_world -with-coverage = 1 -cover-erase = 1 - -[compile_catalog] -directory = hello_world/locale -domain = hello_world -statistics = true - -[extract_messages] -add_comments = TRANSLATORS: -output_file = hello_world/locale/hello_world.pot -width = 80 -mapping_file = message-extraction.ini - -[init_catalog] -domain = hello_world -input_file = hello_world/locale/hello_world.pot -output_dir = hello_world/locale - -[update_catalog] -domain = hello_world -input_file = hello_world/locale/hello_world.pot -output_dir = hello_world/locale -previous = true diff --git a/docs/getting_started/quick_glance/package/setup.py b/docs/getting_started/quick_glance/package/setup.py deleted file mode 100644 index f118ed5fb..000000000 --- a/docs/getting_started/quick_glance/package/setup.py +++ /dev/null @@ -1,41 +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() - -# Start Requires -requires = ['pyramid>=1.0.2', 'pyramid_jinja2', 'pyramid_debugtoolbar'] -# End Requires - -setup(name='hello_world', - version='0.0', - description='hello_world', - long_description=README + '\n\n' + CHANGES, - classifiers=[ - "Programming Language :: Python", - "Framework :: Pylons", - "Topic :: Internet :: WWW/HTTP", - "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", - ], - author='', - author_email='', - url='', - keywords='web pyramid pylons', - packages=find_packages(), - include_package_data=True, - zip_safe=False, - install_requires=requires, - tests_require=requires, - test_suite="hello_world", - entry_points="""\ - [paste.app_factory] - main = hello_world:main - """, - paster_plugins=['pyramid'], - extras_require={ - 'testing': ['nose', ], - } -) \ No newline at end of file diff --git a/docs/getting_started/quick_glance/requests/app.py b/docs/getting_started/quick_glance/requests/app.py deleted file mode 100644 index 7ac81eb50..000000000 --- a/docs/getting_started/quick_glance/requests/app.py +++ /dev/null @@ -1,24 +0,0 @@ -from wsgiref.simple_server import make_server -from pyramid.config import Configurator -from pyramid.response import Response - - -def hello_world(request): - # Some parameters from a request such as /?name=lisa - url = request.url - name = request.params.get('name', 'No Name Provided') - - body = 'URL %s with name: %s' % (url, name) - return Response( - content_type="text/plain", - body=body - ) - - -if __name__ == '__main__': - config = Configurator() - config.add_route('hello', '/') - config.add_view(hello_world, route_name='hello') - app = config.make_wsgi_app() - server = make_server('0.0.0.0', 6543, app) - server.serve_forever() \ No newline at end of file diff --git a/docs/getting_started/quick_glance/routing/app.py b/docs/getting_started/quick_glance/routing/app.py deleted file mode 100644 index 04a8a6344..000000000 --- a/docs/getting_started/quick_glance/routing/app.py +++ /dev/null @@ -1,12 +0,0 @@ -from wsgiref.simple_server import make_server -from pyramid.config import Configurator - -if __name__ == '__main__': - config = Configurator() - # Start Route 1 - config.add_route('hello', '/howdy/{first}/{last}') - # End Route 1 - config.scan('views') - app = config.make_wsgi_app() - server = make_server('0.0.0.0', 6543, app) - server.serve_forever() \ No newline at end of file diff --git a/docs/getting_started/quick_glance/routing/views.py b/docs/getting_started/quick_glance/routing/views.py deleted file mode 100644 index 8cb8d3780..000000000 --- a/docs/getting_started/quick_glance/routing/views.py +++ /dev/null @@ -1,10 +0,0 @@ -from pyramid.response import Response -from pyramid.view import view_config - - -# Start Route 1 -@view_config(route_name='hello') -def hello_world(request): - body = '

Hi %(first)s %(last)s!

' % request.matchdict - return Response(body) - # End Route 1 \ No newline at end of file diff --git a/docs/getting_started/quick_glance/sqla_demo/CHANGES.txt b/docs/getting_started/quick_glance/sqla_demo/CHANGES.txt deleted file mode 100644 index 35a34f332..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/CHANGES.txt +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index a432577e9..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index f35d3aec5..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/README.txt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 174468abf..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/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: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 deleted file mode 100644 index dc0ba304f..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/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: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 deleted file mode 100644 index 9f91cd122..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/setup.cfg +++ /dev/null @@ -1,27 +0,0 @@ -[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 deleted file mode 100644 index ac2eed035..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/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='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 deleted file mode 100644 index fa6adb104..000000000 Binary files a/docs/getting_started/quick_glance/sqla_demo/sqla_demo.sqlite and /dev/null 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 deleted file mode 100644 index aac7c5e69..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/__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/sqla_demo/sqla_demo/models.py b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/models.py deleted file mode 100644 index 3dfb40e58..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/models.py +++ /dev/null @@ -1,29 +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() - -# 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 deleted file mode 100644 index 5bb534f79..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/scripts/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# 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 deleted file mode 100644 index 66feb3008..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/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/sqla_demo/sqla_demo/static/favicon.ico b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/favicon.ico deleted file mode 100644 index 71f837c9e..000000000 Binary files a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/favicon.ico and /dev/null 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 deleted file mode 100644 index 1fbc873da..000000000 Binary files a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/footerbg.png and /dev/null 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 deleted file mode 100644 index 0596f2020..000000000 Binary files a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/headerbg.png and /dev/null 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 deleted file mode 100644 index b7c8493d8..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/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/sqla_demo/sqla_demo/static/middlebg.png b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/middlebg.png deleted file mode 100644 index 2369cfb7d..000000000 Binary files a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/middlebg.png and /dev/null 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 deleted file mode 100644 index 4b1c017cd..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/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/sqla_demo/sqla_demo/static/pyramid-small.png b/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pyramid-small.png deleted file mode 100644 index a5bc0ade7..000000000 Binary files a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pyramid-small.png and /dev/null 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 deleted file mode 100644 index 347e05549..000000000 Binary files a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/pyramid.png and /dev/null 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 deleted file mode 100644 index 0341802e5..000000000 Binary files a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/static/transparent.gif and /dev/null 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 deleted file mode 100644 index e0ac9d440..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/templates/mytemplate.pt +++ /dev/null @@ -1,76 +0,0 @@ - - - - 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 deleted file mode 100644 index 6fef6d695..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/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'], '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 deleted file mode 100644 index 768a7e42e..000000000 --- a/docs/getting_started/quick_glance/sqla_demo/sqla_demo/views.py +++ /dev/null @@ -1,37 +0,0 @@ -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/quick_glance/static_assets/app.py b/docs/getting_started/quick_glance/static_assets/app.py deleted file mode 100644 index 9c808972f..000000000 --- a/docs/getting_started/quick_glance/static_assets/app.py +++ /dev/null @@ -1,14 +0,0 @@ -from wsgiref.simple_server import make_server -from pyramid.config import Configurator - -if __name__ == '__main__': - config = Configurator() - config.add_route('hello', '/howdy/{name}') - # Start Static 1 - config.add_static_view(name='static', path='static') - # End Static 1 - config.include('pyramid_jinja2') - config.scan('views') - app = config.make_wsgi_app() - server = make_server('0.0.0.0', 6543, app) - server.serve_forever() \ No newline at end of file diff --git a/docs/getting_started/quick_glance/static_assets/hello_world.jinja2 b/docs/getting_started/quick_glance/static_assets/hello_world.jinja2 deleted file mode 100644 index f6862e618..000000000 --- a/docs/getting_started/quick_glance/static_assets/hello_world.jinja2 +++ /dev/null @@ -1,10 +0,0 @@ - - - - Quick Glance - - - -

Hello {{ name }}!

- - \ No newline at end of file diff --git a/docs/getting_started/quick_glance/static_assets/hello_world.pt b/docs/getting_started/quick_glance/static_assets/hello_world.pt deleted file mode 100644 index 1797146eb..000000000 --- a/docs/getting_started/quick_glance/static_assets/hello_world.pt +++ /dev/null @@ -1,16 +0,0 @@ - - - Quick Glance - - - - - - - - -

Hello ${name}!

- - \ No newline at end of file diff --git a/docs/getting_started/quick_glance/static_assets/static/app.css b/docs/getting_started/quick_glance/static_assets/static/app.css deleted file mode 100644 index f8acf3164..000000000 --- a/docs/getting_started/quick_glance/static_assets/static/app.css +++ /dev/null @@ -1,4 +0,0 @@ -body { - margin: 2em; - font-family: sans-serif; -} \ No newline at end of file diff --git a/docs/getting_started/quick_glance/static_assets/views.py b/docs/getting_started/quick_glance/static_assets/views.py deleted file mode 100644 index 90730ae32..000000000 --- a/docs/getting_started/quick_glance/static_assets/views.py +++ /dev/null @@ -1,6 +0,0 @@ -from pyramid.view import view_config - - -@view_config(route_name='hello', renderer='hello_world.pt') -def hello_world(request): - return dict(name=request.matchdict['name']) diff --git a/docs/getting_started/quick_glance/templating/app.py b/docs/getting_started/quick_glance/templating/app.py deleted file mode 100644 index 6d1a29f4e..000000000 --- a/docs/getting_started/quick_glance/templating/app.py +++ /dev/null @@ -1,10 +0,0 @@ -from wsgiref.simple_server import make_server -from pyramid.config import Configurator - -if __name__ == '__main__': - config = Configurator() - config.add_route('hello', '/howdy/{name}') - config.scan('views') - app = config.make_wsgi_app() - server = make_server('0.0.0.0', 6543, app) - server.serve_forever() \ No newline at end of file diff --git a/docs/getting_started/quick_glance/templating/hello_world.pt b/docs/getting_started/quick_glance/templating/hello_world.pt deleted file mode 100644 index ae14f447d..000000000 --- a/docs/getting_started/quick_glance/templating/hello_world.pt +++ /dev/null @@ -1,9 +0,0 @@ - - - - Quick Glance - - -

Hello ${name}

- - \ No newline at end of file diff --git a/docs/getting_started/quick_glance/templating/views.py b/docs/getting_started/quick_glance/templating/views.py deleted file mode 100644 index 6c7846efa..000000000 --- a/docs/getting_started/quick_glance/templating/views.py +++ /dev/null @@ -1,8 +0,0 @@ -from pyramid.view import view_config - - -# Start View 1 -@view_config(route_name='hello', renderer='hello_world.pt') -def hello_world(request): - return dict(name=request.matchdict['name']) - # End View 1 \ No newline at end of file diff --git a/docs/getting_started/quick_glance/view_classes/app.py b/docs/getting_started/quick_glance/view_classes/app.py deleted file mode 100644 index 468c8c29e..000000000 --- a/docs/getting_started/quick_glance/view_classes/app.py +++ /dev/null @@ -1,13 +0,0 @@ -from wsgiref.simple_server import make_server -from pyramid.config import Configurator - -if __name__ == '__main__': - config = Configurator() - # Start Routes 1 - config.add_route('hello', '/howdy/{name}') - # End Routes 1 - config.include('pyramid_jinja2') - config.scan('views') - app = config.make_wsgi_app() - server = make_server('0.0.0.0', 6543, app) - server.serve_forever() \ No newline at end of file diff --git a/docs/getting_started/quick_glance/view_classes/delete.jinja2 b/docs/getting_started/quick_glance/view_classes/delete.jinja2 deleted file mode 100644 index ba45b7d16..000000000 --- a/docs/getting_started/quick_glance/view_classes/delete.jinja2 +++ /dev/null @@ -1,9 +0,0 @@ - - - - Delete World - - -

Delete {{ view.name }}!

- - \ No newline at end of file diff --git a/docs/getting_started/quick_glance/view_classes/edit.jinja2 b/docs/getting_started/quick_glance/view_classes/edit.jinja2 deleted file mode 100644 index ce0eb5bd1..000000000 --- a/docs/getting_started/quick_glance/view_classes/edit.jinja2 +++ /dev/null @@ -1,9 +0,0 @@ - - - - Edit World - - -

Edit {{ view.name }}!

- - \ No newline at end of file diff --git a/docs/getting_started/quick_glance/view_classes/hello.jinja2 b/docs/getting_started/quick_glance/view_classes/hello.jinja2 deleted file mode 100644 index 3446b96ce..000000000 --- a/docs/getting_started/quick_glance/view_classes/hello.jinja2 +++ /dev/null @@ -1,17 +0,0 @@ - - - - Hello World - - -

Hello {{ view.name }}!

- -
- - - -
- - - \ No newline at end of file diff --git a/docs/getting_started/quick_glance/view_classes/views.py b/docs/getting_started/quick_glance/view_classes/views.py deleted file mode 100644 index 62556142e..000000000 --- a/docs/getting_started/quick_glance/view_classes/views.py +++ /dev/null @@ -1,32 +0,0 @@ -from pyramid.view import ( - view_config, - view_defaults - ) - - -# Start View 1 -# One route, at /howdy/amy, so don't repeat on each @view_config -@view_defaults(route_name='hello') -class HelloWorldViews: - def __init__(self, request): - self.request = request - # Our templates can now say {{ view.name }} - self.name = request.matchdict['name'] - - # Retrieving /howdy/amy the first time - @view_config(renderer='hello.jinja2') - def hello_view(self): - return dict() - - # Posting to /howdy/amy via the "Edit" submit button - @view_config(request_param='form.edit', renderer='edit.jinja2') - def edit_view(self): - print('Edited') - return dict() - - # Posting to /howdy/amy via the "Delete" submit button - @view_config(request_param='form.delete', renderer='delete.jinja2') - def delete_view(self): - print('Deleted') - return dict() - # End View 1 \ No newline at end of file diff --git a/docs/getting_started/quick_glance/views/app.py b/docs/getting_started/quick_glance/views/app.py deleted file mode 100644 index 54dc9ed4b..000000000 --- a/docs/getting_started/quick_glance/views/app.py +++ /dev/null @@ -1,13 +0,0 @@ -from wsgiref.simple_server import make_server -from pyramid.config import Configurator - -if __name__ == '__main__': - config = Configurator() - config.add_route('home', '/') - config.add_route('hello', '/howdy') - config.add_route('redirect', '/goto') - config.add_route('exception', '/problem') - config.scan('views') - app = config.make_wsgi_app() - server = make_server('0.0.0.0', 6543, app) - server.serve_forever() \ No newline at end of file diff --git a/docs/getting_started/quick_glance/views/views.py b/docs/getting_started/quick_glance/views/views.py deleted file mode 100644 index 9dc795f14..000000000 --- a/docs/getting_started/quick_glance/views/views.py +++ /dev/null @@ -1,29 +0,0 @@ -from pyramid.httpexceptions import HTTPFound -from pyramid.response import Response -from pyramid.view import view_config - - -# First view, available at http://localhost:6543/ -@view_config(route_name='home') -def home_view(request): - return Response('

Visit hello

') - - -# /howdy?name=alice which links to the next view -@view_config(route_name='hello') -def hello_view(request): - name = request.params.get('name', 'No Name') - body = '

Hi %s, this redirects

' - return Response(body % name) - - -# /goto which issues HTTP redirect to the last view -@view_config(route_name='redirect') -def redirect_view(request): - return HTTPFound(location="/problem") - - -# /problem which causes an site error -@view_config(route_name='exception') -def exception_view(request): - raise Exception() diff --git a/docs/getting_started/routes.rst b/docs/getting_started/routes.rst deleted file mode 100644 index ec4fc988c..000000000 --- a/docs/getting_started/routes.rst +++ /dev/null @@ -1,3 +0,0 @@ -=========================== -Designing URLs Using Routes -=========================== diff --git a/docs/getting_started/scaffolds.rst b/docs/getting_started/scaffolds.rst deleted file mode 100644 index 52101495e..000000000 --- a/docs/getting_started/scaffolds.rst +++ /dev/null @@ -1,110 +0,0 @@ -==================================== -Starting New Projects With Scaffolds -==================================== - -So far we have done all of our *Quick Glance* as a single Python file. -No Python packages, no structure. Most Pyramid projects, though, -aren't developed this way. - -To ease the process of getting started, Pyramid provides *scaffolds* -that generate sample projects. You run a command, perhaps answer some -questions, and a sample project is generated for you. Not just Pyramid -itself: add-ons such as ``pyramid_jinja2`` (or your own projects) can -register their own scaffolds. - - - -Pyramid projects are organized using normal Python facilities for -projects. Normal, though, is in the eye of the beholder. This chapter -shows how to use scaffolds to automate the boilerplate and quickly -start development of a new project. - -Topics: scaffolds, packaging, virtual environments - -Pyramid's ``pcreate`` command is used to generate a starting point -from a scaffold. What does this command look like? - -.. code-block:: bash - - $ pcreate --help - Usage: pcreate [options] output_directory - - Render Pyramid scaffolding to an output directory - - Options: - -h, --help show this help message and exit - -s SCAFFOLD_NAME, --scaffold=SCAFFOLD_NAME - Add a scaffold to the create process (multiple -s args - accepted) - -t SCAFFOLD_NAME, --template=SCAFFOLD_NAME - A backwards compatibility alias for -s/--scaffold. - Add a scaffold to the create process (multiple -t args - accepted) - -l, --list List all available scaffold names - --list-templates A backwards compatibility alias for -l/--list. List - all available scaffold names. - --simulate Simulate but do no work - --overwrite Always overwrite - --interactive When a file would be overwritten, interrogate - -Let's see what our Pyramid install supports as starting-point scaffolds: - -.. code-block:: bash - - $ pcreate --list - Available scaffolds: - alchemy: Pyramid SQLAlchemy project using url dispatch - pyramid_jinja2_starter: pyramid jinja2 starter project - starter: Pyramid starter project - zodb: Pyramid ZODB project using traversal - -The ``pyramid_jinja2_starter`` looks interesting. From the parent -directory of where we want our Python package to be generated, -let's use that scaffold to make our project: - -.. code-block:: bash - - $ pcreate --scaffold pyramid_jinja2_starter hello_world - -After printing a bunch of lines about the files being generated, -we now have a Python package. As described in the *official -instructions*, we need to install this as a development package: - -.. code-block:: bash - - $ cd hello_world - $ python ./setup.py develop - -What did we get? A top-level directory ``hello_world`` that includes -some packaging files and a subdirectory ``hello_world`` that has -sample files for our application: - -.. code-block:: bash - - $ ls - CHANGES.txt development.ini hello_world.egg-info - MANIFEST.in message-extraction.ini setup.cfg - README.txt hello_world setup.py - - $ ls hello_world - __init__.py locale static tests.py - __pycache__ models.py templates views.py - -We are moving in the direction of a full-featured Pyramid project, -with a proper setup for Python standards (packaging) and Pyramid -configuration. This includes a new way of running your application: - -.. code-block:: bash - - $ pserve development.ini - -With ``pserve``, your application isn't responsible for finding a WSGI -server and launching your WSGI app. Also, much of the wiring of your -application can be moved to a declarative ``.ini`` configuration file. - -In your browser, visit -`http://localhost:6543/ `_ and you'll see that -things look very different. In the next few sections we'll cover some -decisions made by this scaffold. - -Let's look at ``pserve`` and configuration in more depth. \ No newline at end of file diff --git a/docs/getting_started/security.rst b/docs/getting_started/security.rst deleted file mode 100644 index 5ba1fb103..000000000 --- a/docs/getting_started/security.rst +++ /dev/null @@ -1,3 +0,0 @@ -============================================== -Security With Authentication and Authorization -============================================== diff --git a/docs/getting_started/sessions.rst b/docs/getting_started/sessions.rst deleted file mode 100644 index 02e51f9e3..000000000 --- a/docs/getting_started/sessions.rst +++ /dev/null @@ -1,3 +0,0 @@ -=============================== -Site Visitor Data With Sessions -=============================== diff --git a/docs/getting_started/special_views.rst b/docs/getting_started/special_views.rst deleted file mode 100644 index c2b384bdb..000000000 --- a/docs/getting_started/special_views.rst +++ /dev/null @@ -1,3 +0,0 @@ -========================================= -NotFound, Errors, and Other Special Views -========================================= diff --git a/docs/getting_started/static_assets.rst b/docs/getting_started/static_assets.rst deleted file mode 100644 index b605260a7..000000000 --- a/docs/getting_started/static_assets.rst +++ /dev/null @@ -1,4 +0,0 @@ -====================================================== -Serving CSS, JavaScript, and Images With Static Assets -====================================================== - diff --git a/docs/getting_started/templates.rst b/docs/getting_started/templates.rst deleted file mode 100644 index 32cfea848..000000000 --- a/docs/getting_started/templates.rst +++ /dev/null @@ -1,4 +0,0 @@ -============================= -Rendering HTML With Templates -============================= - diff --git a/docs/getting_started/testing.rst b/docs/getting_started/testing.rst deleted file mode 100644 index af2b335b7..000000000 --- a/docs/getting_started/testing.rst +++ /dev/null @@ -1,4 +0,0 @@ -================================================= -Coding For Quality With Unit and Functional Tests -================================================= - diff --git a/docs/getting_started/top_ten.rst b/docs/getting_started/top_ten.rst deleted file mode 100644 index e207f4ce1..000000000 --- a/docs/getting_started/top_ten.rst +++ /dev/null @@ -1,41 +0,0 @@ -============================== -Top Killer Features In Pyramid -============================== - -As a regular developer - -- Configuration - -- Route factories and contexts - -- Advanced view configuration - -- Route prefixes - -- Asset specifications - -- Events - -- Custom renderers - -- Tweens - -- Transactions - -- Traversal - -- 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 deleted file mode 100644 index f30caea8a..000000000 --- a/docs/getting_started/views.rst +++ /dev/null @@ -1,30 +0,0 @@ -================================ -Handling Web Requests With Views -================================ - -Free-standing functions are the regular way to do views. Many times, -though, you have several views that are closely related. For example, -a document might have many different ways to look at it, -or a form might submit to different targets, or a REST handler might -cover different operations. - -Grouping these together makes logical sense. A view class lets you -group views, centralize some repetitive defaults, share some state -assignments, and use helper functions as class methods. - -As an example, imagine we have some views around saying hello to a -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: - - -...and some routes that wire up the views to URLs: - - -...and a form in ``hello_world.jinja2`` that submits to the second view: - - -Just to review: - -- The ``/howdy/amy`` URL matches the ``hello`` route, handled by the - ``hello_view`` class method. \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index e61fe64d4..c4b81ad7d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -48,30 +48,30 @@ What's New Getting Started =============== -Quick tour of major facilities in Pyramid, including a -:doc:`getting_started/quick_glance` high-level -overview. +If you are new to Pyramid, we have a few resources that can help you get +up to speed right away. Our *Quick Tour* shows a little about a lot: .. toctree:: - :maxdepth: 1 + :maxdepth: 2 + + quick_tour + +Also: + +* To see a minimal Pyramid web application, check out `creating your first + Pyramid application <../narr/firstapp>`_. + +* For help getting Pyramid set up, try the `install guide + <../narr/install>`_. + +* To get the feel of how a Pyramid web application is created, go to the + `single file tasks tutorial `_ page. + +* Like learning by example? Check out to the `wiki tutorial + <../tutorials/wiki2/index.html>`_. + +* Need help? See `Support `_. - getting_started/index - getting_started/quick_glance - getting_started/scaffolds - getting_started/configuration - getting_started/routes - getting_started/views - getting_started/templates - getting_started/static_assets - getting_started/testing - getting_started/forms - getting_started/databases - getting_started/security - getting_started/json - getting_started/sessions - getting_started/internationalization - getting_started/special_views - getting_started/top_ten .. _html_narrative_documentation: diff --git a/docs/quick_tour.rst b/docs/quick_tour.rst new file mode 100644 index 000000000..cc4afe67d --- /dev/null +++ b/docs/quick_tour.rst @@ -0,0 +1,789 @@ +===================== +Quick Tour of Pyramid +===================== + +Pyramid lets you start small and finish big. This *Quick Tour* guide +walks you through many of Pyramid's key features. Let's put the +emphasis on *start* by doing a quick tour through Pyramid, with +snippets of code to illustrate major concepts. + +.. note:: + + We use Python 3 in our samples. Pyramid was one of the first + (October 2011) web frameworks to fully support Python 3. You can + use Python 3 as well for this guide, but you can also use Python 2.7. + +Python Setup +============ + +First things first: we need our Python environment in ship-shape. +Pyramid encourages standard Python development practices (virtual +environments, packaging tools, logging, etc.) so let's get our working +area in place. For Python 3.3: + +.. code-block:: bash + + $ pyvenv-3.3 env33 + $ source env33/bin/activate + $ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python + $ easy_install-3.3 pip + +We make a :term:`virtualenv` then activate it. We then get Python +packaging tools installed so we can use the popular ``pip`` tool for +installing packages. Normal first steps for any Python project. + +Pyramid Installation +==================== + +We now have a standard starting point for Python. Getting Pyramid +installed is easy: + +.. code-block:: bash + + $ pip install pyramid + +Our virtual environment now has the Pyramid software available to its +Python. + +Hello World +=========== + +Microframeworks have shown that learning starts best from a very small +first step. Here's a tiny application in Pyramid: + +.. literalinclude:: quick_tour/hello_world/app.py + :linenos: + +This simple example is easy to run. Save this as ``app.py`` and run it: + +.. code-block:: bash + + $ python ./app.py + +Next, open `http://localhost:6543/ `_ in a +browser and you will see the ``Hello World!`` message. + +New to Python web programming? If so, some lines in module merit +explanation: + +#. *Line 10*. The ``if __name__ == '__main__':`` is Python's way of + saying "Start here when running from the command line". + +#. *Lines 11-13*. Use Pyramid's :term:`configurator` to connect + :term:`view` code to particular URL :term:`route`. + +#. *Lines 6-7*. Implement the view code that generates the + :term:`response`. + +#. *Lines 14-16*. Publish a :term:`WSGI` app using an HTTP server. + +As shown in this example, the :term:`configurator` plays a central role +in Pyramid development. Building an application from loosely-coupled +parts via :doc:`../narr/configuration` is a central idea in Pyramid, +one that we will revisit regurlarly in this *Quick Tour*. + +Handling Web Requests and Responses +=================================== + +Developing for the web means processing web requests. As this is a +critical part of a web application, web developers need a robust, +mature set of software for web requests. + +Pyramid has always fit nicely into the existing world of Python web +development (virtual environments, packaging, scaffolding, +first to embrace Python 3, etc.) For request handling, Pyramid turned +to the well-regarded :term:`WebOb` Python library for request and +response handling. In our example +above, Pyramid hands ``hello_world`` a ``request`` that is +:ref:`based on WebOb `. + +Let's see some features of requests and responses in action: + +.. literalinclude:: quick_tour/requests/app.py + :pyobject: hello_world + +In this Pyramid view, we get the URL being visited from ``request.url``. +Also, if you visited ``http://localhost:6543/?name=alice``, +the name is included in the body of the response:: + + URL http://localhost:6543/?name=alice with name: alice + +Finally, we set the response's content type and return the Response. + +Views +===== + +For the examples above, the ``hello_world`` function is a "view". In +Pyramid, views are the primary way to accept web requests and return +responses. + +So far our examples place everything in one file: + +- the view function + +- its registration with the configurator + +- the route to map it to a URL + +- the WSGI application launcher + +Let's move the views out to their own ``views.py`` module and change +the ``app.py`` to scan that module, looking for decorators that setup +the views. First, our revised ``app.py``: + +.. literalinclude:: quick_tour/views/app.py + :linenos: + +We added some more routes, but we also removed the view code. +Our views, and their registrations (via decorators) are now in a module +``views.py`` which is scanned via ``config.scan('views')``. + +We now have a ``views.py`` module that is focused on handling requests +and responses: + +.. literalinclude:: quick_tour/views/views.py + :linenos: + +We have 4 views, each leading to the other. If you start at +``http://localhost:6543/``, you get a response with a link to the next +view. The ``hello_view`` (available at the URL ``/howdy``) has a link +to the ``redirect_view``, which shows issuing a redirect to the final +view. + +Earlier we saw ``config.add_view`` as one way to configure a view. This +section introduces ``@view_config``. Pyramid's configuration supports +:term:`imperative configuration`, such as the ``config.add_view`` in +the previous example. You can also use :term:`declarative +configuration`, in which a Python :term:`decorator` is placed on the +line above the view. Both approaches result in the same final +configuration, thus usually, it is simply a matter of taste. + + +Routing +======= + +Writing web applications usually means sophisticated URL design. We +just saw some Pyramid machinery for requests and views. Let's look at +features that help in routing. + +Above we saw the basics of routing URLs to views in Pyramid: + +- Your project's "setup" code registers a route name to be used when + matching part of the URL + +- Elsewhere, a view is configured to be called for that route name + +.. note:: + + Why do this twice? Other systems don't make us repeat this! As + illustrated in :ref:`routes_need_ordering`, multiple routes might + match the same URL pattern. Rather than provide ways to help guess, + Pyramid lets you be explicit in ordering. Pyramid also gives + facilities to avoid the problem. + +What if we want part of the URL to be available as data in my view? This +route declaration: + +.. literalinclude:: quick_tour/routing/app.py + :start-after: Start Route 1 + :end-before: End Route 1 + +With this, URLs such as ``/howdy/amy/smith`` will assign ``amy`` to +``first`` and ``smith`` to ``last``. We can then use this data in our +view: + +.. literalinclude:: quick_tour/routing/views.py + :start-after: Start Route 1 + :end-before: End Route 1 + +``request.matchdict`` contains values from the URL that match the +"replacement patterns" (the curly braces) in the route declaration. +This information can then be used in your view. + +As you might imagine, Pyramid provides +:doc:`many more features in routing <../narr/urldispatch>` +(route factories, custom predicates, security statements, +etc.) We will see more features later in *Geting Started*. + +Templating +========== + +Ouch. We have been making our own ``Response`` and filling the response +body with HTML. You usually won't embed an HTML string directly in +Python, but instead, will use a templating language. + +Pyramid doesn't mandate a particular database system, form library, +etc. It encourages replaceability. This applies equally to templating, +which is fortunate: developers have strong views about template +languages. That said, Pyramid bundles Chameleon and Mako, +so in this step, let's use Chameleon as an example: + +.. literalinclude:: quick_tour/templating/views.py + :start-after: Start View 1 + :end-before: End View 1 + +Ahh, that looks better. We have a view that is focused on Python code. +Our ``@view_config`` decorator specifies a :term:`renderer` that points +our template file. Our view then simply returns data which is then +supplied to our template: + +.. literalinclude:: quick_tour/templating/hello_world.pt + :language: html + +Since our view returned ``dict(name=request.matchdict['name'])``, +we can use ``name`` as a variable in our template via +``${name}``. + +Templating With ``jinja2`` +========================== + +We just said Pyramid doesn't prefer one templating language over +another. Time to prove it. Jinja2 is a popular templating system, +modelled after Django's templates. Let's add ``pyramid_jinja2``, +a Pyramid :term:`add-on` which enables Jinja2 as a :term:`renderer` in +our Pyramid applications: + +.. code-block:: bash + + $ pip install pyramid_jinja2 + +With the package installed, we can include the template bindings into +our configuration: + +.. code-block:: python + + config.include('pyramid_jinja2') + +The only change in our view...point the renderer at the ``.jinja2`` file: + +.. literalinclude:: quick_tour/jinja2/views.py + :start-after: Start View 1 + :end-before: End View 1 + +Our Jinja2 template is very similar to our previous template: + +.. literalinclude:: quick_tour/jinja2/hello_world.jinja2 + :language: jinja + +Pyramid's templating add-ons register a new kind of renderer into your +application. The renderer registration maps to different kinds of +filename extensions. In this case, changing the extension from ``.pt`` +to ``.jinja2`` passed the view response through the ``pyramid_jinja2`` +renderer. + +.. note:: + + At the time of this writing, Jinja2 had not released a version + compatible with Python 3.3. + + +Static Assets +============= + +Of course the Web is more than just markup. You need static assets: +CSS, JS, and images. Let's point our web app at a directory where +Pyramid will serve some static assets. First, another call to the +:term:`configurator`: + +.. literalinclude:: quick_tour/static_assets/app.py + :start-after: Start Static 1 + :end-before: End Static 1 + +This tells our WSGI application to map requests under +``http://localhost:6543/static/`` to files and directories inside a +``static`` directory alongside our Python module. + +Next, make a directory ``static`` and place ``app.css`` inside: + +.. literalinclude:: quick_tour/static_assets/static/app.css + :language: css + +All we need to do now is point to it in the ```` of our Jinja2 +template: + +.. literalinclude:: quick_tour/static_assets/hello_world.pt + :language: html + :start-after: Start Link 1 + :end-before: End Link 1 + +This link presumes that our CSS is at a URL starting with ``/static/``. +What if the site is later moved under ``/somesite/static/``? Or perhaps +web developer changes the arrangement on disk? Pyramid gives a helper +that provides flexibility on URL generation: + +.. literalinclude:: quick_tour/static_assets/hello_world.pt + :language: html + :start-after: Start Link 2 + :end-before: End Link 2 + +By using ``request.static_url`` to generate the full URL to the static +assets, you both ensure you stay in sync with the configuration and +gain refactoring flexibility later. + +Returning JSON +============== + +Modern web apps are more than rendered HTML. Dynamic pages now use +JavaScript to update the UI in the browser by requesting server data as +JSON. Pyramid supports this with a JSON renderer: + +.. literalinclude:: quick_tour/json/views.py + :start-after: Start View 1 + :end-before: End View 2 + +This wires up a view that returns some data through the JSON +:term:`renderer`, which calls Python's JSON support to serialize the data +into JSON and set the appropriate HTTP headers. + +View Classes +============ + +So far our views have been simple, free-standing functions. Many times +your views are related: different ways to look at or work on the same +data or a REST API that handles multiple operations. Grouping these +together as a +:ref:`view class ` makes sense: + +- Group views + +- Centralize some repetitive defaults + +- Share some state and helpers + +The following shows a "Hello World" example with three operations: view +a form, save a change, or press the delete button: + +.. literalinclude:: quick_tour/view_classes/views.py + :start-after: Start View 1 + :end-before: End View 1 + +As you can see, the three views are logically grouped together. +Specifically: + +- The first view is returned when you go to ``/howdy/amy``. This URL is + mapped to the ``hello`` route that we centrally set using the optional + ``@view_defaults``. + +- The second view is returned when the form data contains a field with + ``form.edit``, such as clicking on + ````. This rule + is specified in the ``@view_config`` for that view. + +- The third view is returned when clicking on a button such + as ````. + +Only one route needed, stated in one place atop the view class. Also, +the assignment of the ``name`` is done in the ``__init__``. Our +templates can then use ``{{ view.name }}``. + +Quick Project Startup with Scaffolds +==================================== + +So far we have done all of our *Quick Glance* as a single Python file. +No Python packages, no structure. Most Pyramid projects, though, +aren't developed this way. + +To ease the process of getting started, Pyramid provides *scaffolds* +that generate sample projects from templates in Pyramid and Pyramid +add-ons. Pyramid's ``pcreate`` command can list the available scaffolds: + +.. code-block:: bash + + $ pcreate --list + Available scaffolds: + alchemy: Pyramid SQLAlchemy project using url dispatch + pyramid_jinja2_starter: pyramid jinja2 starter project + starter: Pyramid starter project + zodb: Pyramid ZODB project using traversal + +The ``pyramid_jinja2`` add-on gave us a scaffold that we can use. From +the parent directory of where we want our Python package to be generated, +let's use that scaffold to make our project: + +.. code-block:: bash + + $ pcreate --scaffold pyramid_jinja2_starter hello_world + +We next use the normal Python development to setup our package for +development: + +.. code-block:: bash + + $ cd hello_world + $ python ./setup.py develop + +We are moving in the direction of a full-featured Pyramid project, +with a proper setup for Python standards (packaging) and Pyramid +configuration. This includes a new way of running your application: + +.. code-block:: bash + + $ pserve development.ini + +Let's look at ``pserve`` and configuration in more depth. + +Application Running with ``pserve`` +=================================== + +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 +files and reload the server when they change: + +.. code-block:: bash + + $ pserve development.ini --reload + +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. 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_tour/package/development.ini + :language: ini + +Let's take a quick high-level look. First, the ``.ini`` file is divided +into sections: + +- ``[app:hello_world]`` configures our WSGI app + +- ``[pipeline:main]`` sets up our WSGI "pipeline" + +- ``[server:main]`` holds our WSGI server settings + +- Various sections afterwards configure our Python logging system + +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 + package. + +#. *Port number*. ``port = 6543`` tells ``wsgiref`` to listen on port + 6543. + +#. *WSGI app*. What package has our WSGI application in it? + ``use = egg:hello_world`` in the app section tells the + configuration what application to load. + +#. *Easier development by automatic template reloading*. In development + mode, you shouldn't have to restart the server when editing a Jinja2 + template. ``reload_templates = true`` sets this policy, + which might be different in production. + +Additionally, the ``development.ini`` generated by this scaffold wired +up Python's standard logging. We'll now see in the console, for example, +a log on every request that comes in, as well traceback information. + +Easier Development with ``debugtoolbar`` +======================================== + +As we introduce the basics we also want to show how to be productive in +development and debugging. For example, we just discussed template +reloading and earlier we showed ``--reload`` for application reloading. + +``pyramid_debugtoolbar`` is a popular Pyramid add-on which makes +several tools available in your browser. Adding it to your project +illustrates several points about configuration. + +First, change your ``setup.py`` to say: + +.. literalinclude:: quick_tour/package/setup.py + :start-after: Start Requires + :end-before: End Requires + +...and re-run your setup: + +.. code-block:: bash + + $ python ./setup.py develop + +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: + +.. literalinclude:: quick_tour/package/hello_world/__init__.py + :start-after: Start Include + :end-before: End Include + +Now that we have a configuration file, we can use the +``pyramid.includes`` facility and place this in our +``development.ini`` instead: + +.. literalinclude:: quick_tour/package/development.ini + :language: ini + :start-after: Start Includes + :end-before: End Includes + +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. 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`` +======================= + +Yikes! We got this far and we haven't yet discussed tests. Particularly +egregious, as Pyramid has had a deep commitment to full test coverage +since before it was released. + +Our ``pyramid_jinja2_starter`` scaffold generated a ``tests.py`` module +with one unit test in it. To run it, let's install the handy ``nose`` +test runner by editing ``setup.py``. While we're at it, we'll throw in +the ``coverage`` tool which yells at us for code that isn't tested: + +.. code-block:: python + + setup(name='hello_world', + # Some lines removed... + extras_require={ + 'testing': ['nose', 'coverage'], + } + ) + +We changed ``setup.py`` which means we need to re-run +``python ./setup.py develop``. We can now run all our tests: + +.. code-block:: bash + + $ cd hello_world + $ nosetests . + . + Name Stmts Miss Cover Missing + --------------------------------------------------- + hello_world 12 8 33% 11-23 + hello_world.models 5 1 80% 8 + hello_world.tests 14 0 100% + hello_world.views 4 0 100% + --------------------------------------------------- + TOTAL 35 9 74% + ---------------------------------------------------------------------- + Ran 1 test in 0.931s + + OK + +Our unit test passed. What did our test look like? + +.. literalinclude:: quick_tour/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, +makes a dummy request, and sees if the view returns what we expected. + +Logging +======= + +It's important to know what is going on inside our web application. +In development we might need to collect some output. In production, +we might need to detect situations when other people use the site. We +need *logging*. + +Fortunately Pyramid uses the normal Python approach to logging. The +scaffold generated, in your ``development.ini``, a number of lines that +configure the logging for you to some reasonable defaults. You then see +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: + +.. literalinclude:: quick_tour/package/hello_world/views.py + :start-after: Start Logging 1 + :end-before: End Logging 1 + +You can now, in your code, log messages: + +.. literalinclude:: quick_tour/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: + +.. literalinclude:: quick_tour/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. 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. 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. 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: + +.. literalinclude:: quick_tour/package/hello_world/__init__.py + :start-after: Start Sphinx Include 1 + :end-before: End Sphinx Include 1 + +.. warning:: + + As noted in the session docs, this example implementation is + not intended for use in settings with security implications. + +Now make a "factory" and pass it to the :term:`configurator`'s +``session_factory`` argument: + +.. literalinclude:: quick_tour/package/hello_world/__init__.py + :start-after: Start Sphinx Include 2 + :end-before: End Sphinx Include 2 + +Pyramid's :term:`request` object now has a ``session`` attribute +that we can use in our view code: + +.. literalinclude:: quick_tour/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_tour/package/hello_world/templates/mytemplate.jinja2 + :language: jinja + :start-after: Start Sphinx Include 1 + :end-before: End Sphinx Include 1 + + +Databases +========= + +Web applications mean data. Data means databases. Frequently SQL +databases. SQL Databases frequently mean an "ORM" +(object-relational mapper.) In Python, ORM usually leads to the +mega-quality *SQLAlchemy*, a Python package that greatly eases working +with databases. + +Pyramid and SQLAlchemy are great friends. That friendship includes a +scaffold! + +.. code-block:: bash + + $ pcreate --scaffold alchemy sqla_demo + $ cd sqla_demo + $ python setup.py develop + +We now have a working sample SQLAlchemy application with all +dependencies installed. The sample project provides a console script to +initialize a SQLite database with tables. Let's run it and then start +the application: + +.. code-block:: bash + + $ initialize_sqla_demo_db development.ini + $ pserve development.ini + +The ORM eases the mapping of database structures into a programming +language. SQLAlchemy uses "models" for this mapping. The scaffold +generated a sample model: + +.. literalinclude:: quick_tour/sqla_demo/sqla_demo/models.py + :start-after: Start Sphinx Include + :end-before: End Sphinx Include + +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: + +.. literalinclude:: quick_tour/sqla_demo/sqla_demo/views.py + :start-after: Start Sphinx Include + :end-before: End Sphinx Include + +Forms +===== + +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 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 WikiPage(colander.MappingSchema): + title = colander.SchemaNode(colander.String()) + body = colander.SchemaNode( + colander.String(), + widget=deform.widget.RichTextWidget() + ) + +With this in place, we can render the HTML for a form, +perhaps with form data from an existing page: + +.. code-block:: python + + form = self.wiki_form.render() + +We'd like to handle form submission, validation, and saving: + +.. code-block:: python + + # 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()) + + # Change the content and redirect to the view + page['title'] = appstruct['title'] + page['body'] = appstruct['body'] + +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. + +Also, the ``deform_bootstrap`` Pyramid add-on restyles the stock Deform +widgets using attractive CSS from Bootstrap and more powerful widgets +from Chosen. + + +Conclusion +========== + +This *Quick Tour* covered a little about a lot. We introduced a long list +of concepts in Pyramid, many of which are expanded on more fully in the +Pyramid developer docs. \ No newline at end of file -- cgit v1.2.3