Tickling Django

Check-in [8eace4b0e0]
Login
Overview
SHA1:8eace4b0e02cd9a671f1c648383fa9dca7c1216b
Date: 2010-08-02 18:42:23
User: setok
Comment:Started Template class with basic Tcl rendering skillz.
Timelines: family | ancestors | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2010-08-02
18:42
[8eace4b0e0] Leaf: Started Template class with basic Tcl rendering skillz. (user: setok, tags: trunk)
18:28
[56df9b8406] initial empty check-in (user: Setok, tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added tcl_templates.py version [f0d2f15be5].

























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
import Tkinter
#from django.template import RequestContext
from django.template import Template
#from django.template.loaders import app_directories

class TclTemplate(Template):
    interp = None

    def __init__(self, source):
        Template.__init__(self, source)
        self.interp = Tkinter.Tcl()
        self.source = source

    def assoc_ob(self, ob):
        def caller(*args):
            func = getattr(ob, args[0])
            return func()
        proc = self.interp.register(caller)
        #interp.setvar(var, proc)
        return proc
        
    def render(self, context):
        # flatten the Django Context into a single dictionary.
        context_dict = {}
        for (k, v) in context.iteritems():
            if type(v).__name__ == 'instance':
                v = self.assoc_ob(v)
        self.interp.setvar(k, v)

        return self.interp.call("subst", self.source)

        for d in context.dicts:            
            context_dict.update(d)
        l = dict_to_list(context_dict)
        return super(Template, self).render(context_dict)


# class TclTemplateLoader(BaseLoader):
#     is_usable = True

#     def load_template(self, template_name, template_dirs=None):
#         source, origin = self.load_template_source(template_name, template_dirs)
#         template = TclTemplate(source)
#         return template, origin