<?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>kueda.net &#187; code</title>
	<atom:link href="http://kueda.net/blog/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://kueda.net</link>
	<description>I'm Back</description>
	<lastBuildDate>Thu, 02 Feb 2012 19:42:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Deleting Unversioned SVN Files</title>
		<link>http://kueda.net/blog/2008/09/19/deleting-unversioned-svn-files/</link>
		<comments>http://kueda.net/blog/2008/09/19/deleting-unversioned-svn-files/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 05:47:39 +0000</pubDate>
		<dc:creator>Ken-ichi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://kueda.net/?p=216</guid>
		<description><![CDATA[Here&#8217;s a silly bash trick that will delete all unversioned SVN files svn st &#124; grep &#34;^?&#34; &#124; sed s/?&#91;&#91;:space:&#93;&#93;*// &#124; xargs rm -rf Use with care, obviously. If there&#8217;s a more concise method, please let me know. And here&#8217;s how you might use similar commands to apply fmresolve to all conflicted files, and then [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a silly bash trick that will delete all unversioned SVN files</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> st <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^?&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> s<span style="color: #000000; font-weight: bold;">/</span>?<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>:space:<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">*//</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span></pre></div></div>

<p>Use with care, obviously.  If there&#8217;s a more concise method, please let me know.</p>
<p>And here&#8217;s how you might use similar commands to apply <code>fmresolve</code> to all conflicted files, and then resolve them.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> f <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">svn</span> st <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^C&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> s<span style="color: #000000; font-weight: bold;">/</span>C<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>:space:<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">*//</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> fmresolve <span style="color: #007800;">$f</span>; <span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> st <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^C&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> s<span style="color: #000000; font-weight: bold;">/</span>C<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>:space:<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">*//</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">svn</span> resolved</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://kueda.net/blog/2008/09/19/deleting-unversioned-svn-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Active Record Model Adapters</title>
		<link>http://kueda.net/blog/2008/09/09/active-record-model-adapters/</link>
		<comments>http://kueda.net/blog/2008/09/09/active-record-model-adapters/#comments</comments>
		<pubDate>Tue, 09 Sep 2008 22:32:25 +0000</pubDate>
		<dc:creator>Ken-ichi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[designpatterns]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://kueda.net/?p=208</guid>
		<description><![CDATA[I recently refactored some code in iNaturalist that fetches taxon names from external name providers like uBio and the Catalogue of Life. They return names and classification data that are similar but (of course) not identical to ActiveRecord models we use in iNat, so I figured I&#8217;d write adapters for them, and I thought a [...]]]></description>
			<content:encoded><![CDATA[<p>I recently refactored some code in <a href="http://inaturalist.org">iNaturalist</a> that fetches taxon names from external name providers like <a href="http://ubio.org">uBio</a> and the <a href="http://catalogueoflife.org">Catalogue of Life</a>.  They return names and classification data that are similar but (of course) not identical to ActiveRecord models we use in iNat, so I figured I&#8217;d write adapters for them, and I thought a really smart solution would be to subclass the models themselves, simply overriding the attributes with getters that mined a private instance variable holding an XML response from one of the web services.  Big mistake.  ActiveRecord mixes in all kinds of magic into the models that doesn&#8217;t necessarily get passed on to child classes.  I ran into all sorts of fun errors and problems until I remembered the Adapter implementation described <a href="http://www.scribd.com/doc/396559/gof-patterns-in-ruby">here</a>, which takes a much more sensible approach: don&#8217;t sublcass, and instead hold an internal copy of the adaptee, passing calls to anything you don&#8217;t want to override to the adaptee.</p>
<p><span id="more-208"></span>The only real &#8220;gotcha&#8221; is that <code>ActiveRecord::Base</code> overrides some of <code>Object</code>&#8216;s methods, so you need to delegate those to the adaptee as well.  I just delegated them all, though there may be some unforeseen consequences in this, I don&#8217;t know.</p>
<p>Anyway, here&#8217;s my solution: a model adapter module:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># Module for ActiveRecord model adapters.</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># Usage:</span>
<span style="color:#008000; font-style:italic;">#   class YourModelAdapter</span>
<span style="color:#008000; font-style:italic;">#     include ModelAdapter</span>
<span style="color:#008000; font-style:italic;">#     alias :your_model :adaptee # optional</span>
<span style="color:#008000; font-style:italic;">#     </span>
<span style="color:#008000; font-style:italic;">#     def initialize</span>
<span style="color:#008000; font-style:italic;">#       @adaptee = YourModel.new # required!</span>
<span style="color:#008000; font-style:italic;">#     end</span>
<span style="color:#008000; font-style:italic;">#     </span>
<span style="color:#008000; font-style:italic;">#     def some_attribute</span>
<span style="color:#008000; font-style:italic;">#       do_something_different</span>
<span style="color:#008000; font-style:italic;">#     end</span>
<span style="color:#008000; font-style:italic;">#   end</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#9966CC; font-weight:bold;">module</span> ModelAdapter
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:adaptee</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>method, <span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@adaptee</span>.<span style="color:#9900CC;">respond_to</span>? method
      <span style="color:#0066ff; font-weight:bold;">@adaptee</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>method, <span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">NoMethodError</span>, <span style="color:#996600;">&quot;#{self.class} hasn't implemented #{method}&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Redirect calls to public methods in Object to the adaptee</span>
  <span style="color:#CC00FF; font-weight:bold;">Object</span>.<span style="color:#9900CC;">methods</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>method_name<span style="color:#006600; font-weight:bold;">|</span>
    define_method<span style="color:#006600; font-weight:bold;">&#40;</span>method_name.<span style="color:#9900CC;">to_sym</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|*</span>args<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#0066ff; font-weight:bold;">@adaptee</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>method_name.<span style="color:#9900CC;">to_sym</span>, <span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://kueda.net/blog/2008/09/09/active-record-model-adapters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git Cheatsheet</title>
		<link>http://kueda.net/blog/2008/09/02/git-cheatsheet/</link>
		<comments>http://kueda.net/blog/2008/09/02/git-cheatsheet/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 03:32:23 +0000</pubDate>
		<dc:creator>Ken-ichi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[scm]]></category>
		<category><![CDATA[version control]]></category>

		<guid isPermaLink="false">http://kueda.net/?p=117</guid>
		<description><![CDATA[It&#8217;s small, fast, and github is rad. So I am trying to learn it. # Setup git config --global --list git config --global user.name &#34;Ken-ichi&#34; git config --global user.email &#34;fortinbras@norway.net&#34; &#160; # The colors, children. Mm-hey git config --global color.diff auto git config --global color.status auto git config --global color.branch auto &#160; # Getting Info [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s small, fast, and github is rad.  So I am trying to learn it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Setup</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> config <span style="color: #660033;">--global</span> <span style="color: #660033;">--list</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> config <span style="color: #660033;">--global</span> user.name <span style="color: #ff0000;">&quot;Ken-ichi&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> config <span style="color: #660033;">--global</span> user.email <span style="color: #ff0000;">&quot;fortinbras@norway.net&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The colors, children.  Mm-hey</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> config <span style="color: #660033;">--global</span> color.diff auto
<span style="color: #c20cb9; font-weight: bold;">git</span> config <span style="color: #660033;">--global</span> color.status auto
<span style="color: #c20cb9; font-weight: bold;">git</span> config <span style="color: #660033;">--global</span> color.branch auto
&nbsp;
<span style="color: #666666; font-style: italic;"># Getting Info</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> remote <span style="color: #660033;">-v</span> <span style="color: #666666; font-style: italic;"># Display the remote repository URL</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> log <span style="color: #666666; font-style: italic;"># duh</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> show COMMIT <span style="color: #666666; font-style: italic;"># equivalent of svn log -r REV_NUM, but with diffs</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Committing</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> add .
<span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-a</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Amending</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-a</span> <span style="color: #660033;">--amend</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Reverting</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> reset <span style="color: #660033;">--hard</span> HEAD <span style="color: #666666; font-style: italic;"># revert everything to HEAD</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> checkout path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #666666; font-style: italic;"># reset a single file</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Checking out previous states</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> checkout COMMIT
<span style="color: #c20cb9; font-weight: bold;">git</span> checkout master <span style="color: #666666; font-style: italic;"># to get back</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Stashing</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> stash <span style="color: #666666; font-style: italic;"># stash changes on this branch so you can switch and work on something else</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> stash pop <span style="color: #666666; font-style: italic;"># bring back the stashed changes</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Pushing to another repos</span>
<span style="color: #666666; font-style: italic;"># could be local like /path/to/somewhere </span>
<span style="color: #666666; font-style: italic;"># or ssh://me@there.net/path/to/repos</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> push path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>repos
<span style="color: #c20cb9; font-weight: bold;">git</span> push origin master <span style="color: #666666; font-style: italic;"># if you cloned from a remote named origin</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># to switch origins</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> remote <span style="color: #c20cb9; font-weight: bold;">rm</span> origin
<span style="color: #c20cb9; font-weight: bold;">git</span> remote add origin <span style="color: #ff0000;">'path/to/a/bare/repo'</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># note that when sharing a repo with others, you will all want to push/pull from a *bare* repo made with </span>
<span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #660033;">--bare</span> path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>repo
<span style="color: #666666; font-style: italic;"># See http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#public-repositories</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Branching and merging</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> branch new_branch <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">git</span> checkout new_branch <span style="color: #666666; font-style: italic;"># make a new branch and switch to it</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> checkout <span style="color: #660033;">-b</span> new_branch <span style="color: #666666; font-style: italic;"># same as above</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> merge other_branch
<span style="color: #c20cb9; font-weight: bold;">git</span> mergetool <span style="color: #660033;">-t</span> opendiff <span style="color: #666666; font-style: italic;"># resolve conflicts in a merge with FileMerge</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://kueda.net/blog/2008/09/02/git-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.bashrc, .bash_profile, and cloning a remote git repository</title>
		<link>http://kueda.net/blog/2008/07/26/bashrc-bash_profile-and-cloning-a-remote-git-repository/</link>
		<comments>http://kueda.net/blog/2008/07/26/bashrc-bash_profile-and-cloning-a-remote-git-repository/#comments</comments>
		<pubDate>Sat, 26 Jul 2008 08:33:27 +0000</pubDate>
		<dc:creator>Ken-ichi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://kueda.net/?p=19</guid>
		<description><![CDATA[I&#8217;m just getting started with git.  Turns out if your git binaries are in a path specified in something like .bash_profile on your remote machine, something like git clone ssh://you.com/~you/repos.git will fail with an error like bash: git-upload-pack: command not found because sshd ignores .bash_profile, so git won&#8217;t find its binaries. So you need to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m just getting started with git.  Turns out if your git binaries are in a path specified in something like .bash_profile on your remote machine, something like <code>git clone ssh://you.com/~you/repos.git</code> will fail with an error like <code>bash: git-upload-pack: command not found</code> because sshd ignores .bash_profile, so git won&#8217;t find its binaries.  So you need to alter the PATH env var in .bashrc instead.  Fun.  The <a href="http://www.kernel.org/pub/software/scm/git/docs/v1.0.13/git-clone-pack.html">git-clone-pack</a> man page is worth a look.</p>
]]></content:encoded>
			<wfw:commentRss>http://kueda.net/blog/2008/07/26/bashrc-bash_profile-and-cloning-a-remote-git-repository/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending Existing Django ModelAdmin Classes</title>
		<link>http://kueda.net/blog/2008/07/25/extending-existing-django-modeladmin-classes/</link>
		<comments>http://kueda.net/blog/2008/07/25/extending-existing-django-modeladmin-classes/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 19:04:39 +0000</pubDate>
		<dc:creator>Ken-ichi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://kueda.net/?p=11</guid>
		<description><![CDATA[Django 1.0 is coming, and it&#8217;s bringing needed but backwards-incompatible changes to the admin site, ostensibly the best thing about Django.  One problem I&#8217;ve run into while migrating to the new version is inline editing of related classes in existing classes.  For example, it&#8217;s pretty common (and recommended) to &#8220;extend&#8221; Django&#8217;s built-in User model by [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.djangoproject.com/wiki/VersionOneRoadmap">Django 1.0 is coming</a>, and it&#8217;s bringing needed but backwards-incompatible changes to the admin site, ostensibly the best thing about Django.  One problem I&#8217;ve run into while migrating to the new version is inline editing of related classes in existing classes.  For example, it&#8217;s pretty common (and recommended) to &#8220;extend&#8221; Django&#8217;s built-in User model by creating your own, related Profile model.  For the old admin site, you specified the ability to edit a relate Profile in the User form in the Profile model:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> Profile<span style="color: black;">&#40;</span>models.<span style="color: black;">Model</span><span style="color: black;">&#41;</span>:
    <span style="color: #dc143c;">user</span> = models.<span style="color: black;">ForeignKey</span><span style="color: black;">&#40;</span>User, unique=<span style="color: #008000;">True</span>, edit_inline=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span></pre></div></div>

<p>That was simple, but kinda quirky.  Changing the way the User form looks by changing the related Profile model?  Weird.  BUT, it did let you make changes to the User model w/o mucking with the built in Django code.</p>
<p>The new way of doing things is to specify all your admin site options in a separate file, and inline editing is now a little more reasonable: if you want to edit related objects in a model&#8217;s form, you specify that in that model&#8217;s admin options.  But this means you need to alter Django&#8217;s built-in User model&#8217;s admin options, which could mean muckiness.  So here&#8217;s what I did in my <code>myapp/admin.py</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span> <span style="color: #ff7700;font-weight:bold;">import</span> admin
<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
<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> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> ProfileAdmin<span style="color: black;">&#40;</span>admin.<span style="color: black;">ModelAdmin</span><span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;"># just some stuff for my profile forms</span>
    filter_horizontal = <span style="color: black;">&#40;</span><span style="color: #483d8b;">'teams'</span>,<span style="color: black;">&#41;</span>
    radio_fields = <span style="color: black;">&#123;</span><span style="color: #483d8b;">'appointment'</span>: admin.<span style="color: black;">HORIZONTAL</span><span style="color: black;">&#125;</span>
    list_display = <span style="color: black;">&#40;</span><span style="color: #483d8b;">'user'</span>, <span style="color: #483d8b;">'picture'</span>, <span style="color: #483d8b;">'appointment'</span>, <span style="color: #483d8b;">'affiliation'</span><span style="color: black;">&#41;</span>
admin.<span style="color: #dc143c;">site</span>.<span style="color: black;">register</span><span style="color: black;">&#40;</span>Profile, ProfileAdmin<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># need to make an inline class...  ick</span>
<span style="color: #ff7700;font-weight:bold;">class</span> ProfileInline<span style="color: black;">&#40;</span>admin.<span style="color: black;">StackedInline</span><span style="color: black;">&#41;</span>:
    model = Profile
    max_num = <span style="color: #ff4500;">1</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># the meat: grab the existing UserAdmin class, modify it, unregister User,</span>
<span style="color: #808080; font-style: italic;"># and re-register User with the modified UserAdmin</span>
UserAdmin = admin.<span style="color: #dc143c;">site</span>._registry<span style="color: black;">&#91;</span>User<span style="color: black;">&#93;</span>.__class__
UserAdmin.<span style="color: black;">inlines</span> = <span style="color: black;">&#91;</span>ProfileInline,<span style="color: black;">&#93;</span>
admin.<span style="color: #dc143c;">site</span>.<span style="color: black;">unregister</span><span style="color: black;">&#40;</span>User<span style="color: black;">&#41;</span>
admin.<span style="color: #dc143c;">site</span>.<span style="color: black;">register</span><span style="color: black;">&#40;</span>User, UserAdmin<span style="color: black;">&#41;</span></pre></div></div>

<p>Took me a while to realize admin.site._registry held <em>instances</em> of the ModelAdmin classes, not the classes themselves.  This technique also assumes that User gets registered with the admin site <em>before</em> you run this code.  I&#8217;m guessing the order in which <code>admin.autodiscover()</code> registers models is the same as the <code>INSTALLED_APPS</code> setting in <code>settings.py</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://kueda.net/blog/2008/07/25/extending-existing-django-modeladmin-classes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rails Authenticity Tokens and Facebooker</title>
		<link>http://kueda.net/blog/2008/07/17/rails-authenticity-tokens-and-facebooker/</link>
		<comments>http://kueda.net/blog/2008/07/17/rails-authenticity-tokens-and-facebooker/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 18:36:36 +0000</pubDate>
		<dc:creator>Ken-ichi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebooker]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://kueda.net/?p=5</guid>
		<description><![CDATA[In case you&#8217;re working through Developing Facebook Platform Applications with Rails, you might have run into problems with authenticity tokens and FBML forms.  Quick dumb fix to save you 2 seconds: &#60;fb:fbml&#62; &#60;fb:request-form action=&#34;&#60;%= new_invitation_path %&#62;&#34; method=&#34;POST&#34; invite=&#34;true&#34; type=&#34;Karate Poke&#34; content=&#34;YAYS I added this facebbok app&#34;&#62; &#60;fb:multi-friend-selector showborder=&#34;false&#34; actiontext=&#34;Invite your friends to use Karate Poke&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>In case you&#8217;re working through <a href="http://www.pragprog.com/titles/mmfacer/developing-facebook-platform-applications-with-rails">Developing Facebook Platform Applications with Rails</a>, you might have run into <a href="http://rubyforge.org/pipermail/facebooker-talk/2008-June/thread.html#650">problems</a> with authenticity tokens and FBML forms.  Quick dumb fix to save you 2 seconds:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fb:fbml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fb:request-form</span></span>
<span style="color: #009900;">    <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;&lt;%= new_invitation_path %&gt;</span></span>&quot;
    method=&quot;POST&quot;
    invite=&quot;true&quot;
    type=&quot;Karate Poke&quot;
    content=&quot;YAYS I added this facebbok app&quot;&gt;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fb:multi-friend-selector</span></span>
<span style="color: #009900;">      <span style="color: #000066;">showborder</span>=<span style="color: #ff0000;">&quot;false&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">actiontext</span>=<span style="color: #ff0000;">&quot;Invite your friends to use Karate Poke&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;">&lt;%= hidden_field_tag :authenticity_token, form_authenticity_token %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fb:request-form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fb:fbml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://kueda.net/blog/2008/07/17/rails-authenticity-tokens-and-facebooker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

