<?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, 05 Sep 2010 16:58:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<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[<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[<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[<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 0.730 seconds -->
