<?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>treibsand.com &#187; Coding</title>
	<atom:link href="http://www.treibsand.com/tag/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.treibsand.com</link>
	<description></description>
	<lastBuildDate>Tue, 27 Dec 2011 12:46:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>has_many :through mit Checkboxen</title>
		<link>http://www.treibsand.com/2010/11/03/has_many-through-mit-checkboxen/</link>
		<comments>http://www.treibsand.com/2010/11/03/has_many-through-mit-checkboxen/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 16:04:34 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/?p=543</guid>
		<description><![CDATA[Nehmen wir an, wir haben eine Rails Applikation mit einer Many-to-Many Beziehung, bei welcher die Verknüpfungen über Checkboxen und nicht über Multiselect Listen oder ähnliches verwirklicht werden sollen. Die Umsetzung ist gar nicht mal so aufwändig&#8230;;-) Als Beispiel könnte man die Bestellung einer Pizza nehmen. Ein Kunde will eine Pizza über ein Formular bestellen. Im [...]]]></description>
			<content:encoded><![CDATA[<p><img class="linked-to-original" src="http://www.treibsand.com/wp-content/uploads/2010/06/rails-thumb.png" height="111" align="right" width="87" style=" display: inline; float: left; margin: 0 10px 10px 0;" />Nehmen wir an, wir haben eine Rails Applikation mit einer Many-to-Many Beziehung, bei welcher die Verknüpfungen über Checkboxen und nicht über Multiselect Listen oder ähnliches verwirklicht werden sollen. Die Umsetzung ist gar nicht mal so aufwändig&#8230;;-)</p>
<p>Als Beispiel könnte man die Bestellung einer Pizza nehmen. Ein Kunde will eine Pizza über ein Formular bestellen. Im Formular werden alle verfügbaren Beläge in einer Liste mit jeweils eine Checkbox dargestellt, so dass der Kunde einfach per Klick auf die Checkboxen die gewünschte Kombination auswählen kann.</p>
<p><span id="more-543"></span></p>
<p>Die Models würden dann wie folgt aussehen:</p>
<p><strong>app/models/pizza.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Pizza <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  has_many <span style="color:#ff3333; font-weight:bold;">:pizza_toppings</span>, <span style="color:#ff3333; font-weight:bold;">:dependent</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:destroy</span>
  has_many <span style="color:#ff3333; font-weight:bold;">:toppings</span>, <span style="color:#ff3333; font-weight:bold;">:through</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:pizza_toppings</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><strong>app/models/topping.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Topping <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  has_many <span style="color:#ff3333; font-weight:bold;">:pizza_toppings</span>, <span style="color:#ff3333; font-weight:bold;">:dependent</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:destroy</span> 
  has_many <span style="color:#ff3333; font-weight:bold;">:pizzas</span>, <span style="color:#ff3333; font-weight:bold;">:trhough</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:pizza_toppings</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><strong>app/models/pizza_topping.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> PizzaTopping <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  belongs_to <span style="color:#ff3333; font-weight:bold;">:Topping</span>
  belongs_to <span style="color:#ff3333; font-weight:bold;">:Pizza</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Nachdem die Beziehungen definiert sind können wir ohnen großen Aufwand die Beläge den Pizzen zuordnen:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> form_for <span style="color:#0066ff; font-weight:bold;">@pizza</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span> Topping.<span style="color:#9900CC;">all</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>topping<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    &lt;div&gt;
      <span style="color:#006600; font-weight:bold;">&lt;%</span>= check_box_tag <span style="color:#ff3333; font-weight:bold;">:topping_ids</span>, topping.<span style="color:#9900CC;">id</span>, <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'pizza[topping_ids][]'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
      <span style="color:#006600; font-weight:bold;">&lt;%</span>= label_tag <span style="color:#ff3333; font-weight:bold;">:topping_ids</span>, topping.<span style="color:#9900CC;">name</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    &lt;/div&gt;
  <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= submit_tag <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>Wenn das Formular abgeschickt wird, dann wird jeder ausgewählter Belag durch PizzaToppings mit der Pizza verknüpft. Sobald allerdings in einem gespeicherten Datensatz einmal alle Checkboxen abgewählt werden, dann wird das nicht an den Controller geposted. Dies kann man aber leicht im Controller fixen:</p>
<p><strong>app/controllers/pizza_controller.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@pizza</span>.<span style="color:#9900CC;">attributes</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">'topping_ids'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">merge</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:pizza</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2010/11/03/has_many-through-mit-checkboxen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kleine C-Übung</title>
		<link>http://www.treibsand.com/2010/07/02/kleine-c-ubung/</link>
		<comments>http://www.treibsand.com/2010/07/02/kleine-c-ubung/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 08:50:06 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/?p=520</guid>
		<description><![CDATA[Heute hat mir ein Kollege einen kleinen C Quelltext geschickt und mich gebeten, das Ergebnis mal nachzuvollziehen, ohne dabei das Programm zu kompilieren. Ich muss sagen, beim ersten Anlauf hatte ich nicht alle Werte der Variablen richtig. Es gibt doch einige Fallstricke Aber versucht es mal selber! Was kommt raus? Und bitte nicht kompilieren&#8230; #include [...]]]></description>
			<content:encoded><![CDATA[<p>Heute hat mir ein Kollege einen kleinen C Quelltext geschickt und mich gebeten, das Ergebnis mal nachzuvollziehen, ohne dabei das Programm zu kompilieren. Ich muss sagen, beim ersten Anlauf hatte ich nicht alle Werte der Variablen richtig. Es gibt doch einige Fallstricke <img src='http://www.treibsand.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><span id="more-520"></span></p>
<p>Aber versucht es mal selber! Was kommt raus? Und bitte <b>nicht</b> kompilieren&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> func <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> c <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> a <span style="color: #339933;">+</span> b <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>c <span style="color: #339933;">*=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> a <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> b <span style="color: #339933;">=</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> c <span style="color: #339933;">=</span> func<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	a <span style="color: #339933;">*=</span> a<span style="color: #339933;">++;</span>
	b <span style="color: #339933;">*=</span> <span style="color: #339933;">++</span>b<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%d %d %d %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> a<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> c<span style="color: #339933;">,</span> func<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2010/07/02/kleine-c-ubung/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActiveLdap sucht subschemaSubentry</title>
		<link>http://www.treibsand.com/2010/06/16/activeldap-sucht-subschemasubentry/</link>
		<comments>http://www.treibsand.com/2010/06/16/activeldap-sucht-subschemasubentry/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 12:13:21 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/?p=488</guid>
		<description><![CDATA[Heute bin ich über ein interessantes Problem mit OpenLDAP und ActiveLdap für Ruby gestolpert. ActiveLdap wollte mir einfach keine Ergebnisse liefern, obwohl die Abfragen gestimmt haben&#8230; Es kam immer zu folgendem Fehler&#8230; ActiveLdap::LdapError::NoSuchObject&#40;No such object&#41;: filter &#40;objectClass=subschema&#41;: attributes: &#91;&#34;objectClasses&#34;, &#34;attributeTypes&#34;, &#34;matchingRules&#34;, &#34;matchingRuleUse&#34;, &#34;dITStructureRules&#34;, &#34;dITContentRules&#34;, &#34;nameForms&#34;, &#34;ldapSyntaxes&#34;&#93; ActiveLdap hat eine zusätzliche Abfrage gemacht, und sich immer [...]]]></description>
			<content:encoded><![CDATA[<p>Heute bin ich über ein interessantes Problem mit OpenLDAP und ActiveLdap für Ruby gestolpert. ActiveLdap wollte mir einfach keine Ergebnisse liefern, obwohl die Abfragen gestimmt haben&#8230;</p>
<p><span id="more-488"></span></p>
<p>Es kam immer zu folgendem Fehler&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">ActiveLdap::LdapError::NoSuchObject</span><span style="color:#006600; font-weight:bold;">&#40;</span>No such object<span style="color:#006600; font-weight:bold;">&#41;</span>: filter 
<span style="color:#006600; font-weight:bold;">&#40;</span>objectClass=subschema<span style="color:#006600; font-weight:bold;">&#41;</span>: attributes: <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;objectClasses&quot;</span>, <span style="color:#996600;">&quot;attributeTypes&quot;</span>, <span style="color:#996600;">&quot;matchingRules&quot;</span>,
<span style="color:#996600;">&quot;matchingRuleUse&quot;</span>, <span style="color:#996600;">&quot;dITStructureRules&quot;</span>, <span style="color:#996600;">&quot;dITContentRules&quot;</span>, <span style="color:#996600;">&quot;nameForms&quot;</span>,
<span style="color:#996600;">&quot;ldapSyntaxes&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>ActiveLdap hat eine zusätzliche Abfrage gemacht, und sich immer als anonymous beim LDAP Server angemeldet. Sobald man sehr restriktive ACLs auf dem LDAP Server hat, begegnet man diesem Problem sehr früh. Sobald also die ACL keine anonymen Verbindungen zulässt fliegt ActiveLdap auf die Nase.</p>
<p>Wenn folgende ACLs eingetragen werden</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">access to dn.base=<span style="color: #ff0000;">&quot;&quot;</span> by <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #c20cb9; font-weight: bold;">read</span>
access to dn.base=<span style="color: #ff0000;">&quot;cn=Subschema&quot;</span> by <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #c20cb9; font-weight: bold;">read</span></pre></div></div>

<p>dann funktioniert es auch&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2010/06/16/activeldap-sucht-subschemasubentry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shortcut Decorator</title>
		<link>http://www.treibsand.com/2006/08/25/shortcut-decorator/</link>
		<comments>http://www.treibsand.com/2006/08/25/shortcut-decorator/#comments</comments>
		<pubDate>Fri, 25 Aug 2006 19:15:27 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://test.treibsand.com/2006/08/25/shortcut-decorator/</guid>
		<description><![CDATA[Ist es nicht manchmal nervig bei Django in views render_to_response aufzurufen, und gegf. sogar noch den Context? Vor kurzem brauchte ich den Template Processor django.core.context_processors.auth, um auf die Session Variable &#8220;user&#8221; zuzugreifen In generic views ist dies ja bereits automatisch der fall, dass die Variable im Template verfuegbar ist. Bei normalen views muss man allerdings [...]]]></description>
			<content:encoded><![CDATA[<p>Ist es nicht manchmal nervig bei Django in views render_to_response aufzurufen, und gegf. sogar noch den Context? Vor kurzem brauchte ich den Template Processor django.core.context_processors.auth, um auf die Session Variable &#8220;user&#8221; zuzugreifen</p>
<p><span id="more-32"></span><br />
In generic views ist dies ja bereits automatisch der fall, dass die Variable im Template verfuegbar ist. Bei normalen views muss man allerdings jeweils den richtigen Context angeben, wie z.B. mit</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> myview<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:
  ...
  <span style="color: #ff7700;font-weight:bold;">return</span> render_to_response<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;template.html&quot;</span>,
    context_instance=RequestContext<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Das kann mit der Zeit ziemlich nervig werden. Mit folgendem Decorator kann man sich das Leben erheblich leichert machen:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">template</span>.<span style="color: black;">context</span> <span style="color: #ff7700;font-weight:bold;">import</span> RequestContext
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">http</span> <span style="color: #ff7700;font-weight:bold;">import</span> HttpResponse
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">shortcuts</span> <span style="color: #ff7700;font-weight:bold;">import</span> render_to_response
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> page<span style="color: black;">&#40;</span>template=<span style="color: #008000;">None</span>, <span style="color: #66cc66;">**</span>decorator_args<span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">def</span> _wrapper<span style="color: black;">&#40;</span>fn<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> _innerWrapper<span style="color: black;">&#40;</span>request, <span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kw<span style="color: black;">&#41;</span>:
      context_dict = decorator_args.<span style="color: #dc143c;">copy</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
      g = fn<span style="color: black;">&#40;</span>request, <span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kw<span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">hasattr</span><span style="color: black;">&#40;</span>g, <span style="color: #483d8b;">'next'</span><span style="color: black;">&#41;</span>: 
        g = <span style="color: black;">&#40;</span>g,<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> g:
          <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">isinstance</span><span style="color: black;">&#40;</span>i, HttpResponse<span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> i
          <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">type</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span> == <span style="color: #008000;">type</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
            context_dict<span style="color: black;">&#91;</span>i<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> = i<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
          <span style="color: #ff7700;font-weight:bold;">else</span>:
            context_dict.<span style="color: black;">update</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>
        template_name = context_dict.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;template&quot;</span>,  template<span style="color: black;">&#41;</span>
        context_instance = RequestContext<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> render_to_response<span style="color: black;">&#40;</span>template_name, context_dict, context_instance<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> _innerWrapper
  <span style="color: #ff7700;font-weight:bold;">return</span> _wrapper</pre></div></div>

<p>Dadurch kann man bei einem view per Decorator direkt das Template angeben, ohne render_to_response aufzrufen:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">@page<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;template.html&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> myview<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:
  somedata = Data.<span style="color: black;">objects</span>.<span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">yield</span> <span style="color: black;">&#123;</span><span style="color: #483d8b;">'data'</span>: somedata<span style="color: black;">&#125;</span></pre></div></div>

<p>Aber das ist noch nicht alles&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">@page<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;template.html&quot;</span>, title=<span style="color: #483d8b;">&quot;Titel der Seite&quot;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># extra Argument fuer den Context</span>
<span style="color: #ff7700;font-weight:bold;">def</span> myview<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:
  somedata = Data.<span style="color: black;">objects</span>.<span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">yield</span> <span style="color: #008000;">locals</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># lokale Variable werden an den Context uebergeben, in  diesem Fall somedata</span></pre></div></div>

<p>Das Template muss auch nicht umbedingt im Decorator angegeben werden&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">@page<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> myview<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:
  somedata = Data.<span style="color: black;">objects</span>.<span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  template = <span style="color: #483d8b;">&quot;template2.html&quot;</span>
  <span style="color: #ff7700;font-weight:bold;">yield</span> <span style="color: #008000;">locals</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># lokale Variable werden an den Context uebergeben, in  diesem Fall somedata</span></pre></div></div>

<p>Cool oder? <img src='http://www.treibsand.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2006/08/25/shortcut-decorator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Textmate GetBundle</title>
		<link>http://www.treibsand.com/2006/08/24/textmate-getbundle/</link>
		<comments>http://www.treibsand.com/2006/08/24/textmate-getbundle/#comments</comments>
		<pubDate>Thu, 24 Aug 2006 21:38:27 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Textmate]]></category>

		<guid isPermaLink="false">http://test.treibsand.com/2009/01/15/textmate-getbundle/</guid>
		<description><![CDATA[TextMate ist einer der besten Editoren für Mac OSX. Eines der tollen Features sind die Bundles. Nur lassen sie sich teilweise nicht einfach installieren. GetBundle erleichtert die Sache erheblich. GetBundle ist selber ein Bundle und fragt direkt das SVN Repository der Textmate Bundles. Mit der einfachen Bedienung lassen sich in kürzester Zeit nette Erweiterungen installieren, [...]]]></description>
			<content:encoded><![CDATA[<p>TextMate ist einer der besten Editoren für Mac OSX. Eines der tollen Features sind die Bundles. Nur lassen sie sich teilweise nicht einfach installieren.</p>
<p><span id="more-16"></span><br />
GetBundle erleichtert die Sache erheblich. GetBundle ist selber ein Bundle und fragt direkt das SVN Repository der Textmate Bundles. Mit der einfachen Bedienung lassen sich in kürzester Zeit nette Erweiterungen installieren, u.A. Syntax für Django <img src='http://www.treibsand.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2006/08/24/textmate-getbundle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

