Exemplo n.º 1
0
    def render(self, **kwargs):
        """render a file field and the file preview
        """
        html = Base.render(self, **kwargs)
        value = self.field.value
        if value:
            html += self.render_readonly()

            # add the old value for objects not yet stored
            old_value = '%s--old' % self.name
            html += h.hidden_field(old_value, value=value)
        return html
Exemplo n.º 2
0
 def __render_map(self, read_only):
     options = self.__get_options()
     geometry_type = self.__get_type_information()
     
     if len(self.field.errors) > 0:
         # if re-displaying a form with errors, get the WKT string
         # from the form submission
         wkt = self.params.getone(self.name)
     else:
         # if displaying a new form, try to query the geometry in WKT
         wkt = self.__get_wkt_for_field(options);
     
     if not options.get('show_map', True):
         # if no map should be shown, just display a text field
         if read_only:
             return h.text_field(self.name, value=wkt, readonly='readonly')
         else: 
             return h.text_field(self.name, value=wkt)
     
     template_args = {
                     'field_name' : self.name,
                     'wkt' : wkt,
                     'input_field' : h.hidden_field(self.name, value=wkt),
                     #'input_field' : h.text_field(self.name, value=wkt), # for debug
                     'read_only' : 'true' if read_only else 'false',
                     'is_collection' : 'true' if geometry_type['is_collection'] else 'false',
                     'geometry_type' : geometry_type['geometry_type'] ,
                     'default_lat' : options.get('default_lat', None),
                     'default_lon' : options.get('default_lon', None),
                     'zoom' : options.get('zoom', None),
                     'map_width' : options.get('map_width', None),
                     'map_height' : options.get('map_height', None),
                     'base_layer' : options.get('base_layer', None),
                     'openlayers_lib' : options.get('openlayers_lib', None)   
                 }
     
     try:
         """Try to render the template with the FormAlchemy template engine which assumes that
         the 'map.mako' template file is in the same folder as the other FormAlchemy template files.
         This is the case when used inside a Pylons app."""
         return config.engine.render('map', **template_args)
     except (TemplateLookupException, AttributeError, ValueError):
         # otherwise render the default template using an own template engine
         map_template = self.get_templates().get_template('map.mako')
         return map_template.render(**template_args)
Exemplo n.º 3
0
    def __render_map(self, read_only):
        options = self.__get_options()
        geometry_type = self.__get_type_information()

        if len(self.field.errors) > 0:
            # if re-displaying a form with errors, get the WKT string
            # from the form submission
            wkt = self.params.getone(self.name)
        else:
            # if displaying a new form, try to query the geometry in WKT
            wkt = self.__get_wkt_for_field(options)

        if not options.get('show_map', True):
            # if no map should be shown, just display a text field
            if read_only:
                return h.text_field(self.name, value=wkt, readonly='readonly')
            else:
                return h.text_field(self.name, value=wkt)

        template_args = {
            'field_name': self.name,
            'input_field': h.hidden_field(self.name, value=wkt),
            #'input_field' : h.text_field(self.name, value=wkt), # for debug
            'map_width': options.get('map_width', None),
            'map_height': options.get('map_height', None),
            'openlayers_lib': options.get('openlayers_lib', None),
            'insert_libs': options.get('insert_libs', True),
            'run_js': options.get('run_js', True),
            # we use _renderer as renderer is a named argument
            # of pyramid_formalchemy.utils.TemplateEngine:__init__
            # This is fragile!
            '_renderer': self,
        }

        try:
            """Try to render the template with the FormAlchemy template engine which assumes that
            the 'map.mako' template file is in the same folder as the other FormAlchemy template files.
            This is the case when used inside a Pylons app."""
            return config.engine.render('map', **template_args)
        except (TemplateLookupException, AttributeError, ValueError):
            # otherwise render the default template using an own template engine
            map_template = self.get_templates().get_template('map.mako')
            return map_template.render(**template_args)
Exemplo n.º 4
0
 def render(self, **kwargs):
     return h.hidden_field(self.name, value=self._value, **kwargs)