import os import regsub import string import mm_cfg, mm_utils import htmlformat class HTMLFormatter: def InitVars(self): self._template_dir = os.path.join(mm_cfg.TEMPLATE_DIR, self._internal_name) def GetMailmanFooter(self): owners_html = htmlformat.Container() for i in range(len(self.owner)): owner = self.owner[i] owners_html.AddItem(htmlformat.Link('mailto:%s' % owner, owner)) if i + 1 <> len(self.owner): owners_html.AddItem(', ') # Remove the .Format() when htmlformat conversion is done. return htmlformat.Container( '
', htmlformat.Address( htmlformat.Container( 'List run by ', owners_html, '

', 'HTML generated by ', htmlformat.Link( mm_cfg.MAILMAN_URL, "Mailman v %s" % mm_cfg.VERSION)))).Format() def SnarfHTMLTemplate(self, file): filename = os.path.join(self._template_dir, file) f = open(filename,'r') str = f.read() f.close() return str def FormatUsers(self, digest): def NotHidden(x, s=self, v=mm_cfg.ConcealSubscription): return not s.GetUserOption(x, v) if digest: people = filter(NotHidden, self.digest_members) num_concealed = len(self.digest_members) - len(people) else: people = filter(NotHidden, self.members) num_concealed = len(self.members) - len(people) people.sort() if (num_concealed > 0): plurality = (((num_concealed > 1) and "s") or "") concealed = ("(%d private member%s not shown)" % (num_concealed, plurality)) else: concealed = "" def FormatOneUser(person, me=self, disdel=mm_cfg.DisableDelivery): import htmlformat, os id = mm_utils.ObscureEmail(person) if me.obscure_addresses: showing = mm_utils.ObscureEmail(person, for_text=1) else: showing = person got = htmlformat.Link(os.path.join(me.GetScriptURL('options'), id), showing) if me.GetUserOption(person, disdel): got = htmlformat.Italic("(", got, ")") return got items = map(FormatOneUser, people) # Just return the .Format() so this works until I finish # converting everything to htmlformat... return (concealed + apply(htmlformat.UnorderedList, tuple(items)).Format()) def FormatOptionButton(self, type, value, user): users_val = self.GetUserOption(user, type) if users_val == value: checked = ' CHECKED' else: checked = '' name = { mm_cfg.DontReceiveOwnPosts : "dontreceive", mm_cfg.DisableDelivery : "disablemail", mm_cfg.DisableMime : "mime", mm_cfg.AcknowlegePosts : "ackposts", mm_cfg.Digests : "digest", mm_cfg.ConcealSubscription : "conceal" }[type] import sys return ('' % (name, value, checked)) def FormatDigestButton(self): if self.digest_is_default: checked = ' CHECKED' else: checked = '' return '' % checked def FormatSubscriptionMsg(self): "Tailor to approval, roster privacy, and web vetting requirements." msg = "" also = "" if self.web_subscribe_requires_confirmation: msg = msg + ("You will be sent email requesting confirmation, " "to prevent others from gratuitously subscribing " "you. ") if not self.open_subscribe: msg = msg + ("This is a closed list, which means your " "subscription will be held for approval. You will " "be notified of the administrators decision by " "email. ") also = "also " if self.private_roster: msg = msg + ("This is %sa private list, which means that " "the members list is not available to non-" "members. " % also) else: msg = msg + ("This is %sa public list, which means that the " "members list is openly available" % also) if self.obscure_addresses: msg = msg + (" (but we obscure the addresses so they are " "not easily recognizable by spammers). ") else: msg = msg + ". " return msg def FormatUndigestButton(self): if self.digest_is_default: checked = '' else: checked = ' CHECKED' return '' % checked def FormatMimeDigestsButton(self): if self.mime_is_default_digest: checked = ' CHECKED' else: checked = '' return '' % checked def FormatPlainDigestsButton(self): if self.mime_is_default_digest: checked = '' else: checked = ' CHECKED' return '' % checked def FormatEditingOption(self): "Present editing options, according to list privacy." text = ("%s subscribers, to edit your subscription options:" % self.real_name) text = text + " %senter your email address: " if self.private_roster == 0: text = text % "

Either " else: text = text % "" text = (text + htmlformat.TextBox('info', size=40).Format() + " " + htmlformat.SubmitButton('UserOptions', 'Edit Options').Format()) if self.private_roster == 0: text = text + ("

Or visit the subscribers list" " (above) and select your entry.") return text def FormatRosterOptionForAdmin(self): return "Admin subscriber roster would require admin password." def FormatRosterOptionForUser(self): "Provide avenue to subscribers roster, contingent to .private_roster." text = "" if not self.private_roster: text = (text + "Click here for the roster of " + self.real_name + " subscribers: " + htmlformat.SubmitButton('SubscriberRoster', 'Visit Subscriber list' ).Format()) else: if self.private_roster == 1: only = 'members' whom = 'Member:' else: only = 'the list administrator' whom = 'Admin:' # Solicit the user and password. text = (text + ("The subscriber roster is only available to %s.
Enter" % only) + (" your %s address and password to visit the" % string.lower(whom[:-1])) + " subscriber's roster:" "

") return text def FormatFormStart(self, name, extra=''): base_url = self.GetScriptURL(name) full_url = os.path.join(base_url, extra) return ('
' % full_url) def FormatArchiveAnchor(self): return '' % self._base_archive_url def FormatFormEnd(self): return '' def FormatBox(self, name, size=20): return '' % (name, size) def FormatSecureBox(self, name): return '' % name def FormatButton(self, name, text='Submit'): return '' % (name, text) def ParseTags(self, template, replacements): text = self.SnarfHTMLTemplate(template) parts = regsub.splitx(text, ']*>') i = 1 while i < len(parts): tag = string.lower(parts[i]) if replacements.has_key(tag): parts[i] = replacements[tag] else: parts[i] = '' i = i + 2 return string.join(parts, '') # This needs to wait until after the list is inited, so let's build it # when it's needed only. def GetStandardReplacements(self): return { '' : self.GetMailmanFooter(), '' : self.real_name, '' : self._internal_name, '' : self.description, '' : string.join(string.split(self.info, '\n'), '
'), '' : self.FormatFormEnd(), '' : self.FormatArchiveAnchor(), '' : '
', '' : self.FormatUsers(0), '' : self.FormatSubscriptionMsg(), '' : self.FormatUsers(1), '' : `len(self.members)`, '' : `len(self.digest_members)`, '' : (`len(self.members)` + `len(self.digest_members)`), '' : '%s' % self.GetListEmail(), '' : '%s' % self.GetRequestEmail(), '' : self.GetAdminEmail() } def InitTemplates(self): def ExtensionFilter(item): return item[-5:] == '.html' files = filter(ExtensionFilter, os.listdir(mm_cfg.TEMPLATE_DIR)) mm_utils.MakeDirTree(self._template_dir) for filename in files: file1 = open(os.path.join(mm_cfg.TEMPLATE_DIR, filename), 'r') text = file1.read() file1.close() file2 = open(os.path.join(self._template_dir, filename), 'w+') file2.write(text) file2.close()