Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
026da04
commit 018c495
Showing
82 changed files
with
1,088 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
===================================== | ||
4: Quick Project Start With Scaffolds | ||
===================================== | ||
|
||
Getting started quickly on a Python application requires, | ||
as we just saw, several steps. Like other popular web frameworks, | ||
Pyramid provides a facility called "scaffolds" that let you quickly | ||
generate the basics of a Pyramid application. | ||
|
||
Objectives | ||
========== | ||
|
||
- Use ``pcreate`` to see what scaffolds are available | ||
|
||
- Create and install a sample project using one of the available | ||
scaffolds | ||
|
||
Steps | ||
===== | ||
|
||
#. ``(env33)$ cd ..; mkdir step03; cd step03`` | ||
|
||
#. See the usage for ``pcreate``: | ||
|
||
.. code-block:: bash | ||
(env33)$ pcreate --help | ||
#. List the available scaffolds: | ||
|
||
.. code-block:: bash | ||
(env33)$ pcreate --list | ||
#. Make a new Python project called ``tutorial`` using ``starter`` | ||
as a starting point: | ||
|
||
.. code-block:: bash | ||
(env33)$ pcreate -s starter tutorial | ||
#. Visit that project and see the project contents: | ||
|
||
.. code-block:: bash | ||
(env33)$ cd tutorial; ls | ||
#. Install your new project: | ||
|
||
.. code-block:: bash | ||
(env33)$ python3.3 setup.py develop | ||
#. Run the WSGI application with: | ||
|
||
.. code-block:: bash | ||
(env33)$ pserve development.ini | ||
#. Open ``http://127.0.0.1:6543/`` in your browser. *Different port | ||
number!* | ||
|
||
Analysis | ||
======== | ||
|
||
Pyramid has a number of scaffold *templates* that provide different | ||
starting points. ``starter`` is the most basic. ``alchemy`` is useful | ||
for developers wanting SQLAlchemy as a starting point. These scaffolds | ||
provide a way for Pyramid to remain unopinionated, | ||
but still provide starting points with a set of opinions. | ||
|
||
When you visited this project in your browser, you might have seen the | ||
``pyramid_debugtoolbar`` in action. This is a handy helper during | ||
development. | ||
|
||
.. note:: | ||
|
||
The remaining steps in this tutorial do not use scaffolds, | ||
as we want to teach the various decisions being made. | ||
|
||
Extra Credit | ||
============ | ||
|
||
#. If you make a project with one of the scaffolds, can you still | ||
share your project with others? | ||
|
||
#. Can you make scaffolds for your own Pyramid projects? |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[app:main] | ||
use = egg:tutorial | ||
pyramid.reload_templates = true | ||
|
||
[server:main] | ||
use = egg:pyramid#wsgiref | ||
host = 0.0.0.0 | ||
port = 6547 | ||
|
||
[loggers] | ||
keys = root | ||
|
||
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from setuptools import setup | ||
|
||
requires = [ | ||
'pyramid', | ||
] | ||
|
||
setup(name='tutorial', | ||
entry_points="""\ | ||
[paste.app_factory] | ||
main = tutorial:main | ||
""", | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
body { | ||
font-family: sans-serif; | ||
margin: 2em; | ||
} | ||
|
||
h1 a { | ||
vertical-align: bottom; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:metal="http://xml.zope.org/namespaces/metal" | ||
xmlns:tal="http://xml.zope.org/namespaces/tal" | ||
metal:define-macro="layout"> | ||
<head> | ||
<title>Wiki - ${title}</title> | ||
<more metal:define-slot="head-more"></more> | ||
<link rel="stylesheet" | ||
href="${request.static_url('tutorial:static/wiki.css')}"/> | ||
</head> | ||
<body> | ||
<div id="main"> | ||
<h1> | ||
<a href="${request.route_url('wiki_view')}"> | ||
<img src="${request.static_url('tutorial:static/logo.png')}" | ||
alt="Logo"/></a> | ||
${title}</h1> | ||
|
||
<div metal:define-slot="content"> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div metal:use-macro="view.layout"> | ||
<div metal:fill-slot="content"> | ||
<a href="${request.route_url('wikipage_add')}">Add | ||
WikiPage</a> | ||
<ul> | ||
<li tal:repeat="page pages"> | ||
<a href="${request.route_url('wikipage_view', uid=page.uid)}"> | ||
${page.title} | ||
</a> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> |
18 changes: 18 additions & 0 deletions
18
getting_started/09-forms/tutorial/templates/wikipage_addedit.pt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div metal:use-macro="view.layout"> | ||
<more tal:omit-tag="" metal:fill-slot="head-more"> | ||
<tal:block repeat="reqt view.reqts['css']"> | ||
<link rel="stylesheet" type="text/css" | ||
href="${request.static_url('deform:static/' + reqt)}"/> | ||
</tal:block> | ||
<tal:block repeat="reqt view.reqts['js']"> | ||
<script src="${request.static_url('deform:static/' + reqt)}" | ||
type="text/javascript"></script> | ||
</tal:block> | ||
</more> | ||
<div metal:fill-slot="content"> | ||
<p>${structure: form}</p> | ||
<script type="text/javascript"> | ||
deform.load() | ||
</script> | ||
</div> | ||
</div> |
12 changes: 12 additions & 0 deletions
12
getting_started/09-forms/tutorial/templates/wikipage_view.pt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div metal:use-macro="view.layout"> | ||
<div metal:fill-slot="content"> | ||
<a href="${request.route_url('wikipage_edit', uid=uid)}"> | ||
Edit | ||
</a> | | ||
<a href="${request.route_url('wikipage_delete', uid=uid)}"> | ||
Delete | ||
</a> | ||
|
||
<p>${structure: page.body}</p> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import unittest | ||
|
||
from pyramid import testing | ||
|
||
|
||
class WikiViewTests(unittest.TestCase): | ||
def setUp(self): | ||
self.config = testing.setUp() | ||
|
||
def tearDown(self): | ||
testing.tearDown() | ||
|
||
def test_wiki_view(self): | ||
from tutorial.views import WikiViews | ||
|
||
request = testing.DummyRequest() | ||
inst = WikiViews(request) | ||
response = inst.wiki_view() | ||
self.assertEqual(response['title'], 'Welcome to the Wiki') | ||
|
||
|
||
class WikiFunctionalTests(unittest.TestCase): | ||
def setUp(self): | ||
from tutorial import main | ||
|
||
settings = {} | ||
app = main(settings) | ||
from webtest import TestApp | ||
|
||
self.testapp = TestApp(app) | ||
|
||
def test_it(self): | ||
res = self.testapp.get('/', status=200) | ||
self.assertIn(b'Welcome', res.body) | ||
res = self.testapp.get('/add', status=200) | ||
self.assertIn(b'Add Wiki Page', res.body) | ||
res = self.testapp.get('/100', status=200) | ||
self.assertIn(b'100', res.body) | ||
res = self.testapp.get('/100/edit', status=200) | ||
self.assertIn(b'Edit', res.body) | ||
res = self.testapp.get('/100/delete', status=302) | ||
self.assertIn(b'Found', res.body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[app:main] | ||
use = egg:tutorial | ||
pyramid.reload_templates = true | ||
|
||
[server:main] | ||
use = egg:pyramid#wsgiref | ||
host = 0.0.0.0 | ||
port = 6547 | ||
|
||
[loggers] | ||
keys = root | ||
|
||
[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 |
Oops, something went wrong.