<?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>Tom Coote &#187; Tom Coote</title>
	<atom:link href="http://tomcoote.co.uk/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://tomcoote.co.uk</link>
	<description>An ace web developer!</description>
	<lastBuildDate>Sun, 08 Jan 2012 14:18:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Django Site Login Script</title>
		<link>http://tomcoote.co.uk/django/django-site-login-script/</link>
		<comments>http://tomcoote.co.uk/django/django-site-login-script/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 14:18:38 +0000</pubDate>
		<dc:creator>Tom Coote</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://tomcoote.co.uk/?p=722</guid>
		<description><![CDATA[
			
				
			
		
Just having a play around with a Python script that will login to a standard Django login form. I thought I&#8217;d share it as it&#8217;s quite interesting and I&#8217;m sure someone might find a use for it.
It uses the standard Python modules urllib2, urllib and cookielib. It also requires BeautifulSoup for getting the generated CSRF [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px; margin-top:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftomcoote.co.uk%2Fdjango%2Fdjango-site-login-script%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftomcoote.co.uk%2Fdjango%2Fdjango-site-login-script%2F&amp;source=cootetom&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Just having a play around with a Python script that will login to a standard Django login form. I thought I&#8217;d share it as it&#8217;s quite interesting and I&#8217;m sure someone might find a use for it.</p>
<p>It uses the standard Python modules <a href="http://docs.python.org/library/urllib2.html">urllib2</a>, <a href="http://docs.python.org/library/urllib.html">urllib</a> and <a href="http://docs.python.org/library/cookielib.html">cookielib</a>. It also requires <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> for getting the generated CSRF token from the Django login form to use with the authentication credentials.</p>
<p>Here is the script.</p>
<pre class="qoate-code">
import urllib2
import urllib
import cookielib
from BeautifulSoup import BeautifulSoup

LOGIN_URL = 'http://a-django-site.com/login/'

# for handling cookies to and from all requests we make in this script
# because the site uses cookies for authentication data.
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

# need the CSRF token from the login form that allows us to login
login_form = BeautifulSoup(opener.open(LOGIN_URL).read())
csrf = login_form.find('input', attrs={'name': 'csrfmiddlewaretoken'}).attrMap

# sign in by sending the correct credentials to the login form
credentials = {'username': 'admin',
               'password': '123456',
               'remember': '',
               'csrfmiddlewaretoken': csrf['value']
               }

req = urllib2.Request(LOGIN_URL, urllib.urlencode(credentials))
raw_html = opener.open(req).read()

# test if the login was successful
login_success = 'sessionid' in [c.name for c in cj]
print login_success and 'Login successful' or 'Login failed'
</pre>
<p>Pretty straight forward. Once logged in BeautifulSoup could be used to easily navigate and scrape data from the authenticated web site.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomcoote.co.uk/django/django-site-login-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Improve Django SQL Queries Using Debug Toolbar</title>
		<link>http://tomcoote.co.uk/django/improve-django-sql-queries-using-debug-toolbar/</link>
		<comments>http://tomcoote.co.uk/django/improve-django-sql-queries-using-debug-toolbar/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 21:51:52 +0000</pubDate>
		<dc:creator>Tom Coote</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://tomcoote.co.uk/?p=632</guid>
		<description><![CDATA[
			
				
			
		
Django&#8217;s database querying is there to make life easier but it&#8217;s also easy to forget about the SQL that is still generated under the hood. When using Django&#8217;s query objects it&#8217;s extremely difficult to know how often the database is being hit and with what SQL queries. We often write queries in our views, check [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px; margin-top:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftomcoote.co.uk%2Fdjango%2Fimprove-django-sql-queries-using-debug-toolbar%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftomcoote.co.uk%2Fdjango%2Fimprove-django-sql-queries-using-debug-toolbar%2F&amp;source=cootetom&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Django&#8217;s database querying is there to make life easier but it&#8217;s also easy to forget about the SQL that is still generated under the hood. When using Django&#8217;s query objects it&#8217;s extremely difficult to know how often the database is being hit and with what SQL queries. We often write queries in our views, check that they return what we want, then forget them. Lots of the time that is okay but often we&#8217;ll run into performance problems later down the road due to too many database queries. Even if you only have one query in your view, the template might generate more queries without you knowing about them.</p>
<p>Luckily we have the <a href="http://pypi.python.org/pypi/django-debug-toolbar">django debug toolbar</a> to show us how many queries are being sent to our database for a single page request. So I&#8217;m going to go through an example of using the debug toolbar to make a performance improvement for a django view. I&#8217;m not going into how to install the debug tool bar because it&#8217;s all on their download page <a href="http://pypi.python.org/pypi/django-debug-toolbar">here</a>.</p>
<p>I created a simple test site to demonstrate how to find and improve database hits. It has one page which just lists a load of comments from the database. The template HTML is as follows.</p>
<pre class="qoate-code">
&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Debug Demo&lt;/title&gt;

	&lt;style type="text/css"&gt;
	div {
		margin:10px;
		padding:10px;
		border:1px solid #000;
	}
	&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

	&lt;h1&gt;Comments&lt;/h1&gt;

	{% for comment in comments %}
	&lt;div&gt;
	&lt;p&gt;Posted by: {{ comment.posted_by.first_name }}&lt;/p&gt;
	&lt;p&gt;Date: {{ comment.post_date|date:"D jS M" }}&lt;/p&gt;

	{{ comment.text|linebreaks }}
	&lt;/div&gt;
	{% endfor %}

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>So as you can see, the template is expecting a list of comments and is just going to create markup to display each of them. The Django model and view are as follows.</p>
<pre class="qoate-code">
from django.db import models
from django.contrib.auth.models import User

class Comment(models.Model):
    post_date = models.DateTimeField(auto_now_add=True)
    posted_by = models.ForeignKey(User)
    text = models.TextField()
</pre>
<pre class="qoate-code">
from django.shortcuts import render
from DebugDemo.models import Comment

def comments(request):

    return render(request, 'comments.html', {
                     'comments': Comment.objects.all()
                    })
</pre>
<p>The result is as expected, the page loads and we see all comments in the database. What you may think by looking at our view code is that one database hit is made, just one that gets all comments. In reality we have one hit to get the comments plus one hit per comment that is retrieved. So to put this in Python form we have len(comments)+1 database hits. The problem is that we won&#8217;t notice a performance problem for this until we have loads of comments to show and loads of visitors wanting to see them. We can see the SQL that was sent to the database by using the debug toolbar and opening the SQL tab. In my example I had two comments in the database so I had three queries as shown below.</p>
<p><img src="http://tomcoote.co.uk/wp-content/uploads/2011/10/debug_toolbar.png" alt="" width="1363" height="351" class="aligncenter size-full wp-image-638" /></p>
<p>What&#8217;s happening here is that the view will run one database query to retrieve all the comment data then our template needs the user&#8217;s name to show against each comment, so when it get&#8217;s to that it will do another query to retrieve each user for each comment. Understanding why these queries are generated is half the battle but it&#8217;s made a lot easier with the debug toolbar as we can see what the SQL is and therefor know what data each is retrieving. When our list of SQL queries has one for comments and loads more for users it&#8217;s pretty obvious what&#8217;s going on. </p>
<p>Solving this is a matter of re-writing our view query so that it retrieves the data that our template needs all at once. To do that we can use the query objects <em>values</em> method. It&#8217;s always about <a href="https://docs.djangoproject.com/en/1.3/topics/db/optimization/#don-t-retrieve-things-you-don-t-need">not retrieving the things you don&#8217;t need</a>. So our new view looks like this.</p>
<pre class="qoate-code">
from django.shortcuts import render
from DebugDemo.models import Comment

def comments(request):

    comments = Comment.objects.all().values('post_date', 'posted_by__first_name', 'text')

    return render(request, 'comments.html', {
                     'comments': comments
                    })
</pre>
<p>You can see that we&#8217;re using the values method to tell Django to only retrieve the three columns that our template needs. The problem now is that our template needs a bit of an update. It currently calls <em>comment.posted_by.first_name</em> to print the users name but this is no longer correct because our new query returns a dictionary of key value pairs not a list of model objects. So here is the new template code, it&#8217;s just using <em>comments.posted_by__first_name</em> instead.</p>
<pre class="qoate-code">
&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Debug Demo&lt;/title&gt;

	&lt;style type="text/css"&gt;
	div {
		margin:10px;
		padding:10px;
		border:1px solid #000;
	}
	&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

	&lt;h1&gt;Comments&lt;/h1&gt;

	{% for comment in comments %}
	&lt;div&gt;
	&lt;p&gt;Posted by: {{ comment.posted_by__first_name }}&lt;/p&gt;
	&lt;p&gt;Date: {{ comment.post_date|date:"D jS M" }}&lt;/p&gt;

	{{ comment.text|linebreaks }}
	&lt;/div&gt;
	{% endfor %}

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The result is just one query which we can see in the debug toolbar.</p>
<p><img src="http://tomcoote.co.uk/wp-content/uploads/2011/10/debug_toolbar1.png" alt="" width="1308" height="344" class="aligncenter size-full wp-image-645" /></p>
<p>I hope I&#8217;ve shown how important it is to keep on eye on the queries that are going on because even in this really simple example we can see how performance problems can easily creep in. My advice is to always run through the pages you build with the debug toolbar to have a quick look at the queries to see if there is anything unexpected going on.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomcoote.co.uk/django/improve-django-sql-queries-using-debug-toolbar/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Writing functions inside loops in JavaScript</title>
		<link>http://tomcoote.co.uk/javascript/writing-functions-inside-loops-in-javascript/</link>
		<comments>http://tomcoote.co.uk/javascript/writing-functions-inside-loops-in-javascript/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 16:57:58 +0000</pubDate>
		<dc:creator>Tom Coote</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://tomcoote.co.uk/?p=669</guid>
		<description><![CDATA[
			
				
			
		
I&#8217;ve created a short video to help explain what the issues are when writing JavaScript functions inside loops and how to use function scope to solve those issues. Enjoy.
Full screen it in order to read the code.

]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px; margin-top:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftomcoote.co.uk%2Fjavascript%2Fwriting-functions-inside-loops-in-javascript%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftomcoote.co.uk%2Fjavascript%2Fwriting-functions-inside-loops-in-javascript%2F&amp;source=cootetom&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I&#8217;ve created a short video to help explain what the issues are when writing JavaScript functions inside loops and how to use function scope to solve those issues. Enjoy.</p>
<p><em>Full screen it in order to read the code.</em></p>
<p><iframe src="http://www.screenr.com/embed/jCOs" width="650" height="396" frameborder="0"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://tomcoote.co.uk/javascript/writing-functions-inside-loops-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code To Give Users Time To Read Feedback</title>
		<link>http://tomcoote.co.uk/javascript/code-to-give-users-time-to-read-feedback/</link>
		<comments>http://tomcoote.co.uk/javascript/code-to-give-users-time-to-read-feedback/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 13:42:58 +0000</pubDate>
		<dc:creator>Tom Coote</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://tomcoote.co.uk/?p=618</guid>
		<description><![CDATA[
			
				
			
		
I&#8217;ve blogged before about giving users of a web application feedback on the page whilst they wait for something to load and also about slowing down the responses from AJAX requests in order to give those users time to fully read and understand that feedback. I&#8217;ve recently built some more code to help achieve this. [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px; margin-top:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftomcoote.co.uk%2Fjavascript%2Fcode-to-give-users-time-to-read-feedback%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftomcoote.co.uk%2Fjavascript%2Fcode-to-give-users-time-to-read-feedback%2F&amp;source=cootetom&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I&#8217;ve blogged before about giving users of a web application <a href="/ui/loading-feedback/">feedback</a> on the page whilst they wait for something to load and also about <a href="/ui/slow-down-your-web-site/">slowing down</a> the responses from AJAX requests in order to give those users time to fully read and understand that feedback. I&#8217;ve recently built some more code to help achieve this. This is a jQuery extension.</p>
<p>If you&#8217;re going to use AJAX to load some content into the page as the user requests it then it&#8217;s a good idea to tell the user what is happening. This is often done with some sort of message on the page saying something like &#8220;stuff is loading here, won&#8217;t be long&#8221;. Also it&#8217;s a good idea for the round trip to the server and back to be quick because you don&#8217;t want your users to be waiting all day long. However, if the round trip is less than half a second then the user probably didn&#8217;t get time to read that message and, depending on the scenario, this could lead to an un-happy web experience. </p>
<p>So I have some code that extends the jQuery AJAX &#8216;post&#8217; and &#8216;get&#8217; functions so that we can invoke them but ensure that our success callback function isn&#8217;t invoked until at east the N number of milliseconds that we have set have passed.</p>
<p>So the process is as follows:</p>
<ul>
<li>User clicks a button to request some information.</li>
<li>JavaScript is called and immediately puts some sort of loading message on to the page.</li>
<li>A post or get request is made using my extension and is asked to wait at least 500 milliseconds before the success callback function is invoked.</li>
<li>If the request takes less than 500 milliseconds then the remainder is set to pass before invoking the success function. If the request takes longer than 500 milliseconds then the success function is invoked as soon as the request returns.</li>
<li>The success function removes the loading message from the page and replaces it with the content the user asked for.</li>
</ul>
<p>This ensures that the user had time to understand the feedback on the page but also ensures the data they requested get&#8217;s displayed to them as soon as possible after.</p>
<p>Check out the <a href="/wp-content/CodeBank/Demos/requestWithTimeout/test.html">demo page</a> to see this working.<br />
<a href="/wp-content/CodeBank/Downloads/requestWithTimeout.zip">Download</a> the source to start using it yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomcoote.co.uk/javascript/code-to-give-users-time-to-read-feedback/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google plus, where to go from here?</title>
		<link>http://tomcoote.co.uk/internet/google-plus-where-to-go-from-here/</link>
		<comments>http://tomcoote.co.uk/internet/google-plus-where-to-go-from-here/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 15:22:35 +0000</pubDate>
		<dc:creator>Tom Coote</dc:creator>
				<category><![CDATA[Internet]]></category>

		<guid isPermaLink="false">http://tomcoote.co.uk/?p=601</guid>
		<description><![CDATA[
			
				
			
		
Yesterday I happily got an invite to Google+ from @quagliero. Not sure if it&#8217;s still invite only but I&#8217;ve been having a go with it yesterday and today. Also installed the Android app which brings everything together really nicely. So far I can safely say I really like the service.
However, I have a bit of [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px; margin-top:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftomcoote.co.uk%2Finternet%2Fgoogle-plus-where-to-go-from-here%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftomcoote.co.uk%2Finternet%2Fgoogle-plus-where-to-go-from-here%2F&amp;source=cootetom&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Yesterday I happily got an invite to Google+ from <a href="http://twitter.com/#!/quagliero">@quagliero</a>. Not sure if it&#8217;s still invite only but I&#8217;ve been having a go with it yesterday and today. Also installed the Android app which brings everything together really nicely. So far I can safely say I really like the service.</p>
<p>However, I have a bit of a gripe with there being yet another social network service. It&#8217;s only a social network if your real world social network are all using the same service!</p>
<p>The problem with saying that not everyone wants service X and that for those people they could use service Y is that being the minority on a social website is useless by contradiction. If the majority of people that you want to connect with socially on the internet use a particular service then your decision is pretty much made for you.</p>
<p>The social web needs to move towards easy integration for it&#8217;s users sake. The big guys need to come together and figure out a way of allowing a user of one social network to connect with their friends on a different social network. However, the problem with taking an <a href="http://code.google.com/apis/opensocial/">opensocial</a> approach is that the leading sites end up opening themselves up to losing sign ups and therefore losing potential income.</p>
<p>I guess from a business perspective it comes down to potential income and for that you need sign ups on your social network, not someone else&#8217;s. However, I do think that the problem is there to be solved and certainly is solvable. It shouldn&#8217;t be open source like opensocial it should be a private network of proven web companies coming together to define a closed approach to integrating their services. Open source isn&#8217;t the answer here due to the competitive nature of market share and income.</p>
<p>Aggregators and/or API&#8217;s are also not the answer. They force the user to move away from the social network experience they really want due to the equal want to connect with all their friends across different networks.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomcoote.co.uk/internet/google-plus-where-to-go-from-here/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SimpleModal version 2</title>
		<link>http://tomcoote.co.uk/javascript/simplemodal-version-2/</link>
		<comments>http://tomcoote.co.uk/javascript/simplemodal-version-2/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 16:13:20 +0000</pubDate>
		<dc:creator>Tom Coote</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://tomcoote.co.uk/?p=593</guid>
		<description><![CDATA[
			
				
			
		
I have just updated my SimpleModal JavaScript component and released it as version 2. You can read about the script and download it from it&#8217;s page here.
I&#8217;ve just improved it a little to better support newer browsers and tested in the latest jQuery version.
I&#8217;d like to mention that I&#8217;ve been using this script in all [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px; margin-top:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftomcoote.co.uk%2Fjavascript%2Fsimplemodal-version-2%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftomcoote.co.uk%2Fjavascript%2Fsimplemodal-version-2%2F&amp;source=cootetom&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I have just updated my SimpleModal JavaScript component and released it as version 2. You can read about the script and download it from it&#8217;s page <a href="/code-bank/simple-modal/">here</a>.</p>
<p>I&#8217;ve just improved it a little to better support newer browsers and tested in the latest jQuery version.</p>
<p>I&#8217;d like to mention that I&#8217;ve been using this script in all of my web projects for years now. It&#8217;s simplicity makes it so flexible which I think is why it&#8217;s stood the test of time for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomcoote.co.uk/javascript/simplemodal-version-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django Class Based Generic API</title>
		<link>http://tomcoote.co.uk/django/django-class-based-generic-api/</link>
		<comments>http://tomcoote.co.uk/django/django-class-based-generic-api/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 14:06:47 +0000</pubDate>
		<dc:creator>Tom Coote</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://tomcoote.co.uk/?p=582</guid>
		<description><![CDATA[
			
				
			
		
It has been a pretty rainy weekend so I&#8217;ve decided to do some Python programming and have come up with a set of tools to help build API&#8217;s in django. 
I know there are a few libraries already available for building API&#8217;s in django (I&#8217;ve used and contributed to some of them) but since django [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px; margin-top:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftomcoote.co.uk%2Fdjango%2Fdjango-class-based-generic-api%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftomcoote.co.uk%2Fdjango%2Fdjango-class-based-generic-api%2F&amp;source=cootetom&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>It has been a pretty rainy weekend so I&#8217;ve decided to do some Python programming and have come up with a set of tools to help build API&#8217;s in <a href="https://docs.djangoproject.com/en/1.3/">django</a>. </p>
<p>I know there are a few libraries already available for building API&#8217;s in django (I&#8217;ve used and contributed to some of them) but since django 1.3 was released with the class based generic views then a lot of the functionality needed to create API&#8217;s is already in the framework. So I decided to just build a few extra things to make API&#8217;s easy in django by using the framework for most of the heavy lifting. </p>
<p>I&#8217;ve made the code available on <a href="https://github.com/cootetom/ClassBasedGenericAPI">GitHub</a>. Here are the features in a nut shell;</p>
<ul>
<li>A new generic class view called APIView which provides a mini framework for supporting different data formats for an API and providing some common API responses. </li>
<li>A throttling decorator to limit API calls per user.</li>
<li>Support for  base64 http authentication.</li>
</ul>
<p>I&#8217;ve put basic support in for JSON requests and responses. The code acts as a good basis for a complete API in django and allows an easy way to extend it for new data formats. It makes good use of POST, GET, PUT and DELETE request methods.</p>
<p><a href="https://github.com/cootetom/ClassBasedGenericAPI">View the repository on GitHub.</a> I would be interested to know how anyone gets on using it and if anyone adds in support for different data formats.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomcoote.co.uk/django/django-class-based-generic-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Input Character Counter</title>
		<link>http://tomcoote.co.uk/javascript/input-character-counter/</link>
		<comments>http://tomcoote.co.uk/javascript/input-character-counter/#comments</comments>
		<pubDate>Sun, 22 May 2011 16:02:08 +0000</pubDate>
		<dc:creator>Tom Coote</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://tomcoote.co.uk/?p=571</guid>
		<description><![CDATA[
			
				
			
		
I built this whilst watching Britain&#8217;s Got Talent yesterday. I wasn&#8217;t enjoying the show to much. It&#8217;s a simple jQuery plugin that you can attach to textarea or input elements which will limit the amount of characters that are allowed for the input and also show a counter in the top right corner to indicate [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px; margin-top:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftomcoote.co.uk%2Fjavascript%2Finput-character-counter%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftomcoote.co.uk%2Fjavascript%2Finput-character-counter%2F&amp;source=cootetom&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I built this whilst watching Britain&#8217;s Got Talent yesterday. I wasn&#8217;t enjoying the show to much. It&#8217;s a simple jQuery plugin that you can attach to textarea or input elements which will limit the amount of characters that are allowed for the input and also show a counter in the top right corner to indicate the character count.</p>
<p>All you need is the CSS and JavaScript on your page then attach it to something like this;</p>
<pre class="qoate-code">
$(textarea).charCount(100);
</pre>
<p>Visit the <a href="http://tomcoote.co.uk/wp-content/CodeBank/Demos/CharCount/index.html">demo page</a> to have a go or <a href="http://tomcoote.co.uk/wp-content/CodeBank/Downloads/jQuery_charCount_1_1.zip">download the source</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomcoote.co.uk/javascript/input-character-counter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Daily Windows PostgreSQL Backups</title>
		<link>http://tomcoote.co.uk/database/daily-windows-postgresql-backups/</link>
		<comments>http://tomcoote.co.uk/database/daily-windows-postgresql-backups/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 21:12:44 +0000</pubDate>
		<dc:creator>Tom Coote</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://tomcoote.co.uk/?p=560</guid>
		<description><![CDATA[
			
				
			
		
Recently I installed PostgreSQL on a Windows 2003 server. I also wanted to back up one of the PostgreSQL databases to a folder on the server on a daily basis as an extra precautionary measure. PostgreSQL comes with a program called pg_dump which can be used to create a back up of a database. You [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px; margin-top:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftomcoote.co.uk%2Fdatabase%2Fdaily-windows-postgresql-backups%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftomcoote.co.uk%2Fdatabase%2Fdaily-windows-postgresql-backups%2F&amp;source=cootetom&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Recently I installed PostgreSQL on a Windows 2003 server. I also wanted to back up one of the PostgreSQL databases to a folder on the server on a daily basis as an extra precautionary measure. PostgreSQL comes with a program called pg_dump which can be used to create a back up of a database. You give it the database to back up, the file to back up to and it does all the work for you.</p>
<p>The extra work needed here is to back up to a file name that differs each day so that you can have a folder of back ups per day. It would be handy for pg_dump to generate a file name based on date but it doesn&#8217;t. So I created a batch file to do the job in one go including a file name based on the date.</p>
<pre class="qoate-code">
@echo off
set date=%date:/=_%
set BACKUP_FILE=D:\PostgreSQL_Backups\DBName\DBName_%date%.backup
pg_dump -h localhost -p 5432 -U postgres -F p -b -v -f %BACKUP_FILE% DBName
</pre>
<p>Then I created a Windows task scheduled to run daily which just runs the above batch file.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomcoote.co.uk/database/daily-windows-postgresql-backups/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Ajax HTML5 in IE</title>
		<link>http://tomcoote.co.uk/javascript/ajax-html5-in-ie/</link>
		<comments>http://tomcoote.co.uk/javascript/ajax-html5-in-ie/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 20:31:25 +0000</pubDate>
		<dc:creator>Tom Coote</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://tomcoote.co.uk/?p=531</guid>
		<description><![CDATA[
			
				
			
		
We have recently moved towards the use of HTML 5 at my work. For those who have done the same you will already know of the extra work you need to do before HTML 5 will work in Internet Explorer browsers. The way we did it, which is probably the way most people do it, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px; margin-top:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftomcoote.co.uk%2Fjavascript%2Fajax-html5-in-ie%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftomcoote.co.uk%2Fjavascript%2Fajax-html5-in-ie%2F&amp;source=cootetom&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>We have recently moved towards the use of HTML 5 at my work. For those who have done the same you will already know of the extra work you need to do before HTML 5 will work in Internet Explorer browsers. The way we did it, which is probably the way most people do it, was to add the <a href="http://code.google.com/p/html5shiv/">html5shiv</a> script onto the web page if IE browsers are being used. This script will get you up and running unless you need to AJAX HTML 5 content into the page. That content will not get parsed and so will not behave properly. The answer to that is another script called <a href="http://jdbartlett.github.com/innershiv/">innershiv</a> which provides a function to pass HTML 5 content to and receive that content back parsed ready for IE browsers.</p>
<p>Both of these scripts are really useful and for most people they are pretty much the difference between making use of HTML 5 or not. The one problem that remains is all the extra work needed to run HTML content through the innershiv function at the end of every single AJAX request in IE browsers. It&#8217;s a lot of work! So for those of you who use jQuery I can show you how to tell jQuery to run all content from AJAX requests through innershiv automatically for IE so that you don&#8217;t have to do any more coding than you normally would. </p>
<pre class="qoate-code">
&lt;!--[if lt IE 9]&gt;
&lt;script type="text/javascript"&gt;
jQuery.ajaxSetup({
	dataFilter: function(data, dataType) {
		if (typeof innerShiv === 'function' &#038;&#038; dataType === 'html') {
			return innerShiv(data);
		}
		else {
			return data;
		}
	}
});
&lt;/script&gt;
&lt;![endif]--&gt;
</pre>
<p>This script will work if the browser version is IE8 or lower and relies on jQuery, html5shiv and innershiv all being on the page. </p>
<p>I haven&#8217;t tested this code a great deal so far, it&#8217;s something I built today. It appears to work very well on the web site I&#8217;m currently building. All comments welcome as always!  </p>
]]></content:encoded>
			<wfw:commentRss>http://tomcoote.co.uk/javascript/ajax-html5-in-ie/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

