def editlive(context, context_variable, **kwargs): try: field_value = Variable(context_variable).resolve(context) except VariableDoesNotExist: # When a relation is missing it might raise an exception # and break the entire site. So we just set it blank. field_value = '' field_name = context_variable.split('.')[-1] # Ex: "editlive.adaptors.TextAdaptor" adaptor_str = kwargs.get('adaptor', None) try: context_obj = Variable(context_variable.split('.')[0])\ .resolve(context) request = Variable('request').resolve(context) if kwargs.get('formset'): try: kwargs['field-index'] = Variable('forloop.counter0')\ .resolve(context) except VariableDoesNotExist: kwargs['field-index'] = 0 adaptor = get_adaptor(request, context_obj, field_name, field_value=field_value, kwargs=kwargs, adaptor=adaptor_str) return adaptor.render() except VariableDoesNotExist: logger.warning( "editlive: the template variable \"%s\" doesn't exists." % context_variable) return u''
def save(request, **kwargs): field_name = kwargs.get('field_name') field_value = kwargs.get('field_value') object_id = kwargs.get('object_id') app_label = kwargs.get('app_label') module_name = kwargs.get('module_name') field_options = kwargs.get('field_options') Model = get_model(app_label, module_name) obj = get_object_or_404(Model, pk=object_id) adaptor = get_adaptor(obj, field_name) tpl_filters = kwargs.get('tpl_filters') load_tags = kwargs.get('load_tags') if tpl_filters: adaptor.template_filters = tpl_filters.split('|') if load_tags: adaptor.load_tags = load_tags.split('|') adaptor.set_value(field_value) return simplejson.dumps(adaptor.save())
def save(request, **kwargs): field_name = kwargs.get('field_name') field_value = kwargs.get('field_value') object_id = kwargs.get('object_id') app_label = kwargs.get('app_label') module_name = kwargs.get('module_name') # Unused ? field_options = kwargs.get('field_options') Model = get_model(app_label, module_name) obj = get_object_or_404(Model, pk=object_id) adaptor = get_adaptor(request, obj, field_name) tpl_filters = kwargs.get('tpl_filters') load_tags = kwargs.get('load_tags') if tpl_filters: adaptor.template_filters = tpl_filters.split('|') if load_tags: adaptor.load_tags = load_tags.split('|') adaptor.set_value(field_value) return simplejson.dumps(adaptor.save())
def editlive(context, context_variable, **kwargs): try: field_value = Variable(context_variable).resolve(context) except VariableDoesNotExist: # When a relation is missing it might raise an exception # and break the entire site. So we just set it blank. field_value = '' field_name = context_variable.split('.')[-1] # Ex: "editlive.adaptors.TextAdaptor" adaptor_str = kwargs.get('adaptor', None) context_obj = Variable(context_variable.split('.')[0])\ .resolve(context) if kwargs.get('formset'): try: kwargs['field-index'] = Variable('forloop.counter0')\ .resolve(context) except: kwargs['field-index'] = 0 adaptor = get_adaptor(context_obj, field_name, field_value=field_value,\ kwargs=kwargs, adaptor=adaptor_str) return adaptor.render()