def create_page_link(self, page): page_link = Element("a") page_link["href"] = self._get_page_link(page) page_link.append(str(page + 1)) if page == self.page: page_link.add_class("selected") return page_link
def create_select_button(self): select_button = Element("button", name="relation-select", type="submit", class_name="ItemSelector-button select", value=self.member.type.full_name + "-" + self._param_name) select_button.append(translations("woost.views.ItemSelector select")) return select_button
def create_language_label(self, member, language): label = Element("span") label.add_class("field_language") text = translate_locale(language) if self.redundant_translation_labels: text = "(" + text + ")" label.append(text) return label
def create_page_size_control(self): control = Element() control.add_class("page_size") control.append( translations("cocktail.html.PagingControls.results_per_page")) control.input = Element("input", type="text") control.input["name"] = self.page_size_param_name control.append(control.input) return control
def create_group(self, grouping): container = Element() container.add_class("group") container.label = self.create_group_label(grouping) container.append(container.label) self._create_entries(grouping.items, container) self._create_nested_groups(grouping, container) return container
def create_heading(self): if self.heading_type == "hidden_h1": heading = Element("h1") heading.set_style("display", "none") elif self.heading_type == "generic": heading = Element() else: heading = Element(self.heading_type) heading.add_class("heading") heading.append(self.heading) return heading
def build_member_explanation(self, member, entry): explanation = member.get_member_explanation() if explanation and not self.get_member_hidden(member): entry.explanation = \ self.create_member_explanation(member, explanation) if self.table_layout: entry.explanation.tag = "td" row = Element("tr") row.add_class("explanation_row") row.append(entry.explanation) entry.parent.append(row) else: entry.append(entry.explanation)
def create_search_options(self, column, language): filters = [filter.id for filter in self.filters] \ if self.filters \ else [] filter_id = "member-" + column.name filters.append(filter_id) options = Element() options.add_class("search_options") title = Element("div") title.add_class("options_header") title.append(translations("woost.views.ContentTable search header")) options.append(title) add_filter = Element("a") add_filter.add_class("add_filter") add_filter["href"] = "?" + view_state(filter = filters, page = 0) add_filter.append( translations("woost.views.ContentTable add column filter") ) add_filter.set_client_param("filterId", filter_id) options.append(add_filter) return options
def create_label(self, item): label = Element("div") label.add_class("entry_label") label.append(self.get_item_label(item)) if self.filter_item \ and self._is_accessible(item) != ACCESSIBLE: label.add_class("filtered") else: url = self.get_item_url(item) if url is not None: label.tag = "a" label["href"] = url return label
def create_entry(self, item): entry = Element() entry.add_class("entry") entry.check = CheckBox() entry.check.name = self.name entry.check.value = self.is_selected(item) entry.check["value"] = self.get_item_value(item) entry.append(entry.check) entry.label = Element("label") entry.label["for"] = entry.check.require_id() entry.label.append(self.get_item_label(item)) entry.append(entry.label) return entry
def create_label(self, item): if self.should_link(item): label = Element("a") label["href"] = self.get_item_uri(item) else: label = Element("span") label.append(self.get_item_label(item)) if self.emphasized_selection and item is self.selection: if label.tag == "a": label = Element("strong", children=[label]) else: label.tag = "strong" return label
def _ready(self): styles = [ "%s=%s" % (translations(style), style.class_name) for style in Style.select({"applicable_to_text": True}) ] d = self.tinymce_params.setdefault d("theme_advanced_styles", ";".join(styles)) d("init_instance_callback", "woost.initRichTextEditor") load_plugin = Element("script") load_plugin["type"] = "text/javascript" load_plugin.append( "tinymce.PluginManager.load('advimagescale', '/resources/scripts/advimagescale/editor_plugin.js');" ) self.append(load_plugin) TinyMCE._ready(self)
def create_button(self, name): button = Element("a") button.add_class("button") button.add_class(name) button.icon = Element("img", src="/resources/images/%s.png" % name, alt=translations( "cocktail.html.Pager.%s_button" % name)) button.icon["title"] = button.icon["alt"] @when(button.icon.ready_stage) def set_button_style(e): if self.button_style == "characters": button.icon.tag = "span" button.icon["src"] = None button.icon["alt"] = None button.icon.append(self.button_characters[name]) button.append(button.icon) return button
def create_member_entry(self, member): value = member.schema.full_name + "." + member.name entry = Element() entry.check = CheckBox() entry.check["name"] = self.name entry.check.require_id() entry.check.value = value in self.value entry.check["value"] = value entry.append(entry.check) entry.label = Element("label") entry.label["for"] = entry.check["id"] entry.label.append(translations(member.schema.name + "." + member.name)) entry.append(entry.label) return entry
def create_class_entry(self, cls): entry = Element() entry.add_class("content_type") entry.label = self.create_class_label(cls) entry.append(entry.label) entry.members_container = Element() entry.members_container.add_class("members") has_visible_members = False for member in cls.members(False).itervalues(): if self.member_is_eligible(member): has_visible_members = True entry.members_container.append( self.create_member_entry(member)) if has_visible_members: entry.append(entry.members_container) entry.derived_classes_container = Element() entry.derived_classes_container.add_class("derived_classes") entry.append(entry.derived_classes_container) for derived_schema in cls.derived_schemas(recursive=False): if derived_schema.visible: entry.derived_classes_container.append( self.create_class_entry(derived_schema)) return entry
def create_label(self, member, language=None): label = Element("label") label.add_class("field_label") text = self.get_member_label(member) if text: label.label_title = self.create_label_title(member, text) label.append(label.label_title) if language and self.redundant_translation_labels: label.label_language = self.create_language_label( member, language) label.append(label.label_language) if self.required_marks and member.editable == schema.EDITABLE: if isinstance(member, schema.Collection): is_required = (isinstance(member.min, int) and member.min) else: is_required = (member.required == True) if is_required: label.required_mark = self.create_required_mark(member) label.append(label.required_mark) else: label.visible = False return label
def create_empty_option(self): entry = Element("li") entry.control = Element("input", type=self._control_type, name=self.name, value="", checked=self.value is None) bind_member(self, entry.control) entry.append(entry.control) entry.label = Element("label") entry.label.add_class("entry_label") entry.label.add_class("empty_option") entry.label.append( translations("woost.views.ContentTypePicker.empty_label")) entry.append(entry.label) entry.label["for"] = entry.control.require_id() return entry
def create_fieldset(self, group_id): fieldset = Element("fieldset") fieldset.add_class(group_id.replace(".", "-")) fieldset.legend = self.create_fieldset_legend(group_id) if fieldset.legend is None: fieldset.add_class("anonymous") else: fieldset.append(fieldset.legend) fieldset.fields = Element("table" if self.table_layout else "div") fieldset.fields.add_class("fieldset_fields") fieldset.append(fieldset.fields) explanation = self.schema.translate_group(group_id, suffix=".explanation") if explanation: fieldset.explanation = \ self.create_fieldset_explanation(explanation) fieldset.fields.append(fieldset.explanation) return fieldset
def create_new_button(self): new_button = Element(class_name="ItemSelector-button new") instantiable_types = set( content_type for content_type in ([self.member.type] + list(self.member.type.derived_schemas())) if content_type.visible and content_type.instantiable and get_current_user().has_permission(CreatePermission, target=content_type)) if len(instantiable_types) > 1: new_button.add_class("selector") label = Element("span", class_name="label") new_button.append(label) container = Element(class_name="selector_content") new_button.append(container) content_type_tree = templates.new("woost.views.ContentTypeTree") content_type_tree.root = self.member.type content_type_tree.filter_item = instantiable_types.__contains__ @extend(content_type_tree) def create_label(tree, content_type): label = call_base(content_type) label.tag = "button" label["type"] = "submit" label["name"] = "relation-new" label[ "value"] = self.member.name + "-" + content_type.full_name return label container.append(content_type_tree) else: new_button.tag = "button" new_button["type"] = "submit" new_button["name"] = "relation-new" new_button["value"] = \ self.member.name + "-" + list(instantiable_types)[0].full_name label = new_button label.append(translations("woost.views.ItemSelector new")) return new_button
def _ready(self): if self.redundant_translation_labels: self.add_class("redundant_translation_labels") else: self.add_class("grouped_translation_labels") self._fill_fields() if self.embeded: if self.tag == "form": self.tag = "fieldset" self.buttons.visible = False elif self.default_button: hidden_button_block = Element() hidden_button_block.set_style("position", "absolute") hidden_button_block.set_style("left", "-1000px") hidden_button_block.set_style("top", "-1000px") hidden_button = Element(self.default_button.tag) for key, value in self.default_button.attributes.items(): hidden_button[key] = value hidden_button_block.append(hidden_button) self.insert(0, hidden_button_block)
def create_field_instance(self, member, language=None): field_instance = Element("td" if self.table_layout else "div") field_instance.add_class("field_instance") # Label if not self.get_member_hidden(member): if member.translated and not self.redundant_translation_labels: label = self.create_language_label(member, language) else: label = self.create_label(member, language) field_instance.label = label field_instance.append(label) # Control with language_context(language): field_instance.control = self.create_control(self.data, member) if field_instance.control.class_css: for class_name in field_instance.control.class_css.split(" "): field_instance.add_class("field_instance-" + class_name) insert = getattr(field_instance.control, "insert_into_form", None) if insert: insert(self, field_instance) else: field_instance.append(field_instance.control) if field_instance.control.tag \ in ("input", "button", "select", "textarea"): field_instance.label["for"] = field_instance.control.require_id() return field_instance
def create_sorting_options(self, column, language): if self.order: direction = self._sorted_columns.get((column.name, language)) else: direction = None order_param = column.name if language: order_param += "." + language options = Element() options.add_class("sorting_options") title = Element("div") title.add_class("options_header") title.append(translations("woost.views.ContentTable sorting header")) options.append(title) asc = options.ascending = Element("a") asc.add_class("ascending") asc["href"] = "?" + view_state(order = order_param, page = 0) asc.append(translations("woost.views.ContentTable sort ascending")) options.append(asc) if direction is PositiveExpression: asc.add_class("selected") desc = options.ascending = Element("a") desc.add_class("descending") desc["href"] = "?" + view_state(order = "-" + order_param, page = 0) desc.append(translations("woost.views.ContentTable sort descending")) options.append(desc) if direction is NegativeExpression: desc.add_class("selected") return options
def create_header_options(self, column, language): options = Element() options.add_class("selector_content") if self.get_member_sortable(column): sorting_options = self.create_sorting_options(column, language) options.append(sorting_options) if column.grouping: grouping_options = self.create_grouping_options( column, language ) options.append(grouping_options) if self.get_member_searchable(column): search_options = self.create_search_options(column, language) options.append(search_options) return options
def create_field(self, member): hidden = self.get_member_hidden(member) entry = Element("tr" if self.table_layout else "div") entry.field_instances = [] if hidden: entry.tag = None else: entry.add_class("field") entry.add_class(member.name + "_field") if member.required: entry.add_class("required") def create_instance(language=None): if hidden: with language_context(language): return self.create_hidden_input(self.data, member) else: instance = self.create_field_instance(member, language) entry.field_instances.append(instance) return instance if member.translated: entry.add_class("translated") if not hidden and not self.redundant_translation_labels: entry.append(self.create_label(member)) for language in (self.translations if self.translations is not None else (get_language(), )): field_instance = create_instance(language) field_instance.add_class(language) entry.append(field_instance) else: entry.append(create_instance()) return entry
def create_value_cell(self, value): value_cell = Element("td") value_cell.display = self.ui_generator.create_member_display( self.value, self.member.values, value) value_cell.append(value_cell.display) return value_cell
def create_key_cell(self, key): key_cell = Element("th") key_cell.display = self.ui_generator.create_member_display( self.value, self.member.keys, key) key_cell.append(key_cell.display) return key_cell
def create_required_mark(self, member): mark = Element("span") mark.add_class("required_mark") mark.append("*") return mark
def create_label_title(self, member, text): label_title = Element("span") label_title.add_class("label_title") label_title.append(text) return label_title
def create_member_explanation(self, member, explanation): label = Element() label.add_class("explanation") label.append(explanation) return label
def create_fieldset_explanation(self, explanation): label = Element() label.add_class("explanation") label.append(explanation) return label