Example #1
0
 def render(self, **kwargs):
     from formalchemy import helpers as h
     data = self.field.parent.data
     x_name = self.name + '-x'
     y_name = self.name + '-y'
     x_value = (data is not None and x_name in data) and data[x_name] or str(self.field.value and self.field.value.x or '')
     y_value = (data is not None and y_name in data) and data[y_name] or str(self.field.value and self.field.value.y or '')
     return h.text_field(x_name, value=x_value) + h.text_field(y_name, value=y_value)
Example #2
0
 def render(self, **kwargs):
     from_, to = self._get_value()
     from_html = fa_h.text_field(self.name + '-from',
                                 value=from_,
                                 class_="medium-width",
                                 **kwargs)
     to_html = fa_h.text_field(self.name + '-to',
                               value=to,
                               class_="medium-width",
                               **kwargs)
     html = '%s - %s' % (from_html, to_html)
     return html
Example #3
0
 def render(self, **kwargs):
     from formalchemy import helpers as h
     data = self.field.parent.data
     x_name = self.name + '-x'
     y_name = self.name + '-y'
     x_value = (data is not None
                and x_name in data) and data[x_name] or str(
                    self.field.value and self.field.value.x or '')
     y_value = (data is not None
                and y_name in data) and data[y_name] or str(
                    self.field.value and self.field.value.y or '')
     return h.text_field(x_name, value=x_value) + h.text_field(
         y_name, value=y_value)
Example #4
0
    def render(self, **kwargs):
        from formalchemy import helpers as h
        value= self._value and self._value or ''
        v = value.split('-->')
#        # print len(v)
        von = ''
        bis = ''
        if len(v) == 2:
            von = v[0]
            bis = v[1]
        kw1 = {'class':'datefrom'}
        kw2 = {'class':'dateuntil'}
        return "%s %s" % (h.text_field("%s__von" % self.name, value=von, **kw1), h.text_field("%s__bis" % self.name, value=bis, **kw2))
Example #5
0
        def render(self, options, **kwargs):
            selected = self.value
            if selected is None:
                selected = self.field.default
            options = [('', '')
                       ] + options + [(_('other - please specify'), 'other')]
            option_keys = [key for value, key in options]
            if selected in option_keys:
                select_field_selected = selected
                text_field_value = u''
            elif selected:
                select_field_selected = u'other'
                text_field_value = selected or u''
            else:
                select_field_selected = u''
                text_field_value = u''
            fa_version_nums = formalchemy.__version__.split('.')
            # Requires FA 1.3.2 onwards for this select i/f
            html = literal(
                fa_h.select(self.name,
                            select_field_selected,
                            options,
                            class_="short",
                            **kwargs))

            other_name = self.name + '-other'
            html += literal('<label class="inline" for="%s">%s: %s</label>'
                            ) % (other_name, _('Other'),
                                 literal(
                                     fa_h.text_field(other_name,
                                                     value=text_field_value,
                                                     class_="medium-width",
                                                     **kwargs)))
            return html
Example #6
0
 def render(self, **kwargs):
     value= self._value and self._value or ''
     if value:
         v2 = value.split('-')
         v2.reverse()
         value = ".".join(v2) 
     return h.text_field(self.name, value=str(value), **kwargs)
Example #7
0
 def render(self, **kwargs):
     kwargs['class'] = 'autocomplete'
     kwargs['data-autocomplete-url'] = h.url_for(controller='package',
                                                 action='autocomplete',
                                                 id=None)
     html = fa_h.text_field(self.name, **kwargs)
     return html
Example #8
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)
Example #9
0
 def render(self, **kwargs):
     kwargs['value'] = ' '.join(self.value)
     kwargs['size'] = 60
     api_url = config.get('ckan.api_url', '/').rstrip('/')
     tagcomplete_url = api_url+h.url_for(controller='apiv2/package', action='autocomplete', id=None)
     kwargs['data-tagcomplete-url'] = tagcomplete_url
     kwargs['data-tagcomplete-queryparam'] = 'incomplete'
     kwargs['class'] = 'long tagComplete'
     html = literal(fa_h.text_field(self.name, **kwargs))
     return html
Example #10
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)
Example #11
0
 def render(self, **kwargs):
     kwargs['value'] = ' '.join(self.value)
     kwargs['size'] = 60
     api_url = config.get('ckan.api_url', '/').rstrip('/')
     tagcomplete_url = api_url + h.url_for(
         controller='api', action='tag_autocomplete', id=None)
     kwargs['data-tagcomplete-url'] = tagcomplete_url
     kwargs['data-tagcomplete-queryparam'] = 'incomplete'
     kwargs['class'] = 'long tagComplete'
     html = literal(fa_h.text_field(self.name, **kwargs))
     return html
Example #12
0
 def render(self, **kwargs):
     kwargs['size'] = '40'
     bool_value = (self.value == u'yes')
     return fa_h.check_box(self.name,
                           u'yes',
                           checked=bool_value,
                           **kwargs)
     return fa_h.text_field(self.name,
                            value=bool_value,
                            maxlength=self.length,
                            **kwargs)
 def _render(self, **kwargs):
     data = self.params
     F_ = self.get_translator(**kwargs)
     month_options = [(F_('Month'), 'MM')] + [(F_('month_%02i' % i), str(i)) for i in xrange(1, 13)]
     day_options = [(F_('Day'), 'DD')] + [(i, str(i)) for i in xrange(1, 32)]
     mm_name = self.name + '__month'
     dd_name = self.name + '__day'
     yyyy_name = self.name + '__year'
     mm = _ternary((data is not None and mm_name in data), lambda: data[mm_name],  lambda: str(self.field.model_value and self.field.model_value.month))
     dd = _ternary((data is not None and dd_name in data), lambda: data[dd_name], lambda: str(self.field.model_value and self.field.model_value.day))
     # could be blank so don't use and/or construct
     if data is not None and yyyy_name in data:
         yyyy = data[yyyy_name]
     else:
         yyyy = str(self.field.model_value and self.field.model_value.year or 'YYYY')
     selects = dict(
             m=h.select(mm_name, h.options_for_select(month_options, selected=mm), **kwargs),
             d=h.select(dd_name, h.options_for_select(day_options, selected=dd), **kwargs),
             y=h.text_field(yyyy_name, value=yyyy, maxlength=4, size=4, **kwargs))
     value = [selects.get(l) for l in self.edit_format.split('-')]
     return ' '.join(value)
Example #14
0
 def render(self, **kwargs):
     kwargs['size'] = '40'
     return fa_h.check_box(self.name, True, checked=self.value, **kwargs)
     return fa_h.text_field(self.name, value=self.value, maxlength=self.length, **kwargs)
Example #15
0
 def render(self, **kwargs):
     kwargs['size'] = 60
     return h.text_field(self.name, value=self._value, maxlength=self.length, **kwargs)
Example #16
0
 def render(self, **kwargs):
     value = self._rbase()
     return h.text_field(self.name, value=str(value), **kwargs)
Example #17
0
 def render(self, **kwargs):
     """render html for edit mode"""
     from formalchemy import helpers as h
     return h.text_field(self.name, value='', **kwargs)
Example #18
0
 def render(self, **kwargs):
     # TODO: Will make sense when we have user names
     #kwargs['class'] = 'autocomplete'
     #kwargs['data-autocomplete-url'] = h.url_for(controller='user', action='autocomplete', id=None)
     html = fa_h.text_field(self.name, **kwargs)
     return html
Example #19
0
 def render(self, **kwargs):
     kwargs['size'] = '40'
     bool_value = (self.value == u'yes')
     return fa_h.check_box(self.name, u'yes', checked=bool_value, **kwargs)
     return fa_h.text_field(self.name, value=bool_value, maxlength=self.length, **kwargs)
Example #20
0
 def render(self, options, **kwargs):
     selected = self.value 
     if selected is None: 
         selected = self.field.default
     options = [('', '')] + options + [(_('other - please specify'), 'other')]
     option_keys = [key for value, key in options]
     if selected in option_keys:
         select_field_selected = selected
         text_field_value = u''
     elif selected:
         select_field_selected = u'other'
         text_field_value = selected or u''
     else:
         select_field_selected = u''
         text_field_value = u''
     fa_version_nums = formalchemy.__version__.split('.')
     # Requires FA 1.3.2 onwards for this select i/f
     html = literal(fa_h.select(self.name, select_field_selected,
         options, class_="short", **kwargs))
         
     other_name = self.name+'-other'
     html += literal('<label class="inline" for="%s">%s: %s</label>') % (other_name, _('Other'), literal(fa_h.text_field(other_name, value=text_field_value, class_="medium-width", **kwargs)))
     return html
Example #21
0
 def render(self, **kwargs):
     kwargs['class'] = 'autocomplete-user'
     html = fa_h.text_field(self.name, **kwargs)
     return html
Example #22
0
 def render(self, **kwargs):
     kwargs['class'] = 'autocomplete'
     kwargs['data-autocomplete-url'] = h.url_for(controller='package', action='autocomplete', id=None)
     html = fa_h.text_field(self.name, **kwargs)
     return html
Example #23
0
	def render(self, **kwargs):
		return fa_h.text_field(self.name, value=self.value, maxlength=20, **kwargs)
 def render(self, **kwargs):
     return h.text_field(self.name, value=self._value, maxlength=self.length, **kwargs)
Example #25
0
 def render(self, **kwargs):
     kwargs['size'] = '40'
     return fa_h.text_field(self.name,
                            value=self.value,
                            maxlength=self.length,
                            **kwargs)
Example #26
0
 def render(self, **kwargs):
     return h.text_field(self.name, value=self.value, **kwargs)
 def render(self, **kwargs):
     # TODO: Will make sense when we have user names
     #kwargs['class'] = 'autocomplete'
     #kwargs['data-autocomplete-url'] = h.url_for(controller='user', action='autocomplete', id=None)
     html = fa_h.text_field(self.name, **kwargs)
     return html
Example #28
0
 def render(self, **kwargs):
     from_, to = self._get_value()
     from_html = fa_h.text_field(self.name + '-from', value=from_, class_="medium-width", **kwargs)
     to_html = fa_h.text_field(self.name + '-to', value=to, class_="medium-width", **kwargs)
     html = '%s - %s' % (from_html, to_html)
     return html
Example #29
0
 def render(self, **kwargs):
     return fa_h.text_field(self.name,
                            value=self.value,
                            maxlength=20,
                            **kwargs)
Example #30
0
 def render(self, **kwargs):
     kwargs['size'] = '40'
     return fa_h.text_field(self.name, value=self.value, maxlength=self.length, **kwargs)
Example #31
0
 def render(self, **kwargs):
     kwargs['class'] = 'autocomplete-user'
     html = fa_h.text_field(self.name, **kwargs)
     return html
Example #32
0
 def render(self, **kwargs):
     """
         Anything is rendered into a text_field.
     """
     return h.text_field(self.name, value=self.value, **kwargs)
Example #33
0
 def render(self, **kwargs):
     shape = self.field.model_value
     geo_interface = shape.__geo_interface__
     json = simplejson.dumps(geo_interface)
     return h.text_field(self.name, value=json)