Beispiel #1
0
 def render_readonly(self, options=None, **kwargs):
     if self.raw_value == CustomerRequest.PLACEMENT_BACKLOG:
         return h.literal(u'<span class="label label-important">Backlog</span>')
     elif self.raw_value == CustomerRequest.PLACEMENT_GROOMING:
         return h.literal(u'<span class="label label-warning">Grooming</span>')
     elif self.raw_value == CustomerRequest.PLACEMENT_BOARD:
         return h.literal(u'<span class="label label-success">Board</span>')
     else:
         return h.literal(self.raw_value)
Beispiel #2
0
 def _render(self, default=None, **kwargs):
     value = default or self.value
     self.radios = []
     for i, (choice_name, choice_value) in enumerate( [('Ja','True'),('Nein','False')]):
         choice_id = '%s_%i' % (self.name, i)
         radio = self.widget(self.name, choice_value, id=choice_id,
                             checked=self._is_checked(choice_value, value),
                             **kwargs)
         label = h.label(choice_name, for_=choice_id)
         self.radios.append(h.literal(self.format % dict(field=radio,
                                                         label=label)))
     return h.tag("br").join(self.radios)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
0
        def render(self, **kwargs):
            fanstatic_resources.autocomplete.need()
            filter_by = self.jq_options.get('filter_by')
            if self.raw_value:
                label = getattr(self.raw_value, filter_by, u'Not selected')
            else:
                label = u''

            radio = h.radio_button(self.name, value=self.value, **kwargs)
            radio += h.literal('&nbsp;')
            radio += h.content_tag('span', label)
            children = h.content_tag("span", radio, class_="add-on")
            html = h.content_tag("div", children, class_="input-prepend")
            return ''.join(html)
Beispiel #6
0
        def render(self, **kwargs):
            fanstatic_resources.autocomplete.need()
            filter_by = self.jq_options.get('filter_by')
            if self.raw_value:
                label = getattr(self.raw_value, filter_by, u'Not selected')
            else:
                label = u''

            radio = h.radio_button(self.name, value=self.value, **kwargs)
            radio += h.literal('&nbsp;')
            radio += h.content_tag('span', label)
            children = h.content_tag("span", radio, class_="add-on")
            html = h.content_tag("div", children, class_="input-prepend")
            return ''.join(html)
Beispiel #7
0
    def render_readonly(self, options=None, **kwargs):
        value = self.raw_value
        if value is None:
            return ''

        if not isinstance(value, list):
            if self.request.has_permission('view', value):
                return h.content_tag('a',
                    self.stringify_value(value, as_html=True),
                    href=self.request.fa_url(value.__class__.__name__, fields._pk(value)))
            else:
                return h.content_tag('span', self.stringify_value(value, as_html=True))
        else:
            html = []
            for item in value:
                if self.request.has_permission('view', item):
                    html.append(h.content_tag('a',
                                self.stringify_value(item, as_html=True),
                                href=self.request.fa_url(item.__class__.__name__, fields._pk(item))))
                else:
                    html.append(h.content_tag('span', self.stringify_value(item, as_html=True)))
            return h.literal(',&nbsp;').join(html)
Beispiel #8
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))
Beispiel #9
0
 def render(self, template_name, **kwargs):
     template = self.templates.get(template_name, None)
     return literal(template.render_unicode(**kwargs))
Beispiel #10
0
 def render(self, template_name, **kwargs):
     template = self.templates.get(template_name, None)
     return literal(template.substitute(**kwargs))
Beispiel #11
0
 def render_readonly(self, **kwargs):
     return helpers.content_tag("span", ("," + helpers.tag("br")).join([
         helpers.literal(value) for value in self.raw_value
     ]), style="white-space: nowrap;")
Beispiel #12
0
 def render(self, template_name, **kwargs):
     template = self.templates.get(template_name, None)
     return literal(template.substitute(**kwargs))
Beispiel #13
0
 def render(self, template_name, **kwargs):
     template = self.templates.get(template_name, None)
     return literal(
         template.generate(**kwargs).render('html', doctype=None))
Beispiel #14
0
 def render(self, template_name, **kwargs):
     template = self.templates.get(template_name, None)
     return literal(template.render_unicode(**kwargs))
Beispiel #15
0
 def render_readonly(self, **kwargs):
     v = self.raw_value
     if not v:
         return ''
     return h.literal('<div style="background:%s;">%s</div>' % (v, v))
Beispiel #16
0
 def render(self, template_name, **kwargs):
     template = self.templates.get(template_name, None)
     return literal(template.generate(**kwargs).render('html', doctype=None))
Beispiel #17
0
 def render_readonly(self, **kwargs):
     return helpers.content_tag("span", ("," + helpers.tag("br")).join(
         [helpers.literal(value) for value in self.raw_value]),
                                style="white-space: nowrap;")
Beispiel #18
0
 def render_readonly(self, **kwargs):
     v = self.raw_value
     if not v:
         return ''
     return h.literal('<div style="background:%s;">%s</div>' % (v, v))