<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>This and That. Mostly that.</description><title>Fauzism</title><generator>Tumblr (3.0; @fauzism)</generator><link>http://fauzism.com/</link><item><title>To Shalu</title><description>&lt;p&gt;&lt;canvas id="c"&gt;&lt;/canvas&gt;&lt;script&gt;var b = document.body;var c = document.getElementsByTagName('canvas')[0]; var a = c.getContext('2d');            document.body.clientWidth; &lt;/script&gt;&lt;script&gt; with(m=Math)C=cos,S=sin,P=pow,R=random;c.width=c.height=f=500;h=-250;function p(a,b,c){if(c&gt;60)return[S(a*7)*(13+5/(.2+P(b*4,4)))-S(b)*50,b*f+50,625+C(a*7)*(13+5/(.2+P(b*4,4)))+b*400,a*1-b/2,a];A=a*2-1;B=b*2-1;if(A*A+B*B&lt;1){if(c&gt;37){n=(j=c&amp;1)?6:4;o=.5/(a+.01)+C(b*125)*3-a*300;w=b*h;return[o*C(n)+w*S(n)+j*610-390,o*S(n)-w*C(n)+550-j*350,1180+C(B+A)*99-j*300,.4-a*.1+P(1-B*B,-h*6)*.15-a*b*.4+C(a+b)/5+P(C((o*(a+1)+(B&gt;0?w:-w))/25),30)*.1*(1-B*B),o/1e3+.7-o*w*3e-6]}if(c&gt;32){c=c*1.16-.15;o=a*45-20;w=b*b*h;z=o*S(c)+w*C(c)+620;return[o*C(c)-w*S(c),28+C(B*.5)*99-b*b*b*60-z/2-h,z,(b*b*.3+P((1-(A*A)),7)*.15+.3)*b,b*.7]}o=A*(2-b)*(80-c*2);w=99-C(A)*120-C(b)*(-h-c*4.9)+C(P(1-b,7))*50+c*2;z=o*S(c)+w*C(c)+700;return[o*C(c)-w*S(c),B*99-C(P(b, 7))*50-c/3-z/1.35+450,z,(1-b/1.2)*.9+a*.1, P((1-b),20)/4+.05]}}setInterval('for(i=0;i&lt;1e4;i++)if(s=p(R(),R(),i%46/.74)){z=s[2];x=~~(s[0]*f/z-h);y=~~(s[1]*f/z-h);if(!m[q=y*f+x]|m[q]&gt;z)m[q]=z,a.fillStyle="rgb("+~(s[3]*h)+","+~(s[4]*h)+","+~(s[3]*s[3]*-80)+")",a.fillRect(x,y,1,1)}',0)&lt;/script&gt;&lt;/p&gt;</description><link>http://fauzism.com/post/17604812576</link><guid>http://fauzism.com/post/17604812576</guid><pubDate>Tue, 14 Feb 2012 18:19:00 +0530</pubDate></item><item><title>Shivling : Avoiding boilerplate in views in Django</title><description>&lt;p&gt;I have been unable to find time to continue my &lt;a href="http://fauzism.com/post/6684122984/shiv-django"&gt;Shiv series&lt;/a&gt;, however, a chat with a 
friend(&lt;a href="http://twitter.com/arihersh"&gt;@arihersh&lt;/a&gt;) who has just started learning django reminded me of a small piece of code I had written sometime back. The chat went something like this&lt;/p&gt;
&lt;div style="background-color:#EBEBEB; padding: 10px; margin-bottom:10px;-moz-box-shadow:inset 0 0 10px #000000;
   -webkit-box-shadow:inset 0 0 10px #000000;
   box-shadow:inset 0 0 10px #000000;"&gt;
    &lt;div&gt;&lt;strong style="color:#5F5F00"&gt;&lt;a href="http://blog.tabulaw.com/"&gt;&lt;/a&gt;&lt;a href="http://blog.tabulaw.com/"&gt;Ari Hershowitz&lt;/a&gt;:&lt;/strong&gt;&lt;/div&gt;
    &lt;div style="margin:2px 0 4px 10px"&gt;I’d like to have html “widgets” that have certain actions, without having to create an artificial url + view to control the widget.&lt;/div&gt;
    
    &lt;div style="margin:2px 0 4px 10px"&gt;Maybe that’s what your framework does?&lt;/div&gt;
    
    &lt;div&gt;&lt;strong style="color:#800000"&gt;Yousuf Fauzan:&lt;/strong&gt;&lt;/div&gt;
    &lt;div style="margin:2px 0 4px 10px"&gt;gimme an example &lt;/div&gt;
    
    &lt;div&gt;&lt;strong style="color:#5F5F00"&gt;&lt;a href="http://blog.tabulaw.com/"&gt;Ari Hershowitz&lt;/a&gt;:&lt;/strong&gt;&lt;/div&gt;
    &lt;div style="margin:2px 0 4px 10px"&gt;Ok…&lt;/div&gt;
    
    &lt;div style="margin:2px 0 4px 10px"&gt;I’ll try to describe… &lt;/div&gt;
    
    &lt;div style="margin:2px 0 4px 10px"&gt;I want to create a search bar that goes on any page.&lt;/div&gt;
    
    &lt;div style="margin:2px 0 4px 10px"&gt;To do this in Django, I think I need to: (1) create a search form, (2) put it into a template, (3) include the template into any other template.&lt;/div&gt;
    
    &lt;div style="margin:2px 0 4px 10px"&gt;I also need to create a view for the search bar, with its own url, right?&lt;/div&gt;
    
    &lt;div&gt;&lt;strong style="color:#800000"&gt;Yousuf Fauzan:&lt;/strong&gt;&lt;/div&gt;
    &lt;div style="margin:2px 0 4px 10px"&gt;you need a search result view &lt;/div&gt;
    
    &lt;div&gt;&lt;strong style="color:#5F5F00"&gt;&lt;a href="http://blog.tabulaw.com/"&gt;Ari Hershowitz&lt;/a&gt;:&lt;/strong&gt;&lt;/div&gt;
    &lt;div style="margin:2px 0 4px 10px"&gt;So if I have the search bar on page x, I’ll have to call the search bar’s url from page x. &lt;/div&gt;
    
    &lt;div&gt;&lt;strong style="color:#800000"&gt;Yousuf Fauzan:&lt;/strong&gt;&lt;/div&gt;
    &lt;div style="margin:2px 0 4px 10px"&gt;i.e. the url that the searcdh form will post to &lt;/div&gt;
    
    &lt;div&gt;&lt;strong style="color:#5F5F00"&gt;&lt;a href="http://blog.tabulaw.com/"&gt;Ari Hershowitz&lt;/a&gt;:&lt;/strong&gt;&lt;/div&gt;
    &lt;div style="margin:2px 0 4px 10px"&gt;Yes, actually that’s the issue:&lt;/div&gt;
    
    &lt;div style="margin:2px 0 4px 10px"&gt;I found that on each page I include the search form, I’m writing a lot of boilerplate code into *each* view of the pages that use the search form.&lt;/div&gt;
    &lt;div style="margin:2px 0 4px 10px"&gt;What I’d like is to write the template and view for a unit once (e.g. a search form). Then only have to include it in the other page’s template, without making any changes to the views in order to pass variables around&lt;/div&gt;
&lt;/div&gt;
&lt;!-- more --&gt;
&lt;p&gt;At first I suggested Shiv to make the views more modular, but it was kinda overkill for the particular project. Then I remembered a piece of code that I had written well after Shiv which can be viewed as a motivation for Shiv (though it was written after Shiv).&lt;/p&gt;
&lt;div&gt;It basically consists of 2 files&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;1. element_registry.py&lt;/strong&gt;&lt;/div&gt;
&lt;p&gt;This is for ajax views. Its almost identical to the one in Shiv. You will need to create a url entry in urls.py and follow some sort of url pattern so that the registered name can be passed.&lt;/p&gt;
&lt;p&gt;Every ajax view contains a key member (func.key) which can be used to generate the desired url. You can look at the ajax_view function below to understand how the required view is called.&lt;/p&gt;


&lt;!-- HTML generated using hilite.me --&gt;&lt;div style="background: #f8f8f8; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style="margin: 0; line-height: 125%"&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style="margin: 0; line-height: 125%"&gt;&lt;span style="color: #008000; font-weight: bold"&gt;from&lt;/span&gt; &lt;span style="color: #0000FF; font-weight: bold"&gt;django.http&lt;/span&gt; &lt;span style="color: #008000; font-weight: bold"&gt;import&lt;/span&gt; HttpResponse, HttpResponseRedirect, HttpResponseNotFound

&lt;span style="color: #008000; font-weight: bold"&gt;class&lt;/span&gt; &lt;span style="color: #0000FF; font-weight: bold"&gt;AjaxRegistry&lt;/span&gt;(&lt;span style="color: #008000"&gt;object&lt;/span&gt;):
    _instance &lt;span style="color: #666666"&gt;=&lt;/span&gt; &lt;span style="color: #008000"&gt;None&lt;/span&gt;
    _registry &lt;span style="color: #666666"&gt;=&lt;/span&gt; {}
    _index &lt;span style="color: #666666"&gt;=&lt;/span&gt; &lt;span style="color: #666666"&gt;0&lt;/span&gt;
    
    &lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;__new__&lt;/span&gt;(cls, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs):
        &lt;span style="color: #008000; font-weight: bold"&gt;if&lt;/span&gt; cls &lt;span style="color: #666666"&gt;!=&lt;/span&gt; &lt;span style="color: #008000"&gt;type&lt;/span&gt;(cls&lt;span style="color: #666666"&gt;.&lt;/span&gt;_instance):
            cls&lt;span style="color: #666666"&gt;.&lt;/span&gt;_instance &lt;span style="color: #666666"&gt;=&lt;/span&gt; &lt;span style="color: #008000"&gt;object&lt;/span&gt;&lt;span style="color: #666666"&gt;.&lt;/span&gt;__new__(cls, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs)
        &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; cls&lt;span style="color: #666666"&gt;.&lt;/span&gt;_instance
    
    &lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;register&lt;/span&gt;(&lt;span style="color: #008000"&gt;self&lt;/span&gt;, func):
        key &lt;span style="color: #666666"&gt;=&lt;/span&gt; &lt;span style="color: #008000"&gt;str&lt;/span&gt;(&lt;span style="color: #008000"&gt;self&lt;/span&gt;&lt;span style="color: #666666"&gt;.&lt;/span&gt;_index)&lt;span style="color: #666666"&gt;+&lt;/span&gt;func&lt;span style="color: #666666"&gt;.&lt;/span&gt;func_name
        &lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;wrap&lt;/span&gt;(&lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs):
            &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; func(&lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs)
            
        &lt;span style="color: #008000"&gt;self&lt;/span&gt;&lt;span style="color: #666666"&gt;.&lt;/span&gt;_registry[key] &lt;span style="color: #666666"&gt;=&lt;/span&gt; wrap
        &lt;span style="color: #008000"&gt;self&lt;/span&gt;&lt;span style="color: #666666"&gt;.&lt;/span&gt;_index&lt;span style="color: #666666"&gt;+=1&lt;/span&gt;
        wrap&lt;span style="color: #666666"&gt;.&lt;/span&gt;key&lt;span style="color: #666666"&gt;=&lt;/span&gt;key
        wrap&lt;span style="color: #666666"&gt;.&lt;/span&gt;name &lt;span style="color: #666666"&gt;=&lt;/span&gt; func&lt;span style="color: #666666"&gt;.&lt;/span&gt;func_name
        &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; wrap
        
&lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;ajax_view&lt;/span&gt;(request, view_name):
    &lt;span style="color: #008000; font-weight: bold"&gt;if&lt;/span&gt; request&lt;span style="color: #666666"&gt;.&lt;/span&gt;is_ajax():
        return_type &lt;span style="color: #666666"&gt;=&lt;/span&gt; &lt;span style="color: #BA2121"&gt;"template"&lt;/span&gt;
        
        &lt;span style="color: #008000; font-weight: bold"&gt;if&lt;/span&gt; request&lt;span style="color: #666666"&gt;.&lt;/span&gt;GET:
            &lt;span style="color: #008000; font-weight: bold"&gt;if&lt;/span&gt; &lt;span style="color: #BA2121"&gt;"return_type"&lt;/span&gt; &lt;span style="color: #AA22FF; font-weight: bold"&gt;in&lt;/span&gt; request&lt;span style="color: #666666"&gt;.&lt;/span&gt;GET:
                return_type &lt;span style="color: #666666"&gt;=&lt;/span&gt; request&lt;span style="color: #666666"&gt;.&lt;/span&gt;GET[&lt;span style="color: #BA2121"&gt;'return_type'&lt;/span&gt;]
                
        ar &lt;span style="color: #666666"&gt;=&lt;/span&gt; AjaxRegistry()
        func &lt;span style="color: #666666"&gt;=&lt;/span&gt; ar&lt;span style="color: #666666"&gt;.&lt;/span&gt;_registry[view_name]
        ret &lt;span style="color: #666666"&gt;=&lt;/span&gt; func(request)
        ret[&lt;span style="color: #BA2121"&gt;'key'&lt;/span&gt;] &lt;span style="color: #666666"&gt;=&lt;/span&gt; view_name
        
        &lt;span style="color: #008000; font-weight: bold"&gt;if&lt;/span&gt; return_type &lt;span style="color: #666666"&gt;==&lt;/span&gt; &lt;span style="color: #BA2121"&gt;"template"&lt;/span&gt;:
            &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; HttpResponse(get_template(ret[&lt;span style="color: #BA2121"&gt;'template'&lt;/span&gt;])&lt;span style="color: #666666"&gt;.&lt;/span&gt;render(RequestContext(request, ret)))
        &lt;span style="color: #008000; font-weight: bold"&gt;else&lt;/span&gt;:
            json &lt;span style="color: #666666"&gt;=&lt;/span&gt; simplejson&lt;span style="color: #666666"&gt;.&lt;/span&gt;dumps(ret)
            &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; HttpResponse(json, mimetype&lt;span style="color: #666666"&gt;=&lt;/span&gt;&lt;span style="color: #BA2121"&gt;'application/javascript'&lt;/span&gt;)
    &lt;span style="color: #008000; font-weight: bold"&gt;else&lt;/span&gt;:
        &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; HttpResponseNotFound()
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;&lt;strong&gt;2. element.py &lt;/strong&gt;&lt;/div&gt;
&lt;p&gt;This is where the main action happens. There are two kind of functions here. The ones which are called by urls.py directly and the other which are used by the first one to create the response.&lt;/p&gt;


&lt;div style="background: #f8f8f8; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style="margin: 0; line-height: 125%"&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style="margin: 0; line-height: 125%"&gt;&lt;span style="color: #008000; font-weight: bold"&gt;from&lt;/span&gt; &lt;span style="color: #0000FF; font-weight: bold"&gt;django.contrib.auth.decorators&lt;/span&gt; &lt;span style="color: #008000; font-weight: bold"&gt;import&lt;/span&gt; login_required
&lt;span style="color: #008000; font-weight: bold"&gt;from&lt;/span&gt; &lt;span style="color: #0000FF; font-weight: bold"&gt;django.shortcuts&lt;/span&gt; &lt;span style="color: #008000; font-weight: bold"&gt;import&lt;/span&gt; render_to_response
 
&lt;span style="color: #008000; font-weight: bold"&gt;from&lt;/span&gt; &lt;span style="color: #0000FF; font-weight: bold"&gt;django.template&lt;/span&gt; &lt;span style="color: #008000; font-weight: bold"&gt;import&lt;/span&gt; RequestContext
&lt;span style="color: #008000; font-weight: bold"&gt;from&lt;/span&gt; &lt;span style="color: #0000FF; font-weight: bold"&gt;django.template.loader&lt;/span&gt; &lt;span style="color: #008000; font-weight: bold"&gt;import&lt;/span&gt; get_template
&lt;span style="color: #008000; font-weight: bold"&gt;from&lt;/span&gt; &lt;span style="color: #0000FF; font-weight: bold"&gt;django.http&lt;/span&gt; &lt;span style="color: #008000; font-weight: bold"&gt;import&lt;/span&gt; HttpResponse
&lt;span style="color: #008000; font-weight: bold"&gt;from&lt;/span&gt; &lt;span style="color: #0000FF; font-weight: bold"&gt;element_registry&lt;/span&gt; &lt;span style="color: #008000; font-weight: bold"&gt;import&lt;/span&gt; AjaxRegistry

ar &lt;span style="color: #666666"&gt;=&lt;/span&gt; AjaxRegistry()

&lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;fragment&lt;/span&gt;(template):
    template &lt;span style="color: #666666"&gt;=&lt;/span&gt; get_template(template)
    &lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;wrapper&lt;/span&gt;(func):
        &lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;inner&lt;/span&gt;(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs):
            di &lt;span style="color: #666666"&gt;=&lt;/span&gt; func(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs)
            di[&lt;span style="color: #BA2121"&gt;'key'&lt;/span&gt;] &lt;span style="color: #666666"&gt;=&lt;/span&gt; func&lt;span style="color: #666666"&gt;.&lt;/span&gt;key
            &lt;span style="color: #008000; font-weight: bold"&gt;if&lt;/span&gt; di&lt;span style="color: #666666"&gt;.&lt;/span&gt;has_key(&lt;span style="color: #BA2121"&gt;'extra_key'&lt;/span&gt;): 
                di[&lt;span style="color: #BA2121"&gt;'key'&lt;/span&gt;] &lt;span style="color: #666666"&gt;=&lt;/span&gt;  di[&lt;span style="color: #BA2121"&gt;'key'&lt;/span&gt;] &lt;span style="color: #666666"&gt;+&lt;/span&gt; &lt;span style="color: #BA2121"&gt;'+'&lt;/span&gt; &lt;span style="color: #666666"&gt;+&lt;/span&gt; &lt;span style="color: #008000"&gt;str&lt;/span&gt;(di[&lt;span style="color: #BA2121"&gt;'extra_key'&lt;/span&gt;])
            &lt;span style="color: #008000; font-weight: bold"&gt;if&lt;/span&gt; request&lt;span style="color: #666666"&gt;.&lt;/span&gt;is_ajax() &lt;span style="color: #AA22FF; font-weight: bold"&gt;and&lt;/span&gt; ajax_is_json:
                &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; di
            c &lt;span style="color: #666666"&gt;=&lt;/span&gt; RequestContext(request, di)
            &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; template&lt;span style="color: #666666"&gt;.&lt;/span&gt;render(c)
        inner&lt;span style="color: #666666"&gt;.&lt;/span&gt;name &lt;span style="color: #666666"&gt;=&lt;/span&gt; &lt;span style="color: #008000"&gt;getattr&lt;/span&gt;(func, &lt;span style="color: #BA2121"&gt;'name'&lt;/span&gt;, func&lt;span style="color: #666666"&gt;.&lt;/span&gt;func_name)
        &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; inner
    &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; wrapper
    
&lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;make_and_render&lt;/span&gt;(template&lt;span style="color: #666666"&gt;=&lt;/span&gt;&lt;span style="color: #008000"&gt;None&lt;/span&gt;, mimetype&lt;span style="color: #666666"&gt;=&lt;/span&gt;&lt;span style="color: #BA2121"&gt;"text/html"&lt;/span&gt;, auto_render_sidebar&lt;span style="color: #666666"&gt;=&lt;/span&gt;&lt;span style="color: #008000"&gt;False&lt;/span&gt;):
    &lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;wrapper&lt;/span&gt;(func):
        template &lt;span style="color: #666666"&gt;=&lt;/span&gt; get_template(template)
        &lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;inner&lt;/span&gt;(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs):
            ret &lt;span style="color: #666666"&gt;=&lt;/span&gt; func(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs)
            args &lt;span style="color: #666666"&gt;=&lt;/span&gt; &lt;span style="color: #008000"&gt;len&lt;/span&gt;(ret) &lt;span style="color: #666666"&gt;&gt;&lt;/span&gt; &lt;span style="color: #666666"&gt;2&lt;/span&gt; &lt;span style="color: #AA22FF; font-weight: bold"&gt;and&lt;/span&gt; ret[&lt;span style="color: #666666"&gt;2&lt;/span&gt;] &lt;span style="color: #AA22FF; font-weight: bold"&gt;or&lt;/span&gt; args
            kwargs &lt;span style="color: #666666"&gt;=&lt;/span&gt; &lt;span style="color: #008000"&gt;len&lt;/span&gt;(ret) &lt;span style="color: #666666"&gt;&gt;&lt;/span&gt; &lt;span style="color: #666666"&gt;3&lt;/span&gt; &lt;span style="color: #AA22FF; font-weight: bold"&gt;and&lt;/span&gt; ret[&lt;span style="color: #666666"&gt;3&lt;/span&gt;] &lt;span style="color: #AA22FF; font-weight: bold"&gt;or&lt;/span&gt; kwargs
            
            centre &lt;span style="color: #666666"&gt;=&lt;/span&gt; &lt;span style="color: #008000"&gt;dict&lt;/span&gt;([(e&lt;span style="color: #666666"&gt;.&lt;/span&gt;name, e(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs)) &lt;span style="color: #008000; font-weight: bold"&gt;for&lt;/span&gt; e &lt;span style="color: #AA22FF; font-weight: bold"&gt;in&lt;/span&gt; ret[&lt;span style="color: #666666"&gt;0&lt;/span&gt;]])
            sidebar &lt;span style="color: #666666"&gt;=&lt;/span&gt; &lt;span style="color: #008000"&gt;dict&lt;/span&gt;([(e&lt;span style="color: #666666"&gt;.&lt;/span&gt;name, e(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs)) &lt;span style="color: #008000; font-weight: bold"&gt;for&lt;/span&gt; e &lt;span style="color: #AA22FF; font-weight: bold"&gt;in&lt;/span&gt; ret[&lt;span style="color: #666666"&gt;1&lt;/span&gt;]])
            
            context_vars &lt;span style="color: #666666"&gt;=&lt;/span&gt; {&lt;span style="color: #BA2121"&gt;'centre'&lt;/span&gt;: centre, &lt;span style="color: #BA2121"&gt;'sidebar'&lt;/span&gt;: sidebar, &lt;span style="color: #BA2121"&gt;'auto_render_sidebar'&lt;/span&gt;: auto_render_sidebar}
            &lt;span style="color: #008000; font-weight: bold"&gt;for&lt;/span&gt; k &lt;span style="color: #AA22FF; font-weight: bold"&gt;in&lt;/span&gt; kwargs:
                context_vars[k] &lt;span style="color: #666666"&gt;=&lt;/span&gt; kwargs[k]
            c &lt;span style="color: #666666"&gt;=&lt;/span&gt; RequestContext(request, context_vars)
            &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; template&lt;span style="color: #666666"&gt;.&lt;/span&gt;render(c)
        &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; inner
    &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; wrapper
        

&lt;span style="color: #408080; font-style: italic"&gt;###&lt;/span&gt;
&lt;span style="color: #408080; font-style: italic"&gt;### Example Usage&lt;/span&gt;
&lt;span style="color: #408080; font-style: italic"&gt;###&lt;/span&gt;

&lt;span style="color: #408080; font-style: italic"&gt;# This is the main view. It will include several fragments. Fragments can be divided in a datastructure based upon the need. &lt;/span&gt;
&lt;span style="color: #408080; font-style: italic"&gt;# In the example below we are using 2 lists as needed by make_and_render wrapper. If you need a different datastructure, &lt;/span&gt;
&lt;span style="color: #408080; font-style: italic"&gt;# make changes to make_and_render wrapper first&lt;/span&gt;
&lt;span style="color: #AA22FF"&gt;@make_and_render&lt;/span&gt;(template&lt;span style="color: #666666"&gt;=&lt;/span&gt;&lt;span style="color: #BA2121"&gt;'home.html'&lt;/span&gt;)
&lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;home&lt;/span&gt;(request):
    centre &lt;span style="color: #666666"&gt;=&lt;/span&gt; [frag1]
    sidebar &lt;span style="color: #666666"&gt;=&lt;/span&gt; [frag2]
    &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; centre, sidebar

&lt;span style="color: #408080; font-style: italic"&gt;# Below are 2 fragments&lt;/span&gt;
&lt;span style="color: #AA22FF"&gt;@fragment&lt;/span&gt;(template&lt;span style="color: #666666"&gt;=&lt;/span&gt;&lt;span style="color: #BA2121"&gt;'elem1.html'&lt;/span&gt;)
&lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;frag1&lt;/span&gt;(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs):
    context &lt;span style="color: #666666"&gt;=&lt;/span&gt; {}
    &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; context

&lt;span style="color: #AA22FF"&gt;@fragment&lt;/span&gt;(template&lt;span style="color: #666666"&gt;=&lt;/span&gt;&lt;span style="color: #BA2121"&gt;'elem2.html'&lt;/span&gt;)
&lt;span style="color: #AA22FF"&gt;@ar.register&lt;/span&gt;
&lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;frag2&lt;/span&gt;(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs):
    context &lt;span style="color: #666666"&gt;=&lt;/span&gt; {}
    &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; {}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;For example, suppose I have got a sidebar containing my Menu and the centre portion containing a header, search bar, 
and either some static text or search result. In this case I will make two main views corresponding to two main pages 
(The one with static content in the centre and the other one with search result) and 5 fragments. The entire key mechanism of the ajax 
functions is a bit involved andneeds to be understood and its interfacing with the urls.py and how it is passed to the html and from there to javascript. I am no expert of JS 
but I will try to outline the basics of it. I don’t think I have done a good job of explaining it here and I am sorry for that. Ping me if you would 
like to know more.&lt;/p&gt;
&lt;div style="background: #f8f8f8; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style="margin: 0; line-height: 125%"&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style="margin: 0; line-height: 125%"&gt;&lt;span style="color: #408080; font-style: italic"&gt;# This returns a list of links and their title, along with a boolean indicating if its the current page&lt;/span&gt;
&lt;span style="color: #408080; font-style: italic"&gt;# Determination of current page can also be done in template, and perhaps thats a better place.&lt;/span&gt;
&lt;span style="color: #AA22FF"&gt;@render&lt;/span&gt;(template&lt;span style="color: #666666"&gt;=&lt;/span&gt;&lt;span style="color: #BA2121"&gt;'menu.html'&lt;/span&gt;)
&lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;menu&lt;/span&gt;(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs):
    items &lt;span style="color: #666666"&gt;=&lt;/span&gt; [(&lt;span style="color: #BA2121"&gt;'Home'&lt;/span&gt;, &lt;span style="color: #BA2121"&gt;'/'&lt;/span&gt;, request&lt;span style="color: #666666"&gt;.&lt;/span&gt;path &lt;span style="color: #666666"&gt;==&lt;/span&gt; &lt;span style="color: #BA2121"&gt;'/'&lt;/span&gt;), (&lt;span style="color: #BA2121"&gt;'Search'&lt;/span&gt;, &lt;span style="color: #BA2121"&gt;'/'&lt;/span&gt;, request&lt;span style="color: #666666"&gt;.&lt;/span&gt;path &lt;span style="color: #666666"&gt;==&lt;/span&gt; &lt;span style="color: #BA2121"&gt;'/search'&lt;/span&gt;)]
    &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; {&lt;span style="color: #BA2121"&gt;'items'&lt;/span&gt;: items}

&lt;span style="color: #408080; font-style: italic"&gt;# Again, user authentication test might be done in template. &lt;/span&gt;
&lt;span style="color: #408080; font-style: italic"&gt;# However, there could be other info that could be sent to header from here&lt;/span&gt;
&lt;span style="color: #AA22FF"&gt;@render&lt;/span&gt;(template&lt;span style="color: #666666"&gt;=&lt;/span&gt;&lt;span style="color: #BA2121"&gt;'header.html'&lt;/span&gt;)
&lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;header&lt;/span&gt;(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs):
    &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; {&lt;span style="color: #BA2121"&gt;'logged_in'&lt;/span&gt;: request&lt;span style="color: #666666"&gt;.&lt;/span&gt;user&lt;span style="color: #666666"&gt;.&lt;/span&gt;is_authenticated()}

&lt;span style="color: #AA22FF"&gt;@render&lt;/span&gt;(template &lt;span style="color: #666666"&gt;=&lt;/span&gt; &lt;span style="color: #BA2121"&gt;'search_bar.html'&lt;/span&gt;)
&lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;search_bar&lt;/span&gt;(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs):
    &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; {&lt;span style="color: #BA2121"&gt;'q'&lt;/span&gt;: request&lt;span style="color: #666666"&gt;.&lt;/span&gt;GET&lt;span style="color: #666666"&gt;.&lt;/span&gt;get(&lt;span style="color: #BA2121"&gt;'q'&lt;/span&gt;, &lt;span style="color: #BA2121"&gt;''&lt;/span&gt;)}

&lt;span style="color: #AA22FF"&gt;@render&lt;/span&gt;(template &lt;span style="color: #666666"&gt;=&lt;/span&gt; &lt;span style="color: #BA2121"&gt;'static_box.html'&lt;/span&gt;)
&lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;static_box&lt;/span&gt;(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs):
    &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; {}

&lt;span style="color: #408080; font-style: italic"&gt;# Dummy search view. As an example we are using a model called MyModel with a text field called body.&lt;/span&gt;
&lt;span style="color: #408080; font-style: italic"&gt;# For rendering, we will require the number of results found and the page number along with the results.&lt;/span&gt;
&lt;span style="color: #408080; font-style: italic"&gt;# This fragment can also be called via ajax.&lt;/span&gt;
&lt;span style="color: #AA22FF"&gt;@render&lt;/span&gt;(template &lt;span style="color: #666666"&gt;=&lt;/span&gt; &lt;span style="color: #BA2121"&gt;'search_result.html'&lt;/span&gt;)
&lt;span style="color: #AA22FF"&gt;@ar.register&lt;/span&gt;
&lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;search_result&lt;/span&gt;(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs):
    result &lt;span style="color: #666666"&gt;=&lt;/span&gt; MyModel&lt;span style="color: #666666"&gt;.&lt;/span&gt;objects&lt;span style="color: #666666"&gt;.&lt;/span&gt;filter(body__contains&lt;span style="color: #666666"&gt;=&lt;/span&gt;request&lt;span style="color: #666666"&gt;.&lt;/span&gt;GET&lt;span style="color: #666666"&gt;.&lt;/span&gt;get(&lt;span style="color: #BA2121"&gt;'q'&lt;/span&gt;))
    count &lt;span style="color: #666666"&gt;=&lt;/span&gt; result&lt;span style="color: #666666"&gt;.&lt;/span&gt;count()
    page &lt;span style="color: #666666"&gt;=&lt;/span&gt; request&lt;span style="color: #666666"&gt;.&lt;/span&gt;GET&lt;span style="color: #666666"&gt;.&lt;/span&gt;get(&lt;span style="color: #BA2121"&gt;'page'&lt;/span&gt;, &lt;span style="color: #666666"&gt;0&lt;/span&gt;)
    &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; {&lt;span style="color: #BA2121"&gt;'items'&lt;/span&gt;: result[page:page&lt;span style="color: #666666"&gt;+10&lt;/span&gt;], &lt;span style="color: #BA2121"&gt;'count'&lt;/span&gt;: count, &lt;span style="color: #BA2121"&gt;'page'&lt;/span&gt;: page}

&lt;span style="color: #AA22FF"&gt;@make_and_render&lt;/span&gt;(template&lt;span style="color: #666666"&gt;=&lt;/span&gt;&lt;span style="color: #BA2121"&gt;'home.html'&lt;/span&gt;)
&lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;home&lt;/span&gt;(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs):
    centre &lt;span style="color: #666666"&gt;=&lt;/span&gt; [header, search_bar, static_box]
    sidebar &lt;span style="color: #666666"&gt;=&lt;/span&gt; [menu]
    &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; centre, sidebar


&lt;span style="color: #AA22FF"&gt;@make_and_render&lt;/span&gt;(template&lt;span style="color: #666666"&gt;=&lt;/span&gt;&lt;span style="color: #BA2121"&gt;'search.html'&lt;/span&gt;)
&lt;span style="color: #008000; font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #0000FF"&gt;search&lt;/span&gt;(request, &lt;span style="color: #666666"&gt;*&lt;/span&gt;args, &lt;span style="color: #666666"&gt;**&lt;/span&gt;kwargs):
    centre &lt;span style="color: #666666"&gt;=&lt;/span&gt; [header, search_bar, search_result]
    sidebar &lt;span style="color: #666666"&gt;=&lt;/span&gt; [menu]
    &lt;span style="color: #008000; font-weight: bold"&gt;return&lt;/span&gt; centre, sidebar, [], {&lt;span style="color: #BA2121"&gt;'search_ajax_key'&lt;/span&gt;: search_result&lt;span style="color: #666666"&gt;.&lt;/span&gt;key}

&lt;span style="color: #408080; font-style: italic"&gt;# We have passed search_result.key to this view's template. This can now be used to make ajax calls&lt;/span&gt;
&lt;span style="color: #408080; font-style: italic"&gt;# We can put the key in some hidden element inside the html and then use it to construct our ajax-url&lt;/span&gt;
&lt;span style="color: #408080; font-style: italic"&gt;# Our urls.py will have something like&lt;/span&gt;
urlpatterns &lt;span style="color: #666666"&gt;=&lt;/span&gt; patterns(&lt;span style="color: #BA2121"&gt;''&lt;/span&gt;,
	url(&lt;span style="color: #BA2121"&gt;'ajax-view/(?P&lt;view_name&gt;[\w-]+)/'&lt;/span&gt;, &lt;span style="color: #BA2121"&gt;'ajax_view'&lt;/span&gt;, {}, name&lt;span style="color: #666666"&gt;=&lt;/span&gt;&lt;span style="color: #BA2121"&gt;"ajax_view"&lt;/span&gt;),
    &lt;span style="color: #666666"&gt;...&lt;/span&gt;
)
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And the html can create a hidden element like&lt;/p&gt;

&lt;div style="background: #f8f8f8; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style="margin: 0; line-height: 125%"&gt;1
2
3&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style="margin: 0; line-height: 125%"&gt;$(&lt;span style="color: #BA2121"&gt;'#next'&lt;/span&gt;).live(&lt;span style="color: #BA2121"&gt;'click'&lt;/span&gt;, &lt;span style="color: #008000; font-weight: bold"&gt;function&lt;/span&gt;(){
    $.get($(&lt;span style="color: #BA2121"&gt;'#ajax-url'&lt;/span&gt;).html(), somefunction);
    });
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;While the Javascript will override the Next link&lt;/p&gt;
&lt;div style="background: #f8f8f8; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style="margin: 0; line-height: 125%"&gt;1&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style="margin: 0; line-height: 125%"&gt;&lt;span style="color: #008000; font-weight: bold"&gt;&lt;div&lt;/span&gt; &lt;span style="color: #7D9029"&gt;id=&lt;/span&gt;&lt;span style="color: #BA2121"&gt;"ajax-url"&lt;/span&gt; &lt;span style="color: #7D9029"&gt;style=&lt;/span&gt;&lt;span style="color: #BA2121"&gt;"display:none"&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold"&gt;&gt;&lt;/span&gt;/ajax-view/&lt;span style="color: #BC7A00"&gt;{{&lt;/span&gt;&lt;span style="color: #19177C"&gt;search_ajax_key&lt;/span&gt;&lt;span style="color: #BC7A00"&gt;}}&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold"&gt;&lt;/div&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Next, I will get back to talking more about Shiv. I hope the above helps in explaining the reason I started writing Shiv.&lt;/p&gt;</description><link>http://fauzism.com/post/8053641789</link><guid>http://fauzism.com/post/8053641789</guid><pubDate>Tue, 26 Jul 2011 01:33:00 +0530</pubDate><category>Django</category><category>Shiv</category></item><item><title>Shiv The Third - Return of Tutorial</title><description>&lt;p&gt;Continuing from my previous posts on Shiv, &lt;a href="http://fauzism.com/post/6684122984/shiv-django"&gt;Shiv - A wrapper over Django&lt;/a&gt; and &lt;a href="http://fauzism.com/post/7184677585/shiv-part-deux"&gt;Shiv - Part Deux&lt;/a&gt;, I will now try to explain about various components involved in Shiv. In this post we will talk about Media and Element. In later parts, we will explore Tabs, Boxes, Widgets, Pages, and Caching.&lt;/p&gt;

&lt;div&gt;An app using Shiv should have the following files&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;1. &lt;strong&gt;page.py&lt;/strong&gt;: This will contain the definition for all Page container classes&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;2. &lt;strong&gt;box.py&lt;/strong&gt;: This will contain the definition for all Box container classes&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;3. &lt;strong&gt;widget.py&lt;/strong&gt;: This will contain the definition for all Widget container classes&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;4. &lt;strong&gt;tab.py&lt;/strong&gt;: This will contain the definition for all Tab container classes&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;5. &lt;strong&gt;element.py&lt;/strong&gt;: This will contain the definition for all Element container classes&lt;/div&gt;
&lt;div style="padding-left: 30px;margin-bottom: 15px"&gt;6. &lt;strong&gt;media.py&lt;/strong&gt;: This will contain the definition for all Media classes&lt;/div&gt;
&lt;div&gt;&lt;span style="font-size: large;"&gt;&lt;strong&gt;Media&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;Media classes define the various media used by all the containers of the Project. Shiv uses a naming convention for media classes. The media class of a container class named “ABC” should be “ABCMedia” and it must be derived from shiv.media.Media.&lt;/p&gt;&lt;!-- more --&gt;
&lt;div&gt;Media class has following class variables&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;a. &lt;strong&gt;template&lt;/strong&gt;: &lt;i&gt;This is the path of the template file.&lt;/i&gt;&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;b. &lt;strong&gt;css&lt;/strong&gt;: &lt;i&gt;A list of css file paths which this container requires&lt;/i&gt;&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;c. &lt;strong&gt;js&lt;/strong&gt;: &lt;i&gt;A list of css file paths which this container requires&lt;/i&gt;&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;d. &lt;strong&gt;css_prefix&lt;/strong&gt;: &lt;i&gt;A prefix which will be added to all css file in the css variables, except those which are sourced from a web url, i.e.start with ‘http’. Defaults to ‘/static/css/’&lt;/i&gt;&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;e. &lt;strong&gt;js_prefix&lt;/strong&gt;: &lt;i&gt;Similar to css_prefix. Defaults to ‘/static/js/’&lt;/i&gt;&lt;/div&gt;
&lt;div style="padding-left: 30px;margin-bottom: 15px"&gt;f. &lt;strong&gt;images&lt;/strong&gt;: &lt;i&gt;A datastructure of image file paths which this container requires&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;Example:&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color: #999999;"&gt;&lt;em&gt;media.py&lt;/em&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;"&gt;
&lt;pre style="margin: 0; line-height: 125%;"&gt;
&lt;span style="color: #aa22ff; font-weight: bold;"&gt;from&lt;/span&gt; &lt;span style="color: #0000ff; font-weight: bold;"&gt;shiv.media&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;import&lt;/span&gt; Media

&lt;span style="color: #aa22ff; font-weight: bold;"&gt;class&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;FeedbackBoxMedia&lt;/span&gt;(Media):
    template &lt;span style="color: #666666;"&gt;=&lt;/span&gt; &lt;span style="color: #bb4444;"&gt;'master/BFeedback.html'&lt;/span&gt;
    css &lt;span style="color: #666666;"&gt;=&lt;/span&gt; [&lt;span style="color: #bb4444;"&gt;'master/BFeedback.css'&lt;/span&gt;, &lt;span style="color: #bb4444;"&gt;'common/ElementDefault.css'&lt;/span&gt;]
    js &lt;span style="color: #666666;"&gt;=&lt;/span&gt; [&lt;span style="color: #bb4444;"&gt;'master/BFeedback.js'&lt;/span&gt;, &lt;span style="color: #bb4444;"&gt;'common/FormsCommon.js'&lt;/span&gt;, &lt;span style="color: #bb4444;"&gt;'jquery.form.js'&lt;/span&gt;]
    images &lt;span style="color: #666666;"&gt;=&lt;/span&gt; {&lt;span style="color: #bb4444;"&gt;'title'&lt;/span&gt;:&lt;span style="color: #bb4444;"&gt;'/static/images/prelogin/feedback-v3.png'&lt;/span&gt;}
&lt;/pre&gt;
&lt;/div&gt;
&lt;p style="margin-top:10px;"&gt;The above Media class is for the container class FeedbackBox&lt;/p&gt;
&lt;div&gt;&lt;strong&gt;&lt;span style="font-size: large;"&gt;Element&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;p&gt;Element is the lowest level container in Shiv. It gets instantiated by a Tab. &lt;/p&gt;
&lt;div&gt;Below are the members of Element&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;a. &lt;strong&gt;__init__(self, client, request)&lt;/strong&gt;&lt;/div&gt;
&lt;div style="padding-left: 60px;"&gt;&lt;i&gt;client: Any variable that the element needs to render itself. This could be a database row object, or a string, or a complex data structure.&lt;/i&gt;&lt;/div&gt;
&lt;div style="padding-left: 60px;"&gt;&lt;i&gt;request: The HttpRequest object&lt;/i&gt;&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;b. &lt;strong&gt;_prepare(self)&lt;/strong&gt;&lt;/div&gt;
&lt;div style="padding-left: 60px;"&gt;&lt;i&gt;This function will be used to prepare context dictionary which will be passed to the template. This is the function that you must override.&lt;/i&gt;&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;c. &lt;strong&gt;show(self, template = None, context = None, is_json = False)&lt;/strong&gt;&lt;/div&gt;
&lt;div style="padding-left: 60px;"&gt;&lt;i&gt;Normally you wouldn’t need to override this method. Element knows its template and the context dictionary is created in the _prepare method.&lt;/i&gt;&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;d. &lt;strong&gt;self.client&lt;/strong&gt;&lt;/div&gt;
&lt;div style="padding-left: 60px;"&gt;&lt;i&gt;This is the client object that was passed to the constructor&lt;/i&gt;&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;e. &lt;strong&gt;self.request&lt;/strong&gt;&lt;/div&gt;
&lt;div style="padding-left: 60px;"&gt;&lt;i&gt;This is the HttpRequest object passed to the constructor&lt;/i&gt;&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;f. &lt;strong&gt;self.user&lt;/strong&gt;&lt;/div&gt;
&lt;div style="padding-left: 60px;"&gt;&lt;i&gt;This is the user object of the current user&lt;/i&gt;&lt;/div&gt;
&lt;div style="padding-left: 30px;"&gt;g. &lt;strong&gt;self.context&lt;/strong&gt;&lt;/div&gt;
&lt;div style="padding-left: 60px;margin-bottom: 15px"&gt;&lt;i&gt;This is created in _prepare method. If this is not created, then an empty dictionary is passed to template unless one overrides the show method&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;Example:&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color: #999999;"&gt;element.py&lt;/span&gt;&lt;/div&gt;
&lt;div style="background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;"&gt;
&lt;pre style="margin: 0; line-height: 125%;"&gt;
&lt;span style="color: #aa22ff; font-weight: bold;"&gt;from&lt;/span&gt; &lt;span style="color: #0000ff; font-weight: bold;"&gt;shiv.callback&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;import&lt;/span&gt; Callback
&lt;span style="color: #aa22ff; font-weight: bold;"&gt;from&lt;/span&gt; &lt;span style="color: #0000ff; font-weight: bold;"&gt;shiv.ajax&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;import&lt;/span&gt; allowAnonymous
&lt;span style="color: #aa22ff; font-weight: bold;"&gt;from&lt;/span&gt; &lt;span style="color: #0000ff; font-weight: bold;"&gt;shiv.element&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;import&lt;/span&gt; Element
&lt;span style="color: #aa22ff; font-weight: bold;"&gt;from&lt;/span&gt; &lt;span style="color: #0000ff; font-weight: bold;"&gt;shiv.json_utils&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;import&lt;/span&gt; JsonResponse
&lt;span style="color: #aa22ff; font-weight: bold;"&gt;import&lt;/span&gt; &lt;span style="color: #0000ff; font-weight: bold;"&gt;json&lt;/span&gt;
cb &lt;span style="color: #666666;"&gt;=&lt;/span&gt; Callback()
&lt;span style="color: #aa22ff; font-weight: bold;"&gt;class&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;MyFirstElement&lt;/span&gt;(Element):
    &lt;span style="color: #aa22ff; font-weight: bold;"&gt;def&lt;/span&gt; &lt;span style="color: #00a000;"&gt;_prepare&lt;/span&gt;(&lt;span style="color: #aa22ff;"&gt;self&lt;/span&gt;):
        &lt;span style="color: #aa22ff;"&gt;self&lt;/span&gt;&lt;span style="color: #666666;"&gt;.&lt;/span&gt;context &lt;span style="color: #666666;"&gt;=&lt;/span&gt; {
            &lt;span style="color: #bb4444;"&gt;'message'&lt;/span&gt;: &lt;span style="color: #bb4444;"&gt;'Hello'&lt;/span&gt;,
            &lt;span style="color: #bb4444;"&gt;'ajax_key'&lt;/span&gt;: &lt;span style="color: #aa22ff;"&gt;self&lt;/span&gt;&lt;span style="color: #666666;"&gt;.&lt;/span&gt;ajax_message&lt;span style="color: #666666;"&gt;.&lt;/span&gt;key
        }
    &lt;span style="color: #aa22ff;"&gt;@staticmethod&lt;/span&gt;
    &lt;span style="color: #aa22ff;"&gt;@allowAnonymous&lt;/span&gt;
    &lt;span style="color: #aa22ff;"&gt;@cb.register&lt;/span&gt;
    &lt;span style="color: #aa22ff; font-weight: bold;"&gt;def&lt;/span&gt; &lt;span style="color: #00a000;"&gt;ajax_message&lt;/span&gt;(request):
        &lt;span style="color: #aa22ff; font-weight: bold;"&gt;return&lt;/span&gt; JsonResponse(json&lt;span style="color: #666666;"&gt;.&lt;/span&gt;dumps({&lt;span style="color: #bb4444;"&gt;'message'&lt;/span&gt;: &lt;span style="color: #bb4444;"&gt;'Hello from Ajax'&lt;/span&gt;})
&lt;/pre&gt;
&lt;/div&gt;
&lt;p style="margin-top:10px;"&gt;In the code above allowAnonymous ensures that Anonymous users can call this callback and cb.register registers this function as an Ajax Callback function and provides it a key. The ajax_message method can be called using a url with its key as one of the parameters. Look at the template and js below to understand how.&lt;/p&gt;
&lt;div&gt;&lt;span style="color: #999999;"&gt;media.py&lt;/span&gt;&lt;/div&gt;
&lt;div style="background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;margin-bottom:15px"&gt;
&lt;pre style="margin: 0; line-height: 125%;"&gt;
&lt;span style="color: #aa22ff; font-weight: bold;"&gt;from&lt;/span&gt; &lt;span style="color: #0000ff; font-weight: bold;"&gt;shiv.media&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;import&lt;/span&gt; Media
&lt;span style="color: #aa22ff; font-weight: bold;"&gt;class&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;MyFirstElementMedia&lt;/span&gt;(Media):
    template &lt;span style="color: #666666;"&gt;=&lt;/span&gt; &lt;span style="color: #bb4444;"&gt;'element.html'&lt;/span&gt;
    js &lt;span style="color: #666666;"&gt;=&lt;/span&gt; [&lt;span style="color: #bb4444;"&gt;'jquery.js'&lt;/span&gt;, &lt;span style="color: #bb4444;"&gt;'message.js'&lt;/span&gt;]
&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span style="color: #999999;"&gt;element.html&lt;/span&gt;&lt;/div&gt;
&lt;div style="background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;;margin-bottom:15px"&gt;
&lt;pre style="margin: 0; line-height: 125%;"&gt;
&lt;span style="color: #008000; font-weight: bold;"&gt;&lt;div&lt;/span&gt; &lt;span style="color: #bb4444;"&gt;class="myelem"&lt;/span&gt; &lt;span style="color: #bb4444;"&gt;data-id="&lt;/span&gt;&lt;span style="color: #008800;"&gt;{{&lt;/span&gt;&lt;span style="color: #b8860b;"&gt;ajax_key&lt;/span&gt;&lt;span style="color: #008800;"&gt;}}&lt;/span&gt;&lt;span style="color: #bb4444;"&gt;"&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;&gt;&lt;/span&gt;
    &lt;span style="color: #008800;"&gt;{{&lt;/span&gt;&lt;span style="color: #b8860b;"&gt;message&lt;/span&gt;&lt;span style="color: #008800;"&gt;}}&lt;/span&gt;
&lt;span style="color: #008000; font-weight: bold;"&gt;&lt;/div&gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;Once you click on this div element, an alert box with message “Hello from Ajax will be displayed.&lt;/div&gt;
&lt;div&gt;&lt;span style="color: #999999;"&gt;message.js&lt;/span&gt;&lt;/div&gt;
&lt;div style="background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;;margin-bottom:15px"&gt;
&lt;pre style="margin: 0; line-height: 125%;"&gt;
$(&lt;span style="color: #bb4444;"&gt;'.myelem'&lt;/span&gt;).live(&lt;span style="color: #bb4444;"&gt;'click'&lt;/span&gt;, &lt;span style="color: #aa22ff; font-weight: bold;"&gt;function&lt;/span&gt;(){
    &lt;span style="color: #aa22ff; font-weight: bold;"&gt;var&lt;/span&gt; data_id &lt;span style="color: #666666;"&gt;=&lt;/span&gt; $(&lt;span style="color: #aa22ff; font-weight: bold;"&gt;this&lt;/span&gt;).attr(&lt;span style="color: #bb4444;"&gt;"data-id"&lt;/span&gt;);
    $.get(AJAX_URL, {
        &lt;span style="color: #bb4444;"&gt;'data_id'&lt;/span&gt;&lt;span style="color: #666666;"&gt;:&lt;/span&gt; data_id
      }, &lt;span style="color: #aa22ff; font-weight: bold;"&gt;function&lt;/span&gt;(response) {
        alert(response.message);
      });
});
&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;Your base.html should have the following structure.&lt;/div&gt;
&lt;div&gt;&lt;span style="color: #999999;"&gt;base.html&lt;/span&gt;&lt;/div&gt;
&lt;div style="background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;;margin-bottom:15px"&gt;
&lt;pre style="margin: 0; line-height: 125%;"&gt;
.....
&lt;span style="color: #008000; font-weight: bold;"&gt;&lt;head&gt;&lt;/span&gt;
    ....
    .... Other css declarations
    &lt;span style="color: #008800;"&gt;{%&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: #b8860b;"&gt;c&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #b8860b;"&gt;css&lt;/span&gt; &lt;span style="color: #008800;"&gt;%}&lt;/span&gt;
    &lt;span style="color: #008000; font-weight: bold;"&gt;&lt;link&lt;/span&gt; &lt;span style="color: #bb4444;"&gt;rel="stylesheet"&lt;/span&gt; &lt;span style="color: #bb4444;"&gt;type="text/css"&lt;/span&gt; &lt;span style="color: #bb4444;"&gt;href="&lt;/span&gt;&lt;span style="color: #008800;"&gt;{{&lt;/span&gt;&lt;span style="color: #b8860b;"&gt;c&lt;/span&gt;&lt;span style="color: #008800;"&gt;}}&lt;/span&gt;&lt;span style="color: #bb4444;"&gt;"&lt;/span&gt; &lt;span style="color: #008000; font-weight: bold;"&gt;/&gt;&lt;/span&gt;
    &lt;span style="color: #008800;"&gt;{%&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;endfor&lt;/span&gt; &lt;span style="color: #008800;"&gt;%}&lt;/span&gt;
    &lt;span style="color: #008800;"&gt;{%&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;block&lt;/span&gt; &lt;span style="color: #b8860b;"&gt;page_css&lt;/span&gt;&lt;span style="color: #008800;"&gt;%}&lt;/span&gt;
    &lt;span style="color: #008800;"&gt;{%&lt;/span&gt;&lt;span style="color: #aa22ff; font-weight: bold;"&gt;endblock&lt;/span&gt; &lt;span style="color: #008800;"&gt;%}&lt;/span&gt;
    ....
    ....
&lt;span style="color: #008000; font-weight: bold;"&gt;&lt;/head&gt;&lt;/span&gt;
&lt;span style="color: #008000; font-weight: bold;"&gt;&lt;body&gt;&lt;/span&gt;
...
...
&lt;span style="color: #008000; font-weight: bold;"&gt;&lt;/body&gt;&lt;/span&gt;
...
... Other js declarations
&lt;span style="color: #008800;"&gt;{%&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: #b8860b;"&gt;j&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #b8860b;"&gt;js&lt;/span&gt; &lt;span style="color: #008800;"&gt;%}&lt;/span&gt;
    &lt;span style="color: #008000; font-weight: bold;"&gt;&lt;script &lt;/span&gt;&lt;span style="color: #bb4444;"&gt;type="text/javascript"&lt;/span&gt; &lt;span style="color: #bb4444;"&gt;src="&lt;/span&gt;&lt;span style="color: #008800;"&gt;{{&lt;/span&gt;&lt;span style="color: #b8860b;"&gt;j&lt;/span&gt;&lt;span style="color: #008800;"&gt;}}&lt;/span&gt;&lt;span style="color: #bb4444;"&gt;"&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;&gt;&lt;/script&gt;&lt;/span&gt;
&lt;span style="color: #008800;"&gt;{%&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;endfor&lt;/span&gt; &lt;span style="color: #008800;"&gt;%}&lt;/span&gt;
&lt;span style="color: #008800;"&gt;{%&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;block&lt;/span&gt; &lt;span style="color: #b8860b;"&gt;page_js&lt;/span&gt; &lt;span style="color: #008800;"&gt;%}&lt;/span&gt;
&lt;span style="color: #008800;"&gt;{%&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;endblock&lt;/span&gt; &lt;span style="color: #008800;"&gt;%}&lt;/span&gt;
&lt;span style="color: #008000; font-weight: bold;"&gt;&lt;script &lt;/span&gt;&lt;span style="color: #bb4444;"&gt;type="text/javascript"&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;&gt;&lt;/span&gt;
    AJAX_URL &lt;span style="color: #666666;"&gt;=&lt;/span&gt; &lt;span style="color: #bb4444;"&gt;"&lt;/span&gt;&lt;span style="color: #008800;"&gt;{%&lt;/span&gt; &lt;span style="color: #aa22ff; font-weight: bold;"&gt;url&lt;/span&gt; &lt;span style="color: #b8860b;"&gt;ajax_url&lt;/span&gt; &lt;span style="color: #008800;"&gt;%}&lt;/span&gt;&lt;span style="color: #bb4444;"&gt;"&lt;/span&gt;
&lt;span style="color: #008000; font-weight: bold;"&gt;&lt;/script&gt;&lt;/span&gt;
&lt;span style="color: #008000; font-weight: bold;"&gt;&lt;/html&gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span style="color: #999999;"&gt;urls.py&lt;/span&gt;&lt;/div&gt;
&lt;div style="background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;;margin-bottom:15px"&gt;
&lt;pre style="margin: 0; line-height: 125%;"&gt;
&lt;span style="color: #666666;"&gt;...&lt;/span&gt;
urlpatterns &lt;span style="color: #666666;"&gt;=&lt;/span&gt; patterns(&lt;span style="color: #bb4444;"&gt;''&lt;/span&gt;,
                &lt;span style="color: #666666;"&gt;...&lt;/span&gt;,
                &lt;span style="color: #666666;"&gt;...&lt;/span&gt;,
                (&lt;span style="color: #bb4444;"&gt;r'^async/'&lt;/span&gt;, include(&lt;span style="color: #bb4444;"&gt;'shiv.urls'&lt;/span&gt;)),
                &lt;span style="color: #666666;"&gt;...&lt;/span&gt;,
                &lt;span style="color: #666666;"&gt;...&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We will look into Tab next. And hopefully if I find enough time, we will discuss about Box and Widgets too.&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://fauzism.com/post/6684122984/shiv-django"&gt;Part 1&lt;/a&gt; | &lt;a href="http://fauzism.com/post/7184677585/shiv-part-deux"&gt;Part 2&lt;/a&gt;&lt;/p&gt;</description><link>http://fauzism.com/post/7299616780</link><guid>http://fauzism.com/post/7299616780</guid><pubDate>Wed, 06 Jul 2011 17:16:00 +0530</pubDate><category>Django</category><category>Shiv</category></item><item><title>Shiv - Part Deux</title><description>&lt;p&gt;After debating whether to release early or release well, I have settled for the former. I hope that once the code is out in the open and I get ridiculed for the lousy code quality, it will motivate me to find time more aggressively to correct and refine the framework.&lt;/p&gt;
&lt;p&gt;I will try to find some time to continue my little tutorial of Shiv with sample applications in the next installment. In the meantime, here is the link to the git repository. Have a look and feel free to ask me any question that you might have.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/lzdev/Shiv"&gt;&lt;a href="https://github.com/lzdev/Shiv"&gt;https://github.com/lzdev/Shiv&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
 &lt;p&gt;&lt;a href="http://fauzism.com/post/6684122984/shiv-django"&gt;Part 1&lt;/a&gt; | &lt;a href="http://fauzism.com/post/7299616780/shiv-the-third-return-of-tutorial"&gt;Part 3&lt;/a&gt;&lt;/p&gt;</description><link>http://fauzism.com/post/7184677585</link><guid>http://fauzism.com/post/7184677585</guid><pubDate>Sun, 03 Jul 2011 12:29:00 +0530</pubDate><category>Django</category><category>Shiv</category></item><item><title>Shiv - A wrapper over Django</title><description>&lt;p&gt;I joined &lt;a title="LazyZach" target="_blank" href="http://lazyzach.com"&gt;LazyZach&lt;/a&gt; as the first hire back in 2009. I was already in love with Python by then and when it came to deciding which technology to use, the answer was quite obviously, Django.&lt;/p&gt;
&lt;p&gt;While Django does speed up development, I wanted something a bit more streamlined to my thought process. Having my “views” all over the place was definitely not the way I wanted to go. Plus, there was a need for a more clear separation of back end and front end tasks (I was, and still am, a bit weary of all the html and css stuff that goes around). All this and some more made me develop &lt;strong&gt;Shiv&lt;/strong&gt;, a thin wrapper over Django.&lt;/p&gt;
&lt;p&gt;For all those Django noobs out there, one thing I wish to say is that “Django is Python”. Realize this, and life will be so much simpler for you. And yes, do not go about learning Django, learn Python and you will know Django inside out.&lt;/p&gt;
&lt;p&gt;In this post, I will discuss the basic idea behind Shiv. Other key features and benefits like AJAX handling, Widgets, auto JS/CSS minimization, will be discussed in later posts.&lt;/p&gt;
&lt;p&gt;&lt;!-- more --&gt;Coming from a non-web dev background, the way I saw a web site was that it has a bunch of pages. Each page contains a bunch of boxes. Each box in-turn will consist of other boxes.&lt;/p&gt;
&lt;p&gt;Its sort of container containing container model with each container having an associated view.&lt;/p&gt;
&lt;p&gt;The idea of Shiv is to take this abstract container, and add specific behavior to it.&lt;/p&gt;
&lt;p&gt;While the higher level containers will mostly have other lower level containers, a low level container will have some specific data.&lt;/p&gt;
&lt;p&gt;Based on the needs of &lt;a title="LazyZach" target="_blank" href="http://lazyzach.com"&gt;LazyZach&lt;/a&gt;, I came up with the following containers:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Page&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is the parent level item. A URL will call the show() method of this container. It consists of a bunch of boxes and template to show them, along with other media requirements. While rendering, it calls the show method of each box.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Box&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There are 3 kinds of boxes.&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Vanilla Box - Consists of many types of Tab Boxes&lt;/li&gt;
&lt;li&gt;Tab Box - Consists of a single type of Element. Its basically a list of that type of Element&lt;/li&gt;
&lt;li&gt;Widget Box - Same as Vanilla Box except that instead of a Page including it as a property, it itself defines the Pages it wants to be a part of&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;3. Element&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is the lowest level container. Most of the action happens here. An Element’s direct parent box will have only one type of Element in it.&lt;/p&gt;
&lt;p&gt;Each container listed above has a corresponding Media class. A media class will define the template that the container needs plus any other JS/CSS/Images that it may require. All Media classes are defined separately. So if you have separate people writing your back end and front end code, the front end guy will be responsible for handling the Media file.&lt;/p&gt;
&lt;p&gt;I will show some sample code for creating the various containers and some more internals of Shiv in the next installment. The project will be open sourced as soon as I am able to remove some of the coupling that it has with LazyZach’s codebase.&lt;/p&gt;
&lt;p&gt;After LazyZach, I used Shiv for my side project too (&lt;a title="CinEight" target="_blank" href="http://cineight.com"&gt;CinEight&lt;/a&gt;, I have not worked on it for quite a while now). &lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: I am not too good at writing posts, so if this post is confusing or if you have any questions, feel free to leave a comment below or contact me. My HN ID is yousuffauzan.&lt;/em&gt;&lt;/p&gt; 

&lt;p&gt;&lt;a href="http://fauzism.com/post/7184677585/shiv-part-deux"&gt;Part 2&lt;/a&gt; | &lt;a href="http://fauzism.com/post/7299616780/shiv-the-third-return-of-tutorial"&gt;Part 3&lt;/a&gt;&lt;/p&gt;</description><link>http://fauzism.com/post/6684122984</link><guid>http://fauzism.com/post/6684122984</guid><pubDate>Sun, 19 Jun 2011 15:12:00 +0530</pubDate><category>Django</category><category>Shiv</category></item></channel></rss>

