Example #1
0
    def make_content(self):
        nperm = None
        if self.owner_form:
            nperms = [
                nperms for nperms in self.owner_form.get_nperms()
                if nperms.split('.')[-1] == self.get_nperm()
            ]
            nperm = nperms[0] if nperms else None
        self.content = []
        # add/remove empty choice according
        if self.required and self.choices and self.choices[
                0] == self.empty_choice:  # remove empty choice:
            self.choices.pop(0)
        elif not self.required and (not self.choices or
                                    (self.choices and self.choices[0] !=
                                     self.empty_choice)):  # add empty choice:
            self.choices.insert(0, self.empty_choice)

        if self.choices:
            user = cherrypy.session.get('user')
            for value, caption in list(self.choices):
                if user and nperm and user.has_nperm(nperm, value):
                    continue
                if self.as_radio_buttons:
                    item = label(
                        input(attr(type='radio', name=self.name, value=value),
                              tagid('radio_input')), caption)
                else:
                    item = option(attr(value=value), caption)
                if unicode(value) == unicode(self.value):
                    if self.as_radio_buttons:
                        item.radio_input.checked = 'checked'
                    else:
                        item.selected = 'selected'
                self.add(item)
Example #2
0
    def create_layout(self):
        form = self.form
        self.add(tbody(tagid('tbody')))
        
        if form.non_field_errors():
            self.tbody.add(tr(td(attr(colspan=self.columns_count), _('Errors:'), form.non_field_errors())))
        hidden_fields = []
        for field in form.fields.values():
            if field.is_hidden:
                hidden_fields.append(field)
                continue
            
            label_str = self.get_label_name(field)
            
            if field.required:
                cell_tag = th
            else:
                cell_tag = td
            
            errors = form.errors.get(field.name_orig, None)
                
            self.tbody.add(tr(
                cell_tag(label(label_str)),
                td(errors, field)))
        self.add(hidden_fields)

        if not form.is_nested:
            self.tbody.add(self.get_submit_row())
Example #3
0
    def create_layout(self):
        detail = self.detail
        self.add(tbody(tagid('tbody')))

        for field in detail.fields.values():
            label_str = self.get_label_name(field)
            self.tbody.add(
                tr(td(attr(cssc='left_label'), label(label_str)), td(field)))
Example #4
0
 def create_layout(self):
     detail = self.detail
     self.add(tbody(tagid('tbody')))
     
     for field in detail.fields.values():
         label_str = self.get_label_name(field)
         self.tbody.add(tr(td(attr(cssc='left_label'), label(label_str)),
                           td(field)
                          )
                       )
    def build_field_row(self, field, errors=None, for_javascript=False):
        if for_javascript:
            label_str = REPLACE_ME_WITH_LABEL + ':'
        else:
            label_str = self.get_label_name(field)

        negation_field = BooleanField('negation|' + field.name, field.negation)
        if for_javascript:
            # Needed for detecting presence of fields such as checkboxes
            # and multiple selects, because they do not send data if they
            # are not checked or no option is selected.
            presention_field = HiddenField('presention|' + field.name, 'on')
        else:
            # Dtto.
            presention_field = HiddenField('presention|' + field.name,
                                           '%03d' % self.field_counter)
            self.field_counter += 1

        if not isinstance(field, CompoundFilterField):
            return notag(td(attr(cssc='label_cell'), label(label_str)),
                         td(presention_field, errors, field),
                         td(negation_field, label('NOT')))
Example #6
0
 def __init__(self, context = None):
     super(BaseSiteMenu, self).__init__(context)
     c = self.context
     if c.has_key('menu'):
         self.menu_container.add(div(attr(id='main-menu'), c.menu))
     if c.get('body_id'):
         self.body.add(attr(id=c.body_id))
     if c.get('headline'):
         self.main.add(h1(c.headline))
     self.right_menu_container.add(
         input(save(self, 'history_checkbox'),
               attr(media_files=['/js/history_button.js', '/js/ext/ext-base.js', '/js/ext/ext-all.js'],
                    id='history_checkbox', 
                    type='checkbox', onchange='setHistory(this)')), 
               label(attr(for_id='history_checkbox'), _('history'))
     )
     if c.history:
         self.history_checkbox.checked = ['', 'checked'][c.history]