<?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>Ben Jao Ming &#187; Django</title>
	<atom:link href="http://overtag.dk/wordpress/category/computers/django/feed/" rel="self" type="application/rss+xml" />
	<link>http://overtag.dk/wordpress</link>
	<description>101% objective... always</description>
	<lastBuildDate>Wed, 02 May 2012 13:16:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Overriding change_form.html and accessing the object instance</title>
		<link>http://overtag.dk/wordpress/2012/04/overriding-change_form-html-and-accessing-the-object-instance/</link>
		<comments>http://overtag.dk/wordpress/2012/04/overriding-change_form-html-and-accessing-the-object-instance/#comments</comments>
		<pubDate>Tue, 03 Apr 2012 09:55:39 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=304</guid>
		<description><![CDATA[Here&#8217;s an example for a custom change_form.html located in app/templates/admin/appname/modelname/change_form.html &#8211; and the cool thing is that it accesses the actual instance of the object, which I found to be very convenient and undocumented. If you want it to be &#8230; <a href="http://overtag.dk/wordpress/2012/04/overriding-change_form-html-and-accessing-the-object-instance/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an example for a custom change_form.html located in app/templates/admin/appname/modelname/change_form.html &#8211; and the cool thing is that it accesses the actual instance of the object, which I found to be very convenient and undocumented. If you want it to be more explicit than access through the builtin context variable adminform.form.instance, you can also make your own <a href="https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#django.contrib.admin.ModelAdmin.change_view" target="_blank">change_view</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">{% extends &quot;admin/change_form.html&quot; %}
&nbsp;
{% block object-tools %}
  {{ block.super }}
  &lt;h2&gt;{{ adminform.form.instance }}&lt;/h2&gt;
{% endblock %}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2012/04/overriding-change_form-html-and-accessing-the-object-instance/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>django-cms 2.0.2 and Django 1.2 &#8211; 1.3</title>
		<link>http://overtag.dk/wordpress/2012/02/django-cms-2-0-2-and-django-1-2-1-3/</link>
		<comments>http://overtag.dk/wordpress/2012/02/django-cms-2-0-2-and-django-1-2-1-3/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 14:56:33 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[django-cms]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=280</guid>
		<description><![CDATA[If you are running an old version of django-cms, you can still upgrade Django. I would strongly suggest doing this since it&#8217;s very uncomplicated. However, if you are running django-cms 2.0, you should first upgrade to 2.0.2 and run the &#8230; <a href="http://overtag.dk/wordpress/2012/02/django-cms-2-0-2-and-django-1-2-1-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you are running an old version of django-cms, you can still upgrade Django. I would strongly suggest doing this since it&#8217;s very uncomplicated. However, if you are running django-cms 2.0, you should first upgrade to 2.0.2 and run the South migrations, which is also totally uncomplicated.</p>
<p>django-cms 1.x are most likely stuck on older versions of Django as well. I did once try to get them running on new Django versions but gave up.</p>
<p>Basically this guide just fixes a little bug in admin/pageadmin.py and a few issues regarding a missing csrf_token in the templates. It also means that django-cms 2.0.2 becomes SSL compatible. This is not backwards-compatible, however, so if you apply this stuff, your django-cms will no longer work with Django 1.1.</p>
<p>After upgrading to django 1.3.1 (also tested on 1.2.X btw), you need to make the following corrections manually in your django-cms installation.</p>
<p>1) Edit cms/admin/pageadmin.py, line 59 to say:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">    exclude = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></pre></div></div>

<p>2) Edit cms/templates/admin/cms/page/plugin_change_form.html, line 77, by adding the csrf_token tag:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form id=&quot;{{ opts.module_name }}_form&quot; action=&quot;{{ form_url }}&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;{% block form_top %}{% endblock %}
{% csrf_token %}</pre></div></div>

<p>2.1) Do the same in cms/templates/admin/cms/page/change_form.html, line 99:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form id=&quot;page_form&quot; action=&quot;?language={{ language }}{%if request.GET.target %}&amp;amp;target={{ request.GET.target }}{% endif %}&amp;amp;{%if request.GET.target %}position={{ request.GET.position }}{% endif %}&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;{% block form_top %}{% endblock %}
{% csrf_token %}</pre></div></div>

<p>2.2) Do the same in cms/templates/admin/cms/page/dialog/base.html, line 5:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">                {% block form %}{% if form %}&lt;form id=&quot;{{ dialog_id }}-form&quot;&gt;{% csrf_token %}{{ form.as_p }}{% endif %}{% endblock %}</pre></div></div>

<p>3) Ensure that you have CsrfViewMiddleware and CsrfResponseMiddleware installed. Your settings.py should contain something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">MIDDLEWARE_CLASSES = <span style="color: black;">&#40;</span>
    <span style="color: #483d8b;">'django.middleware.common.CommonMiddleware'</span>,
    <span style="color: #483d8b;">'django.contrib.sessions.middleware.SessionMiddleware'</span>,
    <span style="color: #483d8b;">'django.middleware.csrf.CsrfViewMiddleware'</span>,
    <span style="color: #483d8b;">'django.middleware.csrf.CsrfResponseMiddleware'</span>,
    <span style="color: #483d8b;">'django.contrib.auth.middleware.AuthenticationMiddleware'</span>,
    <span style="color: #483d8b;">'django.contrib.messages.middleware.MessageMiddleware'</span>,
    <span style="color: #483d8b;">'cms.middleware.page.CurrentPageMiddleware'</span>,
    <span style="color: #483d8b;">'cms.middleware.user.CurrentUserMiddleware'</span>,
<span style="color: black;">&#41;</span></pre></div></div>

<p>5) Finally, you need to bring in a file from later django-cms, csrf.js (<a href="https://github.com/divio/django-cms/blob/1dff25788a30b9e6e5c8cada405db60ae74764b7/cms/media/cms/js/csrf.js">github revision that I used</a>). Place it in media/cms/js/.</p>
<p>6) Add csrf.js to cms/admin/widgets.py in PluginEditor.media, around line 17:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">    <span style="color: #ff7700;font-weight:bold;">class</span> Media:
        js = <span style="color: black;">&#91;</span>join<span style="color: black;">&#40;</span>settings.<span style="color: black;">CMS_MEDIA_URL</span>, path<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> path <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: black;">&#40;</span>
            <span style="color: #483d8b;">'js/lib/jquery.js'</span>,
            <span style="color: #483d8b;">'js/lib/ui.core.js'</span>,
            <span style="color: #483d8b;">'js/lib/ui.sortable.js'</span>,
            <span style="color: #483d8b;">'js/csrf.js'</span>,
            <span style="color: #483d8b;">'js/plugin_editor.js'</span>,
        <span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></pre></div></div>

<p>7) Add this around line 97 in cms/media/cms/js/change_list.js:</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">	$(document).ready(function() {
		$.fn.cmsPatchCSRF();
	    selected_page = false;
	    action = false;</pre></div></div>

<p><span>8</span>) Do the same in cms/media/cms/js/plugin_editor.js at the first line:</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">$(document).ready(function() {
  	$.fn.cmsPatchCSRF();</pre></div></div>

<p>9) In /cms/templates/admin/cms/page/change_list.html you should also include csrf.js, around line 33:</p>
<pre class="js">&lt;script type="text/javascript" src="{{ CMS_MEDIA_URL }}js/csrf.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="{{ CMS_MEDIA_URL }}js/change_list.js"&gt;&lt;/script&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2012/02/django-cms-2-0-2-and-django-1-2-1-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stopforumspam Django Middleware</title>
		<link>http://overtag.dk/wordpress/2011/09/stopforumspam-django-middleware/</link>
		<comments>http://overtag.dk/wordpress/2011/09/stopforumspam-django-middleware/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 03:07:32 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=269</guid>
		<description><![CDATA[I have created a new Django app for keeping out spammers on the basis of data collected by stopforumspam.com. Read all about it here » It&#8217;s free, open source, and I hope people will make it better on github.]]></description>
			<content:encoded><![CDATA[<p><a href="http://overtag.dk/wordpress/wp-content/uploads/Screenshot.png"><img class="alignright size-thumbnail wp-image-272" title="Screenshot" src="http://overtag.dk/wordpress/wp-content/uploads/Screenshot-150x150.png" alt="" width="150" height="150" /></a>I have created a new Django app for keeping out spammers on the basis of data collected by stopforumspam.com. <a title="Stopforumspam Django Middleware" href="http://overtag.dk/wordpress/projects/stopforumspam-django-middleware/">Read all about it here »</a></p>
<p>It&#8217;s free, open source, and I hope people will make it better on github.</p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2011/09/stopforumspam-django-middleware/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing the Django Admin site title</title>
		<link>http://overtag.dk/wordpress/2010/04/changing-the-django-admin-site-title/</link>
		<comments>http://overtag.dk/wordpress/2010/04/changing-the-django-admin-site-title/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 23:45:52 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[django-admin]]></category>
		<category><![CDATA[translation]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=191</guid>
		<description><![CDATA[Often the Django Admin should look a little different for the sake of your users or for the sake of yourself (running multiple django sites with identical looks and titles can be such a pain). Often users don&#8217;t know what &#8230; <a href="http://overtag.dk/wordpress/2010/04/changing-the-django-admin-site-title/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Often the Django Admin should look a little different for the sake of your users or for the sake of yourself (running multiple django sites with identical looks and titles can be such a pain). Often users don&#8217;t know what Django is, and it takes ages to explain, and even after that they have no clue. Also, often my administration has nothing to do with a website, so I don&#8217;t want the text &#8220;Site administration&#8221;.</p>
<p>First of all, you wanna add <strong>templates/admin/base_site.html</strong> to your project. This file can safely be overwritten, since it&#8217;s a file that the django devs have intended for the exact purpose of customizing your admin site a bit. Here&#8217;s an example of what to put in the file:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">{% extends &quot;admin/base.html&quot; %}
{% load i18n %}
&nbsp;
{% block title %}{{ title }} | {% trans 'Some Organisation' %}{% endblock %}
&nbsp;
{% block branding %}
&lt;style type=&quot;text/css&quot;&gt;
  #header
  {
    /* your style here */
  }
&lt;/style&gt;
&lt;h1 id=&quot;site-name&quot;&gt;{% trans 'Organisation Website' %}&lt;/h1&gt;
{% endblock %}
&nbsp;
{% block nav-global %}{% endblock %}</pre></div></div>

<p>This is common practice. But I noticed after this that I was still left with an annoying &#8220;Site Administration&#8221; on the main admin index page. And this string was not inside any of the template, but rather set inside the admin view. Luckily it&#8217;s quite easy to change. Assuming your language is set to English, run the following commands from your project directory:</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
$ .<span style="color: #000000; font-weight: bold;">/</span>manage.py makemessages <span style="color: #660033;">-l</span> en</pre></div></div>

<p>Now open up the file <strong>locale/en/LC_MESSAGES/django.po</strong> and add two lines after the header information (the last two lines of this example)</p>

<div class="wp_syntax"><div class="code"><pre class="gettext" style="font-family:monospace;"><span style="color: #ff0000;">&quot;Project-Id-Version: PACKAGE VERSION<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Report-Msgid-Bugs-To: <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;POT-Creation-Date: 2010-04-03 03:25+0200<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Last-Translator: FULL NAME &lt;EMAIL@ADDRESS&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Language-Team: LANGUAGE &lt;LL@li.org&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;MIME-Version: 1.0<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Content-Type: text/plain; charset=UTF-8<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Content-Transfer-Encoding: 8bit<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">msgid</span> <span style="color: #ff0000;">&quot;Site administration&quot;</span>
<span style="color: #000000; font-weight: bold;">msgstr</span> <span style="color: #ff0000;">&quot;Main administration index&quot;</span></pre></div></div>

<p>After this, remember to run this and reload your project&#8217;s server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>manage.py compilemessages</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2010/04/changing-the-django-admin-site-title/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Django tip: Automatic logins</title>
		<link>http://overtag.dk/wordpress/2010/02/django-tip-automatic-logins/</link>
		<comments>http://overtag.dk/wordpress/2010/02/django-tip-automatic-logins/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 13:21:56 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[authenticate]]></category>
		<category><![CDATA[login]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=182</guid>
		<description><![CDATA[In the Django documentation we see the following: When you&#8217;re manually logging a user in, you must call authenticate() before you call login(). That&#8217;s all really nice, because it makes sure that all your authentication backends are tried out; but &#8230; <a href="http://overtag.dk/wordpress/2010/02/django-tip-automatic-logins/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the Django documentation we see the following:</p>
<blockquote><p>When you&#8217;re manually logging a user in, you must call <strong>authenticate()</strong> before you call<strong> login()</strong>.</p></blockquote>
<p>That&#8217;s all really nice, because it makes sure that all your authentication backends are tried out; but if you want a really quick remedy for getting the job done, then you&#8217;ll need to set the <em>user.backend</em> property to the specific backend that authenticated the user. Beware that the Django developers can change these requirements. I wanted this to avoid writing my own backend, so I did this to log users in via a special view accepting a hash from the URL (from an e-mail that had a link that&#8217;d automatically log a user in). This could also become useful if you want to <em>become</em> a different user.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> get_hash<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">import</span> hashlib
    m = hashlib.<span style="color: #dc143c;">md5</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    m.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span> + settings.<span style="color: black;">LOGIN_SECRET</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>m.<span style="color: black;">hexdigest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> auto_login<span style="color: black;">&#40;</span>request, user_id, secret<span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #dc143c;">user</span> = get_object_or_404<span style="color: black;">&#40;</span>User, <span style="color: #008000;">id</span>=user_id<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> secret == get_hash<span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>user_id<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">raise</span> Http404<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #dc143c;">user</span>.<span style="color: black;">backend</span> = <span style="color: #483d8b;">&quot;django.contrib.auth.backends.ModelBackend&quot;</span>
    login<span style="color: black;">&#40;</span>request, <span style="color: #dc143c;">user</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> HttpResponseRedirect<span style="color: black;">&#40;</span>reverse<span style="color: black;">&#40;</span><span style="color: #483d8b;">'frontpage'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p><strong>BEWARE!</strong><br />
I strongly suggest that you don&#8217;t log any superusers in this way. You could add a conditional statement <em>not user.is_superuser</em> or similar.</p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2010/02/django-tip-automatic-logins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django localized date template filter</title>
		<link>http://overtag.dk/wordpress/2009/07/django-localized-date-template-filter/</link>
		<comments>http://overtag.dk/wordpress/2009/07/django-localized-date-template-filter/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 22:24:13 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[template filter]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=155</guid>
		<description><![CDATA[UPDATE! This is going to be redundant in Django 1.2, in which you can add DATE_FORMAT to your django.po files. I&#8217;ve often been frustrated that using settings.DATE_FORMAT does not give a localized date. Granted that the name of a month &#8230; <a href="http://overtag.dk/wordpress/2009/07/django-localized-date-template-filter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE!</strong> This is going to be redundant in Django 1.2, in which you can add DATE_FORMAT to your django.po files.</p>
<p>I&#8217;ve often been frustrated that using <strong>settings.DATE_FORMAT</strong> does not give a localized date. Granted that the name of a month may be localized, but the format string does not change. So let&#8217;s start out by modifying <strong>settings.py</strong>. We wrap our default date format in a <b>ugettext</b> so the makemessages command will detect it, and we need to make it a dummy function, because the i18n library cannot be imported in settings.py due to circularity (it depends on settings.py).</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">ugettext = <span style="color: #ff7700;font-weight:bold;">lambda</span> s: s
DATE_FORMAT = ugettext<span style="color: black;">&#40;</span><span style="color: #483d8b;">'N j, Y'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Run compilemessages and type in your localized date formats. Now we need a template filter that uses a localized format for calling the Django date format function. This is really simple:</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;">template</span>.<span style="color: black;">defaultfilters</span> <span style="color: #ff7700;font-weight:bold;">import</span> stringfilter
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">utils</span> <span style="color: #ff7700;font-weight:bold;">import</span> dateformat
<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
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">conf</span> <span style="color: #ff7700;font-weight:bold;">import</span> settings
&nbsp;
@register.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> localdate<span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;Format date with localized date format&quot;&quot;&quot;</span>
    format = ugettext<span style="color: black;">&#40;</span>settings.<span style="color: black;">DATE_FORMAT</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> dateformat.<span style="color: black;">format</span><span style="color: black;">&#40;</span>value, format<span style="color: black;">&#41;</span></pre></div></div>

<p>And done. Using the filter is straight forward:</p>
<p><code><br />
Date: {{ my_date|localdate }}<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2009/07/django-localized-date-template-filter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Presenting: django-simple-wiki</title>
		<link>http://overtag.dk/wordpress/2009/04/presenting-django-simple-wiki/</link>
		<comments>http://overtag.dk/wordpress/2009/04/presenting-django-simple-wiki/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 23:52:57 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[django application]]></category>
		<category><![CDATA[django-simple-wiki]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[wiki]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=142</guid>
		<description><![CDATA[It was bothering me that all the wikis I tried, all had either errors, feature lacks, too many dependencies or were simply unmaintained. So I decided to create yet another one. Curiously, the third hit when googling &#8216;django wiki&#8217; is &#8230; <a href="http://overtag.dk/wordpress/2009/04/presenting-django-simple-wiki/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It was bothering me that all the wikis I tried, all had either errors, feature lacks, too many dependencies or were simply unmaintained. So I decided to create yet another one. Curiously, the third hit when googling &#8216;django wiki&#8217; is <a href="http://showmedo.com/videotutorials/video?name=1100000">Create a wiki in 20 minutes</a>. Luckily that&#8217;s not really true, so all the PHP guys and MediaWiki can continue breathing. This took me several days.</p>
<blockquote style="font-size: 150%;"><p><strong><a href="http://code.google.com/p/django-simple-wiki/">Google Code project page</a></strong></p></blockquote>
<blockquote style="font-size: 150%;"><p><strong><a href="http://wikidemo.overtag.dk/">Demo website</a></strong></p></blockquote>
<p><strong>Hierarchy and relations</strong><br />
First of all, as in the Trac wiki system, I chose to create a system for hierarchy, meaning that it&#8217;s possible to create an article and then create sub-articles. The hierarchy does not support multiple inheritance, because it needs to be basis for the permission system. That&#8217;s where the relation system comes in place: All articles can contain symmetrical relations to any other articles in the hierarchy.</p>
<p><strong>Parsing</strong><br />
Python and Django supports Markdown pretty much out of the box, so it&#8217;s an obvious choice to use this for parsing. The HTML features of normal Markdown have been removed, so all HTML is escaped in django-simple-wiki. And parsing is static, so every time a revision is created, the contents are passed and stored. This means that the contents of the article itself are not supposed to be dynamic. On the other hand, it is desirable to avoid parsing contents for every page hit. The parsing area of the application is only a few lines of code, and can be expanded if further parsing needs to be done, or someone wants to replace Markdown completely. For instance, if no parsing is done and HTML escaping is disabled, the wiki becomes a very simple CMS.</p>
<p><strong>Curious issues</strong><br />
There are a few out standing problems:</p>
<ul>
<li>Permission system is related to User entries in the Django auth system. But maybe this is too much of an annoyance, if the project already has groups setup in the existing auth system. On the other hand, other users would be bothered to setup both wiki groups and user groups, if the permission system was linked to user groups. And directly linking articles to user groups would require wiki-related groups to be created directly in the auth system.</li>
<li>Since relations are symmetrical, what should happen if one article is locked, but a user modifies it&#8217;s relations by deleting them from related articles?</li>
<li>Title editing: The title can only be created once, since it is coupled to the &#8216;slug&#8217; of the article. A user can deliberately create a completely different title, which is fine, but should subsequent editing be allowed, which would add complexity to the revision system?</li>
<li>Article deletion: When an article is deleted from the backend it shouldn&#8217;t worry anyone. But if the feature is added to the frontend, we would want to handle maliciousness etc. But should we really store all these files and revisions? Should we alert admins, so they can do the final cleanup?</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2009/04/presenting-django-simple-wiki/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Django tip: Translating your application names (app_label)</title>
		<link>http://overtag.dk/wordpress/2008/07/django-tip-translating-your-application-names-app_label/</link>
		<comments>http://overtag.dk/wordpress/2008/07/django-tip-translating-your-application-names-app_label/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 21:03:57 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[gettext]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[makemessages]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=61</guid>
		<description><![CDATA[This MUST be a common issue for international developers: We use some geeky English name for our application and afterwards find that the translated admin index looks a little silly in the eyes of our native speaking users. Apparently a &#8230; <a href="http://overtag.dk/wordpress/2008/07/django-tip-translating-your-application-names-app_label/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This MUST be a common issue for international developers: We use some geeky English name for our application and afterwards find that the translated admin index looks a little silly in the eyes of our native speaking users. Apparently <a href="http://code.djangoproject.com/ticket/1668">a patch</a> has been accepted in the Django dev version, but it&#8217;s not yet in the trunk. Here&#8217;s what to do: In your applications&#8217; <em>__init__.py</em> files put:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td 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> gettext_noop
gettext_noop<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;AppName&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>When your run <strong>manage.py makemessages -a</strong> there will be entries for these. Make sure to remove lines saying <em>#, fuzzy</em>. Now all you have to do is to customize the default admin template called <em>index.html</em> so it will actually do the translation of the application names.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>18
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">        &lt;caption&gt;{% trans app.name %}&lt;/caption&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2008/07/django-tip-translating-your-application-names-app_label/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Django auto-translation of field values</title>
		<link>http://overtag.dk/wordpress/2008/07/django-auto-translation-of-field-values/</link>
		<comments>http://overtag.dk/wordpress/2008/07/django-auto-translation-of-field-values/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 22:04:26 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[gettext]]></category>
		<category><![CDATA[models]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=59</guid>
		<description><![CDATA[What&#8217;s really nice in Django is the gettext implementation and the _ convention. But when running django-admin.py makemessages we&#8217;re not generating any translations for dynamic values such as field values. So let&#8217;s say that we have a model and we&#8217;d &#8230; <a href="http://overtag.dk/wordpress/2008/07/django-auto-translation-of-field-values/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>What&#8217;s really nice in Django is the gettext implementation and the _ convention. But when running <em>django-admin.py makemessages</em> we&#8217;re not generating any translations for dynamic values such as field values. So let&#8217;s say that we have a model and we&#8217;d like what&#8217;s in it to be displayed in a translated manner. In the new Django development version we&#8217;re able to create our own special field types. And we can extend the CharField to provide automatic translation:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">db</span> <span style="color: #ff7700;font-weight:bold;">import</span> models
<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> gettext_lazy <span style="color: #ff7700;font-weight:bold;">as</span> _
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> AutoTranslateField<span style="color: black;">&#40;</span>models.<span style="color: black;">CharField</span><span style="color: black;">&#41;</span>:
    <span style="color: #0000cd;">__metaclass__</span> = models.<span style="color: black;">SubfieldBase</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> to_python<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, value<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>_<span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>After that we just add whatever translations we know of to our <em>locale/CODE/LC_MESSAGES/django.po</em> file and run <em>compilemessages</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2008/07/django-auto-translation-of-field-values/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tip: Extending Django flatpages</title>
		<link>http://overtag.dk/wordpress/2008/07/tip-extending-django-flatpages/</link>
		<comments>http://overtag.dk/wordpress/2008/07/tip-extending-django-flatpages/#comments</comments>
		<pubDate>Sat, 12 Jul 2008 22:59:28 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=53</guid>
		<description><![CDATA[I did a Google search and since nothing came up, I&#8217;m writing this little tip on creating your own CMS by extending Django&#8217;s flatpages. What&#8217;s good about flatpages is that they&#8217;re included in Django and has some basic code to &#8230; <a href="http://overtag.dk/wordpress/2008/07/tip-extending-django-flatpages/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I did a Google search and since nothing came up, I&#8217;m writing this little tip on creating your own CMS by extending Django&#8217;s flatpages. What&#8217;s good about flatpages is that they&#8217;re included in Django and has some basic code to get you started. But clearly they&#8217;re not enough if you want other people to administer a site.. you&#8217;ll want to add extra fields and special help texts for the admin. But we still don&#8217;t want to rewrite those ~150 lines of code, and they can really help you get past all the boring stuff and into the action.</p>
<p>Simply do the following:</p>
<blockquote><p>
cp -R /usr/share/python-support/python-django/django/contrib/flatpages my_project/my_flatpages
</p></blockquote>
<p><i>views.py</i></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> my_project.<span style="color: black;">my_flatpages</span>.<span style="color: black;">models</span> <span style="color: #ff7700;font-weight:bold;">import</span> FlatPage</pre></td></tr></table></div>

<p><i>middleware.py</i></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> my_project.<span style="color: black;">my_flatpages</span>.<span style="color: black;">views</span> <span style="color: #ff7700;font-weight:bold;">import</span> flatpage</pre></td></tr></table></div>

<p><i>urls.py</i></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>3
4
5
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">urlpatterns = patterns<span style="color: black;">&#40;</span><span style="color: #483d8b;">'my_project.my_flatpages.views'</span>,
    <span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^(?P&lt;url&gt;.*)$'</span>, <span style="color: #483d8b;">'flatpage'</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p><em>my_project.my_flatpages.middleware.FlatpageFallbackMiddleware</em> has to be added to your <strong>MIDDLEWARE_CLASSES</strong> and <em>my_project.my_flatpages</em> to your <strong>INSTALLED_APPS</strong> and you&#8217;ll need to run <em>manage.py syncdb</em>, possibly changing the table name in <em>models.py</em>, so it doesn&#8217;t conflict with the old flatpages table. That&#8217;s basically it. After that you can work on the templates as described in the other howto&#8217;s, but now you have your own model to extend.</p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2008/07/tip-extending-django-flatpages/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

