Esempio n. 1
0
 def apply_markup(self, rmap, parent=None):
     table = TABLE('\n\t\t')
     if parent is None:
         try:
             first_para = rmap[next(iter(self))]
         except StopIteration:
             return
         parent = first_para.getparent()
         idx = parent.index(first_para)
         parent.insert(idx, table)
     else:
         parent.append(table)
     for row in XPath('./w:tr')(self.tbl):
         tr = TR('\n\t\t\t')
         tr.tail = '\n\t\t'
         table.append(tr)
         for tc in XPath('./w:tc')(row):
             td = TD()
             td.tail = '\n\t\t\t'
             tr.append(td)
             for x in XPath('./w:p|./w:tbl')(tc):
                 if x.tag.endswith('}p'):
                     td.append(rmap[x])
                 else:
                     self.sub_tables[x].apply_markup(rmap, parent=td)
         if len(tr):
             tr[-1].tail = '\n\t\t'
     if len(table):
         table[-1].tail = '\n\t'
Esempio n. 2
0
 def apply_markup(self, rmap, parent=None):
     table = TABLE('\n\t\t')
     if parent is None:
         try:
             first_para = rmap[next(iter(self))]
         except StopIteration:
             return
         parent = first_para.getparent()
         idx = parent.index(first_para)
         parent.insert(idx, table)
     else:
         parent.append(table)
     for row in XPath('./w:tr')(self.tbl):
         tr = TR('\n\t\t\t')
         tr.tail = '\n\t\t'
         table.append(tr)
         for tc in XPath('./w:tc')(row):
             td = TD()
             td.tail = '\n\t\t\t'
             tr.append(td)
             for x in XPath('./w:p|./w:tbl')(tc):
                 if x.tag.endswith('}p'):
                     td.append(rmap[x])
                 else:
                     self.sub_tables[x].apply_markup(rmap, parent=td)
         if len(tr):
             tr[-1].tail = '\n\t\t'
     if len(table):
         table[-1].tail = '\n\t'
Esempio n. 3
0
def build_navigation(start, num, total, url_base):  # {{{
    end = min((start + num - 1), total)
    tagline = SPAN("Books %d to %d of %d" % (start, end, total), style="display: block; text-align: center;")
    left_buttons = TD(CLASS("button", style="text-align:left"))
    right_buttons = TD(CLASS("button", style="text-align:right"))

    if start > 1:
        for t, s in [("First", 1), ("Previous", max(start - num, 1))]:
            left_buttons.append(A(t, href="%s&start=%d" % (url_base, s)))

    if total > start + num:
        for t, s in [("Next", start + num), ("Last", total - num + 1)]:
            right_buttons.append(A(t, href="%s&start=%d" % (url_base, s)))

    buttons = TABLE(TR(left_buttons, right_buttons), CLASS("buttons"))
    return DIV(tagline, buttons, CLASS("navigation"))
Esempio n. 4
0
    def apply_markup(self, rmap, page, parent=None):
        table = TABLE('\n\t\t')
        if self.bidi:
            table.set('dir', 'rtl')
        self.table_style.page = page
        style_map = {}
        if parent is None:
            try:
                first_para = rmap[next(iter(self))]
            except StopIteration:
                return
            parent = first_para.getparent()
            idx = parent.index(first_para)
            parent.insert(idx, table)
        else:
            parent.append(table)
        for row in self.namespace.XPath('./w:tr')(self.tbl):
            tr = TR('\n\t\t\t')
            style_map[tr] = self.style_map[row]
            tr.tail = '\n\t\t'
            table.append(tr)
            for tc in self.namespace.XPath('./w:tc')(row):
                td = TD()
                style_map[td] = s = self.style_map[tc]
                if s.col_span is not inherit:
                    td.set('colspan', type('')(s.col_span))
                if s.row_span is not inherit:
                    td.set('rowspan', type('')(s.row_span))
                td.tail = '\n\t\t\t'
                tr.append(td)
                for x in self.namespace.XPath('./w:p|./w:tbl')(tc):
                    if x.tag.endswith('}p'):
                        td.append(rmap[x])
                    else:
                        self.sub_tables[x].apply_markup(rmap, page, parent=td)
            if len(tr):
                tr[-1].tail = '\n\t\t'
        if len(table):
            table[-1].tail = '\n\t'

        table_style = self.table_style.css
        if table_style:
            table.set('class', self.styles.register(table_style, 'table'))
        for elem, style in style_map.iteritems():
            css = style.css
            if css:
                elem.set('class', self.styles.register(css, elem.tag))
Esempio n. 5
0
    def apply_markup(self, rmap, page, parent=None):
        table = TABLE('\n\t\t')
        if self.bidi:
            table.set('dir', 'rtl')
        self.table_style.page = page
        style_map = {}
        if parent is None:
            try:
                first_para = rmap[next(iter(self))]
            except StopIteration:
                return
            parent = first_para.getparent()
            idx = parent.index(first_para)
            parent.insert(idx, table)
        else:
            parent.append(table)
        for row in self.namespace.XPath('./w:tr')(self.tbl):
            tr = TR('\n\t\t\t')
            style_map[tr] = self.style_map[row]
            tr.tail = '\n\t\t'
            table.append(tr)
            for tc in self.namespace.XPath('./w:tc')(row):
                td = TD()
                style_map[td] = s = self.style_map[tc]
                if s.col_span is not inherit:
                    td.set('colspan', type('')(s.col_span))
                if s.row_span is not inherit:
                    td.set('rowspan', type('')(s.row_span))
                td.tail = '\n\t\t\t'
                tr.append(td)
                for x in self.namespace.XPath('./w:p|./w:tbl')(tc):
                    if x.tag.endswith('}p'):
                        td.append(rmap[x])
                    else:
                        self.sub_tables[x].apply_markup(rmap, page, parent=td)
            if len(tr):
                tr[-1].tail = '\n\t\t'
        if len(table):
            table[-1].tail = '\n\t'

        table_style = self.table_style.css
        if table_style:
            table.set('class', self.styles.register(table_style, 'table'))
        for elem, style in iteritems(style_map):
            css = style.css
            if css:
                elem.set('class', self.styles.register(css, elem.tag))
Esempio n. 6
0
def build_navigation(start, num, total, url_base):  # {{{
    end = min((start + num - 1), total)
    tagline = SPAN('Books %d to %d of %d' % (start, end, total),
                   style='display: block; text-align: center;')
    left_buttons = TD(CLASS('button', style='text-align:left'))
    right_buttons = TD(CLASS('button', style='text-align:right'))

    if start > 1:
        for t, s in [('First', 1), ('Previous', max(start - num, 1))]:
            left_buttons.append(A(t, href='%s;start=%d' % (url_base, s)))

    if total > start + num:
        for t, s in [('Next', start + num), ('Last', total - num + 1)]:
            right_buttons.append(A(t, href='%s;start=%d' % (url_base, s)))

    buttons = TABLE(TR(left_buttons, right_buttons), CLASS('buttons'))
    return DIV(tagline, buttons, CLASS('navigation'))
Esempio n. 7
0
    def apply_markup(self, rmap, page, parent=None):
        table = TABLE("\n\t\t")
        self.table_style.page = page
        style_map = {}
        if parent is None:
            try:
                first_para = rmap[next(iter(self))]
            except StopIteration:
                return
            parent = first_para.getparent()
            idx = parent.index(first_para)
            parent.insert(idx, table)
        else:
            parent.append(table)
        for row in self.namespace.XPath("./w:tr")(self.tbl):
            tr = TR("\n\t\t\t")
            style_map[tr] = self.style_map[row]
            tr.tail = "\n\t\t"
            table.append(tr)
            for tc in self.namespace.XPath("./w:tc")(row):
                td = TD()
                style_map[td] = s = self.style_map[tc]
                if s.col_span is not inherit:
                    td.set("colspan", type("")(s.col_span))
                if s.row_span is not inherit:
                    td.set("rowspan", type("")(s.row_span))
                td.tail = "\n\t\t\t"
                tr.append(td)
                for x in self.namespace.XPath("./w:p|./w:tbl")(tc):
                    if x.tag.endswith("}p"):
                        td.append(rmap[x])
                    else:
                        self.sub_tables[x].apply_markup(rmap, page, parent=td)
            if len(tr):
                tr[-1].tail = "\n\t\t"
        if len(table):
            table[-1].tail = "\n\t"

        table_style = self.table_style.css
        if table_style:
            table.set("class", self.styles.register(table_style, "table"))
        for elem, style in style_map.iteritems():
            css = style.css
            if css:
                elem.set("class", self.styles.register(css, elem.tag))
Esempio n. 8
0
def build_navigation(start, num, total, url_base): # {{{
    end = min((start+num-1), total)
    tagline = SPAN('Books %d to %d of %d'%(start, end, total),
            style='display: block; text-align: center;')
    left_buttons = TD(CLASS('button', style='text-align:left'))
    right_buttons = TD(CLASS('button', style='text-align:right'))

    if start > 1:
        for t,s in [('First', 1), ('Previous', max(start-num,1))]:
            left_buttons.append(A(t, href='%s;start=%d'%(url_base, s)))

    if total > start + num:
        for t,s in [('Next', start+num), ('Last', total-num+1)]:
            right_buttons.append(A(t, href='%s;start=%d'%(url_base, s)))

    buttons = TABLE(
            TR(left_buttons, right_buttons),
            CLASS('buttons'))
    return DIV(tagline, buttons, CLASS('navigation'))
Esempio n. 9
0
 def apply_markup(self, object_map):
     rmap = {v:k for k, v in object_map.iteritems()}
     for tbl, blocks in self.tables.iteritems():
         if not blocks:
             continue
         parent = rmap[blocks[0]].getparent()
         table = TABLE('\n\t\t')
         idx = parent.index(rmap[blocks[0]])
         parent.insert(idx, table)
         for row in XPath('./w:tr')(tbl):
             tr = TR('\n\t\t\t')
             tr.tail = '\n\t\t'
             table.append(tr)
             for tc in XPath('./w:tc')(row):
                 td = TD()
                 td.tail = '\n\t\t\t'
                 tr.append(td)
                 for p in XPath('./w:p')(tc):
                     block = rmap[p]
                     td.append(block)
             if len(tr):
                 tr[-1].tail = '\n\t\t'
         if len(table):
             table[-1].tail = '\n\t'
Esempio n. 10
0
def build_index(books, num, search, sort, order, start, total, url_base, CKEYS,
                prefix):
    logo = DIV(IMG(src=prefix + '/static/calibre.png', alt=__appname__),
               id='logo')

    search_box = build_search_box(num, search, sort, order, prefix)
    navigation = build_navigation(start, num, total, prefix + url_base)
    navigation2 = build_navigation(start, num, total, prefix + url_base)
    bookt = TABLE(id='listing')

    body = BODY(logo, search_box, navigation, HR(CLASS('spacer')), bookt,
                HR(CLASS('spacer')), navigation2)

    # Book list {{{
    for book in books:
        thumbnail = TD(
            IMG(type='image/jpeg',
                border='0',
                src=prefix + '/get/thumb/%s' % book['id']), CLASS('thumbnail'))

        data = TD()
        for fmt in book['formats'].split(','):
            if not fmt or fmt.lower().startswith('original_'):
                continue
            a = quote(ascii_filename(book['authors']))
            t = quote(ascii_filename(book['title']))
            s = SPAN(
                A(fmt.lower(),
                  href=prefix + '/get/%s/%s-%s_%d.%s' %
                  (fmt, a, t, book['id'], fmt.lower())), CLASS('button'))
            s.tail = u''
            data.append(s)

        div = DIV(CLASS('data-container'))
        data.append(div)

        series = u'[%s - %s]'%(book['series'], book['series_index']) \
                if book['series'] else ''
        tags = u'Tags=[%s]' % book['tags'] if book['tags'] else ''

        ctext = ''
        for key in CKEYS:
            val = book.get(key, None)
            if val:
                ctext += '%s=[%s] ' % tuple(val.split(':#:'))

        first = SPAN(
            u'\u202f%s %s by %s' % (book['title'], series, book['authors']),
            CLASS('first-line'))
        div.append(first)
        second = SPAN(
            u'%s - %s %s %s' % (book['size'], book['timestamp'], tags, ctext),
            CLASS('second-line'))
        div.append(second)

        bookt.append(TR(thumbnail, data))
    # }}}

    body.append(
        DIV(A(_('Switch to the full interface (non-mobile interface)'),
              href=prefix + "/browse",
              style="text-decoration: none; color: blue",
              title=_('The full interface gives you many more features, '
                      'but it may not work well on a small screen')),
            style="text-align:center"))
    return HTML(
        HEAD(
            TITLE(__appname__ + ' Library'),
            LINK(rel='icon',
                 href='http://calibre-ebook.com/favicon.ico',
                 type='image/x-icon'),
            LINK(rel='stylesheet',
                 type='text/css',
                 href=prefix + '/mobile/style.css'),
            LINK(rel='apple-touch-icon',
                 href="/static/calibre.png")),  # End head
        body)  # End html
Esempio n. 11
0
def build_index(books, num, search, sort, order, start, total, url_base, CKEYS,
        prefix):
    logo = DIV(IMG(src=prefix+'/static/calibre.png', alt=__appname__), id='logo')

    search_box = build_search_box(num, search, sort, order, prefix)
    navigation = build_navigation(start, num, total, prefix+url_base)
    navigation2 = build_navigation(start, num, total, prefix+url_base)
    bookt = TABLE(id='listing')

    body = BODY(
        logo,
        search_box,
        navigation,
        HR(CLASS('spacer')),
        bookt,
        HR(CLASS('spacer')),
        navigation2
    )

    # Book list {{{
    for book in books:
        thumbnail = TD(
                IMG(type='image/jpeg', border='0',
                    src=prefix+'/get/thumb/%s' %
                            book['id']),
                CLASS('thumbnail'))

        data = TD()
        for fmt in book['formats'].split(','):
            if not fmt or fmt.lower().startswith('original_'):
                continue
            a = quote(ascii_filename(book['authors']))
            t = quote(ascii_filename(book['title']))
            s = SPAN(
                A(
                    fmt.lower(),
                    href=prefix+'/get/%s/%s-%s_%d.%s' % (fmt, a, t,
                        book['id'], fmt.lower())
                ),
                CLASS('button'))
            s.tail = u''
            data.append(s)

        div = DIV(CLASS('data-container'))
        data.append(div)

        series = u'[%s - %s]'%(book['series'], book['series_index']) \
                if book['series'] else ''
        tags = u'Tags=[%s]'%book['tags'] if book['tags'] else ''

        ctext = ''
        for key in CKEYS:
            val = book.get(key, None)
            if val:
                ctext += '%s=[%s] '%tuple(val.split(':#:'))

        first = SPAN(u'\u202f%s %s by %s' % (book['title'], series,
            book['authors']), CLASS('first-line'))
        div.append(first)
        second = SPAN(u'%s - %s %s %s' % ( book['size'],
            book['timestamp'],
            tags, ctext), CLASS('second-line'))
        div.append(second)

        bookt.append(TR(thumbnail, data))
    # }}}

    body.append(DIV(
        A(_('Switch to the full interface (non-mobile interface)'),
            href=prefix+"/browse",
            style="text-decoration: none; color: blue",
            title=_('The full interface gives you many more features, '
                'but it may not work well on a small screen')),
        style="text-align:center"))
    return HTML(
        HEAD(
            TITLE(__appname__ + ' Library'),
            LINK(rel='icon', href='http://calibre-ebook.com/favicon.ico',
                type='image/x-icon'),
            LINK(rel='stylesheet', type='text/css',
                href=prefix+'/mobile/style.css'),
            LINK(rel='apple-touch-icon', href="/static/calibre.png")
        ), # End head
        body
    ) # End html
Esempio n. 12
0
def build_index(books, num, search, sort, order, start, total, url_base, CKEYS, prefix, have_kobo_browser=False):
    logo = DIV(IMG(src=prefix + "/static/calibre.png", alt=__appname__), id="logo")

    search_box = build_search_box(num, search, sort, order, prefix)
    navigation = build_navigation(start, num, total, prefix + url_base)
    navigation2 = build_navigation(start, num, total, prefix + url_base)
    bookt = TABLE(id="listing")

    body = BODY(logo, search_box, navigation, HR(CLASS("spacer")), bookt, HR(CLASS("spacer")), navigation2)

    # Book list {{{
    for book in books:
        thumbnail = TD(
            IMG(type="image/jpeg", border="0", src=prefix + "/get/thumb/%s" % book["id"]), CLASS("thumbnail")
        )

        data = TD()
        for fmt in book["formats"].split(","):
            if not fmt or fmt.lower().startswith("original_"):
                continue
            file_extension = "kepub.epub" if have_kobo_browser and fmt.lower() == "kepub" else fmt
            a = quote(ascii_filename(book["authors"]))
            t = quote(ascii_filename(book["title"]))
            s = SPAN(
                A(fmt.lower(), href=prefix + "/get/%s/%s-%s_%d.%s" % (fmt, a, t, book["id"], file_extension.lower())),
                CLASS("button"),
            )
            s.tail = u""
            data.append(s)

        div = DIV(CLASS("data-container"))
        data.append(div)

        series = u"[%s - %s]" % (book["series"], book["series_index"]) if book["series"] else ""
        tags = u"Tags=[%s]" % book["tags"] if book["tags"] else ""

        ctext = ""
        for key in CKEYS:
            val = book.get(key, None)
            if val:
                ctext += "%s=[%s] " % tuple(val.split(":#:"))

        first = SPAN(
            u"\u202f%s %s by %s"
            % (clean_xml_chars(book["title"]), clean_xml_chars(series), clean_xml_chars(book["authors"])),
            CLASS("first-line"),
        )
        div.append(first)
        second = SPAN(u"%s - %s %s %s" % (book["size"], book["timestamp"], tags, ctext), CLASS("second-line"))
        div.append(second)

        bookt.append(TR(thumbnail, data))
    # }}}

    body.append(
        DIV(
            A(
                _("Switch to the full interface (non-mobile interface)"),
                href=prefix + "/browse",
                style="text-decoration: none; color: blue",
                title=_(
                    "The full interface gives you many more features, " "but it may not work well on a small screen"
                ),
            ),
            style="text-align:center",
        )
    )
    return HTML(
        HEAD(
            TITLE(__appname__ + " Library"),
            LINK(rel="icon", href="//calibre-ebook.com/favicon.ico", type="image/x-icon"),
            LINK(rel="stylesheet", type="text/css", href=prefix + "/mobile/style.css"),
            LINK(rel="apple-touch-icon", href="/static/calibre.png"),
            META(name="robots", content="noindex"),
        ),  # End head
        body,
    )  # End html