Changeset 1457

Show
Ignore:
Timestamp:
05/09/06 16:22:46 (3 years ago)
Author:
kevin
Message:

doc updates, turning off syntax highlighter in widget browser (for now)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/newdocs/docs/tutorials/wiki20/index.html

    r991 r1457  
    5555    <pre class="command">Enter project name: Wiki 20 
    5656Enter package name [wiki20]: wiki20 
    57     </pre> 
     57Do you need Identity (usernames/passwords) in this project? [no] no 
     58</pre> 
    5859     
    5960    <p>This creates a few files in a directory tree just below your current directory. Let's go in there and you can take a look around.</p> 
     
    8889    <textarea name="code" class="py" rows="3" cols="60"> 
    8990class Page(SQLObject): 
    90     pagename=StringCol(alternateID=True, length=30) 
    91     data=StringCol() 
     91    pagename = UnicodeCol(alternateID=True, length=30) 
     92    data = UnicodeCol() 
    9293</textarea> 
    9394 
  • branches/1.0/newdocs/docs/tutorials/wiki20/page2.html

    r596 r1457  
    1212    <h2>Pointing to a database</h2> 
    1313     
    14     <p>TurboGears has a minimum of required configuration. It <em>does</em> need to know where your database lives. The quickstart creates a couple of simple Python config files for you.</p> 
     14    <p>TurboGears has a minimum of required configuration. It <em>does</em> need to know where your database lives. The quickstart creates a couple of simple config files for you.</p> 
    1515     
    16     <p>Since we're working in a development environment and not a production deployment one, edit the "devcfg.py" file. You'll just need to uncomment the sqlobject.dburi line that corresponds to your database and provide the proper connection info.</p> 
     16    <p>If you have sqlite installed, you can get started in development without configuring anything (skip the rest of this section).</p> 
     17     
     18    <p>Since we're working in a development environment and not a production deployment one, edit the "dev.cfg" file. You'll just need to uncomment the sqlobject.dburi line that corresponds to your database and provide the proper connection info.</p> 
    1719     
    1820    <p>Restart the web server by hitting control-C and running the startup script again:</p> 
     
    4143    <textarea name="code" class="html" cols="60"><![CDATA[ 
    4244    <div style="float:right; width: 10em"> 
    43         Viewing <span py:replace="pagename">Page Name Goes Here</span> 
     45        Viewing <span py:replace="page.pagename">Page Name Goes Here</span> 
    4446        <br/> 
    4547        You can return to the <a href="/">FrontPage</a>. 
    4648    </div> 
    4749     
    48     <div py:replace="XML(data)">Page text goes here.</div> 
     50    <div py:replace="XML(page.data)">Page text goes here.</div> 
    4951]]> 
    5052</textarea> 
     
    5456    <p>TurboGears greatly reduces the amount of code you need to write, but it does not eliminate it. Let's add a couple of imports to the top of controllers.py:</p> 
    5557    <textarea name="code" class="py"> 
    56 from model import Page 
     58from wiki20.model import Page 
    5759from docutils.core import publish_parts 
    5860</textarea> 
     
    6870     
    6971    <textarea name="code" class="py"> 
    70     @turbogears.expose(html=".templates.page") 
     72    @expose("wiki20.templates.page") 
    7173    def index(self, pagename="FrontPage"): 
    7274        page = Page.byPagename(pagename) 
  • branches/1.0/newdocs/docs/tutorials/wiki20/page3.html

    r596 r1457  
    3838 
    3939        <textarea name="code" cols="60" class="xhtml"><![CDATA[ 
    40         <form action="save" method="post"> 
    41             <input type="hidden" name="pagename" py:attrs="value=pagename"/> 
    42             <textarea name="data" py:content="data" rows="10" cols="60"/> 
    43             <input type="submit" name="submit" value="Save"/> 
    44         </form> 
    45     ]]> 
     40        $${wikiform.display(page, action="save")} 
     41]]> 
    4642    </textarea> 
     43     
     44        <p>wikiform is a TurboGears widget. Widgets make data entry forms easy. We need to define that form, just above our Root class in controllers.py. Here's what it looks like:</p> 
     45         
     46        <textarea name="code" class="py" cols="60"><![CDATA[ 
     47from turbogears.widgets import * 
     48 
     49class wikifields(WidgetsList): 
     50    pagename = TextField() 
     51    data = TextArea(rows=10, cols=50) 
     52 
     53wikiform = TableForm(fields=wikifields()) 
     54]]></textarea> 
    4755 
    4856        <p>We need something to use this template now. We'll add an "edit" method to our controller:</p> 
    4957 
    5058        <textarea name="code" cols="60" class="py"><![CDATA[ 
    51     @turbogears.expose(html=".templates.edit") 
     59    @expose("wiki20.templates.edit") 
    5260    def edit(self, pagename): 
    5361        page = Page.byPagename(pagename) 
    54         return dict(pagename=page.pagename, data=page.data
     62        return dict(page=page, wikiform=wikiform
    5563    ]]> 
    5664        </textarea> 
     
    6876        <h2>Saving our edits</h2> 
    6977 
    70         <p>The form we made in the last section had an action of "save". So, we need to make a method called save in our controller. Here's what it looks like:</p> 
     78        <p>When we displayed our wikiform in the last section, the action was "save". So, we need to make a method called save in our controller. Here's what it looks like:</p> 
    7179 
    7280        <textarea name="code" cols="60" class="py"><![CDATA[ 
    73         @turbogears.expose() 
    74         def save(self, pagename, data, submit): 
     81        @expose() 
     82        @validate(form=wikiform) 
     83        def save(self, pagename, data): 
    7584            page = Page.byPagename(pagename) 
    7685            page.data = data 
     
    7988        ]]></textarea> 
    8089 
    81        <p>The <tt>submit</tt> parameter is supplied because it will be passed by the form. If we don't supply this, Python will complain about an unexpected parameter. An alternative is to use **keywords.</p> 
     90       <p>Though we're not using validation here, by telling validate that we're getting input from the wikiform, the submit button that is passed in will automatically be stripped out. Otherwise, the submit button would be passed to the method, just like any other parameter that comes from the web.</p> 
    8291 
    8392        <p>Interesting things to note about this:</p> 
  • branches/1.0/newdocs/docs/tutorials/wiki20/page4.html

    r596 r1457  
    1515 
    1616    <textarea name="code" cols="60" class="py"><![CDATA[ 
    17     @turbogears.expose(html=".templates.page"
     17    @expose(
    1818    def default(self, pagename): 
    1919        return self.index(pagename) 
     
    4747        page = Page.byPagename(pagename) 
    4848    except SQLObjectNotFound: 
    49         raise turbogears.redirect("/notfound", pagename= pagename) 
     49        raise redirect("/notfound", pagename = pagename) 
    5050    ]]></textarea> 
    5151     
     
    5959 
    6060    <textarea name="code" cols="60" class="py"><![CDATA[ 
    61     @turbogears.expose(html=".templates.edit") 
     61    @expose("wiki20.templates.edit") 
    6262    def notfound(self, pagename): 
    63         return dict(pagename=pagename, data="", new=True) 
     63        page = Page(pagename=pagename, data="") 
     64        return dict(page=page, wikiform=wikiform) 
    6465    ]]></textarea> 
    65  
    66     <p>Notice that the dictionary includes a variable called "new" for use in the template. Change the edit method to set new=False when it returns its dictionary:</p> 
    67  
    68     <pre class="command">        return dict(pagename=page.pagename, data=page.data, new=False)</pre> 
    69  
    70     <p>We need to be able to save a new item, so, we'll have to change the save method like this:</p> 
    71  
    72     <textarea name="code" cols="60" class="py"><![CDATA[ 
    73     @turbogears.expose() 
    74     def save(self, pagename, data, submit, new): 
    75         if new == "True": 
    76             page = Page(pagename=pagename, data=data) 
    77         else: 
    78             page = Page.byPagename(pagename) 
    79             page.data = data 
    80         turbogears.flash("Changes saved!") 
    81         raise turbogears.redirect("/%s" % pagename) 
    82     ]]></textarea> 
    83  
    84     <p>With SQLObject, just instantiating an object is enough to insert it in the database.</p> 
    85  
    86     <p>The one last thing we need to do is pass along the "new" variable to the save method via the form in edit.kid:</p> 
    87  
    88     <pre class="command"><![CDATA[        <input type="hidden" name="new" value="$${new}" />]]></pre> 
     66     
     67    <p>With SQLObject, just instantiating an object is enough to insert it in the database, so this method will create a brand new page in our database.</p> 
    8968 
    9069    <p>Give it a try! You should be able to create new pages now.</p> 
  • branches/1.0/newdocs/docs/tutorials/wiki20/page5.html

    r596 r1457  
    1010 
    1111<body> 
    12     <h2>Converting incoming arguments</h2> 
    13      
    14     <p>Something that's a little ugly in that save method is the 'if new == "True"'. Wouldn't it be nicer to just use the more pythonic 'if new'? Piece of cake... we just need to use a validator. First, we need an import:</p> 
    15      
    16     <pre class="command">from turbogears import validators</pre> 
    17      
    18     <p>Then, we specify the validator. The StringBoolean validator converts a string like "True" into the proper boolean. Doing that, we can change to using "if new". Here's the top of the save method:</p> 
    19      
    20     <textarea name="code" cols="60" class="py"><![CDATA[ 
    21     @turbogears.expose() 
    22     @turbogears.validate(validators=dict(new=validators.StringBoolean())) 
    23     def save(self, pagename, data, submit, new): 
    24         if new: 
    25             page = Page(pagename=pagename, data=data) 
    26     ]]></textarea> 
    27      
    2812    <h2>Adding a page list</h2> 
    2913     
     
    5842     
    5943    <textarea name="code" cols="60" class="py"><![CDATA[ 
    60     @turbogears.expose(html=".templates.pagelist") 
     44    @expose("wiki20.templates.pagelist") 
    6145    def pagelist(self): 
    6246        pages = [page.pagename for page in Page.select(orderBy=Page.q.pagename)] 
  • branches/1.0/newdocs/docs/tutorials/wiki20/page6.html

    r961 r1457  
    1212    <h2>You want AJAX? We got AJAX!</h2> 
    1313 
    14     <p>This part of the tutorial is not technically AJAX. The "X" in AJAX stands for XML. I'm going to use <a href="http://www.json.org/" target="_blank">JSON</a> instead. JSON is easy and lightweight and efficient to use for all browsers. To use JSON for this TurboGears example, we just have to tell TurboGears that we want to use it. Change the expose decorator for our new pagelist method to be:</p> 
     14    <p>This part of the tutorial is not technically AJAX. The "X" in AJAX stands for XML. I'm going to use <a href="http://www.json.org/" target="_blank">JSON</a> instead. JSON is easy and lightweight and efficient to use for all browsers. To use JSON for this TurboGears example, we just have to tell TurboGears that we want to use it. Just below the expose decorator, let's add another:</p> 
    1515     
    16     <pre class="command">@turbogears.expose(html=".templates.pagelist", allow_json=True)</pre> 
     16    <pre class="command">@expose("json")</pre> 
    1717     
    1818    <p>Now, point your browser at <a href="http://localhost:8080/pagelist?tg_format=json" target="_blank">http://localhost:8080/pagelist?tg_format=json</a>. There's your pagelist in JSON format.</p> 
     
    2424    <p>The first thing we need to do is have MochiKit included in all of our pages. We can actually do this right from the project configuration file. This file is config/app.cfg in the Python package that quickstart created for your project. Open that up, and in your editor you'll find a commented out "VIEW" part of the config. Uncomment the line that says "tg.mochikit_all" and change the value to True. The line will end up looking like this:</p> 
    2525     
    26     <pre class="command">"tg.mochikit_all" : True,</pre> 
     26    <pre class="command">tg.mochikit_all = True</pre> 
    2727     
    2828    <p>This setting will tell TurboGears to include MochiKit in every page. After making this configuration change, <b>restart the server.</b></p> 
  • branches/1.0/setup.cfg

    r1305 r1457  
    88 
    99[egg_info] 
    10 tag_build = dev 
    11 tag_svn_revision = true 
     10# tag_build = dev 
     11# tag_svn_revision = true 
    1212 
    1313[aliases] 
  • branches/1.0/turbogears/docgen.py

    r1098 r1457  
    225225        if self.noprintable: 
    226226            return 
     227        self._make_printable(os.path.join("docs", "tutorials", "wiki20"), 3) 
    227228        self._make_printable(os.path.join("docs", "wiki20")) 
    228         self._make_printable(os.path.join("docs", "tutorials", "wiki20"), 3) 
    229229     
    230230    def _make_printable(self, tutdir, up_to_root=2): 
  • branches/1.0/turbogears/qstemplates/quickstartbig/+package+/controllers/root.py_tmpl

    r1382 r1457  
    44 
    55import turbogears 
    6 from turbogears import controllers, expose, redirect 
     6from turbogears import controllers, expose, validate, redirect 
    77#if $identity != "none" 
    88from turbogears import identity 
  • branches/1.0/turbogears/qstemplates/quickstart/+package+/controllers.py_tmpl

    r1382 r1457  
    44 
    55import turbogears 
    6 from turbogears import controllers, expose, redirect 
     6from turbogears import controllers, expose, validate, redirect 
    77#if $identity != "none" 
    88from turbogears import identity 
  • branches/1.0/turbogears/toolbox/widgets.kid

    r1455 r1457  
    5151                <div class="tabbertab"> 
    5252                    <h2>Source Code</h2> 
    53                     <textarea name="code" class="py" py:content="widgetdesc.source" /> 
     53                    <textarea py:content="widgetdesc.source" rows="10" cols="60" wrap="none"/> 
    5454                </div> 
    5555                <div class="tabbertab" py:if="widgetdesc.for_widget.params"> 
     
    6464                <div py:if="widgetdesc.for_widget.template" class="tabbertab"> 
    6565                    <h2>Template</h2> 
    66                     <textarea name="code" class="xml" py:content="widgetdesc.for_widget.template" /> 
     66                    <textarea rows="10" cols="60" wrap="none" py:content="widgetdesc.for_widget.template" /> 
    6767                </div> 
    6868            </div>