<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.1.3" -->
<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/"
	>

<channel>
	<title>yazzgoth.org</title>
	<link>http://yazzgoth.org</link>
	<description>my brains' I/O</description>
	<pubDate>Wed, 25 Jun 2008 09:15:28 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.3</generator>
	<language>en</language>
			<item>
		<title>Django row-level permissions</title>
		<link>http://yazzgoth.org/2008/06/17/django-row-level-permissions/</link>
		<comments>http://yazzgoth.org/2008/06/17/django-row-level-permissions/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 19:20:51 +0000</pubDate>
		<dc:creator>yazzgoth</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<category><![CDATA[News]]></category>

		<category><![CDATA[Django]]></category>

		<guid isPermaLink="false">http://yazzgoth.org/2008/06/17/django-row-level-permissions/</guid>
		<description><![CDATA[It is a common need to have per-row (instance) permissions in a web application.
I&#8217;ve created a very simple and non intrusive module to help with that.
You can find the source code of the django-granular-permissions on Google Code here:
 http://code.google.com/p/django-granular-permissions/
It&#8217;s fully functional, only thing missing are unittests and templatetag  that would use the request.user provided [...]]]></description>
			<content:encoded><![CDATA[<p>It is a common need to have per-row (instance) permissions in a web application.</p>
<p>I&#8217;ve created a very simple and non intrusive module to help with that.</p>
<p>You can find the source code of the django-granular-permissions on Google Code here:</p>
<p><a href="http://code.google.com/p/django-granular-permissions/"> http://code.google.com/p/django-granular-permissions/</a></p>
<p>It&#8217;s fully functional, only thing missing are unittests and templatetag  that would use the request.user provided by the session middleware context.</p>
<p>To use the package simply add it somewhere to your PYTHONPATH (ie. under your django project, or use</p>
<p><em>easy_install -U django-granular-permissions</em></p>
<p>to grab it from cheeseshop)  and add the &#8216;django_granular_permissions&#8217; to your INSTALLED_APPS in your projects settings.py</p>
<p>That&#8217;s it. From now on you can check, add and remove permissions for any instance of models class in your project like this:</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4889a6890e147">
<div class="synthi_header" style="font-weight:bold;"> Python <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4889a6890e147').style.display='block';document.getElementById('plain_synthi_4889a6890e147').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
# adding permission 'edit' to a user 'Bart' on an instance of a MyObject from myapp.models
 from django.contrib.auth.models import User, Group
 from myapp.models import MyObject
 user = User.objects.get(username='Bart')
 obj = MyObject()
 obj.save()
 user.add_row_perm(obj, 'edit')
 user.has_row_perm(obj, 'edit')
True
 user.has_row_perm(obj, 'delete')
False 

# similar for groups
 group = Group.objects.get(pk=1) # get first group in the db
 group.add_row_perm(obj, 'read')

# now we'll add the user to the group and he will inherit the 'read' permission
 user.groups.add(group)
 user.has_row_perm(obj, 'read')
True

# now to remove permission
 user.del_row_perm(obj, 'edit')
 user.has_row_perm(obj, 'edit')
False

# note that when you try to remove a permission from a user that is granted to him through group nothing changes
 user.del_row_perm(obj, 'read')
 user.has_row_perm(obj, 'read')
True</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4889a6890e147">
<div class="synthi_header" style="font-weight:bold;"> Python <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4889a6890e147').style.display='block';document.getElementById('styled_synthi_4889a6890e147').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="python" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># adding permission &#8216;edit&#8217; to a user &#8216;Bart&#8217; on an instance of a MyObject from myapp.models</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span>.<span style="color: black;">auth</span>.<span style="color: black;">models</span> <span style="color: #ff7700;font-weight:bold;">import</span> User, Group</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #ff7700;font-weight:bold;">from</span> myapp.<span style="color: black;">models</span> <span style="color: #ff7700;font-weight:bold;">import</span> MyObject</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #dc143c;">user</span> = User.<span style="color: black;">objects</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span>username=<span style="color: #483d8b;">&#8216;Bart&#8217;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;obj = MyObject<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;obj.<span style="color: black;">save</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #dc143c;">user</span>.<span style="color: black;">add_row_perm</span><span style="color: black;">&#40;</span>obj, <span style="color: #483d8b;">&#8216;edit&#8217;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #dc143c;">user</span>.<span style="color: black;">has_row_perm</span><span style="color: black;">&#40;</span>obj, <span style="color: #483d8b;">&#8216;edit&#8217;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008000;">True</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #dc143c;">user</span>.<span style="color: black;">has_row_perm</span><span style="color: black;">&#40;</span>obj, <span style="color: #483d8b;">&#8216;delete&#8217;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008000;">False</span> </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># similar for groups</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;group = Group.<span style="color: black;">objects</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span>pk=<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># get first group in the db</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;group.<span style="color: black;">add_row_perm</span><span style="color: black;">&#40;</span>obj, <span style="color: #483d8b;">&#8216;read&#8217;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># now we&#8217;ll add the user to the group and he will inherit the &#8216;read&#8217; permission</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #dc143c;">user</span>.<span style="color: black;">groups</span>.<span style="color: black;">add</span><span style="color: black;">&#40;</span>group<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #dc143c;">user</span>.<span style="color: black;">has_row_perm</span><span style="color: black;">&#40;</span>obj, <span style="color: #483d8b;">&#8216;read&#8217;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008000;">True</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># now to remove permission</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #dc143c;">user</span>.<span style="color: black;">del_row_perm</span><span style="color: black;">&#40;</span>obj, <span style="color: #483d8b;">&#8216;edit&#8217;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #dc143c;">user</span>.<span style="color: black;">has_row_perm</span><span style="color: black;">&#40;</span>obj, <span style="color: #483d8b;">&#8216;edit&#8217;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008000;">False</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># note that when you try to remove a permission from a user that is granted to him through group nothing changes</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #dc143c;">user</span>.<span style="color: black;">del_row_perm</span><span style="color: black;">&#40;</span>obj, <span style="color: #483d8b;">&#8216;read&#8217;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #dc143c;">user</span>.<span style="color: black;">has_row_perm</span><span style="color: black;">&#40;</span>obj, <span style="color: #483d8b;">&#8216;read&#8217;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008000;">True</span></div>
</li>
</ol>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://yazzgoth.org/2008/06/17/django-row-level-permissions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Timing a python function with a decorator and saving results to CSV file</title>
		<link>http://yazzgoth.org/2008/04/07/timing-a-python-function-with-a-decorator-and-saving-results-to-csv-file/</link>
		<comments>http://yazzgoth.org/2008/04/07/timing-a-python-function-with-a-decorator-and-saving-results-to-csv-file/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 18:56:59 +0000</pubDate>
		<dc:creator>yazzgoth</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://yazzgoth.org/2008/04/07/timing-a-python-function-with-a-decorator-and-saving-results-to-csv-file/</guid>
		<description><![CDATA[Here&#8217;s a sample I wrote and find very useful for quick performance tests of python functions.

 Python [Show Styled Code]:

import timing
from datetime import datetime
def timeit(fn):
    def wrapper(*args, *kw):
        timing.start()
        fn(*args, **kw)
        [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a sample I wrote and find very useful for quick performance tests of python functions.</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4889a6893eb42">
<div class="synthi_header" style="font-weight:bold;"> Python <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4889a6893eb42').style.display='block';document.getElementById('plain_synthi_4889a6893eb42').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
import timing
from datetime import datetime
def timeit(fn):
    def wrapper(*args, *kw):
        timing.start()
        fn(*args, **kw)
        timing.finish()
        f = open(&#034;timing.csv&#034;, &#034;a&#034;)
        f.write(&#034;%s,%s,%dn&#034;%(datetime.now(), fn.__name__, timing.micro()))
        f.flush()
        f.close()
    return wrapper
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4889a6893eb42">
<div class="synthi_header" style="font-weight:bold;"> Python <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4889a6893eb42').style.display='block';document.getElementById('styled_synthi_4889a6893eb42').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="python" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">import</span> timing</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">datetime</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #dc143c;">timeit</span><span style="color: black;">&#40;</span>fn<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> wrapper<span style="color: black;">&#40;</span>*args, *kw<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; timing.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; fn<span style="color: black;">&#40;</span>*args, **kw<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; timing.<span style="color: black;">finish</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;timing.csv&quot;</span>, <span style="color: #483d8b;">&quot;a&quot;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; f.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s,%s,%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>%<span style="color: black;">&#40;</span><span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>, fn.__name__, timing.<span style="color: black;">micro</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; f.<span style="color: black;">flush</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> wrapper</div>
</li>
</ol>
</div>
</div>
<p>You can then import it to OpenOffice Calculator or MS Excel and do some fancy charts or whatever <img src='http://yazzgoth.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
Note that this function is using disk I/O so by itself it is also causing some overhead (especially for functions called multiple times per second).<br />
Obviously it&#8217;s not thread safe.</p>
]]></content:encoded>
			<wfw:commentRss>http://yazzgoth.org/2008/04/07/timing-a-python-function-with-a-decorator-and-saving-results-to-csv-file/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Still here :)</title>
		<link>http://yazzgoth.org/2008/03/21/still-here/</link>
		<comments>http://yazzgoth.org/2008/03/21/still-here/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 19:18:06 +0000</pubDate>
		<dc:creator>yazzgoth</dc:creator>
		
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://yazzgoth.org/2008/03/21/still-here/</guid>
		<description><![CDATA[Woah it&#8217;s been a while since last post hehehehe.
Well stay tuned (anyone? :P) for some updates and more thoughts and tips soon.
]]></description>
			<content:encoded><![CDATA[<p>Woah it&#8217;s been a while since last post hehehehe.</p>
<p>Well stay tuned (anyone? :P) for some updates and more thoughts and tips soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://yazzgoth.org/2008/03/21/still-here/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Non-blocking use of Django models API</title>
		<link>http://yazzgoth.org/2008/01/08/non-blocking-use-of-django-models-api/</link>
		<comments>http://yazzgoth.org/2008/01/08/non-blocking-use-of-django-models-api/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 12:14:26 +0000</pubDate>
		<dc:creator>yazzgoth</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://yazzgoth.org/2008/01/08/non-blocking-use-of-django-models-api/</guid>
		<description><![CDATA[If you&#8217;ve ever used Twisted framework and got through the first a bit hard learning curve, you most likely fell in love with it.
And if you&#8217;ve every used Django you most likely thought - isn&#8217;t there a way for it to run faster and in non-blocking fashion - especially if you want to write a [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever used <a href="http://twistedmatrix.com/">Twisted</a> framework and got through the first a bit hard learning curve, you most likely fell in love with it.<br />
And if you&#8217;ve every used <a href="http://djangoproject.com/">Django</a> you most likely thought - isn&#8217;t there a way for it to run faster and in non-blocking fashion - especially if you want to write a web application that integrates other protocols.<br />
One major block on the road is the DB models API which I&#8217;ll focus on now.</p>
<p>So let&#8217;s say you&#8217;re considering to use Django&#8217;s models in Twisted application.<br />
As in my <a href="http://yazzgoth.org/2007/09/26/writing-an-external-script-that-can-access-your-django-models/">previous post</a> you&#8217;ll have to prepare the environment to access the models, then use Twisted&#8217;s threaded deferred to make it non-blocking.</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4889a68965c31">
<div class="synthi_header" style="font-weight:bold;"> Python <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4889a68965c31').style.display='block';document.getElementById('plain_synthi_4889a68965c31').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
from twisted.internet import reactor, threads
from django.core.management import setup_environ
import settings
import string
setup_environ(settings)
from foo import models

def getUser(user):
   print &#034;Hello %s %s&#034;%(user.first_name, user.last_name)

def handleError(e):
   print &#034;Error &#034;+str(e)

deferred = threads.deferToThread(models.User.objects.get, username='yazzgoth')
deferred.addCallback(getUser)
deferred.addErrback(handleError)
reactor.run()
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4889a68965c31">
<div class="synthi_header" style="font-weight:bold;"> Python <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4889a68965c31').style.display='block';document.getElementById('styled_synthi_4889a68965c31').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="python" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">internet</span> <span style="color: #ff7700;font-weight:bold;">import</span> reactor, threads</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">core</span>.<span style="color: black;">management</span> <span style="color: #ff7700;font-weight:bold;">import</span> setup_environ</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">import</span> settings </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">string</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">setup_environ<span style="color: black;">&#40;</span>settings<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">from</span> foo <span style="color: #ff7700;font-weight:bold;">import</span> models</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">def</span> getUser<span style="color: black;">&#40;</span><span style="color: #dc143c;">user</span><span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Hello %s %s&quot;</span>%<span style="color: black;">&#40;</span><span style="color: #dc143c;">user</span>.<span style="color: black;">first_name</span>, <span style="color: #dc143c;">user</span>.<span style="color: black;">last_name</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">def</span> handleError<span style="color: black;">&#40;</span>e<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Error &quot;</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>e<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">deferred = threads.<span style="color: black;">deferToThread</span><span style="color: black;">&#40;</span>models.<span style="color: black;">User</span>.<span style="color: black;">objects</span>.<span style="color: black;">get</span>, username=<span style="color: #483d8b;">&#8216;yazzgoth&#8217;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">deferred.<span style="color: black;">addCallback</span><span style="color: black;">&#40;</span>getUser<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">deferred.<span style="color: black;">addErrback</span><span style="color: black;">&#40;</span>handleError<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">reactor.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
</ol>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://yazzgoth.org/2008/01/08/non-blocking-use-of-django-models-api/feed/</wfw:commentRss>
		</item>
		<item>
		<title>SL-Messenger 2.0 is closing in&#8230; with Jabber integration</title>
		<link>http://yazzgoth.org/2008/01/08/sl-messenger-20-is-closing-in-with-jabber-integration/</link>
		<comments>http://yazzgoth.org/2008/01/08/sl-messenger-20-is-closing-in-with-jabber-integration/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 11:51:17 +0000</pubDate>
		<dc:creator>yazzgoth</dc:creator>
		
		<category><![CDATA[News]]></category>

		<category><![CDATA[Second Life]]></category>

		<guid isPermaLink="false">http://yazzgoth.org/2008/01/08/sl-messenger-20-is-closing-in-with-jabber-integration/</guid>
		<description><![CDATA[After some delays and then some more delays SL-messenger.com 2.0 is closing in fast to public release.
There are some big changes in the new version, completely overhauled database design for speed (don&#8217;t worry we&#8217;ll migrite all your data from 1.0 to 2.0), Twitter/Jaiku support, Jabber, GTalk, MSN, AIM, ICQ, Gadu-Gadu support - yes you&#8217;ll be [...]]]></description>
			<content:encoded><![CDATA[<p>After some delays and then some more delays <a href="http://sl-messenger.com/">SL-messenger.com</a> 2.0 is closing in fast to public release.</p>
<p>There are some big changes in the new version, completely overhauled database design for speed (don&#8217;t worry we&#8217;ll migrite all your data from 1.0 to 2.0), Twitter/Jaiku support, Jabber, GTalk, MSN, AIM, ICQ, Gadu-Gadu support - yes you&#8217;ll be able to chat with your IM friends from SL :-), bookmarks, region rankings, screenshots, new badges and badge creation wizzard, and of course new web design.</p>
<p>Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://yazzgoth.org/2008/01/08/sl-messenger-20-is-closing-in-with-jabber-integration/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Downgrading iPod Touch from 1.1.2 to 1.1.1 (on a Mac)</title>
		<link>http://yazzgoth.org/2007/11/27/downgrading-ipod-touch-from-112-to-111-on-a-mac/</link>
		<comments>http://yazzgoth.org/2007/11/27/downgrading-ipod-touch-from-112-to-111-on-a-mac/#comments</comments>
		<pubDate>Tue, 27 Nov 2007 22:46:52 +0000</pubDate>
		<dc:creator>yazzgoth</dc:creator>
		
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://yazzgoth.org/2007/11/27/downgrading-ipod-touch-from-112-to-111-on-a-mac/</guid>
		<description><![CDATA[So you have upgraded your iPod to 1.1.2 by accident (or am I only one that stupid:P) and you&#8217;d like to downgrade back to 1.1.1 so you can jailbreak it?
Nothing easier done&#8230;
Download the 1.1.1 firmware
Start iTunes and click on the iPod on the left menu.
Hold down ALT and click on Update button. This will open [...]]]></description>
			<content:encoded><![CDATA[<p>So you have upgraded your iPod to 1.1.2 by accident (or am I only one that stupid:P) and you&#8217;d like to downgrade back to 1.1.1 so you can jailbreak it?<br />
Nothing easier done&#8230;<br />
Download the <a href="http://www.megaupload.com/?d=V7H8X2QQ">1.1.1 firmware</a><br />
Start iTunes and click on the iPod on the left menu.<br />
Hold down ALT and click on Update button. This will open a file selection menu, choose the firmware file you&#8217;ve downloaded.<br />
After 1~2min you should be happy 1.1.1 iPod user <img src='http://yazzgoth.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> now only a quick visit on jailbreakme.com and you&#8217;re done.</p>
]]></content:encoded>
			<wfw:commentRss>http://yazzgoth.org/2007/11/27/downgrading-ipod-touch-from-112-to-111-on-a-mac/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Overriding name of file in ImageField(FileField) in Django</title>
		<link>http://yazzgoth.org/2007/11/08/overriding-name-of-file-in-imagefieldfilefield-in-django/</link>
		<comments>http://yazzgoth.org/2007/11/08/overriding-name-of-file-in-imagefieldfilefield-in-django/#comments</comments>
		<pubDate>Thu, 08 Nov 2007 13:03:48 +0000</pubDate>
		<dc:creator>yazzgoth</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://yazzgoth.org/2007/11/08/overriding-name-of-file-in-imagefieldfilefield-in-django/</guid>
		<description><![CDATA[If you&#8217;re wondering how to override a name of a file you&#8217;re uploading to ImageField/FileField in Django, here&#8217;s one of the possible solutions:
Add this to your models.py

 Python [Show Styled Code]:

from django.dispatch import dispatcher
import shutil, os, settings, re

class CustomImageField(models.ImageField):
    &#034;&#034;&#034;
    Model class should have a method like:

   [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re wondering how to override a name of a file you&#8217;re uploading to ImageField/FileField in Django, here&#8217;s one of the possible solutions:</p>
<p>Add this to your models.py</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4889a689c5b2b">
<div class="synthi_header" style="font-weight:bold;"> Python <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4889a689c5b2b').style.display='block';document.getElementById('plain_synthi_4889a689c5b2b').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
from django.dispatch import dispatcher
import shutil, os, settings, re

class CustomImageField(models.ImageField):
    &#034;&#034;&#034;
    Model class should have a method like:

        def personalize_name(self, field_attname):
            return &#034;path/to/file/%d.jpg&#034; % self.id

    &#034;&#034;&#034;
    def contribute_to_class(self, cls, name):
            super(CustomImageField, self).contribute_to_class(cls, name)
            dispatcher.connect(self._save, models.signals.pre_save, sender=cls)

    def _save(self, instance):
        oldname = getattr(instance, self.attname)
        extension = re.findall(r'.[wd]+$', oldname)
        if len(extension)>0:
            extension = extension[0]
        else: extension = &#034;&#034;
        filename = instance.personalize_name(self.attname)
        filename = self.upload_to + '_'.join(re.findall(r'[a-zA-Z0-9]+', filename)) + extension # leave only alphanum characters and add extension and add extension
        try:
            shutil.move(os.path.join(settings.MEDIA_ROOT, oldname), os.path.join(settings.MEDIA_ROOT, filename))
        except IOError:
            filename = oldname
        setattr(instance, self.attname, filename)

    def db_type(self):
        &#034;&#034;&#034;Required by Django for ORM.&#034;&#034;&#034;
        return 'varchar(100)'
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4889a689c5b2b">
<div class="synthi_header" style="font-weight:bold;"> Python <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4889a689c5b2b').style.display='block';document.getElementById('styled_synthi_4889a689c5b2b').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="python" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">dispatch</span> <span style="color: #ff7700;font-weight:bold;">import</span> dispatcher</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">shutil</span>, <span style="color: #dc143c;">os</span>, settings, <span style="color: #dc143c;">re</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">class</span> CustomImageField<span style="color: black;">&#40;</span>models.<span style="color: black;">ImageField</span><span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #483d8b;">&nbsp; &nbsp; Model class should have a method like:</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #483d8b;">&nbsp; &nbsp; &nbsp; &nbsp; def personalize_name(self, field_attname):</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #483d8b;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return &quot;</span>path/to/<span style="color: #008000;">file</span>/%d.<span style="color: black;">jpg</span><span style="color: #483d8b;">&quot; % self.id</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #483d8b;">&nbsp; &nbsp; &quot;</span><span style="color: #483d8b;">&quot;&quot;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> contribute_to_class<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, cls, name<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>CustomImageField, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: black;">contribute_to_class</span><span style="color: black;">&#40;</span>cls, name<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._save, models.<span style="color: black;">signals</span>.<span style="color: black;">pre_save</span>, sender=cls<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> _save<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, instance<span style="color: black;">&#41;</span>: </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; oldname = <span style="color: #008000;">getattr</span><span style="color: black;">&#40;</span>instance, <span style="color: #008000;">self</span>.<span style="color: black;">attname</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; extension = <span style="color: #dc143c;">re</span>.<span style="color: black;">findall</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&#8216;<span style="color: #000099; font-weight: bold;">\.</span>[<span style="color: #000099; font-weight: bold;">\w</span><span style="color: #000099; font-weight: bold;">\d</span>]+$&#8217;</span>, oldname<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>extension<span style="color: black;">&#41;</span>&gt;<span style="color: #ff4500;">0</span>:</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extension = extension<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">else</span>: extension = <span style="color: #483d8b;">&quot;&quot;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; filename = instance.<span style="color: black;">personalize_name</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">attname</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; filename = <span style="color: #008000;">self</span>.<span style="color: black;">upload_to</span> + <span style="color: #483d8b;">&#8216;_&#8217;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">re</span>.<span style="color: black;">findall</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&#8216;[a-zA-Z0-9]+&#8217;</span>, filename<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + extension <span style="color: #808080; font-style: italic;"># leave only alphanum characters and add extension and add extension</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">try</span>:</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #dc143c;">shutil</span>.<span style="color: black;">move</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>settings.<span style="color: black;">MEDIA_ROOT</span>, oldname<span style="color: black;">&#41;</span>, <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>settings.<span style="color: black;">MEDIA_ROOT</span>, filename<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">IOError</span>:</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filename = oldname</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">setattr</span><span style="color: black;">&#40;</span>instance, <span style="color: #008000;">self</span>.<span style="color: black;">attname</span>, filename<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> db_type<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;Required by Django for ORM.&quot;</span><span style="color: #483d8b;">&quot;&quot;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&#8216;varchar(100)&#8217;</span></div>
</li>
</ol>
</div>
</div>
<p>And to your class definition you need to add something like this:</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4889a689e9cba">
<div class="synthi_header" style="font-weight:bold;"> Python <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4889a689e9cba').style.display='block';document.getElementById('plain_synthi_4889a689e9cba').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
class MyPhoto(models.Model):
    photo = CustomImageField(upload_to=&#034;photos/&#034;)
    owner = models.CharField(max_length=32)
    uploaded = models.DateTimeField(auto_add_now=True)

    def personalize_name(self, field_attname):
        return &#034;%s %s&#034; % ( self.owner, self.uploaded ) # don't worry about the non-alphanum characters
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4889a689e9cba">
<div class="synthi_header" style="font-weight:bold;"> Python <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4889a689e9cba').style.display='block';document.getElementById('styled_synthi_4889a689e9cba').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="python" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">class</span> MyPhoto<span style="color: black;">&#40;</span>models.<span style="color: black;">Model</span><span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; photo = CustomImageField<span style="color: black;">&#40;</span>upload_to=<span style="color: #483d8b;">&quot;photos/&quot;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; owner = models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length=<span style="color: #ff4500;">32</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; uploaded = models.<span style="color: black;">DateTimeField</span><span style="color: black;">&#40;</span>auto_add_now=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> personalize_name<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, field_attname<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;%s %s&quot;</span> % <span style="color: black;">&#40;</span> <span style="color: #008000;">self</span>.<span style="color: black;">owner</span>, <span style="color: #008000;">self</span>.<span style="color: black;">uploaded</span> <span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># don&#8217;t worry about the non-alphanum characters</span></div>
</li>
</ol>
</div>
</div>
<p>Assuming that the owner will be Bartosz Ptaszynski and the uploaded date 08-11-2007 13:06:00 and the file is photo.jpg the saved file will be:</p>
<p>photos/Bartosz_Ptaszynski_08_11_2007_13_06_00.jpg  </p>
<p>Inspired by <a href="http://scottbarnham.com/blog/2007/07/">this</a> blog. Thanks Scott.</p>
]]></content:encoded>
			<wfw:commentRss>http://yazzgoth.org/2007/11/08/overriding-name-of-file-in-imagefieldfilefield-in-django/feed/</wfw:commentRss>
		</item>
		<item>
		<title>&#8220;The Witcher&#8221; against my expectations it&#8217;s a great game!</title>
		<link>http://yazzgoth.org/2007/11/06/the-witcher-against-my-expectations-its-a-great-game/</link>
		<comments>http://yazzgoth.org/2007/11/06/the-witcher-against-my-expectations-its-a-great-game/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 10:16:31 +0000</pubDate>
		<dc:creator>yazzgoth</dc:creator>
		
		<category><![CDATA[News]]></category>

		<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://yazzgoth.org/2007/11/06/the-witcher-against-my-expectations-its-a-great-game/</guid>
		<description><![CDATA[&#8220;The Witcher&#8221; had been developed for many years now, originally based on NWN engine it grew to something beautiful.
The Witcher (or in polish original &#8220;Wiedzmin&#8221;) is based on Andrzej Sapkowski&#8217;s novels. Sapkowski is one of my favorite polish writers and I&#8217;ve read all of his work (even those that was published years ago in some [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;The Witcher&#8221; had been developed for many years now, originally based on NWN engine it grew to something beautiful.<br />
The Witcher (or in polish original &#8220;Wiedzmin&#8221;) is based on Andrzej Sapkowski&#8217;s novels. Sapkowski is one of my favorite polish writers and I&#8217;ve read all of his work (even those that was published years ago in some fantasy magazines before he became famous).<br />
As with many good literature like in this case someone had this brilliant idea to make a movie based on it.<br />
Unfortunately for fans, polish movie directors got their hands on an exclusive rights to shoot the movie and that guaranteed them time (I believe it was 2years) before anyone else could even think about creating a movie based on the novels, and to my knowledge some Holywood producers were looking into it (god I was so suprised when I&#8217;ve seen intro to &#8220;Beowulf&#8221; with Christopher Lambert - I thought: &#8216;No way they&#8217;ve made Wiedzmin!&#8217; as the main character resembles Witcher so much <img src='http://yazzgoth.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )<br />
Anyway, long story short, the movie was a hoax. Then they&#8217;ve made a TV series, which was bad, but not as much as the movie.</p>
<p>So I&#8217;ve lost my hopes in polish productions. Don&#8217;t know why, I know that we have good programers and talented graphic artists in Poland (hey I&#8217;m one of them right? <img src='http://yazzgoth.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) but somehow I&#8217;ve pushed away the idea of a good game based on The Witcher novels and after like 4years after the development started I almost forgot about it, until now.</p>
<p>So, on Sunday I&#8217;ve visited GameStop looking for a RPG to waste time on as my mood pointed me to this genre at the time. To be honest I was looking for the NWN2 Mask of the Betrayer, when my eyes landed on a familiar sign - the Witcher&#8217;s medallion - a wolf&#8217;s head. After few moments of gazing at the back where you can find microscopic sized screenshots I said to myself what the hell at least I&#8217;ll support the guys who made it in some way if I&#8217;ll buy it. Same afternoon I&#8217;ve installed it and the game sucked me in good. My girlfriend gave up trying talk to me when she saw that I&#8217;m not giving any responses beside &#8220;mhm&#8221;, &#8220;right&#8221;, &#8220;yeah you&#8217;re right&#8221; and I&#8217;ve got totally immersed into the world I came to know so well.<br />
Some monsters and characters I&#8217;ve imagined a bit differently but hey, overall I&#8217;ve got great impression from the art.<br />
Game runs on almost highest settings on my rig (Intel Pentium D 2,66GHz, ATI Radeon X1950XTX, 2GB DDR2) but to be honest the system could use a reinstall. I&#8217;ve just had to change the resolution down to 1024&#215;768 and the anizo down to x8 and I&#8217;ve got constant 20-30FPS which is playable enough for this kind of game and the sights are uh oh gorgeous.<br />
The dialogues are technically on a level of Fallout, they repeat themselves if you try to talk to one person second time, you&#8217;re getting same &#8216;hello&#8217; kind of message from a NPC you&#8217;re trying to talk to, but still the story and immersion is great.<br />
You can evolve your character as you gain more experience, or perhaps as you recover your experience after loosing all memory as Geralt, the main character, is one of the best Witchers around, well was, err will be again <img src='http://yazzgoth.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> So you have 4 attributes Strength, Dexterity, Stamina and Intelligence. Each one of them has five levels of advancement. First two require bronze skill points, third and fourth requires silver, and fifth gold. Investing in each level unlocks set of skills you can invest in same kind of points as in the level itself.<br />
Beside attributes you can (re)learn witcher&#8217;s signs. They are kind of simple magic signs ie for telekinesis (Aard sign), causing pain (Yrden sign), fireball (Igni sign), etc.<br />
Witchers also know their way in alchemy, so we&#8217;re be also able to brew potions that will boost us in those dark, smelly sewers, crypts, graveyards, forests or dungeons. Witchers are mutants, by definition they&#8217;re faster, stronger, more durable than humans, but they also have limits on how much they can handle. So beside the stamina and everobious HPs you have a toxicity level. More stuff you drink that you&#8217;ve brewed, more screwed you get. Of course you can invest a bit more in the elixir base (which is alcohol) to have better quality potions(stronger the better).<br />
I must say it&#8217;s a game that doesn&#8217;t get borring after 30min, heck after 4hrs that I&#8217;ve spent the other day I was considering - warm bed or zombie-like appearance next day. I&#8217;ve chosen bed not because the game isn&#8217;t good enough to sacrifice a good night sleep, but because I&#8217;m a good boyfriend and my girl needs a goodnight hug <img src='http://yazzgoth.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> Anyhoo I believe that the 80+ hrs of gameplay is not overestimated, and not only because of longish load times between locations, but because there&#8217;s so much going on, and the amount of great cinematographic moments in the game just keeps you glued to the keyboard and mouse glazing at the screen.<br />
There&#8217;s nothing more funny and exciting to get drunk in an inn with your ol&#8217;friend dwarf Zoltan and fist fight with some peasants when the screen is blurry and our character barely stands on his feet.<br />
Anyway it&#8217;s a bit too soon for me to give a good overall review of the game, but from what I&#8217;ve seen so far I can recommend this game to anyone looking for great time playing RPG and all fans of Sapkowski&#8217;s work.</p>
]]></content:encoded>
			<wfw:commentRss>http://yazzgoth.org/2007/11/06/the-witcher-against-my-expectations-its-a-great-game/feed/</wfw:commentRss>
		</item>
		<item>
		<title>3G broadband in Ireland is a joke&#8230;</title>
		<link>http://yazzgoth.org/2007/11/01/3g-broadband-in-ireland-is-a-joke/</link>
		<comments>http://yazzgoth.org/2007/11/01/3g-broadband-in-ireland-is-a-joke/#comments</comments>
		<pubDate>Thu, 01 Nov 2007 12:33:46 +0000</pubDate>
		<dc:creator>yazzgoth</dc:creator>
		
		<category><![CDATA[Networking]]></category>

		<category><![CDATA[Lifestyle]]></category>

		<guid isPermaLink="false">http://yazzgoth.org/2007/11/01/3g-broadband-in-ireland-is-a-joke/</guid>
		<description><![CDATA[Recently I&#8217;ve moved to new house. And because I simply can&#8217;t be offline as I work over the net I&#8217;ve decided to give 3G a try.
I gave 3Ireland a chance at first. Unfortunately their &#8220;Up to 3.6Mb/s&#8221; is far from advertised. I didn&#8217;t expect it to reach speeds they advertise but something closer to 1Mb/s, [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve moved to new house. And because I simply can&#8217;t be offline as I work over the net I&#8217;ve decided to give 3G a try.<br />
I gave 3Ireland a chance at first. Unfortunately their &#8220;Up to 3.6Mb/s&#8221; is far from advertised. I didn&#8217;t expect it to reach speeds they advertise but something closer to 1Mb/s, but in practice I&#8217;ve got only 200-300Kb/s down and 50Kb/s up and the connection choked so often it wasn&#8217;t even funny. So the next day I have returned it and went to Vodafone.</p>
<p>Vodafone turned out to be more reliable in terms of stability and speed. It can fallback from 3G to GPRS if the signal gets too weak (and in some parts of my home it does). While on 3G I&#8217;m getting speeds of ~1Mb/s down and 400Kb/s up which is great, on GPRS it&#8217;s ~380Kb/s down and ~50-90Kb/s up.<br />
Latency is not as bad as I&#8217;ve expected: 100-250ms for most servers.<br />
So&#8230; Vodafone is nice but there&#8217;s a catch&#8230; 5GB traffic limit per month.. AND it&#8217;s aggregate traffic for upload and download!<br />
With my day to day internet habits and work I&#8217;m using 300-1000MB each day, and no that&#8217;s without any P2P traffic.<br />
As of yet Vodafone seemed unwilling to make any kind of deal to get a better package, and I&#8217;m not sure I&#8217;m prepared to pay hundreds euro per month for medicore broadband.<br />
I guess I could always try out O2, and I may actually do that, because I&#8217;m sure I&#8217;ll resign from Vodafone Broadband before the 14days return warranty.</p>
<p>I&#8217;m trying to get a DSL at home, but that may take anything between few weeks and 3months. I guess I&#8217;ll be calling BT everyday to check when the installer will come and in the meantime I have to look for an office space with nice internet connection.</p>
]]></content:encoded>
			<wfw:commentRss>http://yazzgoth.org/2007/11/01/3g-broadband-in-ireland-is-a-joke/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Kinetic Style Sheets (KSS) or how to AJAX without JavaScript</title>
		<link>http://yazzgoth.org/2007/10/31/kinetic-style-sheets-kss-or-how-to-ajax-without-javascript/</link>
		<comments>http://yazzgoth.org/2007/10/31/kinetic-style-sheets-kss-or-how-to-ajax-without-javascript/#comments</comments>
		<pubDate>Wed, 31 Oct 2007 15:34:19 +0000</pubDate>
		<dc:creator>yazzgoth</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://yazzgoth.org/2007/10/31/kinetic-style-sheets-kss-or-how-to-ajax-without-javascript/</guid>
		<description><![CDATA[I&#8217;ve just found a very interesting framework designed for Python/AJAX developers.
It&#8217;s called Kinetic Style Sheets, or KSS for short, and it&#8217;s goal is to use CSS with some additional syntax to pass marshalled data from server back to the client to manipulate the DOM without using a single line of JavaScript (most of the times). [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just found a very interesting framework designed for Python/AJAX developers.<br />
It&#8217;s called <a href="http://kssproject.org/">Kinetic Style Sheets</a>, or KSS for short, and it&#8217;s goal is to use CSS with some additional syntax to pass marshalled data from server back to the client to manipulate the DOM without using a single line of JavaScript (most of the times).       </p>
<p>Apparently it&#8217;s included in <a href="http://plone.org/">PLONE</a> 3.0, a new version of framework I&#8217;ve used some time back, but due to my migration to lighter frameworks (<a href="http://turbogears.org/">TurboGears</a>/<a href="http://djangoproject.com">Django</a>) existence of KSS had evaded my attention until now.<br />
&#8220;So what&#8217;s so hot about Kinetic Style Sheets?&#8221; you may ask &#8220;Does it move things?&#8221;&#8230; Well pretty much <img src='http://yazzgoth.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> But that&#8217;s not the killer feat.</p>
<p>It&#8217;s designed for Python developers who wish to keep their nose in Python code as much as possible avoiding hairy JavaScript(browser) world.</p>
<p>It&#8217;s also designed not to break compatibility with JavaScript-disabled browsers. <br/><br />
Well that&#8217;s that for wetting appetite&#8230; It&#8217;s time to get a bite of this framework, and then I&#8217;ll be back with more thoughts.</p>
]]></content:encoded>
			<wfw:commentRss>http://yazzgoth.org/2007/10/31/kinetic-style-sheets-kss-or-how-to-ajax-without-javascript/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
