class STXTopic(TextTopic): """ A structured-text topic. Holds a HTMLFile object. """ index_html = None def __call__(self, REQUEST=None): """ View the STX Help Topic """ self._check_for_update() return self.htmlfile(self, REQUEST) htmlfile = HTML("""\ <html> <head><title><dtml-var title_or_id></title> </head> <body bgcolor="#FFFFFF"> <dtml-var obj fmt="structured-text"> </body> </html>""")
class ReSTTopic(TextTopic): """ A reStructuredText [1]_ topic. Similar to STXTopic, it uses a simle DTML construct to render its contents - this time using the *reStructuredText* language. .. [1] reStructuredText (http://docutils.sourceforge.net/rst.html) """ index_html = None def __call__(self, REQUEST=None): """ Renders the ReST Help Topic """ self._check_for_update() return self.htmlfile(self, REQUEST) htmlfile = HTML("""\ <html> <head><title><dtml-var title_or_id></title> </head> <body bgcolor="#FFFFFF"> <dtml-var obj fmt="restructured-text"> </body> </html>""")
class BadFile(FSObject): """ Represent a file which was not readable or parseable as its intended type. """ meta_type = 'Bad File' icon = 'p_/broken' BAD_FILE_VIEW = """\ <dtml-var manage_page_header> <dtml-var manage_tabs> <h2> Bad Filesystem Object: &dtml-getId; </h2> <h3> File Contents </h3> <pre> <dtml-var getFileContents> </pre> <h3> Exception </h3> <pre> <dtml-var getExceptionText> </pre> <dtml-var manage_page_footer> """ manage_options = ({'label': 'Error', 'action': 'manage_showError'},) def __init__(self, id, filepath, exc_str='', fullname=None, properties=None): id = fullname or id # Use the whole filename. self.exc_str = exc_str self.file_contents = '' FSObject.__init__(self, id, filepath, fullname, properties) security = ClassSecurityInfo() showError = HTML(BAD_FILE_VIEW) security.declareProtected(ManagePortal, 'manage_showError') def manage_showError(self, REQUEST): """ """ return self.showError(self, REQUEST) security.declarePrivate('_readFile') def _readFile(self, reparse): """Read the data from the filesystem. """ try: file = open(self._filepath, 'rb') try: data = self.file_contents = file.read() finally: file.close() except: # No errors of any sort may propagate data = self.file_contents = None #give up return data security.declarePublic('getFileContents') def getFileContents(self): """ Return the contents of the file, if we could read it. """ return self.file_contents security.declarePublic('getExceptionText') def getExceptionText(self): """ Return the exception thrown while reading or parsing the file. """ return self.exc_str
class HelpSys(Implicit, ObjectManager, Item, Persistent): """ Zope Help System Provides browsing and searching of Zope Product Help. """ meta_type = 'Help System' security = ClassSecurityInfo() security.declareObjectProtected(View) manage_options = ( { 'label': 'Contents', 'action': 'menu' }, { 'label': 'Search', 'action': 'search' }, ) def __init__(self, id='HelpSys'): self.id = id security.declareProtected(access_contents_information, 'helpValues') def helpValues(self, spec=None): "ProductHelp objects of all Products that have help" hv = [] for product in self.Control_Panel.Products.objectValues(): productHelp = product.getProductHelp() # only list products that actually have help if productHelp.helpValues(): hv.append(productHelp) return hv # Seaching does an aggregated search of all ProductHelp # objects. Only Help Topics for which the user has permissions # are returned. security.declareProtected(View, '__call__') def __call__(self, REQUEST=None, **kw): "Searchable interface" if REQUEST is not None: perms = [] sm = getSecurityManager() for p in self.ac_inherited_permissions(all=True): if sm.checkPermission(p[0], self): perms.append(p[0]) REQUEST.set('permissions', perms) results = [] for ph in self.helpValues(): results.append(apply(getattr(ph, '__call__'), (REQUEST, ), kw)) return LazyCat(results) security.declareProtected(View, 'searchResults') searchResults = __call__ security.declareProtected(View, 'index_html') index_html = DTMLFile('dtml/frame', globals()) security.declareProtected(View, 'menu') menu = DTMLFile('dtml/menu', globals()) security.declareProtected(View, 'search') search = DTMLFile('dtml/search', globals()) security.declareProtected(View, 'results') results = DTMLFile('dtml/results', globals()) security.declareProtected(View, 'main') main = HTML("""<html></html>""") standard_html_header = DTMLFile('dtml/menu_header', globals()) standard_html_footer = DTMLFile('dtml/menu_footer', globals()) button = DTMLFile('dtml/button', globals()) security.declareProtected(View, 'HelpButton') def HelpButton(self, topic, product): """ Insert a help button linked to a help topic. """ return self.button(self, self.REQUEST, product=product, topic=topic) helpURL = DTMLFile('dtml/helpURL', globals()) security.declareProtected(View, 'helpLink') def helpLink(self, product='OFSP', topic='ObjectManager_Contents.stx'): # Generate an <a href...> tag linking to a help topic. This # is a little lighter weight than the help button approach. basepath = self.REQUEST['BASEPATH1'] products = self.Control_Panel.Products.objectIds() if product not in products: return None help_url = '%s/Control_Panel/Products/%s/Help/%s' % (basepath, product, topic) help_url = '%s?help_url=%s' % (self.absolute_url(), help_url) script="window.open('%s','zope_help','width=600,height=500," \ "menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes');" \ "return false;" % escape(help_url, 1).replace("'", "\\'") h_link='<a href="%s" onClick="%s" onMouseOver="window.status=' \ '\'Open online help\'; return true;" onMouseOut="' \ 'window.status=\'\'; return true;">Help!</a>' % ( escape(help_url, 1), script ) return h_link def tpValues(self): """ Tree protocol - returns child nodes Aggregates Product Helps with the same title. """ helps = {} for help in self.helpValues(): if helps.has_key(help.title): helps[help.title].append(help) else: helps[help.title] = [help] cols = [] for k, v in helps.items(): cols.append(TreeCollection(k, v, 0)) return cols
MessageDialog = HTML(""" <HTML> <HEAD> <TITLE>&dtml-title;</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF"> <FORM ACTION="&dtml-action;" METHOD="GET" <dtml-if target>TARGET="&dtml-target;"</dtml-if>> <TABLE BORDER="0" WIDTH="100%" CELLPADDING="10"> <TR> <TD VALIGN="TOP"> <BR> <CENTER><B><FONT SIZE="+6" COLOR="#77003B">!</FONT></B></CENTER> </TD> <TD VALIGN="TOP"> <BR><BR> <CENTER> <dtml-var message> </CENTER> </TD> </TR> <TR> <TD VALIGN="TOP"> </TD> <TD VALIGN="TOP"> <CENTER> <INPUT TYPE="SUBMIT" VALUE=" Ok "> </CENTER> </TD> </TR> </TABLE> </FORM> </BODY></HTML>""", target='', action='manage_main', title='Changed')