Esempio n. 1
0
def index(req):
    try:
        url_list = _get_url_list()
        page = Template(name='downloadform')
        page.url_list = url_list
    except:
        return "Unexpected error: " + str(sys.exc_info()[1])
    return page.serialize(output='html')
Esempio n. 2
0
def demoResponse(school_name, rooms, status=''):
    template = Template(encoding="utf-8",
                    format='xhtml',
                    file='web-form.kid',
                    rooms=rooms,
                    school_name=school_name,
                    status=status,
                    current_room=current_room)
    return template.serialize(output="xhtml")
Esempio n. 3
0
def getUploadPage(user, tree, errors=None, messages=None, admin_context="", gallery_context=""):
    upload = Template(name="templates.upload")
    upload.user = user
    upload.root_node = tree
    upload.errors = errors
    upload.messages = messages
    upload.admin_context = admin_context
    upload.gallery_context = gallery_context

    return upload.serialize(output="html")
Esempio n. 4
0
def getEditFolderPage(
    user,
    folder,
    parent,
    files,
    is_empty,
    errors=None,
    title="",
    description="",
    messages=None,
    admin_context="",
    gallery_context="",
):
    editfolder = Template(name="templates.editfolder")
    editfolder.user = user
    if folder:
        editfolder.folder = folder.replace("\\", "/")
        editfolder.folder_name = path.basename(folder)
    else:
        editfolder.folder = ""
        editfolder.folder_name = ""
    editfolder.files = files
    editfolder.parent = parent
    editfolder.errors = errors
    editfolder.messages = messages
    editfolder.is_empty = is_empty
    editfolder.description = description
    editfolder.title = title
    editfolder.admin_context = admin_context
    editfolder.gallery_context = gallery_context

    return editfolder.serialize(output="html")
Esempio n. 5
0
def test_expand_fragments():
    """Testcase for expanding XML fragments (ticket #145)."""
    template = """<div xmlns:py="http://purl.org/kid/ns#"
        py:replace="stream" />"""
    t = Template("""\
        <div xmlns:py="http://purl.org/kid/ns#">
            <div py:for="i in range(3)">
                <p>Hello World #$i</p>
            </div>
        </div>""")
    s = t.serialize(fragment=True)
    expected = """<div>
            <div>
                <p>Hello World #0</p>
            </div><div>
                <p>Hello World #1</p>
            </div><div>
                <p>Hello World #2</p>
            </div>
        </div>"""
    assert s == expected
    stream = ElementStream(t.transform()).expand()
    t2 = Template(source=template, stream=stream)
    s2 = t2.serialize(fragment=True)
    assert s2 == s
    t = Template("""\
        <div xmlns:py="http://purl.org/kid/ns#" py:for="i in range(3)">
            <p>Hello World #$i</p>
        </div>""")
    s = t.serialize(fragment=True)
    expected = """<div>
            <p>Hello World #0</p>
        </div><div>
            <p>Hello World #1</p>
        </div><div>
            <p>Hello World #2</p>
        </div>"""
    assert s == expected
    stream = ElementStream(t.transform()).expand()
    t2 = Template(source=template, stream=stream)
    s2 = t2.serialize(fragment=True)
    assert s2 == s
    t = Template("""\
        <div xmlns:py="http://purl.org/kid/ns#">
            <div py:strip="True">
                <p>Hello World</p>
            </div>
        </div>""")
    s = t.serialize(fragment=True)
    expected = """<div>
                <p>Hello World</p>
        </div>"""
    assert s == expected
    stream = ElementStream(t.transform()).expand()
    t2 = Template(source=template, stream=stream)
    s2 = t2.serialize(fragment=True)
    assert s2 == s
    t = Template("""\
        <div xmlns:py="http://purl.org/kid/ns#" py:strip="True">
            <p>Hello World</p>
        </div>""")
    s = t.serialize(fragment=True).strip()
    expected = """<p>Hello World</p>"""
    assert s == expected
    stream = ElementStream(t.transform()).expand()
    t2 = Template(source=template, stream=stream)
    s2 = t2.serialize(fragment=True).strip()
    assert s2 == s
Esempio n. 6
0
def test_expand_fragments():
    """Testcase for expanding XML fragments (ticket #145)."""
    template = """<div xmlns:py="http://purl.org/kid/ns#"
        py:replace="stream" />"""
    t = Template("""\
        <div xmlns:py="http://purl.org/kid/ns#">
            <div py:for="i in range(3)">
                <p>Hello World #$i</p>
            </div>
        </div>""")
    s = t.serialize(fragment=True)
    expected = """<div>
            <div>
                <p>Hello World #0</p>
            </div><div>
                <p>Hello World #1</p>
            </div><div>
                <p>Hello World #2</p>
            </div>
        </div>"""
    assert s == expected
    stream = ElementStream(t.transform()).expand()
    t2 = Template(source=template, stream=stream)
    s2 = t2.serialize(fragment=True)
    assert s2 == s
    t = Template("""\
        <div xmlns:py="http://purl.org/kid/ns#" py:for="i in range(3)">
            <p>Hello World #$i</p>
        </div>""")
    s = t.serialize(fragment=True)
    expected = """<div>
            <p>Hello World #0</p>
        </div><div>
            <p>Hello World #1</p>
        </div><div>
            <p>Hello World #2</p>
        </div>"""
    assert s == expected
    stream = ElementStream(t.transform()).expand()
    t2 = Template(source=template, stream=stream)
    s2 = t2.serialize(fragment=True)
    assert s2 == s
    t = Template("""\
        <div xmlns:py="http://purl.org/kid/ns#">
            <div py:strip="True">
                <p>Hello World</p>
            </div>
        </div>""")
    s = t.serialize(fragment=True)
    expected = """<div>
                <p>Hello World</p>
        </div>"""
    assert s == expected
    stream = ElementStream(t.transform()).expand()
    t2 = Template(source=template, stream=stream)
    s2 = t2.serialize(fragment=True)
    assert s2 == s
    t = Template("""\
        <div xmlns:py="http://purl.org/kid/ns#" py:strip="True">
            <p>Hello World</p>
        </div>""")
    s = t.serialize(fragment=True).strip()
    expected = """<p>Hello World</p>"""
    assert s == expected
    stream = ElementStream(t.transform()).expand()
    t2 = Template(source=template, stream=stream)
    s2 = t2.serialize(fragment=True).strip()
    assert s2 == s
Esempio n. 7
0
    def do_rss(self, repo_data, latest):
        """
        Write the RSS feed.
        
        @param repo_data: the dict containing repository data
        @type  repo_data: dict
        @param latest:    the list of tuples returned by get_latest_packages
        @type  latest:    list
        
        @rtype: void
        """
        self.say('Generating rss feed...')
        etb = TreeBuilder()
        out = os.path.join(self.outdir, RSSFILE)
        etb.start('rss', {'version': '2.0'})
        etb.start('channel')
        etb.start('title')
        etb.data(repo_data['title'])
        etb.end('title')
        etb.start('link')
        etb.data('%s/repoview/%s' % (self.opts.url, RSSFILE))
        etb.end('link')
        etb.start('description')
        etb.data('Latest packages for %s' % repo_data['title'])
        etb.end('description')
        etb.start('lastBuildDate')
        etb.data(time.strftime(ISOFORMAT))
        etb.end('lastBuildDate')
        etb.start('generator')
        etb.data('Repoview-%s' % repo_data['my_version'])
        etb.end('generator')

        rss_tpt = os.path.join(self.opts.templatedir, RSSKID)
        rss_kid = Template(file=rss_tpt)
        rss_kid.assume_encoding = "utf-8"
        rss_kid.repo_data = repo_data
        rss_kid.url = self.opts.url

        for row in latest:
            pkg_data = self.get_package_data(row[0])

            rpm = pkg_data['rpms'][0]
            (epoch, version, release, arch, built) = rpm[:5]
            etb.start('item')
            etb.start('guid')
            etb.data('%s/repoview/%s+%s:%s-%s.%s' %
                     (self.opts.url, pkg_data['filename'], epoch, version,
                      release, arch))
            etb.end('guid')
            etb.start('link')
            etb.data('%s/repoview/%s' % (self.opts.url, pkg_data['filename']))
            etb.end('link')
            etb.start('pubDate')
            etb.data(time.strftime(ISOFORMAT, time.gmtime(int(built))))
            etb.end('pubDate')
            etb.start('title')
            etb.data('Update: %s-%s-%s' % (pkg_data['name'], version, release))
            etb.end('title')
            rss_kid.pkg_data = pkg_data
            description = rss_kid.serialize()
            etb.start('description')
            etb.data(description.decode('utf-8'))
            etb.end('description')
            etb.end('item')

        etb.end('channel')
        etb.end('rss')
        rss = etb.close()

        etree = ElementTree(rss)
        out = os.path.join(self.outdir, RSSFILE)
        etree.write(out, 'utf-8')
        self.say('done\n')
Esempio n. 8
0
    def __init__(self, opts):
        """
        @param opts: OptionParser's opts
        @type  opts: OptionParser
        """
        # list of files to remove at the end of processing
        self.cleanup = []
        self.opts = opts
        self.outdir = os.path.join(opts.repodir, 'repoview')

        self.exclude = '1=1'
        self.state_data = {}  #?
        self.written = {}  #?

        self.groups = []
        self.letter_groups = []

        self.pconn = None  # primary.sqlite
        self.oconn = None  # other.sqlite
        self.sconn = None  # state db

        self.setup_repo()
        self.setup_outdir()
        self.setup_state_db()
        self.setup_excludes()

        if not self.groups:
            self.setup_rpm_groups()

        letters = self.setup_letter_groups()

        repo_data = {
            'title': opts.title,
            'letters': letters,
            'my_version': VERSION
        }

        group_kid = Template(file=os.path.join(opts.templatedir, GRPKID))
        group_kid.assume_encoding = "utf-8"
        group_kid.repo_data = repo_data
        self.group_kid = group_kid

        pkg_kid = Template(file=os.path.join(opts.templatedir, PKGKID))
        pkg_kid.assume_encoding = "utf-8"
        pkg_kid.repo_data = repo_data
        self.pkg_kid = pkg_kid

        count = 0
        for group_data in self.groups + self.letter_groups:
            (grp_name, grp_filename, grp_description, pkgnames) = group_data
            pkgnames.sort()

            group_data = {
                'name': grp_name,
                'description': grp_description,
                'filename': grp_filename,
            }

            packages = self.do_packages(repo_data, group_data, pkgnames)

            if not packages:
                # Empty groups are ignored
                del self.groups[count]
                continue

            count += 1

            group_data['packages'] = packages

            checksum = self.mk_checksum(repo_data, group_data)
            if self.has_changed(grp_filename, checksum):
                # write group file
                self.say('Writing group %s\n' % grp_filename)
                self.group_kid.group_data = group_data
                outfile = os.path.join(self.outdir, grp_filename)
                self.group_kid.write(outfile, output='xhtml-strict')

        latest = self.get_latest_packages()
        repo_data['latest'] = latest
        repo_data['groups'] = self.groups

        checksum = self.mk_checksum(repo_data)
        if self.has_changed('index.html', checksum):
            # Write index.html and rss feed (if asked)
            self.say('Writing index.html...')
            idx_tpt = os.path.join(self.opts.templatedir, IDXKID)
            idx_kid = Template(file=idx_tpt)
            idx_kid.assume_encoding = "utf-8"
            idx_kid.repo_data = repo_data
            idx_kid.url = self.opts.url
            idx_kid.latest = latest
            idx_kid.groups = self.groups
            outfile = os.path.join(self.outdir, 'index.html')
            idx_kid.write(outfile, output='xhtml-strict')
            self.say('done\n')

            # rss feed
            if self.opts.url:
                self.do_rss(repo_data, latest)

        self.remove_stale()
        self.sconn.commit()
Esempio n. 9
0
 def test(self):
     """
     For testing the kid template.
     """
     return Template(name="bookie.views.test").serialize()
Esempio n. 10
0
File: kr.py Progetto: antroy/Home
from kid import Template

class Node (object):
    def __init__(self, name, children=[]):
        self.children = children
        self.name = name
    
    def children(self):
        return self.children


top = Node("top")
a = Node("A", [Node("a")])
b = Node("B", [Node("x"),Node("y")])
top.children = [a, b]
        

template = Template(name="xx")
template.tree = top
print template.serialize(output='html')
Esempio n. 11
0
 def do_rss(self, repo_data, latest):
     """
     Write the RSS feed.
     
     @param repo_data: the dict containing repository data
     @type  repo_data: dict
     @param latest:    the list of tuples returned by get_latest_packages
     @type  latest:    list
     
     @rtype: void
     """
     self.say('Generating rss feed...')
     etb = TreeBuilder()
     out = os.path.join(self.outdir, RSSFILE)
     etb.start('rss', {'version': '2.0'})
     etb.start('channel')
     etb.start('title')
     etb.data(repo_data['title'])
     etb.end('title')
     etb.start('link')
     etb.data('%s/repoview/%s' % (self.opts.url, RSSFILE))
     etb.end('link')
     etb.start('description')
     etb.data('Latest packages for %s' % repo_data['title'])
     etb.end('description')
     etb.start('lastBuildDate')
     etb.data(time.strftime(ISOFORMAT))
     etb.end('lastBuildDate')
     etb.start('generator')
     etb.data('Repoview-%s' % repo_data['my_version'])
     etb.end('generator')
     
     rss_tpt = os.path.join(self.opts.templatedir, RSSKID)
     rss_kid = Template(file=rss_tpt)
     rss_kid.assume_encoding = "utf-8"
     rss_kid.repo_data = repo_data
     rss_kid.url = self.opts.url
     
     for row in latest:
         pkg_data = self.get_package_data(row[0])
         
         rpm = pkg_data['rpms'][0]
         (epoch, version, release, arch, built) = rpm[:5]
         etb.start('item')
         etb.start('guid')
         etb.data('%s/repoview/%s+%s:%s-%s.%s' % (self.opts.url, 
                                                  pkg_data['filename'], 
                                                  epoch, version, release, 
                                                  arch))
         etb.end('guid')
         etb.start('link')
         etb.data('%s/repoview/%s' % (self.opts.url, pkg_data['filename']))
         etb.end('link')
         etb.start('pubDate')
         etb.data(time.strftime(ISOFORMAT, time.gmtime(int(built))))
         etb.end('pubDate')
         etb.start('title')
         etb.data('Update: %s-%s-%s' % (pkg_data['name'], version, release))
         etb.end('title')
         rss_kid.pkg_data = pkg_data
         description = rss_kid.serialize()
         etb.start('description')
         etb.data(description.decode('utf-8'))
         etb.end('description')
         etb.end('item')
     
     etb.end('channel')
     etb.end('rss')
     rss = etb.close()
     
     etree = ElementTree(rss)
     out = os.path.join(self.outdir, RSSFILE)
     etree.write(out, 'utf-8')
     self.say('done\n')
Esempio n. 12
0
 def __init__(self, opts):
     """
     @param opts: OptionParser's opts
     @type  opts: OptionParser
     """
     # list of files to remove at the end of processing
     self.cleanup = []
     self.opts    = opts
     self.outdir  = os.path.join(opts.repodir, 'repoview')
     
     self.exclude    = '1=1'
     self.state_data = {} #?
     self.written    = {} #?
     
     self.groups        = []
     self.letter_groups = []
     
     self.pconn = None # primary.sqlite
     self.oconn = None # other.sqlite
     self.sconn = None # state db
     
     self.setup_repo()
     self.setup_outdir()
     self.setup_state_db()
     self.setup_excludes()
     
     if not self.groups:
         self.setup_rpm_groups()
     
     letters = self.setup_letter_groups()
     
     repo_data = {
                  'title':      opts.title,
                  'letters':    letters,
                  'my_version': VERSION
                 }
     
     group_kid = Template(file=os.path.join(opts.templatedir, GRPKID))
     group_kid.assume_encoding = "utf-8"
     group_kid.repo_data = repo_data
     self.group_kid = group_kid
     
     pkg_kid = Template(file=os.path.join(opts.templatedir, PKGKID))
     pkg_kid.assume_encoding = "utf-8"
     pkg_kid.repo_data = repo_data
     self.pkg_kid = pkg_kid
     
     count = 0
     for group_data in self.groups + self.letter_groups:
         (grp_name, grp_filename, grp_description, pkgnames) = group_data
         pkgnames.sort()
         
         group_data = {
                       'name':        grp_name,
                       'description': grp_description,
                       'filename':    grp_filename,
                       }
         
         packages = self.do_packages(repo_data, group_data, pkgnames)
         
         if not packages:
             # Empty groups are ignored
             del self.groups[count]
             continue
         
         count += 1
         
         group_data['packages'] = packages
         
         checksum = self.mk_checksum(repo_data, group_data)
         if self.has_changed(grp_filename, checksum):
             # write group file
             self.say('Writing group %s\n' % grp_filename)
             self.group_kid.group_data = group_data
             outfile = os.path.join(self.outdir, grp_filename)
             self.group_kid.write(outfile, output='xhtml-strict')
     
     latest = self.get_latest_packages()
     repo_data['latest'] = latest
     repo_data['groups'] = self.groups
     
     checksum = self.mk_checksum(repo_data)
     if self.has_changed('index.html', checksum):
         # Write index.html and rss feed (if asked)
         self.say('Writing index.html...')
         idx_tpt = os.path.join(self.opts.templatedir, IDXKID)
         idx_kid = Template(file=idx_tpt)
         idx_kid.assume_encoding = "utf-8"
         idx_kid.repo_data = repo_data
         idx_kid.url = self.opts.url
         idx_kid.latest = latest
         idx_kid.groups = self.groups
         outfile = os.path.join(self.outdir, 'index.html')
         idx_kid.write(outfile, output='xhtml-strict')
         self.say('done\n')
         
         # rss feed
         if self.opts.url:
             self.do_rss(repo_data, latest)
     
     self.remove_stale()
     self.sconn.commit()
Esempio n. 13
0
 def render_500(message="None"):
     set_header()
     template = Template(file='views/500.xml', message=message)
     print template.serialize()
Esempio n. 14
0
 def item_render(self):
     template = Template(file='views/item.xml', speech_data=self.speech)
     set_header()
     print template.serialize()
Esempio n. 15
0
 def logout(self):
     return Template(name="bookie.views.login").serialize()
Esempio n. 16
0
from os.path import walk, splitext, dirname, abspath
from os.path import join as join_path, exists as path_exists
from time import time, strftime, gmtime

from shutil import copy as copy_file
from distutils.archive_util import make_archive
from docutils import core, frontend
from docutils.writers import html4css1

from kid import Template

rst_doc_root = "../docs/rst"
site_root = "../pub/www"

main_page_template = "sitepage.kid"
_template = Template(file=main_page_template)


def archive_site(root=site_root):
    make_archive(strftime("../hjb_web_site_%Y%m%d_%H%M%S", gmtime(time())),
                 "gztar", abspath(site_root), ".")


def generate_site(doc_root=rst_doc_root):
    """
    Generate the site.

    Copies the rst files to the site, then transforms them into html,
    and creates the final output file using the html and the template.
    
    """
    def buildMessage(self, notice_type, channel, outages, anomalies, replyto_address, from_address):
        """
        Construct an alert message for the given list of outages and anomalies, to be sent to the given channel.

        General process is to construct fragments for each item to be reported on, then assemble them all
        together into the final message.  Need to take into consideration whether we're building text email,
        HTML email, short text email or SMS message, which is determined by the channel.
        """

        customer = channel.contact.customer
        brand = customer.brand
        brand_name = "Panopta"
        if brand and brand.isWhiteLabel():
            brand_name = brand.name

        shorttext_body = u""
        text_body = u""
        html_body = u""

        # Make a list of server names to notify, for use in the subject header
        items = outages + anomalies
        server_names = set()
        for o in outages:
            try:
                target = o.outage_target
            except:
                continue
            server_names.add(target.name)
        for a in anomalies:
            server_names.add(a.server.name)
        server_names = list(server_names)
        server_names.sort()

        # Construct the message body
        if channel.contact_type.textkey in ('sms', 'email.shorttext'):
            
            # Figure out the limit on the message length - shorter for SMS to avoid truncation
            length_limit = 148
            if channel.contact_type.textkey == 'email.shorttext': length_limit = 350

            # Build up a list of all of the things to notify about
            fragments = []
            for o in outages:
                notice_time = o.start_time
                if notice_type == ALL_CLEAR:
                    notice_time = o.end_time
                fragments.append(_("%(server_name)s %(notice_type)s at %(start_time)s: %(service_list)s") % \
                                     {'server_name': o.outage_target.name, 
                                      'notice_type': _(notice_type), 
                                      'start_time': channel.contact.formatLocalTime(notice_time, hide_same_day=1),
                                      'service_list': o.getServiceDisplayNames(join_str=',')})
            for a in anomalies:
                notice_time = a.start_time
                notice_desc = a.server_resource_threshold.getAnomalyDescription(short=1)
                if notice_type == ALL_CLEAR:
                    notice_time = a.end_time
                    notice_desc = a.server_resource_threshold.getAllClearDescription(short=1)
                fragments.append(_("%(server_name)s %(notice_type)s at %(start_time)s") % {'server_name': a.server.name, 
                                                                                           'notice_type': notice_desc,
                                                                                           'start_time': channel.contact.formatLocalTime(notice_time, hide_same_day=1)})

            # Complete the message by including as many fragments as possible while staying under 
            # the length limit.
            shorttext_body = fragments.pop(0)
            while fragments and (len(shorttext_body) + len(fragments[0]) + 2 < length_limit):
                shorttext_body += "; %s" % fragments.pop(0)
            if fragments:
                shorttext_body += _(" + %(count)s more") % {'count': len(fragments)}

        else:
            
            # Build a list of formatted things to report
            fragments = []
            for o in outages:
                fragments.append(self.buildOutageFragment(notice_type, o, customer, channel))
            for a in anomalies:
                fragments.append(self.buildAnomalyFragment(notice_type, a, customer, channel))
                                
            # Get the template fragments, in case the customer has customized them
            header = customer.getTemplateFragment('email.header')
            if notice_type == OUTAGE:
                intro = customer.getTemplateFragment('email.outage.notice.intro')
                conclusion = customer.getTemplateFragment('email.outage.notice.conclusion')
            elif notice_type == ALL_CLEAR:
                intro = customer.getTemplateFragment('email.outage.allclear.intro')
                conclusion = customer.getTemplateFragment('email.outage.allclear.conclusion')
            copyright = customer.getTemplateFragment('email.copyright')

            # Build the text rendering of the list, as we can't easily do this with interpolation
            alert_list = ""
            for (head, sub_list) in fragments:
                alert_list += " o %s\n" % head
                for line in sub_list:
                    alert_list += "   - %s\n" % line
                alert_list += "\n"

            # Build the text body
            if header: text_body += header.body_text + "\n\n"
            if intro: text_body += intro.body_text + "\n\n"

            template = _(unicode(outage_text_template))
            if notice_type == ALL_CLEAR: template = _(unicode(allclear_text_template))
            text_body += template % {'alerts': alert_list,
                                     'brand_name': brand_name}
            if conclusion: text_body += conclusion.body_text + "\n\n"
            if copyright: text_body += copyright.body_text

            if channel.contact_type.textkey == 'email.html':
                
                # Build the HTML body
                template_data = {'alerts': fragments,
                                 'brand_name': brand_name,
                                 'source': unicode(_(outage_html_template)) }
                if notice_type == ALL_CLEAR: template_data['source'] = unicode(_(allclear_html_template))

                if header: html_body += unicode(header.body_html) + u"\n\n"
                if intro: html_body += unicode(intro.body_html) + u"\n\n"

#                tmpl = MarkupTemplate(unicode(_(outage_html_template)))
#                stream = tmpl.generate(alerts=fragments, brand_name=brand_name)
#                frag = stream.render('xhtml')
#                frag = apply(kid.Template, [], template_data).serialize(encoding='utf-8')
                from kid import Template
                t=Template(unicode(_(outage_html_template)),
                           brand_name = brand_name,
                           alerts = fragments)
                frag = unicode(t.serialize(output='xhtml', encoding='utf-8'), 'utf8')

                html_body += frag
                if conclusion: html_body += conclusion.body_html + "\n\n"
                if copyright: html_body += copyright.body_html

        # Build the list of extra headers to embed in the message
        extra_headers = []
        if brand and brand.isWhiteLabel():
            extra_headers.append(('X-Panopta-PartnerKey', customer.partner_key))
            extra_headers.append(('X-Panopta-Package', customer.package.textkey))
        extra_headers.append(('X-Panopta-OutageStatus', notice_type==ALL_CLEAR and 'all-clear' or 'outage'))
        extra_headers.append(('X-Panopta-OutageId', replyto_address.split('@')[0]))  # Grab the email hash from the replyto address
        for server_name in server_names:
	    logging.critical("Adding server name %s" % server_name)
            extra_headers.append(('X-Panopta-ServerFQDN', server_name))
            
        # Build the subject header
        subject = "%s %s: %s" % (brand_name, _(notice_type), server_names.pop(0))
        while server_names and len(subject) < 80:
            subject += "; %s" % server_names.pop(0)
        if server_names:
            subject += _(" + %(count)s more") % {'count': len(server_names)}

        # Build the message object
        if channel.contact_type.textkey == 'sms':
            # If we're sending an SMS, just return the body - there's nothing else to be done
            return shorttext_body
        elif channel.contact_type.textkey == 'email.shorttext':
            msg = buildEmail(from_address, channel.email_address, subject, shorttext_body, "", replyto_address, extra_headers)
        elif channel.contact_type.textkey == 'email.text':
            msg = buildEmail(from_address, channel.email_address, subject, text_body, "", replyto_address, extra_headers)
        else:
            msg = buildEmail(from_address, channel.email_address, subject, text_body, html_body, replyto_address, extra_headers)

        return msg.as_string()
Esempio n. 18
0
 def _q_index(self):
     return Template(name="bookie.views.root").serialize()