From a753f08a668ef72e98ca904be85af11cca6a47e9 Mon Sep 17 00:00:00 2001 From: bwarsaw Date: Mon, 25 Jun 2001 21:10:31 +0000 Subject: Classes Document and HeadlessDocument are almost identical, except that the former adds tags, while the latter suppresses them. Document should be used for pages that are created by the scripts out of whole cloth, while HeadlessDocument should be used for any template-based page (which must supply its own head & body tags, although not all of them do, I think). It turns out to be useful to transform a Document into a HeadlessDocument, so the trigger to output the head & body tags is the instance variable "suppress_head" which Document defaults to 0 and HeadlessDocument defaults to 1. All the real work is performed in Document.Format(). Document.get_content_type(): Add the extra newline here, for convenience. --- Mailman/htmlformat.py | 59 +++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 30 deletions(-) (limited to 'Mailman/htmlformat.py') diff --git a/Mailman/htmlformat.py b/Mailman/htmlformat.py index b07aef86e..e732c1a05 100644 --- a/Mailman/htmlformat.py +++ b/Mailman/htmlformat.py @@ -284,6 +284,7 @@ class Document(Container): title = None language = None bgcolor = mm_cfg.WEB_BG_COLOR + suppress_head = 0 def set_language(self, lang=None): self.language = lang @@ -292,7 +293,7 @@ class Document(Container): ctype = 'Content-type: text/html' if self.language: ctype += '; charset=' + Utils.GetCharSet(self.language) - return ctype + return ctype + '\n' def set_bgcolor(self, color): self.bgcolor = color @@ -301,40 +302,38 @@ class Document(Container): self.title = title def Format(self, indent=0, **kws): - kws.setdefault('bgcolor', self.bgcolor) - tab = ' ' * indent - output = [self.get_content_type(), - '', - tab, - '', - '' - ] - if self.title: - output.append('%s%s' % (tab, self.title)) - output.append('%s' % tab) - output.append('%s' % (tab, SPACE.join(quals))) + output = [self.get_content_type()] + if not self.suppress_head: + kws.setdefault('bgcolor', self.bgcolor) + tab = ' ' * indent + output.extend([tab, + '', + '' + ]) + if self.title: + output.append('%s%s' % (tab, self.title)) + output.append('%s' % tab) + quals = [] + # Default link colors + if mm_cfg.WEB_VLINK_COLOR: + kws.setdefault('vlink', mm_cfg.WEB_VLINK_COLOR) + if mm_cfg.WEB_ALINK_COLOR: + kws.setdefault('alink', mm_cfg.WEB_ALINK_COLOR) + if mm_cfg.WEB_LINK_COLOR: + kws.setdefault('alink', mm_cfg.WEB_LINK_COLOR) + for k, v in kws.items(): + quals.append('%s="%s"' % (k, v)) + output.append('%s' % (tab, SPACE.join(quals))) + # Always do this... output.append(Container.Format(self, indent)) - output.append('%s' % tab) - output.append('%s' % tab) + if not self.suppress_head: + output.append('%s' % tab) + output.append('%s' % tab) return NL.join(output) - class HeadlessDocument(Document): """Document without head section, for templates that provide their own.""" - def Format(self, indent=0, **kws): - return self.get_content_type() + '\n\n' + \ - Container.Format(self, indent) + suppress_head = 1 class StdContainer(Container): def Format(self, indent=0): -- cgit v1.2.3-70-g09d2