Exemplo n.º 1
0
 def _render(self, **kwargs):
     data = self.params
     hour_options = ['HH'] + [(i, str(i)) for i in xrange(24)]
     minute_options = ['MM' ] + [(i, str(i)) for i in xrange(60)]
     second_options = ['SS'] + [(i, str(i)) for i in xrange(60)]
     hh_name = self.name + '__hour'
     mm_name = self.name + '__minute'
     ss_name = self.name + '__second'
     hh = _ternary((data is not None and hh_name in data), lambda: data[hh_name], lambda: str(self.field.model_value and self.field.model_value.hour))
     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.minute))
     ss = _ternary((data is not None and ss_name in data), lambda: data[ss_name], lambda: str(self.field.model_value and self.field.model_value.second))
     return h.select(hh_name, h.options_for_select(hour_options, selected=hh), **kwargs) \
            + ':' + h.select(mm_name, h.options_for_select(minute_options, selected=mm), **kwargs) \
            + ':' + h.select(ss_name, h.options_for_select(second_options, selected=ss), **kwargs)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 def render(self, options, **kwargs):
     if callable(options):
         L = normalized_options(options(self.field.parent))
         if not self.field.is_required() and not self.field.is_collection:
             L.insert(0, self.field._null_option)
     else:
         L = list(options)
     if len(L) > 0:
         if len(L[0]) == 2:
             L = [(k, self.stringify_value(v)) for k, v in L]
         else:
             L = [stringify(k) for k in L]
     return h.select(self.name, h.options_for_select(L, selected=self._value), **kwargs)
Exemplo n.º 4
0
 def render(self, **kwargs):
     karma_url = self.request.registry.settings.get('karma.url')
     if not karma_url:
         return ''
     try:
         karma = requests.get(karma_url, timeout=4, verify=False)
     except requests.exceptions.RequestException:
         return ''
     if karma.status_code != 200:
         return ''
     L = [(k['Titolo'], k['Id']) for k in karma.json()]
     return h.select(self.name, self.value, L, class_='i-can-haz-chzn-select', **kwargs) + \
            h.literal("<script>$('#%s').chosen()</script>" % self.name)
Exemplo n.º 5
0
 def render(self, options, **kwargs):
     if callable(options):
         L = fields._normalized_options(options(self.field.parent))
         if not self.field.is_required() and not self.field.is_collection:
             L.insert(0, self.field._null_option)
     else:
         L = list(options)
     if len(L) > 0:
         if len(L[0]) == 2:
             L = sorted([(k, self.stringify_value(v)) for k, v in L], key=lambda x:unicodelower(x[0]))
         else:
             L = sorted([fields._stringify(k) for k in L], key=unicodelower)
     return h.select(self.name, self.value, L, class_='i-can-haz-chzn-select', **kwargs) + \
            h.literal("<script>$('#%s').chosen()</script>" % self.name)
Exemplo n.º 6
0
 def render(self, options, **kwargs):
     selected = self.value
     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
Exemplo n.º 7
0
    def render(self, options, **kwargs):
        optional_js = ''

        prf = self.project_related_form()
        if prf and self.field.relation_type() == Project:
            optional_js = """\n$("#%(project_id)s").chosen().change(function(){
                                var $project_id = $(this).val();
                                $.getJSON('/admin/Project/'+$project_id+'/list_customer_requests.json', function(data){
                                    var items = [];
            """
            prf_names = [a.renderer.name for a in prf]

            for n in prf_names:
                optional_js += "$('#%s option').remove();" % n
                optional_js += """$.each(data, function(cr) {
                                        items.push("<option value='" + data[cr]['id'] + "'>" + data[cr]['name'] + "</option>");
                                  });
                                  $('#%s').append(items.join(""));""" % n
                optional_js += "$('#%s').trigger('chosen:updated');" % n

            optional_js += "})});"
            optional_js = optional_js % {'project_id':self.name}

        if callable(options):
            L = fields._normalized_options(options(self.field.parent))
            if not self.field.is_required() and not self.field.is_collection:
                L.insert(0, self.field._null_option)
        else:
            L = list(options)
        if len(L) > 0:
            if len(L[0]) == 2:
                L = sorted([(k, self.stringify_value(v)) for k, v in L], key=lambda x:unicodelower(x[0]))
            else:
                L = sorted([fields._stringify(k) for k in L], key=unicodelower)

        return h.select(self.name, self.value, L, class_='i-can-haz-chzn-select', **kwargs) + \
               h.literal("<script>$('#%s').chosen();%s</script>" % (self.name, optional_js))
Exemplo n.º 8
0
 def render(self, options, **kwargs):
     options = [('', '__null_value__')] + [(u.display_name, u.id) for u in model.Session.query(model.User).all()]
     selected = None
     return fa_h.select(self.name, selected, options, **kwargs)
Exemplo n.º 9
0
 def render(self, **kwargs):
     selected = kwargs.get('selected', None) or unicode(self.value)
     options = [(role, role) for role in model.Role.get_all()]
     select = fa_h.select(self.name, selected, options, **kwargs)
     return select
Exemplo n.º 10
0
 def render(self, **kwargs):
     return h.select(self.name, self.value, [('Backlog', '0'), ('Grooming', '1'), ('Board', '2')], **kwargs)
Exemplo n.º 11
0
 def render(self, options, **kwargs):
     options = [('', '__null_value__')] + [(u.name, u.id) for u in model.Session.query(model.AuthorizationGroup).all()]
     selected = None
     return fa_h.select(self.name, selected, options, **kwargs)