def first_letters(self): """Users with non latin chars (cyrillic, arabic, ...) should override this with a better suited dataset.""" glossary_url = self.context.absolute_url() out = [{ "glyph": _("All"), "has_no_term": False, "zoom_link": glossary_url, "css_class": not self.search_letter and "selected" or None, }] exists = any([ brain.letter for brain in api.content.find( context=self.context, depth=1, portal_type="GlossaryTerm", letter=tuple(string.digits), sort_limit=1, ) ]) letter_map = { "glyph": _("[0-9]"), "has_no_term": not exists, "zoom_link": glossary_url + "?search_letter=[0-9]", "css_class": ("[0-9]" == self.search_letter and "selected" or None), } out.append(letter_map) for letter in tuple(string.ascii_uppercase): exists = any([ brain.letter for brain in api.content.find( context=self.context, depth=1, portal_type="GlossaryTerm", letter=letter, sort_limit=1, ) ]) letter_map = { "glyph": letter, "has_no_term": not exists, "zoom_link": glossary_url + "?search_letter=" + letter.lower(), "css_class": (letter.lower() == self.search_letter.lower() and "selected" or None), } out.append(letter_map) return out
class IGlossary(Interface): """Container for GlossaryTerms.""" text = RichText( title=_(u"Body text"), required=False, )
class IGlossarySettings(Interface): """Schema for the control panel form.""" enable_tooltip = schema.Bool( title=_(u"Enable tooltip?"), description=_(u"Enable tooltip."), default=True, ) enabled_content_types = schema.List( title=_(u"Enabled Content Types"), description=_(u"Only objects of these content types will display " u"glossary terms."), required=False, default=DEFAULT_ENABLED_CONTENT_TYPES, # we are going to list only the main content types in the widget value_type=schema.Choice( vocabulary=u"kitconcept.glossary.PortalTypes"), ) description_length = schema.Int( title=_(u"Description length"), required=True, default=100, ) description_limiter = schema.TextLine( title=_(u"Description ellipsis"), required=True, default=u"…", )
class IGlossaryTerm(Interface): title = schema.TextLine( title=_(u"Glossary Term"), required=True, ) form.widget("variants", cols=25, rows=10) variants = schema.Tuple( title=_(u"Variants"), description=_(u"Enter the variants of the term, one per line."), required=False, value_type=schema.TextLine(), missing_value=(), ) definition = RichText( title=_(u"Body text"), description=_(u"Enter the body text."), required=False, ) model.fieldset("settings", label=_(u"Settings"), fields=["exclude_from_nav"]) # https://community.plone.org/t/how-to-change-existing-dexterity-types-and-behaviors/219/6 exclude_from_nav = schema.Bool( title=_(u"label_exclude_from_nav", default=u"Exclude from navigation"), description=_( u"help_exclude_from_nav", default=u"If selected, this item will not appear in the " u"navigation tree", ), default=True, # Need to be True ) form.omitted("exclude_from_nav") form.no_omit(IEditForm, "exclude_from_nav") form.no_omit(IAddForm, "exclude_from_nav")
class GlossarySettingsEditForm(controlpanel.RegistryEditForm): """Control panel edit form.""" schema = IGlossarySettings label = _(u"Glossary") description = _(u"Settings for the kitconcept.glossary package")