77 | Welcome to TurboGears 2 78 | The Python web metaframework 79 |
80 |
85 |
86 | TurboGears is a open source front-to-back web development 89 | framework written in Python. Copyright (c) 2005-2009
90 |├── examples └── tg2 │ ├── migration │ ├── __init__.py │ ├── versions │ │ └── __init__.py │ └── migrate.cfg │ ├── tg2 │ ├── templates │ │ ├── __init__.py │ │ ├── movie.mak │ │ ├── header.mak │ │ ├── simple_mako.mak │ │ ├── error.mak │ │ ├── login.mak │ │ ├── environ.mak │ │ ├── data.mak │ │ ├── index.mak │ │ ├── authentication.mak │ │ ├── master.mak │ │ └── about.mak │ ├── config │ │ ├── __init__.py │ │ ├── environment.py │ │ ├── middleware.py │ │ ├── app_cfg.py │ │ └── deployment.ini_tmpl │ ├── lib │ │ ├── __init__.py │ │ ├── helpers.py │ │ ├── app_globals.py │ │ └── base.py │ ├── __init__.py │ ├── controllers │ │ ├── __init__.py │ │ ├── controller.template │ │ ├── secure.py │ │ ├── template.py │ │ ├── error.py │ │ └── root.py │ ├── public │ │ ├── favicon.ico │ │ ├── images │ │ │ ├── ok.png │ │ │ ├── add.png │ │ │ ├── error.png │ │ │ ├── info.png │ │ │ ├── star.png │ │ │ ├── delete.png │ │ │ ├── inputbg.png │ │ │ ├── loginbg.png │ │ │ ├── menubg.png │ │ │ ├── pagebg.png │ │ │ ├── pencil.png │ │ │ ├── strype2.png │ │ │ ├── warning.png │ │ │ ├── contentbg.png │ │ │ ├── headerbg.png │ │ │ ├── header_inner2.png │ │ │ ├── loginbottombg.png │ │ │ ├── loginheader-left.png │ │ │ ├── loginheader-right.png │ │ │ ├── menu-item-actibg.png │ │ │ ├── menu-item-border.png │ │ │ ├── under_the_hood_blue.png │ │ │ └── menu-item-actibg-first.png │ │ └── css │ │ │ ├── admin.css │ │ │ └── style.css │ ├── tests │ │ ├── functional │ │ │ ├── __init__.py │ │ │ ├── test_root.py │ │ │ └── test_authentication.py │ │ ├── models │ │ │ ├── test_auth.py │ │ │ └── __init__.py │ │ └── __init__.py │ ├── websetup │ │ ├── __init__.py │ │ ├── schema.py │ │ └── bootstrap.py │ ├── model │ │ ├── model.template │ │ ├── __init__.py │ │ └── auth.py │ └── i18n │ │ └── ru │ │ └── LC_MESSAGES │ │ └── tg2.po │ ├── MANIFEST.in │ ├── ez_setup │ ├── README.txt │ └── __init__.py │ ├── test.ini │ ├── README.txt │ ├── fedmsg.d │ ├── ssl.py │ ├── relay.py │ └── base.py │ ├── setup.cfg │ ├── setup.py │ └── development.ini ├── fedmsg_middleware ├── __init__.py └── middleware.py ├── MANIFEST.in ├── .gitignore ├── setup.py ├── README.rst └── LICENSE /examples/tg2/migration/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/tg2/tg2/templates/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/tg2/migration/versions/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/tg2/tg2/config/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | -------------------------------------------------------------------------------- /examples/tg2/tg2/lib/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | -------------------------------------------------------------------------------- /fedmsg_middleware/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | from middleware import * 3 | -------------------------------------------------------------------------------- /examples/tg2/tg2/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """The tg2 package""" 3 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst 2 | include LICENSE 3 | recursive-include fedmsg_middleware/resources * 4 | -------------------------------------------------------------------------------- /examples/tg2/tg2/controllers/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """Controllers for the tg2 application.""" 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.pyo 3 | *.swp 4 | *.egg* 5 | *.db* 6 | *.pdf 7 | dist 8 | build 9 | examples/tg2/data 10 | -------------------------------------------------------------------------------- /examples/tg2/tg2/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/favicon.ico -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/ok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/ok.png -------------------------------------------------------------------------------- /examples/tg2/tg2/tests/functional/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """Functional test suite for the controllers of the application.""" -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/add.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/error.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/info.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/star.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/delete.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/inputbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/inputbg.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/loginbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/loginbg.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/menubg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/menubg.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/pagebg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/pagebg.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/pencil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/pencil.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/strype2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/strype2.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/warning.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/contentbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/contentbg.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/headerbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/headerbg.png -------------------------------------------------------------------------------- /examples/tg2/tg2/templates/movie.mak: -------------------------------------------------------------------------------- 1 | <%inherit file="local:templates.master"/> 2 | 3 | <%def name="content()"> 4 | ${tmpl_context.form() |n} 5 | 6 | %def> 7 | -------------------------------------------------------------------------------- /examples/tg2/MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include tg2/public * 2 | include tg2/public/favicon.ico 3 | recursive-include tg2/i18n * 4 | recursive-include tg2/templates * 5 | -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/header_inner2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/header_inner2.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/loginbottombg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/loginbottombg.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/loginheader-left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/loginheader-left.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/loginheader-right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/loginheader-right.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/menu-item-actibg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/menu-item-actibg.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/menu-item-border.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/menu-item-border.png -------------------------------------------------------------------------------- /examples/tg2/tg2/lib/helpers.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """WebHelpers used in tg2.""" 4 | 5 | from webhelpers import date, feedgenerator, html, number, misc, text 6 | -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/under_the_hood_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/under_the_hood_blue.png -------------------------------------------------------------------------------- /examples/tg2/tg2/public/images/menu-item-actibg-first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedora-infra/fedmsg_middleware/master/examples/tg2/tg2/public/images/menu-item-actibg-first.png -------------------------------------------------------------------------------- /examples/tg2/tg2/templates/header.mak: -------------------------------------------------------------------------------- 1 | <%def name="header()"> 2 |
In this page you can see all the WSGI variables your request object has, 10 | the ones in capital letters are required by the spec, then a sorted by 11 | component list of variables provided by the Components, and at last 12 | the "wsgi." namespace with very useful information about your WSGI Server
13 |The keys in the environment are: 14 |
| ${key} | 18 |${environment[key]} | 19 |
11 | This page shows how you can provide multiple pages 12 | directly from the same controller method. This page is generated 13 | from the expose decorator with the template defintion provided. 14 | You can provide a url with parameters and this page will display 15 | the parameters as html, and the json version will express 16 | the entries as JSON. Here, try it out: /data.html?a=1&b=2 17 |
18 | 19 |Click here for the JSON Version of this page.
20 |The data provided in the template call is: 21 |
| ${key} | 25 |${value} | 26 |
We're sorry but we weren't able to process " 26 | " this request.
") 27 | values = dict(prefix=request.environ.get('SCRIPT_NAME', ''), 28 | code=request.params.get('code', resp.status_int), 29 | message=request.params.get('message', default_message)) 30 | return values 31 | -------------------------------------------------------------------------------- /examples/tg2/tg2/templates/index.mak: -------------------------------------------------------------------------------- 1 | <%inherit file="local:templates.master"/> 2 | 3 | <%def name="title()"> 4 | Welcome to TurboGears 2.1, standing on the shoulders of giants, since 2007 5 | %def> 6 | 7 | ${parent.sidebar_top()} 8 | 9 |TurboGears 2 is rapid web application development toolkit designed to make your life easier.
12 |Design your data model, Create the database, and Add some bootstrap data.
16 |Decide your URLs, Program your controller methods, Design your 20 | templates, and place some static files (CSS and/or JavaScript).
21 |Test your source, Generate project documents, Build a distribution.
25 |If you have access to this page, this means you have enabled authentication and authorization 9 | in the quickstart to create your project.
10 |11 | The paster command will have created a few specific controllers for you. But before you 12 | go to play with those controllers you'll need to make sure your application has been 13 | properly bootstapped. 14 | This is dead easy, here is how to do this: 15 |
16 | 17 | 18 | paster setup-app development.ini 19 | 20 | 21 |22 | inside your application's folder and you'll get a database setup (using the preferences you have 23 | set in your development.ini file). This database will also have been prepopulated with some 24 | default logins/passwords so that you can test the secured controllers and methods. 25 |
26 |27 | To change the comportement of this setup-app command you just need to edit the websetup.py file. 28 |
29 |30 | Now try to visiting the manage_permission_only URL. You will be challenged with a login/password form. 31 |
32 |33 | Only managers are authorized to visit this method. You will need to log-in using: 34 |
35 | 36 | login: manager 37 | 38 |
39 |40 | 41 | password: managepass 42 | 43 |
44 | 45 |46 | Another protected resource is editor_user_only. This one is protected by a different set of permissions. 47 | You will need to be editor with a password of editpass to be able to access it. 48 |
49 |50 | The last kind of protected resource in this quickstarted app is a full so called secure controller. This controller is protected globally. 51 | Instead of having a @require decorator on each method, we have set an allow_only attribute at the class level. All the methods in this controller will 52 | require the same level of access. You need to be manager to access secc or secc/some_where. 53 |
54 || a | 49 |1 | 50 |
| b | 53 |2 | 54 |
85 |
86 | TurboGears is a open source front-to-back web development 89 | framework written in Python. Copyright (c) 2005-2009
90 |The TG2 quickstart command produces this basic TG site. Here's how it works.
12 |When you want a model for storing favorite links or wiki content, 16 | the /model folder in your site is ready to go.
17 |You can build a dynamic site without any data model at all. There 18 | still be a default data-model template for you if you didn't enable 19 | authentication and authorization in quickstart. If you have enabled 20 | authorization, the auth data-model is ready-made.
21 |The "root.py" file under the 25 | /controllers folder has your URLs. When you 26 | called the url or this page (/about), 27 | the command went through the RootController class to the 28 | about() method.
29 |Those Python methods are responsible to create the dictionary of 30 | variables that will be used in your web views (template).
31 |A web page viewed by user could be constructed by single or 35 | several reusable templates under /templates. 36 | Take 'about' page for example, each reusable template generating 37 | a part of the page.
38 | 39 |about.mak - This is the 40 | template that created this page. If you take a look at this template 41 | you will see that there are a lot of wacky symbols, if you are not familiar 42 | with Mako you should probably 43 | check out the docs on their site.
44 | 45 |Let's take a look at what this template does in order of execution. 46 | The first thing this template does 47 | is inherit from master.mak. We'll 48 | go into the details of this later, but for now just know that this 49 | template is allowed to both call on master.mak, and also override it's 50 | capabilites. This inheritance is what gives mako it's power to 51 | provide reusable templates. 52 |
53 |But um, whats that 'local:' stuff about?
54 |55 | Well, TG wants to provide re-usable components like tgext.admin, and also 56 | provide a way for you to use your default site layouts. This is done 57 | easily by providing a shortcut to the namespace of your project, so the 58 | component template finder can find your master.html and format 59 | itself the way you want it to. 60 |
61 |The next thing about.mak does is to create a function called title() 62 | which provides the title for the document. This overrides the title 63 | method provided by master.mak, and therefore, when the template 64 | is rendered, it will use the title provided by this funciton. 65 | 66 |
67 | Next, there are a couple of calls to the master template to set up the 68 | boxes you see in the page over on the right, We'll examine what 69 | these are in the master template in a second. Finally, we get to the meat 70 | of the document, and that's pretty much all about.mak does 71 |
72 | 73 |master.mak - 74 | This template provides the overall layout for your project, and 75 | allows you to override different elements of the overall structure 76 | of your default look-and-feel. Let's take a look at this template 77 | from top to bottom again.
78 |The first 15 lines provide an overall layout for the document, 79 | with definitions for the header, title and body. Each one of these 80 | sections has been turned into a method that you can change within your 81 | child templates, but you do not have to provide any single one of them 82 | TurboGears extensions may however expect these methods to be provided 83 | to display their content properly. Keep this in mind if you decide 84 | to alter your master.mak. You are of course always free to modify 85 | your master template, but doing so can render your extensions useless, 86 | so tread carefully.
87 | 88 |The next section describes the overall layout for the body of the 89 | document, with flash messages appearing at the top, and self.body() 90 | appearing at the bottom. self.body will take whatever is not defined 91 | as a method in your child template and render it in this space. This 92 | is really useful because it allows you to be freestyle with your 93 | body definition. If you don't want to override any of the master 94 | template defines, all you have to do is inherit the master, and then 95 | provide the code you want to appear surrounded by your header and footer. 96 |
97 | 98 |99 | Next are the title, header, footer and sidebar defines. These are all of 100 | course overriddable. 101 |
102 | 103 |The final define sets up the menubar. This provides some links, 104 | as well as a way of highlighing the page you are currently on. 105 |
106 |Good luck with TurboGears 2!
109 |