Example #1
0
 def render(self, context):
     try:
         val = get_field_edit_value(context, None) or ""
         # Use refer-to type if value does not include type..
         typval = fill_type_entity_id(
             val, context['field'].description['field_ref_type'])
         textval = SelectValueMapper.encode(typval)
         options = update_choice_labels(context['field']['options'])
         # print repr(options)
         if textval not in [o.value for o in options]:
             options = list(options)  # clone
             options.insert(0, FieldChoice(
                 textval))  # Add missing current value to options
         with context.push(encoded_field_value=textval,
                           field_options=options):
             result = self._template.render(context)
     except Exception as e:
         log.exception("Exception in Select_edit_renderer.render")
         log.error("Select_edit_renderer.render: " + repr(e))
         # log.error("Field val %r"%(val,))
         # log.error("Field name %r"%(context['field'].field_name,))
         # log.error("Field type ref %r"%(context['field'].description['field_ref_type'],))
         # ex_type, ex, tb = sys.exc_info()
         # traceback.print_tb(tb)
         result = repr(e)
     return result
Example #2
0
 def render(self, context):
     """
     Render field placement for editing
     """
     repeat_prefix = get_context_value(context, 'repeat_prefix', "")
     placement = get_field_edit_value(context, "")
     field_name = get_context_field_description_value(
         context, 'field_name', "_unknown_")
     field_placeholder = get_context_field_description_value(
         context, 'field_placeholder', "small:0,12")
     option_elem = placement_option("",
                                    field_placeholder,
                                    placement_selected=(placement == ""))
     pref = ([
         '''<select class="placement-text" name="%s%s">''' %
         (repeat_prefix, field_name), "  " + option_elem
     ])
     opts = []
     if placement != "" and placement not in placement_occupancy:
         option_elem = placement_option(placement,
                                        field_placeholder,
                                        placement_selected=True)
         opts.append("  " + option_elem)
     for opt in placement_occupancy:
         option_elem = placement_option(
             opt, field_placeholder, placement_selected=(placement == opt))
         opts.append("  " + option_elem)
     suff = ['''</select>''']
     return '\n'.join(pref + opts + suff)
Example #3
0
 def render(self, context):
     try:
         val     = get_field_edit_value(context, None) or ""
         if not is_string(val):
             log.error(ValueError("Entity selector value is not string", val))
             val = "@@ unexpected selector %r"%(val,)
         # Use refer-to type if value does not include type..
         typval  = fill_type_entity_id(
             val, context['field'].description['field_ref_type']
             )
         textval = SelectValueMapper.encode(typval)
         options = update_choice_labels(context['field']['options'])
         # print repr(options)
         if textval not in [ o.value for o in options ]:
             options = list(options)                   # clone
             options.insert(0, FieldChoice(textval))   # Add missing current value to options
         with context.push(encoded_field_value=textval, field_options=options):
             result = self._template.render(context)
     except Exception as e:
         log.exception("Exception in Select_edit_renderer.render")
         log.error("Select_edit_renderer.render: "+repr(e))
         # log.error("Field val %r"%(val,))
         # log.error("Field name %r"%(context['field'].field_name,))
         # log.error("Field type ref %r"%(context['field'].description['field_ref_type'],))
         # ex_type, ex, tb = sys.exc_info()
         # traceback.print_tb(tb)
         result = repr(e)
     return result
Example #4
0
 def render(self, context):
     """
     Render token list for editing
     """
     tokenset = get_field_edit_value(context, None)
     with context.push(encoded_field_value=TokenSetValueMapper.encode(tokenset)):
         return self._template.render(context)
Example #5
0
 def render(self, context):
     """
     Render field placement for editing
     """
     repeat_prefix     = get_context_value(context, 'repeat_prefix', "")
     placement         = get_field_edit_value(context, "")
     field_name        = get_context_field_description_value(
         context, 'field_name', "_unknown_"
         )
     field_placeholder = get_context_field_description_value(
         context, 'field_placeholder', "small:0,12"
         )
     option_elem = placement_option(
         "", field_placeholder, placement_selected=(placement=="")
         )
     pref = (
         [ '''<select class="placement-text" name="%s%s">'''%
               (repeat_prefix, field_name)
         , "  "+option_elem
         ])
     opts = []
     if placement != "" and placement not in placement_occupancy:
         option_elem = placement_option(
             placement, field_placeholder, placement_selected=True
             )
         opts.append("  "+option_elem)
     for opt in placement_occupancy:
         option_elem = placement_option(
             opt, field_placeholder, placement_selected=(placement==opt)
             )
         opts.append("  "+option_elem)
     suff = ['''</select>''']
     return '\n'.join(pref+opts+suff)
Example #6
0
 def render(self, context):
     """
     Render token list for editing
     """
     tokenset = get_field_edit_value(context, None)
     with context.push(encoded_field_value=TokenSetValueMapper.encode(tokenset)):
         return self._template.render(context)
Example #7
0
 def render(self, context):
     """
     Render import link for editing
     """
     val = URIImportValueMapper.encode(get_field_edit_value(context, None))
     with context.push(encoded_field_value=val):
         result = self._template.render(context)
     return result
Example #8
0
 def render(self, context):
     """
     Render import link for editing
     """
     val = URIImportValueMapper.encode(get_field_edit_value(context, None))
     with context.push(encoded_field_value=val):
         result = self._template.render(context)
     return result
Example #9
0
 def render(self, context):
     """
     Render Markdown text for editing
     """
     val     = get_field_edit_value(context, None)
     textval = TextMarkdownValueMapper.encode(val)
     with context.push(encoded_field_value=textval):
         result = self._template.render(context)
     return result
Example #10
0
 def render(self, context):
     """
     Render Markdown text for editing
     """
     val = get_field_edit_value(context, None)
     textval = TextMarkdownValueMapper.encode(val)
     with context.push(encoded_field_value=textval):
         result = self._template.render(context)
     return result
 def render(self, context):
     """
     Render import link for editing
     """
     val = get_field_edit_value(context, None)
     resource_name = FileUploadValueMapper.resource_name(val)
     uploaded_file = FileUploadValueMapper.uploaded_file(val)
     with context.push(resource_name=resource_name, uploaded_file=uploaded_file):
         result = self._template.render(context)
     return result
Example #12
0
 def render(self, context):
     """
     Render language-tagged text for editing
     """
     from annalist.views.fields.render_fieldvalue import get_field_edit_value
     textval = TextLanguageValueMapper.encode(get_field_edit_value(context, ""))
     log.debug("text_language_edit_renderer: textval %r"%(textval,))
     with context.push(encoded_field_value=textval):
         result = self._template.render(context)
     return result
Example #13
0
 def render(self, context):
     """
     Render Boolean value for editing
     """
     val     = get_field_edit_value(context, None)
     boolval = BoolCheckboxValueMapper.decode(val)
     textval = BoolCheckboxValueMapper.encode(val)
     boolval = textval.lower() in ["y", "yes", "t", "true"]
     checked = ''' checked="checked"''' if boolval else ''''''
     with context.push(encoded_field_value=textval, checked=checked):
         result = self._template.render(context)
     return result
Example #14
0
 def render(self, context):
     """
     Render Boolean value for editing
     """
     val     = get_field_edit_value(context, None)
     boolval = BoolCheckboxValueMapper.decode(val)
     textval = BoolCheckboxValueMapper.encode(val)
     boolval = textval.lower() in ["y", "yes", "t", "true"]
     checked = ''' checked="checked"''' if boolval else ''''''
     with context.push(encoded_field_value=textval, checked=checked):
         result = self._template.render(context)
     return result
Example #15
0
 def render(self, context):
     try:
         # val      = get_field_view_value(context, None)
         val      = get_field_edit_value(context, None)
         if val is not None:
             if not is_string(val):
                 log.error(ValueError("Entity selector value is not string", val))
                 val = "@@ unexpected selector %r"%(val,)
         typval   = fill_type_entity_id(
             val, context['field'].description['field_ref_type']
             )
         textval  = SelectValueMapper.encode(typval)
         labelval = textval
         linkval  = None
         linkcont = context['field']['continuation_param']
         options  = context['field']['options']
         for o in options:
             # log.info("Select_view_renderer.render: option %r"%(o,))
             if textval == o.value:
                 labelval = o.label
                 linkval  = o.link
                 break
         # log.info(
         #     "Select_view_renderer.render: textval %s, labelval %s, linkval %s"%
         #     (textval, labelval, linkval)
         #     )
     except TargetIdNotFound_Error as e:
         log.debug(repr(e))
         textval = ""
     except TargetEntityNotFound_Error as e:        
         log.debug(repr(e))
         textval = repr(e)
     except Exception as e:
         log.error(repr(e))
         textval = repr(e)
     with context.push(
         field_textval=textval, 
         field_labelval=labelval, 
         field_linkval=linkval,
         field_continuation_param=linkcont):
         try:
             result = self._template.render(context)
         except Exception as e:
             log.error(repr(e))
             result = repr(e)
     # log.debug("Select_view_renderer.render: result %r"%(result,))
     return result
Example #16
0
 def render(self, context):
     try:
         # val      = get_field_view_value(context, None)
         val = get_field_edit_value(context, None)
         typval = fill_type_entity_id(
             val, context['field'].description['field_ref_type'])
         textval = SelectValueMapper.encode(typval)
         labelval = textval
         linkval = None
         linkcont = context['field']['continuation_param']
         options = context['field']['options']
         for o in options:
             # log.info("Select_view_renderer.render: option %r"%(o,))
             if textval == o.value:
                 labelval = o.label
                 linkval = o.link
                 break
         # log.info(
         #     "Select_view_renderer.render: textval %s, labelval %s, linkval %s"%
         #     (textval, labelval, linkval)
         #     )
     except TargetIdNotFound_Error as e:
         log.debug(repr(e))
         textval = ""
     except TargetEntityNotFound_Error as e:
         log.debug(repr(e))
         textval = repr(e)
     except Exception as e:
         log.error(repr(e))
         textval = repr(e)
     with context.push(field_textval=textval,
                       field_labelval=labelval,
                       field_linkval=linkval,
                       field_continuation_param=linkcont):
         try:
             result = self._template.render(context)
         except Exception as e:
             log.error(repr(e))
             result = repr(e)
     # log.debug("Select_view_renderer.render: result %r"%(result,))
     return result