def make_content(self): self.content = [] self.create_inner_details() if self.inner_details: # Header: thead_row = tr() for field in self.inner_details[0].fields.values(): thead_row.add(th(field.label)) thead_row.add(th(_('From')), th(_('To')), th(_('L.'))) self.add(thead(thead_row)) # rows (each row is made from one detail of object in object list self.add(tbody(tagid('tbody'))) for i, detail in enumerate(self.inner_details): history_rec = self.value[i] date_from = history_rec._from #recoder.corba_to_datetime(history_rec._from) date_to = history_rec.to #recoder.corba_to_datetime(history_rec.to) logger_url = f_urls['logger'] + 'detail/?id=%s' % history_rec.requestId history_tr = tr() if i > 0: history_tr.cssc = 'history_row' log_req_link = a(attr(href=logger_url), img(attr(src='/img/icons/open.png'))) if history_rec.requestId else '' history_tr.add( detail, td(attr(cssc='history_dates_field'), date_from), td(attr(cssc='history_dates_field'), date_to), td(attr(cssc='history_dates_field'), log_req_link) ) self.add(history_tr) else: self.add(div(attr(cssc='field_empty')))
def make_content(self): self.content = [] self.create_inner_details() if self.inner_details: # Header: thead_row = tr() for field in self.inner_details[0].fields.values(): thead_row.add(th(field.label)) thead_row.add(th(_('From')), th(_('To')), th(_('L.'))) self.add(thead(thead_row)) # rows (each row is made from one detail of object in object list self.add(tbody(tagid('tbody'))) for i, detail in enumerate(self.inner_details): history_rec = self.value[i] date_from = history_rec._from #recoder.corba_to_datetime(history_rec._from) date_to = history_rec.to #recoder.corba_to_datetime(history_rec.to) logger_url = f_urls[ 'logger'] + 'detail/?id=%s' % history_rec.requestId history_tr = tr() if i > 0: history_tr.cssc = 'history_row' log_req_link = a(attr( href=logger_url), img(attr(src='/img/icons/open.png')) ) if history_rec.requestId else '' history_tr.add( detail, td(attr(cssc='history_dates_field'), date_from), td(attr(cssc='history_dates_field'), date_to), td(attr(cssc='history_dates_field'), log_req_link)) self.add(history_tr) else: self.add(div(attr(cssc='field_empty')))
def create_layout(self): form = self.form self.add(tbody(tagid('tbody'))) # Following block creates self.all_fields, self.errors and # non_field_errors from fields and their forms (if they are # compound fields) recursively (obtaining linear structure # from tree structure). non_field_errors = [] # [names, labels, form or field], it is stack (depth-first-search) open_nodes = [[[], [], self.form]] while open_nodes: names, labels, tmp_node = open_nodes.pop() # Add errors from this tmp_node - for fields using composed name # and join all non_field_errors together. if isinstance(tmp_node, filterforms.FilterForm): if tmp_node.is_bound: non_field_errors.extend(tmp_node.non_field_errors()) for error_name, error in tmp_node.errors.items(): if error_name == forms.NON_FIELD_ERRORS: continue self.all_errors['-'.join(names + [error_name])] = error # 'reversed': compensation for the reverse order onstack for field in reversed(tmp_node.fields.values()): if not isinstance(field, CompoundFilterField): open_nodes.append([names, labels, field]) else: open_nodes.append([ names + [field.name], labels + [field.label], field.form ]) else: filter_name = tmp_node.name composed_name = '-'.join(names + [filter_name]) tmp_node.label = '.'.join(labels + [tmp_node.label]) self.all_fields.append([composed_name, tmp_node]) if non_field_errors: self.tbody.add( tr( td(attr(colspan=self.columns_count), 'Errors:', form.non_field_errors()))) self.tbody.add( tr(attr(cssc='filtertable_header'), th(attr(colspan='2'), self.form._get_header_title()), th(div(attr(cssc='for_fields_button extjs'))))) for composed_name, field in self.all_fields: errors = self.all_errors.get(composed_name, None) self.tbody.add( tr(attr(cssc='field_row ' + composed_name), self.build_field_row(field, errors))) self.add( script(attr(type='text/javascript'), 'filterObjectName = "%s"' % self.form.get_object_name())) # global javascript variable self.tbody.add(self.build_fields_button())
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())
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)
def layout_fields(self): section_name = self.section_spec[0] section_id = self.section_spec[1] link_id = "%s_display" % section_id self.add(div( attr(style="text-align: right; padding-right: 1em;"), a( "hide", attr(href="JavaScript:void();"), onclick="show_hide('%s', '%s');" % (section_id, link_id), id=link_id))) self.add(table(tagid("table"), id=section_id)) self.add(legend(section_name)) fields_in_section = self.get_fields() hidden_fields = [] for field in fields_in_section: if field.is_hidden: hidden_fields.append(field) continue label_str = self.get_label_name(field) errors = self.form.errors.get(field.name_orig, None) self.table.add(tr( td(label_str), td(errors, field))) self.add(hidden_fields)
def make_content(self): def _add_row(i, j, detail): history_tr = tr() history_tr.cssc = '' if i > 0: history_tr.cssc += ' history_row' if detail: history_tr.add(detail) else: history_tr.add( td(attr(colspan=len(thead_row.content) - 3), div(attr(cssc='field_empty')))) if j == 0: history_tr.cssc += ' history_division_row' rowspan_attr = attr(rowspan=len(self.inner_details[i]) or 1, cssc='history_dates_field') log_req_link = a(attr( href=logger_url), img(src='/img/icons/open.png') ) if history_rec.requestId else '' history_tr.add(td(rowspan_attr, date_from), td(rowspan_attr, date_to), td(rowspan_attr, log_req_link)) self.add(history_tr) self.content = [] self.create_inner_details() if self.inner_details: # Header: thead_row = tr() # Find one (any of them) innter detail for obtaining field labels (cannot take first one, becouse firt can be empty list): some_detail = None for details in self.inner_details: if details: some_detail = details[0] break for field in some_detail.fields.values(): thead_row.add(th(field.label)) thead_row.add(th(_('From')), th(_('To')), th(_('L.'))) self.add(thead(thead_row)) # rows (each row is made from one detail of object in object list self.add(tbody(tagid('tbody'))) for i in range(len(self.inner_details)): history_rec = self.value[i] date_from = history_rec._from #recoder.corba_to_datetime(history_rec._from) date_to = history_rec.to #recoder.corba_to_datetime(history_rec.to) logger_url = f_urls[ 'logger'] + 'detail/?id=%s' % history_rec.requestId if self.inner_details[i]: for j, detail in enumerate(self.inner_details[i]): _add_row(i, j, detail) else: _add_row(i, 0, None) else: self.add(div(attr(cssc='field_empty')))
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 create_layout(self): form = self.form self.add(tbody(tagid('tbody'))) # Following block creates self.all_fields, self.errors and # non_field_errors from fields and their forms (if they are # compound fields) recursively (obtaining linear structure # from tree structure). non_field_errors = [] # [names, labels, form or field], it is stack (depth-first-search) open_nodes = [[[], [], self.form]] while open_nodes: names, labels, tmp_node = open_nodes.pop() # Add errors from this tmp_node - for fields using composed name # and join all non_field_errors together. if isinstance(tmp_node, filterforms.FilterForm): if tmp_node.is_bound: non_field_errors.extend(tmp_node.non_field_errors()) for error_name, error in tmp_node.errors.items(): if error_name == forms.NON_FIELD_ERRORS: continue self.all_errors['-'.join(names + [error_name])] = error # 'reversed': compensation for the reverse order onstack for field in reversed(tmp_node.fields.values()): if not isinstance(field, CompoundFilterField): open_nodes.append([names, labels, field]) else: open_nodes.append([ names + [field.name], labels + [field.label], field.form]) else: filter_name = tmp_node.name composed_name = '-'.join(names + [filter_name]) tmp_node.label = '.'.join(labels + [tmp_node.label]) self.all_fields.append([composed_name, tmp_node]) if non_field_errors: self.tbody.add(tr(td( attr(colspan=self.columns_count), 'Errors:', form.non_field_errors()))) self.tbody.add(tr( attr(cssc='filtertable_header'), th(attr(colspan='2'), self.form._get_header_title()), th(div(attr(cssc='for_fields_button extjs'))))) for composed_name, field in self.all_fields: errors = self.all_errors.get(composed_name, None) self.tbody.add(tr( attr(cssc='field_row ' + composed_name), self.build_field_row(field, errors))) self.add(script( attr(type='text/javascript'), 'filterObjectName = "%s"' % self.form.get_object_name())) # global javascript variable self.tbody.add(self.build_fields_button())
def create_layout(self): formset = self.formset self.add(fieldset(tagid('fieldset'))) self.fieldset.add(tbody(tagid('tbody'))) tb = self.fieldset.tbody if formset.non_form_errors(): tb.add(tr(td( attr(colspan=self.columns_count), _('Errors:'), formset.non_form_errors()))) for form in formset.forms: tb.add(tr(td(form))) formset.add(formset.management_form.fields.values()) if not formset.is_nested: tb.add(self.get_submit_row())
def make_content(self): def _add_row(i, j, detail): history_tr = tr() history_tr.cssc = '' if i > 0: history_tr.cssc += ' history_row' if detail: history_tr.add(detail) else: history_tr.add(td(attr(colspan=len(thead_row.content) - 3), div(attr(cssc='field_empty')))) if j == 0: history_tr.cssc += ' history_division_row' rowspan_attr = attr(rowspan=len(self.inner_details[i]) or 1, cssc='history_dates_field') log_req_link = a(attr(href=logger_url), img(src='/img/icons/open.png')) if history_rec.requestId else '' history_tr.add( td(rowspan_attr, date_from), td(rowspan_attr, date_to), td(rowspan_attr, log_req_link) ) self.add(history_tr) self.content = [] self.create_inner_details() if self.inner_details: # Header: thead_row = tr() # Find one (any of them) innter detail for obtaining field labels (cannot take first one, becouse firt can be empty list): some_detail = None for details in self.inner_details: if details: some_detail = details[0] break for field in some_detail.fields.values(): thead_row.add(th(field.label)) thead_row.add(th(_('From')), th(_('To')), th(_('L.'))) self.add(thead(thead_row)) # rows (each row is made from one detail of object in object list self.add(tbody(tagid('tbody'))) for i in range(len(self.inner_details)): history_rec = self.value[i] date_from = history_rec._from #recoder.corba_to_datetime(history_rec._from) date_to = history_rec.to #recoder.corba_to_datetime(history_rec.to) logger_url = f_urls['logger'] + 'detail/?id=%s' % history_rec.requestId if self.inner_details[i]: for j, detail in enumerate(self.inner_details[i]): _add_row(i, j, detail) else: _add_row(i, 0, None) else: self.add(div(attr(cssc='field_empty')))
def layout_start(self): section_name = self.section_spec[0] css_class = 'section_table' # if self.detail.is_nested: # css_class = 'nested_' + css_class self.cssc = css_class if section_name: self.add(caption(attr(cssc='section_label'), section_name + ':')) self.add(tbody(tagid('tbody')))
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 layout_start(self): section_name = self.section_spec[0] css_class = 'section_table' # if self.detail.is_nested: # css_class = 'nested_' + css_class self.cssc=css_class if section_name: self.add(caption(attr(cssc='section_label'), section_name + ':')) self.add(tbody(tagid('tbody')))
def create_layout(self): self.add(tbody(tagid('tbody'))) form_count = len(self.form.forms) for i, inner_form in enumerate(self.form.forms): if i > 0 and i < form_count: self.tbody.add(tr(attr(cssc='or_row'), self.build_or_row())) self.tbody.add(tr(td(inner_form))) self.tbody.add(self.get_submit_row()) self.tbody.add(script(attr(type='text/javascript'), noesc(self.union_form_js()))) debug('After create unionlayout')
def create_layout(self): self.content = [] formset = self.formset self.add(fieldset(tagid('fieldset'))) self.fieldset.add(tbody(tagid('tbody'))) tb = self.fieldset.tbody if formset.non_form_errors(): tb.add(tr(td( attr(colspan=self.columns_count), _('Errors:'), formset.non_form_errors()))) for form in formset.forms: tb.add(tr(td(form))) formset.add(formset.management_form.fields.values()) if not formset.is_nested: tb.add(self.get_submit_row())
def create_layout(self): self.add(tbody(tagid('tbody'))) form_count = len(self.form.forms) for i, inner_form in enumerate(self.form.forms): if i > 0 and i < form_count: self.tbody.add(tr(attr(cssc='or_row'), self.build_or_row())) self.tbody.add(tr(td(inner_form))) self.tbody.add(self.get_submit_row()) self.tbody.add( script(attr(type='text/javascript'), noesc(self.union_form_js()))) debug('After create unionlayout')
def create_layout(self): formset = self.formset self.add(div(tagid('div'))) if formset.non_form_errors(): self.div.add(div(_('Errors:')), div(formset.non_form_errors())) for form in formset.forms: self.div.add(div(form)) formset.add(formset.management_form.fields.values()) if not formset.is_nested: self.div.add(self.get_submit_row())
def make_content(self): self.content = [] if self.inner_details: parent = self.parent_widget.parent_widget for detail in self.inner_details: if detail.data['type'] == u'MAILING': del detail.fields['type'] del detail.fields['companyName'] detail.layout_class = SectionDetailLayout parent.add( div(attr(cssc='section_label'), 'Mailing address:')) parent.add(detail) self.inner_details.remove(detail) break if self.inner_details: # Header: parent.add( table(tagid('others'), attr(cssc='section_table history_list_table'))) parent.others.add( div(attr(cssc='section_label'), 'Other addresses:')) thead_row = tr() for field in self.inner_details[0].fields.values(): thead_row.add(th(field.label)) parent.others.add(thead(thead_row)) # rows (each row is made from one detail of object in object list parent.others.add(tbody(tagid('tbody'))) for detail in self.inner_details: if not detail.data['type'] == u'MAILING': parent.others.tbody.add(detail) else: self.add(div(attr(cssc='field_empty')))
def layout_fields(self): self.add(table(tagid("table"))) self.add(legend(self.section_spec[0])) fields_in_section = self.get_fields() hidden_fields = [] for field in fields_in_section: if field.is_hidden: hidden_fields.append(field) continue label_str = self.get_label_name(field) errors = self.form.errors.get(field.name_orig, None) self.table.add(tr( td(label_str), td(errors, field))) self.add(hidden_fields)
def make_content(self): self.content = [] if self.inner_details: # Header: thead_row = tr() for field in self.inner_details[0].fields.values(): thead_row.add(th(field.label)) self.add(thead(thead_row)) # rows (each row is made from one detail of object in object list self.add(tbody(tagid('tbody'))) for detail in self.inner_details: self.tbody.add(detail) else: self.add(div(attr(cssc='field_empty')))
def layout_start(self): section_name = self.section_spec[0] section_id = self.section_spec[1] link_id = "%s_display" % section_id if section_name: self.add(legend(section_name)) self.add(div( attr(style="text-align: right; padding-right: 1em;"), a( "hide", attr(href="JavaScript:void();"), onclick="show_hide('%s', '%s');" % (section_id, link_id), id=link_id, title="Click to show or hide the fieldset contents."))) self.add(table( tagid('table'), attr(cssc="form_table"), id=section_id))
def make_content(self): self.content = [] self._create_inner_details() if self.inner_details: # Header: thead_row = tr() for field in self.inner_details[0].fields.values(): thead_row.add(th(field.label)) self.add(thead(thead_row)) # rows (each row is made from one detail of object in object list self.add(tbody(tagid('tbody'))) for detail in self.inner_details: self.tbody.add(detail) else: self.add(div(attr(cssc='field_empty')))
def layout_start(self): section_name = self.section_spec[0] if section_name: self.add(legend(section_name)) self.add(table(tagid('table'), attr(cssc="form_table")))
def create_layout(self): self.add(tbody(tagid('tbody'))) for section_spec in self.detail.sections: self.tbody.add(tr(td(self.create_section(section_spec))))
def __init__(self, context=None): super(FilterPage, self).__init__(context) c = self.context lang_code = config.lang[0:2] if lang_code == 'cs': # conversion between cs and cz identifier of lagnguage lang_code = 'cz' self.head.add( script( attr(type='text/javascript'), 'scwLanguage = "%s"; //sets language of js_calendar' % lang_code, 'scwDateOutputFormat = "%s"; // set output format for js_calendar' % config.js_calendar_date_format)) if context.get('form') and (config.debug or not c.get('itertable') or c.get('show_form')): self.main.add(c.form) self.main.add( script(attr(type='text/javascript'), 'Ext.onReady(function () {addFieldsButtons()})')) else: self.main.add( a( attr(href=append_getpar_to_url(add_par_dict={ 'load': 1, 'show_form': 1 })), _('Modify filter'))) if c.get('result'): self.main.add(p(c['result'])) if c.get('witertable'): if c.get('blocking_mode'): self.main.add( h1(attr(id='blocking_text'), _('Administrative blocking'))) self.main.add(c.witertable) if not c.get('blocking_mode'): self.main.add( p(tagid('exports'), _('Table_as'), a(attr(href='?txt=1'), 'TXT'), ',', a(attr(href='?csv=1'), 'CSV'))) if c.get("display_jump_links"): # Display the 'previous' and 'next' links (they auto-submit # the form to display results for the prev./next time interval). jump_links_info = c.get("display_jump_links") self.main.add( div( a( attr(title="Jumps to the previous time period.", href=(jump_links_info['url'] + 'filter/?jump_prev=1&field_name=%s' % jump_links_info['field_name'])), "prev"), a( attr(title="Jumps to the next time period.", href=(jump_links_info['url'] + 'filter/?jump_next=1&field_name=%s' % jump_links_info['field_name'])), "next"))) if c.get('blocking_possible') and not c.get('blocking_mode'): self.main.add( p( a(attr(href='./blocking_start/'), _('Administrative blocking'))))