# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import FileField, TextField from Products.Archetypes.public import FileWidget, RichWidget from Products.Archetypes.public import BaseContent, registerType, OrderedBaseFolder from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from Widgets import HelpTagsWidget, TagsField from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME from Common import CommonMix schema = BaseSchema class HelpTopic(BaseContent, CommonMix): """help topic""" meta_type = "HelpTopic" archetype_name = "HelpTopic" global_allow = 0 #exclude_from_nav = True filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema + Schema(( TagsField('keywords', accessor="getKeywords", widget=HelpTagsWidget( label="Keywords", label_msgid='label_keywords', i18n_domain="eportfolio" ), ), TextField('helptopic', accessor='getTopic', isMetadata=0, required=True, searchable=True, primary=True, validators = ('isTidyHtmlWithCleanup',), default_output_type = 'text/x-html-safe', allowable_content_types = ('text/html',), widget = RichWidget( label='Body', description="", label_msgid='label_blog_body', description_msgid='description_topic', visible={'view':'visible','edit':'visible'}, i18n_domain="eportfolio", ), ), )) actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Manage portal',), }, { 'id':'metadata', 'visible':False, }, ) def showEditableBorder(self, **args): return 1 registerType(HelpTopic, PROJECT_NAME) class HelpChapter(OrderedBaseFolder): """Help chapter""" meta_type = "HelpChapter" archetype_name = "HelpChapter" global_allow = 0 #exclude_from_nav = True filter_content_types = True allowed_content_types = ('HelpTopic',) security = ClassSecurityInfo() schema = schema + Schema(( TextField('description', accessor='getDescription', validators = ('isTidyHtmlWithCleanup',), default_output_type = 'text/x-html-safe', allowable_content_types = ('text/html',), widget = RichWidget( label="Description", description="", label_msgid='label_description', description_msgid='description_description', visible={'view':'visible','edit':'visible'}, i18n_domain="eportfolio", rows = 10 ), ), )) actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/help_chapterview', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Access Denied',), }, { 'id':'metadata', 'visible':False, }, ) def getChapterTopics(self): """ """ return self.objectValues('HelpTopic') def getChapterTopicsById(self, id): """ """ return getattr(self, id) def showEditableBorder(self, **args): return 1 registerType(HelpChapter, PROJECT_NAME) class Help(OrderedBaseFolder): """ help """ meta_type = "Help" archetype_name = "Help" global_allow = 0 #exclude_from_nav = True filter_content_types = True allowed_content_types = ('HelpTopic', 'HelpChapter',) security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/help_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Access Denied',), }, { 'id':'metadata', 'name':'Properties', 'action':'string:${object_url}/base_metadata', 'permissions': ('Access Denied',), }, { 'id':'miniview', 'name':'miniView', 'action':'string:${object_url}/help_miniview', 'permissions': ('View',), }, ) def __init__(self, id): self.id = id def getHelpChapters(self): """ """ return self.objectValues('HelpChapter') def getHelpTopicsByChapter(self, chapter): """ """ chapter = getattr(self, chapter) return chapter.objectValues('HelpTopic') def getChapterTopicsById(self, chapter, id): """ """ chapter = getattr(self, chapter) return getattr(chapter, id) def getHelpTopics(self): """ """ return self.objectValues('HelpTopic') def getHelpTopicsByKeyword(self, keyword): """ ainult vastava keywordiga""" topics = [] for x in self.objectValues('HelpTopic'): keys = x.getKeywords() if keyword in keys or keyword == '': topics.append(x) chapters = self.objectValues('HelpChapter') for c in chapters: for htopic in c.objectValues('HelpTopic'): keys = htopic.getKeywords() if keyword in keys or keyword == '': topics.append(htopic) return topics def getHelpTopicsById(self, id): """ """ return getattr(self, id) def getAllHelpTopicsById(self, id): """get help topics to miniview""" a = '' try: at = getattr(self, id) except AttributeError: chapters = self.objectValues('HelpChapter') for c in chapters: if a == '': try: at = getattr(c, id) a = 'attr' except AttributeError: a = '' return at def showEditableBorder(self, **args): return 1 registerType(Help, PROJECT_NAME)