<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Mouse Vs. The Python &#187; TurboGears</title>
	<atom:link href="http://www.blog.pythonlibrary.org/tag/turbogears/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blog.pythonlibrary.org</link>
	<description>Python Programming from the Frontlines</description>
	<lastBuildDate>Sun, 08 Jan 2012 12:45:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>TurboGears 2: Setting up on Windows</title>
		<link>http://www.blog.pythonlibrary.org/2011/08/14/turbogears-2-setting-up-on-windows/</link>
		<comments>http://www.blog.pythonlibrary.org/2011/08/14/turbogears-2-setting-up-on-windows/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 17:51:09 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[TurboGears]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web Framework]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Python Web Frameworks]]></category>

		<guid isPermaLink="false">http://www.blog.pythonlibrary.org/?p=1885</guid>
		<description><![CDATA[TurboGears is one of several web frameworks for Python that are available. The most popular by far is Django. Where I work, we chose TurboGears because of its integration with SQLAlchemy which supports composite keys. At that time, Django did not support that feature and I am not sure if it does yet. Anyway, I [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-left"><a href="http://twitter.com/share" class="twitter-share-button" data-counturl="http://www.blog.pythonlibrary.org/2011/08/14/turbogears-2-setting-up-on-windows/" data-url="http://bit.ly/tE5Abk" data-text="TurboGears 2: Setting up on Windows" data-count="vertical" data-via="socializeWP" ><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-left"><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.blog.pythonlibrary.org/2011/08/14/turbogears-2-setting-up-on-windows/&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px !important; height:65px;" allowTransparency="true"></iframe></div></div><p>TurboGears is one of several web frameworks for Python that are available. The most popular by far is Django. Where I work, we chose TurboGears because of its integration with SQLAlchemy which supports composite keys. At that time, Django did not support that feature and I am not sure if it does yet. Anyway, I develop almost exclusively on a Windows box and have found the TurboGears&#8217; documentation on the subject a little confusing. So here&#8217;s how I do it. </p>
<p><em>Note: We&#8217;ll be using TurboGears 2.1 in this tutorial</em><span id="more-1885"></span></p>
<h2>Getting Started</h2>
<p>We&#8217;re going to make sure Python is set up right first. Open a command window by going to <strong>Start &#8211;> Run</strong> and then typing &#8220;cmd&#8221; and pressing <strong>enter</strong>. Try typing &#8220;python&#8221; (without the quotes) in there and hitting your enter. If you see the Python shell, then we&#8217;re halfway there. If you don&#8217;t, then we need to modify some settings.</p>
<h3>Modifying Your Path</h3>
<p>On Windows, I have found that it helps a LOT to modify my Path settings by adding my Python path and the path to the Scripts folder to my Path. Here&#8217;s how you do it:</p>
<ol>
<li>Right-Click &#8220;My Computer&#8221; and choose <strong>Properties </strong>(Windows XP) or you may have to go digging in Control Panel on Windows 7 and do a &#8220;Show All Control Panel Items&#8221; from the path bar and look for <strong>System</strong>. You should see something like this:
<p><a href="http://www.blog.pythonlibrary.org/wp-content/uploads/2011/08/system_properties_xp.png"><img src="http://www.blog.pythonlibrary.org/wp-content/uploads/2011/08/system_properties_xp.png" alt="" title="system_properties_xp" width="419" height="479" class="aligncenter size-full wp-image-1891" /></a></p>
</li>
<li>Go to the <strong>Advanced</strong> tab and press the <strong>Environmental Variable</strong> button to see something like the following:
<p><a href="http://www.blog.pythonlibrary.org/wp-content/uploads/2011/08/environment_vars_xp.png"><img src="http://www.blog.pythonlibrary.org/wp-content/uploads/2011/08/environment_vars_xp.png" alt="" title="environment_vars_xp" width="384" height="423" class="aligncenter size-full wp-image-1894" /></a>
</li>
<li>You will see two types of variables here. In the bottom section are <strong>System Variables</strong>. Scroll down to the one labeled <strong>Path</strong> and at the end of that, add the following two lines: ;C:\Python26;C:\Python26\Scripts  (adjust as necessary according to your version of Python and its location) Note that each entry is separated by a semi-colon, so make sure you do that too or this will not work!</li>
</ol>
<p><strong><br />
<h3>Installing Prerequisites</h3>
<p></strong></p>
<p>Once that&#8217;s done, we need to make sure you have SetupTools installed. Go to the Python Package Index and <a href="http://pypi.python.org/pypi/setuptools" target="_blank">download </a>it if you know you don&#8217;t already have it as SetupTools will install a little script known as easy_install that will make getting TurboGears setup a breeze. Just scroll to the end of the page and pick the exe that corresponds to your Python version. You cannot install an egg unless you already have this installed, so I don&#8217;t know why they have eggs on there to begin with.</p>
<p>Once that&#8217;s done, open a new command window and try typing in the following: easy_install. You should receive an error like this: &#8220;error: No urls, filenames, or requirements specified (see &#8211;help)&#8221; If you do, then you&#8217;ve got it installed and on your path. Good job! </p>
<p>The TurboGears people recommend installing virtualenv to help keep your primary Python installation (PyPI) as pristine as possible. It also helps when you need to experiment with different versions of software that you don&#8217;t want to break current projects. How does this work? Well, virtualenv creates a little virtual workspace for you on your machine where it puts a copy of Python and installs all the software into that virtual place for you to play with. It&#8217;s a development sandbox! Since you now have easy_install, we&#8217;ll use that to install it. In your command window, type: easy_install virtualenv</p>
<p>That will cause easy_install to go out on the internet and try to download and install virtualenv from PyPI. It should look something like this:</p>
<p><a href="http://www.blog.pythonlibrary.org/wp-content/uploads/2011/08/install_virtualenv.png"><img src="http://www.blog.pythonlibrary.org/wp-content/uploads/2011/08/install_virtualenv.png" alt="" title="install_virtualenv" width="572" height="323" class="aligncenter size-full wp-image-1895" /></a></p>
<p>If it completed successfully, then we&#8217;re ready to create a virtual environment for our TurboGears install. Change directories to a location that you&#8217;d like to do this in. On Windows 7, you&#8217;ll probably have security issues if you try to do this outside of your Documents or similar Collections folders, so you should stick with one of those. For this tutorial, we&#8217;ll create it in <strong>My Documents</strong>.</p>
<p>Once you&#8217;re there, type the following: virtualenv &#8211;no-site-packages example</p>
<p>This will create a folder that&#8217;s labeled &#8220;example&#8221; with several folders inside it. You should see the following on your screen:</p>
<p><a href="http://www.blog.pythonlibrary.org/wp-content/uploads/2011/08/virtualenv_example.png"><img src="http://www.blog.pythonlibrary.org/wp-content/uploads/2011/08/virtualenv_example.png" alt="" title="virtualenv_example" width="440" height="156" class="aligncenter size-full wp-image-1902" /></a></p>
<p>The &#8211;no-site-packages command will prevent the virtual environment from inheriting anything from the system Python&#8217;s site-packages folder. Now change directory into your example folder in the command window and type the following: Scripts\activate.bat  (see screenshot below)</p>
<p><a href="http://www.blog.pythonlibrary.org/wp-content/uploads/2011/08/virtualenv_activate.png"><img src="http://www.blog.pythonlibrary.org/wp-content/uploads/2011/08/virtualenv_activate.png" alt="" title="virtualenv_activate" width="544" height="276" class="aligncenter size-full wp-image-1898" /></a></p>
<h2>Installing &#038; Setting Up TurboGears</h2>
<p>Now your virtual environment is active and ready to rock. You can tell because each line is now prefixed with the name of the folder you&#8217;re in, which in this case is &#8220;example&#8221;. You can install Turbogears at this point as your virtual environment also has Setup Tools installed. However, this install is a little different as we will be specifying a specific URL. Type the following (you may want to check the TurboGears website to see if the URL has been updated since the writing of this post):</p>
<p><code><br />
easy_install.exe -i http://www.turbogears.org/2.1/downloads/current/index tg.devtools<br />
</code></p>
<p>Depending on the speed of your PC and your connection, this will take a while. TurboGears is a mashup of a large number of 3rd party Python packages. You can watch it install or you can go get a drink or make a phone call while you wait. Once that&#8217;s finished, we&#8217;re nearly done. </p>
<p><em>Note: All the packages should be installing to your virtual space&#8217;s <strong>lib</strong> folder, NOT your default Python&#8217;s. If the latter is happening, you probably don&#8217;t have the virtual environment activated<br />
</em></p>
<p><strong><br />
<h3>Creating a TurboGears Workspace</h3>
<p></strong></p>
<p>One of the packages we installed earlier was Python Paste. TurboGears uses this package to bootstrap a new TurboGears application. So in your activated virtual environment, type the following command:</p>
<p><code><br />
paster quickstart example<br />
</code></p>
<p><em>Note: If your path to the &#8220;example&#8221; folder has a space in it, you will receive an error about needing the PyWin32 library installed. Very annoying.</em></p>
<p>When you run this, you will need to answer 3 questions. The first is what to name the project. The default is the same name as the folder. Note that the project name has to be in lowercase. Then it asks if you&#8217;d like to use <a href="http://www.makotemplates.org/" target="_blank">Mako templates</a>. What it doesn&#8217;t say is that if you choose no (which is the default), you will get <a href="http://genshi.edgewall.org/" target="_blank">Genshi templates</a> instead. That&#8217;s up to you. Mako looks and feels more &#8220;pythonic&#8221; from what I&#8217;ve seen of it, so I&#8217;d recommend it unless you already know Genshi or something like Genshi. The last question is whether or not you want authentication, which will give you a simple admin interface that you can login to, the default of which is &#8220;yes&#8221;. You can experiment with these or just take the defaults.</p>
<p>The next step is to change directories into your new project directory and then type the following in at the command line:</p>
<p><code><br />
python setup.py develop<br />
</code></p>
<p>This adds your project to the virtual environment and also downloads a few packages to install alongside it that might be useful in your development. I don&#8217;t really know how these help you, but it seems to be a requirement of sorts according to <a href="http://turbogears.org/2.1/docs/main/DownloadInstall.html" target="_blank">TurboGear&#8217;s documentation</a>.</p>
<p>The next to last step is to input the following into your command line window:</p>
<p><code><br />
paster setup-app development.ini<br />
</code></p>
<p>This will initiate your database, which is basically just creating and populating with some default information for the security / authentication you agreed to. If you didn&#8217;t install that stuff or don&#8217;t want to run this step, you don&#8217;t have to. But you won&#8217;t be able to login unless you do.</p>
<p>Finally, you need to type the following:</p>
<p><code><br />
paster serve development.ini<br />
</code></p>
<p>Now you will have a fully functioning website that&#8217;s running on <a href="http://localhost:8080/ " target="_blank">http://localhost:8080/ (or http://127.0.0.1:8080) </a>. If you load up your browser and navigate to that you should see something like this:</p>
<p><a href="http://www.blog.pythonlibrary.org/wp-content/uploads/2011/08/default_tg_web.png"><img src="http://www.blog.pythonlibrary.org/wp-content/uploads/2011/08/default_tg_web-300x198.png" alt="" title="default_tg_web" width="300" height="198" class="aligncenter size-medium wp-image-1904" /></a></p>
<h2>Wrapping Up</h2>
<p>Now you should know how to install and setup a TurboGears web application. The sky&#8217;s the limit after all that work. You&#8217;ll need to start reading the documentation, add a dash of javascript and a bit of CSS and you&#8217;ll have a cool website in no time. Good luck and have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.pythonlibrary.org/2011/08/14/turbogears-2-setting-up-on-windows/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Weekly Python News (12/31/2010)</title>
		<link>http://www.blog.pythonlibrary.org/2010/12/31/weekly-python-news-12312010/</link>
		<comments>http://www.blog.pythonlibrary.org/2010/12/31/weekly-python-news-12312010/#comments</comments>
		<pubDate>Fri, 31 Dec 2010 22:14:42 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Python Web Frameworks]]></category>
		<category><![CDATA[TurboGears]]></category>
		<category><![CDATA[wxPython]]></category>

		<guid isPermaLink="false">http://www.blog.pythonlibrary.org/?p=1471</guid>
		<description><![CDATA[This week&#8217;s Python news covers new modules, updates to old modules, a newish Python Magazine (no, not that one!), an update on what&#8217;s going on with the new wxPython and more! &#8220;TurboGears Joins the Pylons Project&#8221; (Alt title: TurboGears Becomes TurboPyramid). I think the title says it all&#8230;and no, they didn&#8217;t really rename the project. [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-left"><a href="http://twitter.com/share" class="twitter-share-button" data-counturl="http://www.blog.pythonlibrary.org/2010/12/31/weekly-python-news-12312010/" data-url="http://bit.ly/ufSxE6" data-text="Weekly Python News (12/31/2010)" data-count="vertical" data-via="socializeWP" ><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-left"><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.blog.pythonlibrary.org/2010/12/31/weekly-python-news-12312010/&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px !important; height:65px;" allowTransparency="true"></iframe></div></div><p>This week&#8217;s Python news covers new modules, updates to old modules, a newish Python Magazine (no, not <a href="http://pythonmagazine.com/">that </a>one!), an update on what&#8217;s going on with the new wxPython and more!</p>
<ul>
<li>&#8220;<a href="http://compoundthinking.com/blog/index.php/2010/12/28/turbogears-joins-the-pylons-project/">TurboGears Joins the Pylons Project</a>&#8221; (Alt title: TurboGears Becomes TurboPyramid). I think the title says it all&#8230;and no, they didn&#8217;t really rename the project.</li>
<li>wxPython&#8217;s &#8220;Project Phoenix&#8221; gets an <a href="http://groups.google.com/group/wxPython-dev/browse_thread/thread/dd4ace14f0f9c176">update</a> &#8211; this gives an update on how Robin Dunn is moving away from SWIG to make it easier to do documentation and the Python 3 port.</li>
<li>Michael Foord&#8217;s new &#8220;e&#8221; module makes a debut&#8230;read all about it on his <a href="http://www.voidspace.org.uk/python/weblog/arch_d7_2010_12_25.shtml?utm_source=feedburner&#038;utm_medium=feed&#038;utm_campaign=Feed%3A+voidspace+%28The+Voidspace+Techie+Blog%29#e1200">blog</a></li>
<li><a href="http://revista.python.org.ar/1/html-en/">PET: Issue #1</a> &#8211; English translation of a magazine created by the Argentina Python Users Group. Yes, this is kind of old news, but I thought it was really cool and it needs YOUR support!</li>
<p>.</p>
<li>The PSF <a href="http://pyfound.blogspot.com/2010/12/high-school-students-program-robots.html?utm_source=feedburner&#038;utm_medium=feed&#038;utm_campaign=Feed%3A+PythonSoftwareFoundationNews+%28Python+Software+Foundation+News%29">blog </a>talks about high schoolers using Python to program robots under the guidance of Vern Ceder</li>
<li><a href="http://lists.dlitz.net/pipermail/pycrypto/2010q4/000305.html">PyCrypto </a>gets a Python 3 port courtesy of Thorsten Behrens. Check out the thread and download your copy to help find any bugs!</li>
</ul>
<p>That&#8217;s it for this week. Next time we&#8217;ll be in 2011! That&#8217;s amazing! Anyway, I hope you have a nice holiday and you&#8217;ll let me know of any Python news that I should talk about for the next post. Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.pythonlibrary.org/2010/12/31/weekly-python-news-12312010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pyowa &#8211; July 2010 Wrapup</title>
		<link>http://www.blog.pythonlibrary.org/2010/07/03/pyowa-july-2010-wrapup/</link>
		<comments>http://www.blog.pythonlibrary.org/2010/07/03/pyowa-july-2010-wrapup/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 16:29:50 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Pyowa]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[TurboGears]]></category>
		<category><![CDATA[Web Framework]]></category>
		<category><![CDATA[Django]]></category>

		<guid isPermaLink="false">http://www.blog.pythonlibrary.org/?p=1012</guid>
		<description><![CDATA[On Thursday, July 1st, we had our July Pyowa meeting. It was hosted by Matt Morrison at the IMT Group&#8217;s building in Des Moines, IA. We had our largest attendance ever with a total of 15 men showing up. Tavern Pizza and pop were served, which was also a first&#8230;we&#8217;ve had pop before, just not [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-left"><a href="http://twitter.com/share" class="twitter-share-button" data-counturl="http://www.blog.pythonlibrary.org/2010/07/03/pyowa-july-2010-wrapup/" data-url="http://bit.ly/u62Yf5" data-text="Pyowa &#8211; July 2010 Wrapup" data-count="vertical" data-via="socializeWP" ><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-left"><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.blog.pythonlibrary.org/2010/07/03/pyowa-july-2010-wrapup/&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px !important; height:65px;" allowTransparency="true"></iframe></div><div class="socialize-in-button socialize-in-button-left"><script type="text/javascript">
			<!-- 
			reddit_url = "http://www.blog.pythonlibrary.org/2010/07/03/pyowa-july-2010-wrapup/";
			reddit_title = "Pyowa &#8211; July 2010 Wrapup";	//-->
		</script><script type="text/javascript" src="http://www.reddit.com/static/button/button2.js"></script></div><div class="socialize-in-button socialize-in-button-left"><g:plusone size="small" href="http://www.blog.pythonlibrary.org/2010/07/03/pyowa-july-2010-wrapup/"></g:plusone></div></div><p>On Thursday, July 1st, we had our July Pyowa meeting. It was hosted by <a href="http://twitter.com/mattjmorrison">Matt Morrison</a> at the <a href="http://www.imtins.com/">IMT </a>Group&#8217;s building in Des Moines, IA. We had our largest attendance ever with a total of 15 men showing up. <a href="http://www.tavernpizza.com/">Tavern Pizza</a> and pop were served, which was also a first&#8230;we&#8217;ve had pop before, just not any food!</p>
<p>We had two presentations. The first was an around 70 minutes in length and covered introductory materials about <a href="http://www.djangoproject.com/">Django</a>, a full-stack web framework written in Python. It was given by our host and he also included anecdotes about how his company uses Django and what challenges that has presented him. Next up we had a quick talk about <a href="http://turbogears.org/">TurboGears</a>, another web framework. TurboGears is actually a collection of various Python modules that have been pieced together, which makes it much more modular than Django. However, Django has a lot more users behind it and there are some definite advantages to having everything builtin. Anyway, the TurboGears presentation covered a group of different web sites (or web applications) that the presenter had created. It was interesting to compare and contrast the two frameworks and see how they differed or stayed the same.</p>
<p>We are currently looking for presenters for our August and September meetings, so if you want to talk about how you&#8217;re using Python now, in the past or even what you plan to do with it in the future, let me know by emailing me or in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.pythonlibrary.org/2010/07/03/pyowa-july-2010-wrapup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Set up a TurboGears 2 Doc Environment</title>
		<link>http://www.blog.pythonlibrary.org/2009/07/16/how-to-set-up-a-turbogears-2-doc-environment/</link>
		<comments>http://www.blog.pythonlibrary.org/2009/07/16/how-to-set-up-a-turbogears-2-doc-environment/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 13:38:53 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[TurboGears]]></category>
		<category><![CDATA[SetupTools]]></category>
		<category><![CDATA[Sphinx]]></category>
		<category><![CDATA[VirtualEnv]]></category>

		<guid isPermaLink="false">http://www.blog.pythonlibrary.org/?p=230</guid>
		<description><![CDATA[Last month I found some issues with the TurboGears 2 documentation and the guys on the TG IRC channel told me I should download the docs and do something about it. Alas, I didn&#8217;t know what I was doing, but with their guidance I got the code and it was mostly set up. Then my [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-left"><a href="http://twitter.com/share" class="twitter-share-button" data-counturl="http://www.blog.pythonlibrary.org/2009/07/16/how-to-set-up-a-turbogears-2-doc-environment/" data-url="http://bit.ly/vSNpRl" data-text="How to Set up a TurboGears 2 Doc Environment" data-count="vertical" data-via="socializeWP" ><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-left"><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.blog.pythonlibrary.org/2009/07/16/how-to-set-up-a-turbogears-2-doc-environment/&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px !important; height:65px;" allowTransparency="true"></iframe></div><div class="socialize-in-button socialize-in-button-left"><script type="text/javascript">
			<!-- 
			reddit_url = "http://www.blog.pythonlibrary.org/2009/07/16/how-to-set-up-a-turbogears-2-doc-environment/";
			reddit_title = "How to Set up a TurboGears 2 Doc Environment";	//-->
		</script><script type="text/javascript" src="http://www.reddit.com/static/button/button2.js"></script></div><div class="socialize-in-button socialize-in-button-left"><g:plusone size="small" href="http://www.blog.pythonlibrary.org/2009/07/16/how-to-set-up-a-turbogears-2-doc-environment/"></g:plusone></div></div><p>Last month I found some issues with the <a href="http://turbogears.org/2.0/docs/index.html">TurboGears 2 documentation</a> and the guys on the TG IRC channel told me I should download the docs and do something about it. Alas, I didn&#8217;t know what I was doing, but with their guidance I got the code and it was mostly set up. Then my work got in the way and I forgot all about it. Yesterday I got into another conversation about the sad shape the docs are in on the same IRC channel and this time I decided to do it right. Here&#8217;s how you can get set up so you can help too!<span id="more-230"></span></p>
<p>If you just want to jump in, read the short directions at the end.</p>
<p>First, you need to have <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> and <a href="http://pypi.python.org/pypi/setuptools">setuptools</a> installed in your default python install. Virtualenv allows you to create a &#8220;virtual&#8221; environment with it&#8217;s own copy of python and a virgin set of libraries. Why would you want to do this? Because it makes experimenting with packages much easier. You can download and try anything you like without screwing up your main installation and if you find you don&#8217;t like the package, you just delete the folder that contains the virtual environment. Setuptools is needed for <a href="http://peak.telecommunity.com/DevCenter/EasyInstall">easy_install</a> purposes, which is something that TurboGears utilitizes a lot.</p>
<p>Once you have that stuff downloaded and installed, open up a command window (or shell) and navigate to a location where you&#8217;d like to create a virtual environment. Then type the following where &#8220;exampleFolder&#8221; is the name of the folder you want to create the virtual environment in.</p>
<p><code><br />
virtualenv --no-site-packages exampleFolder<br />
</code></p>
<p>The &#8220;&#8211;no-site-packages&#8221; flag tells virtualenv that you do not want to copy your entire tree of site-packages from your main python installation. I recommend this as I have lots of stuff in my site-packages that I don&#8217;t want in my virtualenv. </p>
<p>Next, you need <a href="http://sphinx.pocoo.org/">Sphinx</a> and you can&#8217;t just use the current 0.6.2 version as it doesn&#8217;t work right with the TG2 (as of 07/16/2009). Instead, you&#8217;ll need 0.6.2+, which you can get <a href="https://bitbucket.org/birkenfeld/sphinx-06/">here</a>. To download the source from bitbucket, you&#8217;ll need <a href="http://mercurial.selenic.com/wiki/">Mercurial</a>. I recommend getting the command line version as the GUI tended to mess up file open dialogs on my Windows box due to the way Mercurial did shell overlays (it also screwed up WingWare IDE). This may be fixed now. Once you have Mercurial, follow the &#8220;hg clone&#8221; directions on the site linked above. Then change directories until your inside the source and run &#8220;python setup.py install&#8221; to install Sphinx.</p>
<p>The next step is to get the docs themselves. You have two choices. You can go with the ones on TG2&#8242;s main website, or you can get <a href="https://pedersen@bitbucket.org/pedersen/tg_2_1_docs/">mpedersen&#8217;s set</a>. Just so you know, mpedersen is the IRC handle of the guy who has volunteered to lead the effort in the documentation clean-up. The only difference is that his set will have fixes already in it along with a todo list on each page. I recommend his so that the duplication of effort will be at the minimum. You use the same &#8220;hg clone&#8221; command there as you did for the hacked Sphinx source in the last step.</p>
<p>The next to last step is to download the TG2-dev source and install it. Here&#8217;s the Mercurial command to get the source:</p>
<p><code><br />
hg clone http://bitbucket.org/mramm/tg-21/<br />
</code></p>
<p>Now just install it like you did with Sphinx above. Note that the dev code depends on SqlAlchemy and doesn&#8217;t install it automagically, so be sure to easy_install that as well.</p>
<p>We&#8217;re almost there now. The last step is to build the docs. To do this, navigate into the &#8220;docs&#8221; sub-folder of the docs you downloaded and run the following command (or if you&#8217;re on Linux, use &#8220;make html&#8221;):</p>
<p><code><br />
sphinx-build -b html -d _build/doctrees   . _build/html<br />
</code></p>
<p>Now you can browse the html versions of the docs! Remember, to edit the docs, you must edit the rst files, not the html ones. When you&#8217;re ready to contribute them back, you&#8217;ll use the &#8220;hg push&#8221; command. I haven&#8217;t done this part, so hit up mpedersen on the turbogears IRC channel for more info.</p>
<p>To recap, here&#8217;s a short list of what you need to do:</p>
<p>1) Create a clean virtualenv and activate it<br />
2) Download Sphinx 0.6.2+ from <a href="https://bitbucket.org/birkenfeld/sphinx-06/">https://bitbucket.org/birkenfeld/sphinx-06/</a><br />
3) Get the docs from the main website or from <a href="https://pedersen@bitbucket.org/pedersen/tg_2_1_docs/">mpedersen</a><br />
4) The dev source depends on SqlAlchemy, so easy_install that<br />
5) Get the <a href="http://bitbucket.org/mramm/tg-21/">TG2-dev source</a> and install it<br />
6) Go into the downloaded TG2 docs sub-folder and run<br />
&#8220;sphinx-build -b html -d _build/doctrees   . _build/html&#8221;<br />
(without the quotes)<br />
7) And you&#8217;re done!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.pythonlibrary.org/2009/07/16/how-to-set-up-a-turbogears-2-doc-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Multiple Databases in TurboGears 2</title>
		<link>http://www.blog.pythonlibrary.org/2009/06/13/using-multiple-databases-in-turbogears-2/</link>
		<comments>http://www.blog.pythonlibrary.org/2009/06/13/using-multiple-databases-in-turbogears-2/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 20:13:36 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Framework]]></category>
		<category><![CDATA[TurboGears]]></category>

		<guid isPermaLink="false">http://www.blog.pythonlibrary.org/?p=210</guid>
		<description><![CDATA[Last week, I embarked on an adventure into the world of web application programming. Since my work place uses Python as much as possible and my boss likes TurboGears, I chose it for this endeavor. I have worked through various TurboGears tutorials and thought it looked pretty cool. However, it doesn&#8217;t take long to discover [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-left"><a href="http://twitter.com/share" class="twitter-share-button" data-counturl="http://www.blog.pythonlibrary.org/2009/06/13/using-multiple-databases-in-turbogears-2/" data-url="http://bit.ly/rUQwbo" data-text="Using Multiple Databases in TurboGears 2" data-count="vertical" data-via="socializeWP" ><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-left"><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.blog.pythonlibrary.org/2009/06/13/using-multiple-databases-in-turbogears-2/&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px !important; height:65px;" allowTransparency="true"></iframe></div><div class="socialize-in-button socialize-in-button-left"><script type="text/javascript">
			<!-- 
			reddit_url = "http://www.blog.pythonlibrary.org/2009/06/13/using-multiple-databases-in-turbogears-2/";
			reddit_title = "Using Multiple Databases in TurboGears 2";	//-->
		</script><script type="text/javascript" src="http://www.reddit.com/static/button/button2.js"></script></div><div class="socialize-in-button socialize-in-button-left"><g:plusone size="small" href="http://www.blog.pythonlibrary.org/2009/06/13/using-multiple-databases-in-turbogears-2/"></g:plusone></div></div><p>Last week, I embarked on an adventure into the world of web application programming. Since my work place uses Python as much as possible and my boss likes TurboGears, I chose it for this endeavor. I have worked through various TurboGears tutorials and thought it looked pretty cool. However, it doesn&#8217;t take long to discover that there is a lot of undocumented functionality. In this case, I needed a web application that could access multiple databases. I knew SqlAlchemy could do it and since TG2 uses SqlAlchemy, I figured it would too. In this article you will get to travel down the rabbit hole with me as I explain how I figured it out.<span id="more-210"></span></p>
<p>When you go looking for help, the first article Google is likely to return is Mark Ramm&#8217;s <a href="http://compoundthinking.com/blog/index.php/2008/07/31/10-reasons-why-the-new-turbogears-2-alpha-is-worth-a-look/">blog post</a> about how easy it is to do. However, Ramm does not actually explain how to do it. Another fellow on the TurboGears Google Group posted a link to the <a href="http://pylonshq.com/">Pylons</a> way of setting up<a href="http://www.pylonshq.com/docs/en/0.9.7/models/#multiple-engines"> multiple databases</a>.  If you go there, you&#8217;ll find out that the first step is set up multiple <a href="http://www.sqlalchemy.org">SqlAlchemy</a> URLs in your config file, which in the case of TurboGears is your development.ini file. All you need to do is add one or more SqlAlchemy URLs to the [app:main] section.</p>
<p>So, instead of this:</p>
<p><code><br />
sqlalchemy.url = sqlite:///%(here)s/devdata.db<br />
</code></p>
<p>You would do something like this:</p>
<p><code><br />
sqlalchemy.first.url=mssql://user:password@ntsql.servername.com/database<br />
sqlalchemy.second.url=sqlite:///%(here)s/devdata.db<br />
</code></p>
<p>Notice that you add to the dot notation to make the URLs unique. I think the &#8220;sqlalchemy&#8221; and &#8220;url&#8221; parts are required at the beginning and the end, but the rest can be whatever you want. If that was all you needed to do, this would indeed be an easy setup. However, we have a couple more files to modify. The next part was pretty tricky. I discovered that there&#8217;s some comments on multiple databases in the model folder&#8217;s __init__.py file. It claims that you need to create a new MetaData object, which is true, but the commented out example is misleading. In the example, the metadata is <em>not</em> bound to an engine object. Without that info, the metadata object will be basically useless. I then noticed the init_model method which is there for reflection purposes. Upon further digging, I found that you needed to modify it to pass in the engines needed for your various databases, This is where I ended up putting my new metadata object. Technically, you could create it before the method and then just make it global, but I didn&#8217;t need that in my test case. Change yours as needed. Following are the changes I needed to make:</p>
<pre class="python"><span style="color: #808080; font-style: italic;"># Global session manager: DBSession() returns the Thread-local</span>
<span style="color: #808080; font-style: italic;"># session object appropriate for the current web request.</span>
maker = sessionmaker<span style="color: black;">&#40;</span>autoflush=<span style="color: #008000;">True</span>, autocommit=<span style="color: #008000;">False</span>,
                     extension=ZopeTransactionExtension<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
DBSession = scoped_session<span style="color: black;">&#40;</span>maker<span style="color: black;">&#41;</span>
&nbsp;
maker2 = sessionmaker<span style="color: black;">&#40;</span>autoflush=<span style="color: #008000;">True</span>, autocommit=<span style="color: #008000;">False</span>,
                      extension=ZopeTransactionExtension<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
secondSession = scoped_session<span style="color: black;">&#40;</span>maker2<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> init_model<span style="color: black;">&#40;</span>engineOne, engineTwo<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;Call me before using any of the tables or classes in the
    model.&quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
&nbsp;
    DBSession.<span style="color: black;">configure</span><span style="color: black;">&#40;</span>bind=engineOne<span style="color: black;">&#41;</span>
&nbsp;
    secondSession.<span style="color: black;">configure</span><span style="color: black;">&#40;</span>bind=engineTwo<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># you only need this metadata</span>
    <span style="color: #808080; font-style: italic;"># if you want to autoload a table</span>
    second_metadata = MetaData<span style="color: black;">&#40;</span>engineTwo<span style="color: black;">&#41;</span></pre>
<p>The last file that should be edited is the &#8220;app_cfg.py&#8221; located in the config folder. Here you need to subclass the &#8220;AppConfig&#8221; object to override the &#8220;setup_sqlalchemy&#8221; method. This is required only if you have modified your init_model method (above) to accept multiple engines. If you do not do this, you&#8217;ll receive a lovely traceback about your method needing additional parameters. Here&#8217;s my code:</p>
<pre class="python"><span style="color: #ff7700;font-weight:bold;">from</span> pylons <span style="color: #ff7700;font-weight:bold;">import</span> config as pylons_config
<span style="color: #ff7700;font-weight:bold;">from</span> tg.<span style="color: black;">configuration</span> <span style="color: #ff7700;font-weight:bold;">import</span> config
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> MyAppConfig<span style="color: black;">&#40;</span>AppConfig<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> setup_sqlalchemy<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;Setup SQLAlchemy database engine.&quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">from</span> sqlalchemy <span style="color: #ff7700;font-weight:bold;">import</span> engine_from_config
        engineOne = engine_from_config<span style="color: black;">&#40;</span>pylons_config, <span style="color: #483d8b;">'sqlalchemy.first.'</span><span style="color: black;">&#41;</span>
        engineTwo = engine_from_config<span style="color: black;">&#40;</span>pylons_config, <span style="color: #483d8b;">'sqlalchemy.second.'</span><span style="color: black;">&#41;</span>
        config<span style="color: black;">&#91;</span><span style="color: #483d8b;">'pylons.app_globals'</span><span style="color: black;">&#93;</span>.<span style="color: black;">engineOne</span> = engineOne
        config<span style="color: black;">&#91;</span><span style="color: #483d8b;">'pylons.app_globals'</span><span style="color: black;">&#93;</span>.<span style="color: black;">sa_engine</span> = engineTwo
        <span style="color: #808080; font-style: italic;"># Pass the engine to initmodel, to be able to introspect tables</span>
        init_model<span style="color: black;">&#40;</span>engineOne, engineTwo<span style="color: black;">&#41;</span>
&nbsp;
base_config = MyAppConfig<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre>
<p>It should be noted here that the default websetup.py file is hardwired to use a variable called &#8220;sa_engine&#8221; when you&#8217;re using authentication. Thus, I assign one of the engines to that variable above. You could also go into websetup.py and just edit it as needed to accept whatever customizations are required. I do not know if there are additional files that need to be modified as this I ended up just changing the variable name above rather than mess with additional issues like this one.</p>
<p>Once all that is done, you should be good to go. On the TurboGears IRC, one of the members there mentioned a way to use multiple databases by &#8220;calling setup twice&#8221;. He didn&#8217;t explain how this worked, so I don&#8217;t know if it is simpler, but if you want to investigate this method and report back, that&#8217;s fine by me. I went ahead and created some dummy files with my changes so you can see then in context. They are downloadable below:</p>
<p>Sample files as <a href='http://www.blog.pythonlibrary.org/wp-content/uploads/2009/06/tg_multi_db.zip'>zip</a> or <a href='http://www.blog.pythonlibrary.org/wp-content/uploads/2009/06/tg_multi_db.tar'>tar</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.pythonlibrary.org/2009/06/13/using-multiple-databases-in-turbogears-2/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 2.170 seconds -->

