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 Side-by-Side Diffs Ignore Whitespace Patch

Added tcl_templates.py version [f0d2f15be5].

            1  +import Tkinter
            2  +#from django.template import RequestContext
            3  +from django.template import Template
            4  +#from django.template.loaders import app_directories
            5  +
            6  +class TclTemplate(Template):
            7  +    interp = None
            8  +
            9  +    def __init__(self, source):
           10  +        Template.__init__(self, source)
           11  +        self.interp = Tkinter.Tcl()
           12  +        self.source = source
           13  +
           14  +    def assoc_ob(self, ob):
           15  +        def caller(*args):
           16  +            func = getattr(ob, args[0])
           17  +            return func()
           18  +        proc = self.interp.register(caller)
           19  +        #interp.setvar(var, proc)
           20  +        return proc
           21  +        
           22  +    def render(self, context):
           23  +        # flatten the Django Context into a single dictionary.
           24  +        context_dict = {}
           25  +        for (k, v) in context.iteritems():
           26  +            if type(v).__name__ == 'instance':
           27  +                v = self.assoc_ob(v)
           28  +        self.interp.setvar(k, v)
           29  +
           30  +        return self.interp.call("subst", self.source)
           31  +
           32  +        for d in context.dicts:            
           33  +            context_dict.update(d)
           34  +        l = dict_to_list(context_dict)
           35  +        return super(Template, self).render(context_dict)
           36  +
           37  +
           38  +# class TclTemplateLoader(BaseLoader):
           39  +#     is_usable = True
           40  +
           41  +#     def load_template(self, template_name, template_dirs=None):
           42  +#         source, origin = self.load_template_source(template_name, template_dirs)
           43  +#         template = TclTemplate(source)
           44  +#         return template, origin