diff options
author | Luke Macken <lmacken@redhat.com> | 2008-01-17 11:13:22 -0500 |
---|---|---|
committer | Luke Macken <lmacken@redhat.com> | 2008-01-17 11:13:22 -0500 |
commit | c498c67ed6bd18be1d54f884099df10b1db06509 (patch) | |
tree | db1dd0fba37babcec610421e5857ad3a22f29e62 /funcweb/funcweb | |
parent | aee6076dd78dfb1b88ab4d369e24fb1bbf710816 (diff) | |
download | func-c498c67ed6bd18be1d54f884099df10b1db06509.tar.gz func-c498c67ed6bd18be1d54f884099df10b1db06509.tar.xz func-c498c67ed6bd18be1d54f884099df10b1db06509.zip |
Initial `tg-admin quickstart` of funcweb
Diffstat (limited to 'funcweb/funcweb')
22 files changed, 522 insertions, 0 deletions
diff --git a/funcweb/funcweb/__init__.py b/funcweb/funcweb/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/funcweb/funcweb/__init__.py diff --git a/funcweb/funcweb/config/__init__.py b/funcweb/funcweb/config/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/funcweb/funcweb/config/__init__.py diff --git a/funcweb/funcweb/config/app.cfg b/funcweb/funcweb/config/app.cfg new file mode 100644 index 0000000..5734a78 --- /dev/null +++ b/funcweb/funcweb/config/app.cfg @@ -0,0 +1,52 @@ +[global] +# The settings in this file should not vary depending on the deployment +# environment. dev.cfg and prod.cfg are the locations for +# the different deployment settings. Settings in this file will +# be overridden by settings in those other files. + +# The commented out values below are the defaults + +# VIEW + +# which view (template engine) to use if one is not specified in the +# template name +# tg.defaultview = "kid" + +# The following kid settings determine the settings used by the kid serializer. + +# Kid output method (e.g. html, html-strict, xhtml, xhtml-strict, xml, json) +# and formatting (e.g. default, straight, compact, newlines, wrap, nice) +# kid.outputformat="html default" + +# kid.encoding="utf-8" + +# The sitetemplate is used for overall styling of a site that +# includes multiple TurboGears applications +# tg.sitetemplate="<packagename.templates.templatename>" + +# Allow every exposed function to be called as json, +# tg.allow_json = False + +# List of Widgets to include on every page. +# for exemple ['turbogears.mochikit'] +# tg.include_widgets = [] + +# Set to True if the scheduler should be started +# tg.scheduler = False + +# Set session or cookie +# session_filter.on = True + + +# compress the data sends to the web browser +# [/] +# gzip_filter.on = True +# gzip_filter.mime_types = ["application/x-javascript", "text/javascript", "text/html", "text/css", "text/plain"] + +[/static] +static_filter.on = True +static_filter.dir = "%(top_level_dir)s/static" + +[/favicon.ico] +static_filter.on = True +static_filter.file = "%(top_level_dir)s/static/images/favicon.ico" diff --git a/funcweb/funcweb/config/log.cfg b/funcweb/funcweb/config/log.cfg new file mode 100644 index 0000000..ce776f8 --- /dev/null +++ b/funcweb/funcweb/config/log.cfg @@ -0,0 +1,29 @@ +# LOGGING +# Logging is often deployment specific, but some handlers and +# formatters can be defined here. + +[logging] +[[formatters]] +[[[message_only]]] +format='*(message)s' + +[[[full_content]]] +format='*(asctime)s *(name)s *(levelname)s *(message)s' + +[[handlers]] +[[[debug_out]]] +class='StreamHandler' +level='DEBUG' +args='(sys.stdout,)' +formatter='full_content' + +[[[access_out]]] +class='StreamHandler' +level='INFO' +args='(sys.stdout,)' +formatter='message_only' + +[[[error_out]]] +class='StreamHandler' +level='ERROR' +args='(sys.stdout,)' diff --git a/funcweb/funcweb/controllers.py b/funcweb/funcweb/controllers.py new file mode 100644 index 0000000..5206727 --- /dev/null +++ b/funcweb/funcweb/controllers.py @@ -0,0 +1,12 @@ +from turbogears import controllers, expose, flash +# from model import * +# import logging +# log = logging.getLogger("funcweb.controllers") + +class Root(controllers.RootController): + @expose(template="funcweb.templates.welcome") + def index(self): + import time + # log.debug("Happy TurboGears Controller Responding For Duty") + flash("Your application is now running") + return dict(now=time.ctime()) diff --git a/funcweb/funcweb/json.py b/funcweb/funcweb/json.py new file mode 100644 index 0000000..66d5cfb --- /dev/null +++ b/funcweb/funcweb/json.py @@ -0,0 +1,10 @@ +# A JSON-based API(view) for your app. +# Most rules would look like: +# @jsonify.when("isinstance(obj, YourClass)") +# def jsonify_yourclass(obj): +# return [obj.val1, obj.val2] +# @jsonify can convert your objects to following types: +# lists, dicts, numbers and strings + +from turbojson.jsonify import jsonify + diff --git a/funcweb/funcweb/model.py b/funcweb/funcweb/model.py new file mode 100644 index 0000000..28f2b02 --- /dev/null +++ b/funcweb/funcweb/model.py @@ -0,0 +1,9 @@ +from turbogears.database import PackageHub +from sqlobject import * + +hub = PackageHub('funcweb') +__connection__ = hub + +# class YourDataClass(SQLObject): +# pass + diff --git a/funcweb/funcweb/release.py b/funcweb/funcweb/release.py new file mode 100644 index 0000000..94244db --- /dev/null +++ b/funcweb/funcweb/release.py @@ -0,0 +1,14 @@ +# Release information about funcweb + +version = "1.0" + +# description = "Your plan to rule the world" +# long_description = "More description about your plan" +# author = "Your Name Here" +# email = "YourEmail@YourDomain" +# copyright = "Vintage 2006 - a good year indeed" + +# if it's open source, you might want to specify these +# url = "http://yourcool.site/" +# download_url = "http://yourcool.site/download" +# license = "MIT" diff --git a/funcweb/funcweb/static/css/style.css b/funcweb/funcweb/static/css/style.css new file mode 100644 index 0000000..c98d40e --- /dev/null +++ b/funcweb/funcweb/static/css/style.css @@ -0,0 +1,134 @@ +/*
+ * Quick mash-up of CSS for the TG quick start page.
+ */
+
+html, body {
+ color: black;
+ background-color: #ddd;
+ font: x-small "Lucida Grande", "Lucida Sans Unicode", geneva, verdana, sans-serif;
+ margin: 0;
+ padding: 0;
+}
+
+td, th {padding:3px;border:none;}
+tr th {text-align:left;background-color:#f0f0f0;color:#333;}
+tr.odd td {background-color:#edf3fe;}
+tr.even td {background-color:#fff;}
+
+#header {
+ height: 80px;
+ width: 777px;
+ background: blue URL('../images/header_inner.png') no-repeat;
+ border-left: 1px solid #aaa;
+ border-right: 1px solid #aaa;
+ margin: 0 auto 0 auto;
+}
+
+a.link, a, a.active {
+ color: #369;
+}
+
+
+#main_content {
+ color: black;
+ font-size: 127%;
+ background-color: white;
+ width: 757px;
+ margin: 0 auto 0 auto;
+ border-left: 1px solid #aaa;
+ border-right: 1px solid #aaa;
+ padding: 10px;
+}
+
+#sidebar {
+ border: 1px solid #aaa;
+ background-color: #eee;
+ margin: 0.5em;
+ padding: 1em;
+ float: right;
+ width: 200px;
+ font-size: 88%;
+}
+
+#sidebar h2 {
+ margin-top: 0;
+}
+
+#sidebar ul {
+ margin-left: 1.5em;
+ padding-left: 0;
+}
+
+h1,h2,h3,h4,h5,h6,#getting_started_steps {
+ font-family: "Century Schoolbook L", Georgia, serif;
+ font-weight: bold;
+}
+
+h2 {
+ font-size: 150%;
+}
+
+#getting_started_steps a {
+ text-decoration: none;
+}
+
+#getting_started_steps a:hover {
+ text-decoration: underline;
+}
+
+#getting_started_steps li {
+ font-size: 80%;
+ margin-bottom: 0.5em;
+}
+
+#getting_started_steps h2 {
+ font-size: 120%;
+}
+
+#getting_started_steps p {
+ font: 100% "Lucida Grande", "Lucida Sans Unicode", geneva, verdana, sans-serif;
+}
+
+#footer {
+ border: 1px solid #aaa;
+ border-top: 0px none;
+ color: #999;
+ background-color: white;
+ padding: 10px;
+ font-size: 80%;
+ text-align: center;
+ width: 757px;
+ margin: 0 auto 1em auto;
+}
+
+.code {
+ font-family: monospace;
+}
+
+span.code {
+ font-weight: bold;
+ background: #eee;
+}
+
+#status_block {
+ margin: 0 auto 0.5em auto;
+ padding: 15px 10px 15px 55px;
+ background: #cec URL('../images/ok.png') left center no-repeat;
+ border: 1px solid #9c9;
+ width: 450px;
+ font-size: 120%;
+ font-weight: bolder;
+}
+
+.notice {
+ margin: 0.5em auto 0.5em auto;
+ padding: 15px 10px 15px 55px;
+ width: 450px;
+ background: #eef URL('../images/info.png') left center no-repeat;
+ border: 1px solid #cce;
+}
+
+.fielderror {
+ color: red;
+ font-weight: bold;
+}
\ No newline at end of file diff --git a/funcweb/funcweb/static/images/favicon.ico b/funcweb/funcweb/static/images/favicon.ico Binary files differnew file mode 100644 index 0000000..332557b --- /dev/null +++ b/funcweb/funcweb/static/images/favicon.ico diff --git a/funcweb/funcweb/static/images/header_inner.png b/funcweb/funcweb/static/images/header_inner.png Binary files differnew file mode 100644 index 0000000..2b2d87d --- /dev/null +++ b/funcweb/funcweb/static/images/header_inner.png diff --git a/funcweb/funcweb/static/images/info.png b/funcweb/funcweb/static/images/info.png Binary files differnew file mode 100644 index 0000000..329c523 --- /dev/null +++ b/funcweb/funcweb/static/images/info.png diff --git a/funcweb/funcweb/static/images/ok.png b/funcweb/funcweb/static/images/ok.png Binary files differnew file mode 100644 index 0000000..fee6751 --- /dev/null +++ b/funcweb/funcweb/static/images/ok.png diff --git a/funcweb/funcweb/static/images/tg_under_the_hood.png b/funcweb/funcweb/static/images/tg_under_the_hood.png Binary files differnew file mode 100644 index 0000000..bc9c79c --- /dev/null +++ b/funcweb/funcweb/static/images/tg_under_the_hood.png diff --git a/funcweb/funcweb/static/images/under_the_hood_blue.png b/funcweb/funcweb/static/images/under_the_hood_blue.png Binary files differnew file mode 100644 index 0000000..90e84b7 --- /dev/null +++ b/funcweb/funcweb/static/images/under_the_hood_blue.png diff --git a/funcweb/funcweb/templates/__init__.py b/funcweb/funcweb/templates/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/funcweb/funcweb/templates/__init__.py diff --git a/funcweb/funcweb/templates/login.kid b/funcweb/funcweb/templates/login.kid new file mode 100644 index 0000000..4fd6755 --- /dev/null +++ b/funcweb/funcweb/templates/login.kid @@ -0,0 +1,114 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:py="http://purl.org/kid/ns#"> + +<head> + <meta content="text/html; charset=UTF-8" + http-equiv="content-type" py:replace="''"/> + <title>Login</title> + <style type="text/css"> + #loginBox + { + width: 30%; + margin: auto; + margin-top: 10%; + padding-left: 10%; + padding-right: 10%; + padding-top: 5%; + padding-bottom: 5%; + font-family: verdana; + font-size: 10px; + background-color: #eee; + border: 2px solid #ccc; + } + + #loginBox h1 + { + font-size: 42px; + font-family: "Trebuchet MS"; + margin: 0; + color: #ddd; + } + + #loginBox p + { + position: relative; + top: -1.5em; + padding-left: 4em; + font-size: 12px; + margin: 0; + color: #666; + } + + #loginBox table + { + table-layout: fixed; + border-spacing: 0; + width: 100%; + } + + #loginBox td.label + { + width: 33%; + text-align: right; + } + + #loginBox td.field + { + width: 66%; + } + + #loginBox td.field input + { + width: 100%; + } + + #loginBox td.buttons + { + text-align: right; + } + + </style> +</head> + +<body> + <div id="loginBox"> + <h1>Login</h1> + <p>${message}</p> + <form action="${previous_url}" method="POST"> + <table> + <tr> + <td class="label"> + <label for="user_name">User Name:</label> + </td> + <td class="field"> + <input type="text" id="user_name" name="user_name"/> + </td> + </tr> + <tr> + <td class="label"> + <label for="password">Password:</label> + </td> + <td class="field"> + <input type="password" id="password" name="password"/> + </td> + </tr> + <tr> + <td colspan="2" class="buttons"> + <input type="submit" name="login" value="Login"/> + </td> + </tr> + </table> + + <input py:if="forward_url" type="hidden" name="forward_url" + value="${forward_url}"/> + + <div py:for="name,values in original_parameters.items()" py:strip="1"> + <input py:for="value in isinstance(values, list) and values or [values]" + type="hidden" name="${name}" value="${value}"/> + </div> + </form> + </div> +</body> +</html> diff --git a/funcweb/funcweb/templates/master.kid b/funcweb/funcweb/templates/master.kid new file mode 100644 index 0000000..1b9841a --- /dev/null +++ b/funcweb/funcweb/templates/master.kid @@ -0,0 +1,47 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<?python import sitetemplate ?>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#" py:extends="sitetemplate">
+
+<head py:match="item.tag=='{http://www.w3.org/1999/xhtml}head'" py:attrs="item.items()">
+ <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
+ <title py:replace="''">Your title goes here</title>
+ <meta py:replace="item[:]"/>
+ <style type="text/css">
+ #pageLogin
+ {
+ font-size: 10px;
+ font-family: verdana;
+ text-align: right;
+ }
+ </style>
+ <style type="text/css" media="screen">
+@import "${tg.url('/static/css/style.css')}";
+</style>
+</head>
+
+<body py:match="item.tag=='{http://www.w3.org/1999/xhtml}body'" py:attrs="item.items()">
+ <div py:if="tg.config('identity.on') and not defined('logging_in')" id="pageLogin">
+ <span py:if="tg.identity.anonymous">
+ <a href="${tg.url('/login')}">Login</a>
+ </span>
+ <span py:if="not tg.identity.anonymous">
+ Welcome ${tg.identity.user.display_name}.
+ <a href="${tg.url('/logout')}">Logout</a>
+ </span>
+ </div>
+ <div id="header"> </div>
+ <div id="main_content">
+ <div id="status_block" class="flash" py:if="value_of('tg_flash', None)" py:content="tg_flash"></div>
+
+ <div py:replace="[item.text]+item[:]"/>
+
+ <!-- End of main_content -->
+ </div>
+<div id="footer"> <img src="${tg.url('/static/images/under_the_hood_blue.png')}" alt="TurboGears under the hood" />
+ <p>TurboGears is a open source front-to-back web development
+ framework written in Python</p>
+ <p>Copyright © 2007 Kevin Dangoor</p>
+</div>
+</body>
+
+</html>
diff --git a/funcweb/funcweb/templates/welcome.kid b/funcweb/funcweb/templates/welcome.kid new file mode 100644 index 0000000..9095267 --- /dev/null +++ b/funcweb/funcweb/templates/welcome.kid @@ -0,0 +1,47 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"
+ py:extends="'master.kid'">
+<head>
+<meta content="text/html; charset=utf-8" http-equiv="Content-Type" py:replace="''"/>
+<title>Welcome to TurboGears</title>
+</head>
+<body>
+
+ <div id="sidebar">
+ <h2>Learn more</h2>
+ Learn more about TurboGears and take part in its
+ development
+ <ul class="links">
+ <li><a href="http://www.turbogears.org">Official website</a></li>
+ <li><a href="http://docs.turbogears.org">Documentation</a></li>
+ <li><a href="http://trac.turbogears.org/turbogears/">Trac
+ (bugs/suggestions)</a></li>
+ <li><a href="http://groups.google.com/group/turbogears"> Mailing list</a> </li>
+ </ul>
+ <span py:replace="now">now</span>
+ </div>
+ <div id="getting_started">
+ <ol id="getting_started_steps">
+ <li class="getting_started">
+ <h3>Model</h3>
+ <p> <a href="http://docs.turbogears.org/1.0/GettingStarted/DefineDatabase">Design models</a> in the <span class="code">model.py</span>.<br/>
+ Edit <span class="code">dev.cfg</span> to <a href="http://docs.turbogears.org/1.0/GettingStarted/UseDatabase">use a different backend</a>, or start with a pre-configured SQLite database. <br/>
+ Use script <span class="code">tg-admin sql create</span> to create the database tables.</p>
+ </li>
+ <li class="getting_started">
+ <h3>View</h3>
+ <p> Edit <a href="http://docs.turbogears.org/1.0/GettingStarted/Kid">html-like templates</a> in the <span class="code">/templates</span> folder;<br/>
+ Put all <a href="http://docs.turbogears.org/1.0/StaticFiles">static contents</a> in the <span class="code">/static</span> folder. </p>
+ </li>
+ <li class="getting_started">
+ <h3>Controller</h3>
+ <p> Edit <span class="code"> controllers.py</span> and <a href="http://docs.turbogears.org/1.0/GettingStarted/CherryPy">build your
+ website structure</a> with the simplicity of Python objects. <br/>
+ TurboGears will automatically reload itself when you modify your project. </p>
+ </li>
+ </ol>
+ <div class="notice"> If you create something cool, please <a href="http://groups.google.com/group/turbogears">let people know</a>, and consider contributing something back to the <a href="http://groups.google.com/group/turbogears">community</a>.</div>
+ </div>
+ <!-- End of getting_started -->
+</body>
+</html>
diff --git a/funcweb/funcweb/tests/__init__.py b/funcweb/funcweb/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/funcweb/funcweb/tests/__init__.py diff --git a/funcweb/funcweb/tests/test_controllers.py b/funcweb/funcweb/tests/test_controllers.py new file mode 100644 index 0000000..3c26c58 --- /dev/null +++ b/funcweb/funcweb/tests/test_controllers.py @@ -0,0 +1,32 @@ +import unittest +import turbogears +from turbogears import testutil +from funcweb.controllers import Root +import cherrypy + +cherrypy.root = Root() + +class TestPages(unittest.TestCase): + + def setUp(self): + turbogears.startup.startTurboGears() + + def tearDown(self): + """Tests for apps using identity need to stop CP/TG after each test to + stop the VisitManager thread. + See http://trac.turbogears.org/turbogears/ticket/1217 for details. + """ + turbogears.startup.stopTurboGears() + + def test_method(self): + "the index method should return a string called now" + import types + result = testutil.call(cherrypy.root.index) + assert type(result["now"]) == types.StringType + + def test_indextitle(self): + "The indexpage should have the right title" + testutil.createRequest("/") + response = cherrypy.response.body[0].lower() + assert "<title>welcome to turbogears</title>" in response + diff --git a/funcweb/funcweb/tests/test_model.py b/funcweb/funcweb/tests/test_model.py new file mode 100644 index 0000000..903c2d8 --- /dev/null +++ b/funcweb/funcweb/tests/test_model.py @@ -0,0 +1,22 @@ +# If your project uses a database, you can set up database tests +# similar to what you see below. Be sure to set the db_uri to +# an appropriate uri for your testing database. sqlite is a good +# choice for testing, because you can use an in-memory database +# which is very fast. + +from turbogears import testutil, database +# from funcweb.model import YourDataClass, User + +# database.set_db_uri("sqlite:///:memory:") + +# class TestUser(testutil.DBTest): +# def get_model(self): +# return User +# def test_creation(self): +# "Object creation should set the name" +# obj = User(user_name = "creosote", +# email_address = "spam@python.not", +# display_name = "Mr Creosote", +# password = "Wafer-thin Mint") +# assert obj.display_name == "Mr Creosote" + |