""" various webhelpers template tags, taken from Pylons copyright: Arvis Bickovskis 2007 viestards.lists@gmail.com Pylons webhelpers: http://pylonshq.com/WebHelpers/index.html Ruby on Rails helpers: http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html """ # Prototype function list """ def link_to_remote(name, options={}, **html_options): #started working, unfinished, use remote_function instead def periodically_call_remote(**options): # not started def form_remote_tag(**options): # working on def submit_to_remote(name, value, **options): # not started, is this needed in Django? def update_element_function(element_id, **options): # not started def evaluate_remote_response(): # not started, this only returns text, needed? def remote_function(**options): # working on, def observe_field(field_id, **options): # not started, priority def observe_form(form_id, **options): # not started, priority def options_for_ajax(options): # not started, used inside module def build_observer(cls, name, **options): # not started, used inside module def build_callbacks(options): # not started, used inside module """ from django import template from webhelpers import * #from djangohelpers import rails as django from django.template import Library,Node register = template.Library() var_separator=":" # how separate variables from values in templatetags #-------------------------------------- # functions, that needed to be clear class HelpersNode(template.Node): def __init__(self, widget_code): #print widget_code self.widget_code= widget_code def render(self, context): return self.widget_code def script_visual_effect(parser, token): """Adds various JS visual effects to chosen element {% visual_effect Highlight model1 duration=15 %} """ #print parser, token args = token.split_contents() if len(args)<3: # checking for arg count raise template.TemplateSyntaxError, "%r tag requires at least two arguments" % token.contents[0] args_dict={} # if there is additional arguments, convert from list to dict if len(args)>3: args_dict=list_to_dict(args[3:]) wigdet=rails.scriptaculous.visual_effect(args[1],args[2],**args_dict) return HelpersNode(wigdet) def rails_remote_function(parser, token): """ implementation of Pylons remote function link_to_remote(name, options={}) for docs look into http://pylonshq.com/WebHelpers/module-webhelpers.rails.prototype.html#link_to_remote TODO: write doctests >>> remote_function({'url': 'pong', 'update': 'pongbox'}) new Ajax.Updater('pongbox', 'pong', {asynchronous:true, evalScripts:true}); # If I need to implement exacly the samy behavior as webhelpers, i need inclusion templatetag, but I don't know if it is better. """ # TODO: chech for errors if incorrect separator KeyError args = token.split_contents() if len(args)<3: # checking for arg count raise template.TemplateSyntaxError, "%r tag requires at least two arguments" % token.contents[0] try: widget=rails.prototype.remote_function(**list_to_dict(args[1:])) except KeyError: # if incorrect conversion to dict, return nothing raise template.TemplateSyntaxError, "tag incorrect parameters in tag %r" % token.contents[0] #return HelpersNode(wigdet) # Proof of concept way, return ProofOfConceptNode('remote_function',list_to_dict(args[1:])) def rails_form_remote_tag(parser, token): """ Examples: form_remote_tag(**{'url': 'pong', 'update': 'pongbox'}) '