<?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>/kb &#187; django</title>
	<atom:link href="http://grx.no/kb/tag/django/feed/" rel="self" type="application/rss+xml" />
	<link>http://grx.no/kb</link>
	<description>personal knowledgebase</description>
	<lastBuildDate>Wed, 15 Jun 2011 07:07:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Translation of Django Core</title>
		<link>http://grx.no/kb/2010/08/07/translation-of-django-core/</link>
		<comments>http://grx.no/kb/2010/08/07/translation-of-django-core/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 19:31:27 +0000</pubDate>
		<dc:creator>hgrimelid</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[translation]]></category>

		<guid isPermaLink="false">http://grx.no/kb/?p=202</guid>
		<description><![CDATA[cd django_trunk svn update # Generate .po files: bin/django-admin.py makemessages -l nn bin/django-admin.py makemessages -d djangojs -l nn cd conf/locale/nn/LC_MESSAGES Edit .po files. Search for text string fuzzy and empty double quotes (&#8220;&#8221;) to find untranslated strings. Finally, create diffs: svn diff django.po &#62; nn-django-translation-update.diff svn diff djangojs.po &#62; nn-djangojs-translation-update.diff]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> django_trunk
<span style="color: #c20cb9; font-weight: bold;">svn</span> update
<span style="color: #666666; font-style: italic;"># Generate .po files:</span>
bin<span style="color: #000000; font-weight: bold;">/</span>django-admin.py makemessages <span style="color: #660033;">-l</span> nn 
bin<span style="color: #000000; font-weight: bold;">/</span>django-admin.py makemessages <span style="color: #660033;">-d</span> djangojs <span style="color: #660033;">-l</span> nn
<span style="color: #7a0874; font-weight: bold;">cd</span> conf<span style="color: #000000; font-weight: bold;">/</span>locale<span style="color: #000000; font-weight: bold;">/</span>nn<span style="color: #000000; font-weight: bold;">/</span>LC_MESSAGES</pre></div></div>

<p>Edit .po files. Search for text string fuzzy and empty double quotes (&#8220;&#8221;) to find untranslated strings.</p>
<p>Finally, create diffs:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">diff</span> django.po <span style="color: #000000; font-weight: bold;">&gt;</span> nn-django-translation-update.diff
<span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">diff</span> djangojs.po <span style="color: #000000; font-weight: bold;">&gt;</span> nn-djangojs-translation-update.diff</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://grx.no/kb/2010/08/07/translation-of-django-core/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Translation of Django Apps</title>
		<link>http://grx.no/kb/2010/03/04/translation-of-django-apps/</link>
		<comments>http://grx.no/kb/2010/03/04/translation-of-django-apps/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 13:50:43 +0000</pubDate>
		<dc:creator>hgrimelid</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[translation]]></category>

		<guid isPermaLink="false">http://grx.no/kb/?p=178</guid>
		<description><![CDATA[I recently created a Django app that needed translation of the Django administration. It took some googling and messing around to make it work, so this quick and dirty walkthrough will hopefully be helpful for others. Here&#8217;s how I did it: Add translations for all model fields: class Stuff&#40;models.Model&#41;: title = models.CharField&#40;_&#40;'title'&#41;, max_length=255&#41; the_other_model = [...]]]></description>
			<content:encoded><![CDATA[<p>I recently created a Django app that needed translation of the Django administration. It took some googling and messing around to make it work, so this quick and dirty walkthrough will hopefully be helpful for others. </p>
<p>Here&#8217;s how I did it:</p>
<p>Add translations for all model fields:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> Stuff<span style="color: black;">&#40;</span>models.<span style="color: black;">Model</span><span style="color: black;">&#41;</span>:
    title = models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>_<span style="color: black;">&#40;</span><span style="color: #483d8b;">'title'</span><span style="color: black;">&#41;</span>, max_length=<span style="color: #ff4500;">255</span><span style="color: black;">&#41;</span>
    the_other_model = model.<span style="color: black;">ForeignKey</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'othermodel'</span>, verbose_name=_<span style="color: black;">&#40;</span><span style="color: #483d8b;">'the other model'</span><span style="color: black;">&#41;</span>, verbose_name_plural=_<span style="color: black;">&#40;</span><span style="color: #483d8b;">'the other models'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">class</span> Meta:
      verbose_name = _<span style="color: black;">&#40;</span><span style="color: #483d8b;">'stuff'</span><span style="color: black;">&#41;</span>
      verbose_name_plural = _<span style="color: black;">&#40;</span><span style="color: #483d8b;">'stuffs'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Then the language (.po) files must be created:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> locale
python manage.py makemessages <span style="color: #660033;">-l</span> LANG_CODE</pre></div></div>

<p>Then edit your language files in <code>locale/<strong>_LANGUAGE_</strong>/LC_MESSAGES/django.po</code>.  When you&#8217;ve finished editing the language file must be compiled:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">python manage.py compilemessages</pre></div></div>

<p>If you want to translate app names as well, you can add something like this to your project <code>__init__.py</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">utils</span>.<span style="color: black;">translation</span> <span style="color: #ff7700;font-weight:bold;">import</span> ugettext_lazy <span style="color: #ff7700;font-weight:bold;">as</span> _
&nbsp;
_<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">'auth'</span><span style="color: black;">&#41;</span>
_<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">'configuration'</span><span style="color: black;">&#41;</span>
_<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">'sites'</span><span style="color: black;">&#41;</span>
_<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">'appname'</span><span style="color: black;">&#41;</span>
_<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">'Auth'</span><span style="color: black;">&#41;</span>
_<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">'Configuration'</span><span style="color: black;">&#41;</span>
_<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">'Sites'</span><span style="color: black;">&#41;</span>
_<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">'Appname'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>This feels like a dirty hack but I couldn&#8217;t find any other way to do it.</p>
<p>Source: <a href="http://docs.djangoproject.com/en/dev/topics/i18n/">Django documentation &#8211; Internationalization and localization</a>, and some Google Groups thread that I can&#8217;t find right now, for the app name translation.</p>
]]></content:encoded>
			<wfw:commentRss>http://grx.no/kb/2010/03/04/translation-of-django-apps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Chapter 7 in &#8220;Python Web Development with Django&#8221; &#8211; some notes</title>
		<link>http://grx.no/kb/2009/03/08/chapter-7-in-python-web-development-with-django-some-notes/</link>
		<comments>http://grx.no/kb/2009/03/08/chapter-7-in-python-web-development-with-django-some-notes/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 18:08:07 +0000</pubDate>
		<dc:creator>Morten Wergeland Hansen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://grx.no/kb/?p=103</guid>
		<description><![CDATA[I am currently in the process of learning Django and have just finished chapter 7 in Python Web Development with Django. Here are some notes on how I got it working (except for the index page which still isn&#8217;t completely as expected) on an ubuntu hardy installation. The photo gallery example assumes an apache2 + [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently in the process of learning Django and have just finished chapter 7 in <a href="http://withdjango.com">Python Web Development with Django</a>. Here are some notes on how I got it working (except for the index page which still isn&#8217;t completely as expected) on an ubuntu hardy installation.</p>
<p>The photo gallery example assumes an <em>apache2</em> + <em>mod_python</em> setup. I didn&#8217;t really find it straightforward to get this running from the description in the appendix, so here is how I got it to work (after installation of <em>apache2</em> and <em>mod_python</em>, of course):</p>
<p>In <em>/etc/apache2/sites-available/default</em>, change lines:</p>
<pre>        &lt;Directory /var/www/&gt;
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        &lt;/Directory&gt;</pre>
<p>To:</p>
<pre>        &lt;Directory /var/www/&gt;
                Options Indexes FollowSymLinks MultiViews
                AllowOverride AuthConfig
                Order allow,deny
                allow from all

                AddHandler mod_python .py
                PythonHandler mod_python.publisher
                PythonDebug On
        &lt;/Directory&gt;</pre>
<p>Then I did the changes in <em>/etc/apache2/httpd.conf</em>, but slightly different from the book by adding a <code>PythonOption django.root</code> (didn&#8217;t work for me with the setup in the book):</p>
<pre>&lt;Location "/gallery/"&gt;
      SetHandler python-program
      PythonHandler django.core.handlers.modpython
      SetEnv DJANGO_SETTINGS_MODULE gallery.settings
      PythonOption django.root /gallery
      PythonDebug On
      PythonPath "['/path/to/django/root', '/home/user/django-stuff'] + sys.path"
&lt;/Location&gt;</pre>
<p>With an additional entry for media files:</p>
<pre>&lt;Location "/gallery/media"&gt;
      SetHandler none
&lt;/Location&gt;</pre>
<p>Now, I created a directory <em>/var/www/gallery</em> and a <em>/var/www/gallery/media</em> like explained in &#8220;Preparing for File Uploads&#8221; and edited <em>settings.py</em>:</p>
<p><code>MEDIA_ROOT = '/var/www/gallery/media/'</code><br />
<code>MEDIA_URL = 'http://localhost/gallery/media/'</code><br />
<code>ADMIN_MEDIA_PREFIX = 'http://localhost/gallery/media/admin/'</code></p>
<p>Where admin is a symbolic link (<em>/var/www/gallery/media/admin</em>) to the admin media directory in the Django installation. The two last entries where not mentioned in the book, but they made it work&#8230;</p>
<p>With the settings described above and the <code>PythonOption django.root</code> in <em>httpd.conf</em>, I didn&#8217;t need the section about DRY URLs. And it worked &#8211; as opposed to the stuff in the book.</p>
<p>With all the configuration stuff in place I typed the code outlined in the chapter and to begin with I couldn&#8217;t see any photos, except for the <code>thumb_url</code> in <em>items_list.html</em> (typo: <em>items_listing.html</em> in the last paragraph page 175). I managed to get it working by changing some lines in <em>items_detail.html</em> and <em>photos_detail.html</em> though:</p>
<pre>22                 &lt;img src="{{ photo.image.thumb_url }}" /&gt;</pre>
<p>instead of</p>
<pre>22                 &lt;img src="{{ photo.get_image_thumb_url }}" /&gt;</pre>
<p>and</p>
<pre>8 &lt;img src="{{ object.image.url }}" /&gt;</pre>
<p>instead of:</p>
<pre>8 &lt;img src="{{ object.get_image_url }}" /&gt;</pre>
<p>The alternatives that worked seems more intuitive to me.</p>
<p>I also imported <code>list_detail</code> from <code>django.views.generic</code> in <em>urls.py</em>, but am not sure if this was needed. The photo gallery seems to work fine except for the thumbnails in <em>index.html</em>. I&#8217;ve noticed that the code in <em>urls.py</em> for that template is different from the others, using <code>simple.direct_to_template</code>, but I haven&#8217;t managed getting that part to work.</p>
<p>Thanks to this thread for getting mod_python up and running: <a href="http://ubuntuforums.org/showthread.php?t=91101">Python and Apache2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://grx.no/kb/2009/03/08/chapter-7-in-python-web-development-with-django-some-notes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

