<?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>copyandwaste</title>
	<atom:link href="http://www.copyandwaste.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.copyandwaste.com</link>
	<description></description>
	<lastBuildDate>Fri, 06 Jan 2012 21:09:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Installing Hubot as a Campfire bot on Ubuntu 10.04.2</title>
		<link>http://www.copyandwaste.com/2012/01/06/installing-hubot-as-a-campfire-bot-on-ubuntu-10-04-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=installing-hubot-as-a-campfire-bot-on-ubuntu-10-04-2</link>
		<comments>http://www.copyandwaste.com/2012/01/06/installing-hubot-as-a-campfire-bot-on-ubuntu-10-04-2/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 21:09:03 +0000</pubDate>
		<dc:creator>Andrew Konkol</dc:creator>
				<category><![CDATA[SysAdmin]]></category>
		<category><![CDATA[campfire]]></category>
		<category><![CDATA[hubot]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.copyandwaste.com/?p=420</guid>
		<description><![CDATA[sudo apt-get install python-software-properties sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update sudo apt-get install nodejs nodejs-dev redis-server #check to see if node installed node -v #install npm curl http://npmjs.org/install.sh &#124; sudo sh #verify npm install npm -v cd /tmp git clone https://github.com/github/hubot.git cd hubot npm install sudo npm install -g coffee-script make test sudo cp -R [...]]]></description>
			<content:encoded><![CDATA[<pre>sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js

sudo apt-get update
sudo apt-get install nodejs nodejs-dev redis-server

#check to see if node installed
node -v

#install npm
curl http://npmjs.org/install.sh | sudo sh

#verify npm install
npm -v

cd /tmp

git clone https://github.com/github/hubot.git
cd hubot
npm install
sudo npm install -g coffee-script
make test

sudo cp -R /tmp/hubot /etc/.

export PATH="/etc/hubot/bin:$PATH"
export HUBOT_CAMPFIRE_TOKEN="&lt;YOUR_BOTS_CAMPFIRE_API_TOKEN&gt;"
export HUBOT_CAMPFIRE_ROOMS="&lt;YOUR_CAMPFIRE_ROOM_NUMBER&gt;"
export HUBOT_CAMPFIRE_ACCOUNT="&lt;YOUR_CAMPFIRE_SUBDOMAIN&gt;"

hubot -a campfire -n &lt;YOUR_BOTS_CAMPFIRE_ACCOUNT_NAME&gt; &amp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.copyandwaste.com/2012/01/06/installing-hubot-as-a-campfire-bot-on-ubuntu-10-04-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiprocessing SNMP with Python</title>
		<link>http://www.copyandwaste.com/2011/10/13/multiprocessing-snmp-with-python/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=multiprocessing-snmp-with-python</link>
		<comments>http://www.copyandwaste.com/2011/10/13/multiprocessing-snmp-with-python/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 15:14:29 +0000</pubDate>
		<dc:creator>Andrew Konkol</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[SysAdmin]]></category>

		<guid isPermaLink="false">http://www.copyandwaste.com/?p=406</guid>
		<description><![CDATA[I&#8217;ve written a ton of snmp monitoring scripts and they all suck because they are blocking and take &#8220;too long&#8221; to return results for a large amount of hosts. So how would we make this process faster and make us happier? multiprocessing is a package that supports spawning processes using an API similar to the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written a ton of snmp monitoring scripts and they all suck because they are blocking and take &#8220;too long&#8221; to return results for a large amount of hosts. So how would we make this process faster and make us happier?</p>
<blockquote><p><a href="http://docs.python.org/library/multiprocessing.html"><strong>multiprocessing</strong></a> is a package that supports spawning processes using an API similar to the threading module. The multiprocessing package offers both local and remote concurrency, effectively side-stepping the Global Interpreter Lock by using subprocesses instead of threads. Due to this, the multiprocessing module allows the programmer to fully leverage multiple processors on a given machine. It runs on both Unix and Windows.</p></blockquote>
<p>IBM has published a wonderful article on <a href="http://www.ibm.com/developerworks/aix/library/au-multiprocessing/">Multiprocessing with Python</a> in which I have modified their snippets for my purposes below.</p>
<p>To leverage <a href="http://www.net-snmp.org/">NetSNMP</a> in python you need to compile it with python modules, I wrote a post about this yesterday in <a href="http://www.copyandwaste.com/2011/10/12/compiling-netsnmp-for-ubuntu-with-python-bindings/">Compiling Netsnmp for Ubuntu.</a> After battling through the compiling bit you should be able to get the example in the IBM post to work. I modified this example *slightly* to accommodate instance identifier (iid).  Hopefully this will be suitable for a new project I&#8217;m working on which polls thousands of snmp oids to measure latency between routers using the concept I posted on hatch &#8211; <strong><strong><a href="http://hatch.use.io/generate/configure-rtrsla-ping-in-ios/">Configure RTR/SLA Ping in IOS template.</a></strong></strong></p>
<p>&nbsp;</p>
<pre class="brush:python">!/usr/bin/env python
"""
This is a multiprocessing wrapper for Net-SNMP.
This makes a synchronous API asynchronous by combining
it with Python2.6
"""

import netsnmp
from multiprocessing import Process, Queue, current_process

class HostRecord():
    """This creates a host record"""
    def __init__(self,
                 hostname = None,
                 query = None):
        self.hostname = hostname
        self.query = query

class SnmpSession():
    """A SNMP Session"""
    def __init__(self,
                oid = "sysDescr",
                iid="0",
                Version = 2,
                DestHost = "localhost",
                Community = "public",
                Verbose = True,
                ):
        self.oid = oid
        self.Version = Version
        self.DestHost = DestHost
        self.Community = Community
        self.Verbose = Verbose
        self.var = netsnmp.Varbind(oid, iid)
        self.hostrec = HostRecord()
        self.hostrec.hostname = self.DestHost

    def query(self):
        """Creates SNMP query

        Fills out a Host Object and returns result
        """
        try:
            result = netsnmp.snmpget(self.var,
                                Version = self.Version,
                                DestHost = self.DestHost,
                                Community = self.Community)
            self.hostrec.query = result
        except Exception, err:
            if self.Verbose:
                print err
            self.hostrec.query = None
        finally:
            return self.hostrec

def make_query(host):
    """This does the actual snmp query

    This is a bit fancy as it accepts both instances
    of SnmpSession and host/ip addresses.  This
    allows a user to customize mass queries with
    subsets of different hostnames and community strings
    """
    if isinstance(host,SnmpSession):
        return host.query()
    else:
        s = SnmpSession(DestHost=host)
        return s.query()

# Function run by worker processes
def worker(input, output):
    for func in iter(input.get, 'STOP'):
        result = make_query(func)
        output.put(result)

def main():
    """Runs everything"""

    #clients
    hosts = [
    SnmpSession(DestHost="10.71.1.1", Community="my-pub-community", oid="1.3.6.1.4.1.9.9.42.1.2.10.1.1", iid="1"),
    SnmpSession(DestHost="10.81.1.1", Community="my-pub-community", oid="1.3.6.1.4.1.9.9.42.1.2.10.1.1", iid="123")
    ]
    NUMBER_OF_PROCESSES = len(hosts)

    # Create queues
    task_queue = Queue()
    done_queue = Queue()

    #submit tasks
    for host in hosts:
        task_queue.put(host)

    #Start worker processes
    for i in range(NUMBER_OF_PROCESSES):
        Process(target=worker, args=(task_queue, done_queue)).start()

     # Get and print results
    print 'Unordered results:'
    for i in range(len(hosts)):
        print '\t', done_queue.get().query

    # Tell child processes to stop
    for i in range(NUMBER_OF_PROCESSES):
        task_queue.put('STOP')
        #print "Stopping Process #%s" % i

if __name__ == "__main__":
    main()</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.copyandwaste.com/2011/10/13/multiprocessing-snmp-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compiling Netsnmp for Ubuntu with Python Bindings</title>
		<link>http://www.copyandwaste.com/2011/10/12/compiling-netsnmp-for-ubuntu-with-python-bindings/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=compiling-netsnmp-for-ubuntu-with-python-bindings</link>
		<comments>http://www.copyandwaste.com/2011/10/12/compiling-netsnmp-for-ubuntu-with-python-bindings/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 19:39:35 +0000</pubDate>
		<dc:creator>Andrew Konkol</dc:creator>
				<category><![CDATA[SysAdmin]]></category>

		<guid isPermaLink="false">http://www.copyandwaste.com/?p=403</guid>
		<description><![CDATA[apt-get install gcc apt-get install libperl-dev apt-get install python2.7-dev Download the netsnmp source: wget http://downloads.sourceforge.net/project/net-snmp/net-snmp/5.7.1/net-snmp-5.7.1.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fnet-snmp%2Ffiles%2Fnet-snmp%2F5.7.1%2F&#38;ts=1318446955&#38;use_mirror=surfnet tar xzvf net-snmp-5.7.1.tar.gz cd net-snmp-5.7.1 ./configure &#8211;with-python-modules Answer the questions make make install ldconfig akonkol@cmg005:/home/akonkol/net-snmp-5.7.1# python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type &#8220;help&#8221;, &#8220;copyright&#8221;, &#8220;credits&#8221; or &#8220;license&#8221; for more information. &#62;&#62;&#62; import netsnmp &#62;&#62;&#62;]]></description>
			<content:encoded><![CDATA[<p>apt-get install gcc<br />
apt-get install libperl-dev<br />
apt-get install python2.7-dev</p>
<p><a href="http://downloads.sourceforge.net/project/net-snmp/net-snmp/5.7.1/net-snmp-5.7.1.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fnet-snmp%2Ffiles%2Fnet-snmp%2F5.7.1%2F&amp;ts=1318446955&amp;use_mirror=surfnet">Download the netsnmp source</a>:</p>
<p>wget http://downloads.sourceforge.net/project/net-snmp/net-snmp/5.7.1/net-snmp-5.7.1.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fnet-snmp%2Ffiles%2Fnet-snmp%2F5.7.1%2F&amp;ts=1318446955&amp;use_mirror=surfnet<br />
tar xzvf net-snmp-5.7.1.tar.gz<br />
cd net-snmp-5.7.1</p>
<p>./configure &#8211;with-python-modules</p>
<p>Answer the questions</p>
<p>make</p>
<p>make install</p>
<p>ldconfig</p>
<p>akonkol@cmg005:/home/akonkol/net-snmp-5.7.1# python<br />
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)<br />
[GCC 4.5.2] on linux2<br />
Type &#8220;help&#8221;, &#8220;copyright&#8221;, &#8220;credits&#8221; or &#8220;license&#8221; for more information.<br />
&gt;&gt;&gt; import netsnmp<br />
&gt;&gt;&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.copyandwaste.com/2011/10/12/compiling-netsnmp-for-ubuntu-with-python-bindings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating Share Buttons for Twitter, Facebook, and Linkedin using Django Templatetags</title>
		<link>http://www.copyandwaste.com/2011/08/22/creating-share-buttons-for-twitter-facebook-and-linkedin-using-django-templatetags/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=creating-share-buttons-for-twitter-facebook-and-linkedin-using-django-templatetags</link>
		<comments>http://www.copyandwaste.com/2011/08/22/creating-share-buttons-for-twitter-facebook-and-linkedin-using-django-templatetags/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 19:50:17 +0000</pubDate>
		<dc:creator>Andrew Konkol</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.copyandwaste.com/?p=386</guid>
		<description><![CDATA[It&#8217;s easy to copy and paste urls to share links, but its easier to just click on a button to do it. The way I decided to do it was to write a custom django templatetag. The template tag exists in myproject/myapp/templatetags/sharebuttons.py. You can use the pre-built template here Usage in a template: {% load [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s easy to copy and paste urls to share links, but its easier to just click on a button to do it.  The way I decided to do it was to write a custom <a href="https://docs.djangoproject.com/en/1.1/howto/custom-template-tags/">django templatetag</a>.  The template tag exists in  myproject/myapp/templatetags/sharebuttons.py.</p>
<p>You can use the pre-built template <a href="http://hatch.use.io/generate/create-share-buttons-using-django-templatetags/">here</a></p>
<p><b>Usage in a template:</b></p>
<pre>
{% load sharebuttons %}

{% for p in posts %}
   {% sharebutton p "twitter" %}
   {% sharebutton p "facebook" %}
   {% sharebutton p "linkedin" %}
{% endfor %}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.copyandwaste.com/2011/08/22/creating-share-buttons-for-twitter-facebook-and-linkedin-using-django-templatetags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tweeting from a Django Application</title>
		<link>http://www.copyandwaste.com/2011/08/17/tweeting-from-a-django-application/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tweeting-from-a-django-application</link>
		<comments>http://www.copyandwaste.com/2011/08/17/tweeting-from-a-django-application/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 15:53:29 +0000</pubDate>
		<dc:creator>Andrew Konkol</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Nothing]]></category>
		<category><![CDATA[SysAdmin]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.copyandwaste.com/?p=383</guid>
		<description><![CDATA[It&#8217;s easy to get your application to start setting twitter status updates in django. Create a twitter account twitter.com Create a twitter &#8220;application&#8217; and get your keys dev.twitter.com/apps Click on &#8220;settings&#8221; and set the access to read and write easy_install python-twitter Use this template Whenever you save a &#8220;Post&#8221; object, the def send_tweet method will [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s easy to get your application to start setting twitter status updates  in django.</p>
<ol>
<li>Create a twitter account <a href="http://www.twitter.com">twitter.com</a></li>
<li>Create a twitter &#8220;application&#8217; and get your keys <a href="https://dev.twitter.com/apps">dev.twitter.com/apps</a></li>
<li>Click on &#8220;settings&#8221; and set the access to read and write</li>
<li>easy_install python-twitter
<li>Use this <a href="http://hatch.use.io/generate/tweeting-from-a-django-application/">template</a></li>
</ol>
<p>Whenever you save a &#8220;Post&#8221; object, the def send_tweet method will attempt to tweet a message containing the name of the object as well as the absolute url.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.copyandwaste.com/2011/08/17/tweeting-from-a-django-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Javascript/Jquery Regex with match groups</title>
		<link>http://www.copyandwaste.com/2011/08/09/using-javascriptjquery-regex-with-match-groups/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-javascriptjquery-regex-with-match-groups</link>
		<comments>http://www.copyandwaste.com/2011/08/09/using-javascriptjquery-regex-with-match-groups/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 19:40:09 +0000</pubDate>
		<dc:creator>Andrew Konkol</dc:creator>
				<category><![CDATA[Nothing]]></category>
		<category><![CDATA[SysAdmin]]></category>

		<guid isPermaLink="false">http://www.copyandwaste.com/?p=374</guid>
		<description><![CDATA[I&#8217;m building custom syntax/markup for an editor I am building. The particular markup would look something like this: %[--- This is part of the /etc/apache2/sites-available/example.com ---]% And I want to turn it into &#60;div class=&#34;filerule&#34;&#62;This is part of the /etc/apache2/sites-available/example.com&#60;/div&#62; So first I need to match: %[--- This is part of the /etc/apache2/sites-available/example.com ---]% And [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m building custom syntax/markup for an editor I am building.  The particular markup would look something like this:</p>
<pre class="brush:html">
%[--- This is part of the /etc/apache2/sites-available/example.com ---]%
</pre>
<p>And I want to turn it into </p>
<pre>
&lt;div class=&quot;filerule&quot;&gt;This is part of the /etc/apache2/sites-available/example.com&lt;/div&gt;
</pre>
<p>So first I need to match: %[--- This is part of the /etc/apache2/sites-available/example.com ---]%<br />
And then I need to match: This is part of the /etc/apache2/sites-available/example.com</p>
<p>The regex pattern would look like:</p>
<pre>
pattern = new RegExp('\\%\\[---(.+?)---\\]\\%','gi');
</pre>
<p>This entire pattern matches the whole line and the paranthesis define a match &#8220;group.&#8221;  When looking for this pattern you will find two matches one for the line ( %[--- This is part of the /etc/apache2/sites-available/example.com ---]%) and one for the text (This is part of the /etc/apache2/sites-available/example.com).</p>
<p>You reference these matches by $1, &#8230;,$n where n is the number of that group.</p>
<p>The entire line would be $0 where as the text being matched would be $1.</p>
<p><b>Javascript:</b></p>
<pre>
$(document).ready(function() {

        function CreateFileRulers(){
        var raw_text = $("#raw_text").text();
        pattern = new RegExp('\\%\\[---(.+?)---\\]\\%','gi');
        raw_text = raw_text.replace(pattern,"
<div class=\"filerule\">--- $1 ---</div>

");
        $("#raw_text").html(raw_text);
        }
        CreateFileRulers();

});
</pre>
<p><b>html:</b></p>
<pre>
&lt;div id=&quot;raw_text&quot;&gt;
%[--- This is part of the /etc/apache2/sites-available/example.com ---]%
&lt;/div&gt;
</pre>
<p>After document ready the <b>html:</b></p>
<pre>
&lt;div id=&quot;raw_text&quot;&gt;
&lt;div class=&quot;filerule&quot;--- This is part of the /etc/apache2/sites-available/example.com ---&lt;/div&gt;
&lt;/div&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.copyandwaste.com/2011/08/09/using-javascriptjquery-regex-with-match-groups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jquery UI Autocomplete 1.8 with Django Views</title>
		<link>http://www.copyandwaste.com/2011/08/03/jquery-ui-autocomplete-1-8-with-django-views/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jquery-ui-autocomplete-1-8-with-django-views</link>
		<comments>http://www.copyandwaste.com/2011/08/03/jquery-ui-autocomplete-1-8-with-django-views/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 13:52:13 +0000</pubDate>
		<dc:creator>Andrew Konkol</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.copyandwaste.com/?p=331</guid>
		<description><![CDATA[I have a model named &#8220;Show&#8221; and it has a ForeignKey to a model named &#8220;Venue.&#8221; When users add a &#8220;Show&#8221; I wanted an autocomplete(d) field venue. This solution uses: jquery-1.6.1.min.js jquery-ui.min.js models.py class Venue(models.Model): name = models.CharField(max_length=255, blank=False, null=False, help_text="Name of the venue") class Show(models.Model): date = models.DateTimeField(blank=False, null=False) venue = models.ForeignKey(Venue) headliner = [...]]]></description>
			<content:encoded><![CDATA[<p>I have a model named &#8220;Show&#8221; and it has a ForeignKey to a model named &#8220;Venue.&#8221;  When users add a &#8220;Show&#8221; I wanted an <a href="http://jqueryui.com/demos/autocomplete/#remote">autocomplete</a>(d) field venue.</p>
<p>This solution uses:</p>
<ul>
<li>jquery-1.6.1.min.js</li>
<li>jquery-ui.min.js</li>
</ul>
<p><b>models.py</b></p>
<pre class="brush:python">
class Venue(models.Model):
        name = models.CharField(max_length=255, blank=False, null=False, help_text="Name of the venue")

class Show(models.Model):
        date = models.DateTimeField(blank=False, null=False)
        venue = models.ForeignKey(Venue)
        headliner = models.ForeignKey(Artist, related_name="Headliner")
</pre>
<p><b>urls.py</b></p>
<pre class="brush:python">
(r'venue_lookup/$','projname.appname.views.venue_lookup'),
</pre>
<p><b>views.py</b></p>
<pre class="brush:python">
def venue_lookup(request):
   venues = Venue.objects.filter(name__istartswith=request.REQUEST['term'])
   results = []
   for venue in venues:
      venue_dict = {'id':venue.id, 'label':venue.name, 'value':venue.name}
      results.append(venue_dict)
   return HttpResponse(simplejson.dumps(results),mimetype='application/json')
</pre>
<p><strong>Template:</strong></p>
<pre>
&lt;html&gt;
&lt;head&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/media/jquery-1.6.2.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/media/jquery-ui.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
        $( &quot;#id_venue&quot; ).autocomplete({
           source: &quot;/venue_lookup/&quot;,
           selectFirst:true,
           minLength:2
        });

&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form method=&quot;post&quot; action=&quot;/shows/new&quot;&gt;
        &lt;p&gt;&lt;label for=&quot;id_venue&quot;&gt;Venue&lt;/label&gt;
        &lt;input type=&quot;text&quot; id=&quot;id_venue&quot; name=&quot;venue&quot; /&gt;&lt;/p&gt;
	&lt;input type=&quot;submit&quot; value=&quot;done&quot; /&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.copyandwaste.com/2011/08/03/jquery-ui-autocomplete-1-8-with-django-views/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Indexing Multi-value fields from django-tagging in Haystack</title>
		<link>http://www.copyandwaste.com/2011/07/22/indexing-multi-value-fields-from-django-tagging-in-haystack/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=indexing-multi-value-fields-from-django-tagging-in-haystack</link>
		<comments>http://www.copyandwaste.com/2011/07/22/indexing-multi-value-fields-from-django-tagging-in-haystack/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 16:27:12 +0000</pubDate>
		<dc:creator>Andrew Konkol</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[SysAdmin]]></category>

		<guid isPermaLink="false">http://www.copyandwaste.com/?p=326</guid>
		<description><![CDATA[Enabling tagging on models is easy when you use django-tagging. However, I also have a search feature which is powered by Haystack and Whoosh. I wanted to be able to search for objects by the tags that are associated with them. You need to use the following in your haystack SearchIndex model: tags = indexes.MultiValueField(indexed=True, [...]]]></description>
			<content:encoded><![CDATA[<p>Enabling tagging on models is easy when you use django-tagging.  However, I also have a search feature which is powered by Haystack and Whoosh.  I wanted to be able to search for objects by the tags that are associated with them.  You need to use the following in your haystack SearchIndex model:</p>
<pre>
tags = indexes.MultiValueField(indexed=True, stored=True)
</pre>
<h2>Full Example</h2>
<p><b>myproject/myapp/models.py</b></p>
<pre class="brush:python">
from django.db import models,
from tagging.fields import TagField
class Template(models.Model):
        name = models.CharField(max_length=100)
        pub_date = models.DateTimeField(editable=False, blank=True)
        description = models.TextField(blank=True)
        slug = models.SlugField(unique=True,editable=False,blank=True,null=True)
        tags = TagField()
</pre>
<p><b>myproject/myapp/search_indexes.py</b></p>
<pre class="brush:python">
import datetime
from haystack import indexes
from generator.models import Template

class TemplateIndex(indexes.RealTimeSearchIndex):
    text = indexes.CharField(document=True, use_template=True)
    name = indexes.CharField(model_attr='name')
    description = indexes.CharField(model_attr='description')
    pub_date = indexes.DateTimeField(model_attr='pub_date')
    tags = indexes.MultiValueField(indexed=True, stored=True)

    def get_model(self):
        return Template

    def index_queryset(self):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(pub_date__lte=datetime.datetime.now())
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.copyandwaste.com/2011/07/22/indexing-multi-value-fields-from-django-tagging-in-haystack/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>django-registration Require a unique email address for registration</title>
		<link>http://www.copyandwaste.com/2011/07/20/django-registration-require-a-unique-email-address-for-registration/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=django-registration-require-a-unique-email-address-for-registration</link>
		<comments>http://www.copyandwaste.com/2011/07/20/django-registration-require-a-unique-email-address-for-registration/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 19:06:57 +0000</pubDate>
		<dc:creator>Andrew Konkol</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[SysAdmin]]></category>

		<guid isPermaLink="false">http://www.copyandwaste.com/?p=321</guid>
		<description><![CDATA[Everyone uses django-registration for&#8230; registration&#8230; however.. you may get this error: TypeError at /accounts/register/ register() takes at least 2 non-keyword arguments (1 given) Here&#8217;s what your urls.py should look like for the /accounts/register/ url: urls.py from django.conf.urls.defaults import * from registration.forms import RegistrationFormUniqueEmail urlpatterns = patterns('', (r'^accounts/register/', 'registration.views.register', {'form_class':RegistrationFormUniqueEmail,'backend':'registration.backends.default.DefaultBackend' }), )]]></description>
			<content:encoded><![CDATA[<p>Everyone uses django-registration for&#8230; registration&#8230; however.. you may get this error:</p>
<blockquote><p>
TypeError at /accounts/register/</p>
<p>register() takes at least 2 non-keyword arguments (1 given)
</p></blockquote>
<p>Here&#8217;s what your urls.py should look like for the /accounts/register/ url:</p>
<p><b>urls.py</b></p>
<pre class="brush:python">
from django.conf.urls.defaults import *
from registration.forms import RegistrationFormUniqueEmail

urlpatterns = patterns('',
     (r'^accounts/register/', 'registration.views.register', {'form_class':RegistrationFormUniqueEmail,'backend':'registration.backends.default.DefaultBackend' }),
)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.copyandwaste.com/2011/07/20/django-registration-require-a-unique-email-address-for-registration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unique Slugs for Django Objects</title>
		<link>http://www.copyandwaste.com/2011/07/20/unique-slugs-for-django-objects/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=unique-slugs-for-django-objects</link>
		<comments>http://www.copyandwaste.com/2011/07/20/unique-slugs-for-django-objects/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 18:30:50 +0000</pubDate>
		<dc:creator>Andrew Konkol</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[SysAdmin]]></category>

		<guid isPermaLink="false">http://www.copyandwaste.com/?p=312</guid>
		<description><![CDATA[I&#8217;m working on a new project and decided to use slugs to access object information.  The built-in in &#8220;slugify&#8221; does not generate unique slugs for objects, but I found a solution. Overriding the save method allows us to check to see if there are any other objects which have the same slug such as &#8220;how-to-make-a-table&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a new project and decided to use slugs to access object information.  The built-in in &#8220;slugify&#8221; does not generate unique slugs for objects, but I found a <a href="http://djangosnippets.org/snippets/761/">solution</a>.  Overriding the save method allows us to check to see if there are any other objects which have the same slug such as &#8220;how-to-make-a-table&#8221; and if there are we append a number to it such as &#8220;how-to-make-a-table-2.&#8221; Below is a real-world example of a model &#8220;Project&#8221; which has pretty typical fields in it and the code to generate a unique slug.</p>
<p><b>file: /myproject/myapp/models.py</p>
<pre class="brush:python">
from django.contrib.auth.models import User
from sorl.thumbnail import ImageField
import datetime
import re

class Project(models.Model):
        title = models.CharField(max_length=255,blank=True)
        description = models.TextField(blank=True)
        photo = ImageField(upload_to=get_project_upload_path, blank=True, null=True)
        author = models.ForeignKey(User, editable=False,blank=True, null=True)
        pub_date = models.DateTimeField(editable=False, blank=True)
        slug = models.SlugField(unique=True,blank=True)

        def save(self, *args, **kwargs):
		#set pub_date as right now
                self.pub_date=datetime.datetime.now()

		#As long as this object does NOT have a slug
                if not self.slug:
                   from django.template.defaultfilters import slugify

		   #Take the title and replace spaces with hypens, make lowercase
                   potential_slug = slugify(self.title)
                   self.slug = potential_slug

                   while True:
                      try:
			 #try to save the object
                         super(Project, self).save(*args, **kwargs)

		      #if this slug already exists we get an error
                      except IntegrityError:
			 #match the slug or look for a trailing number
                         match_obj = re.match(r'^(.*)-(\d+)$', self.slug)

			 #if we find a match
                         if match_obj:
			    #take the found number and increment it by 1
                            next_int = int(match_obj.group(2)) + 1
                            self.slug = match_obj.group(1) + "-" + str(next_int)
                         else:
			    #There are no matches for <slug>-# so create one with -2
                            self.slug += '-2'
		      #different error than IntegrityError
                      else:
                         break

        def __unicode__(self):
                return self.title
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.copyandwaste.com/2011/07/20/unique-slugs-for-django-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

