Example #1
0
    def exporter(self, block, xmlfile, zipfile):
        filename = "pageblocks/%s-description.txt" % block.pageblock().pk
        zipfile.writestr(filename, block.description.encode("utf8"))

        print >> xmlfile, (
            u"""<quiz rhetorical="%s" description_src="%s">""" % (
                block.rhetorical, filename))

        for question in block.question_set.all():
            print >> xmlfile, u"""<question type="%s">""" % (
                question.question_type)

            filename = "pageblocks/%s-%s-text.txt" % (block.pageblock()
                                                      .pk, question.pk)
            zipfile.writestr(filename, question.text.encode("utf8"))
            print >> xmlfile, u"<text src='%s' />" % filename

            filename = "pageblocks/%s-%s-explanation.txt" % (block.pageblock()
                                                             .pk, question.pk)
            zipfile.writestr(filename, question.explanation.encode("utf8"))
            print >> xmlfile, u"<explanation src='%s' />" % filename

            filename = "pageblocks/%s-%s-introtext.txt" % (block.pageblock()
                                                           .pk, question.pk)
            zipfile.writestr(filename, question.intro_text.encode("utf8"))
            print >> xmlfile, u"<introtext src='%s' />" % filename

            for answer in question.answer_set.all():
                print >> xmlfile, (
                    u"""<answer label="%s" value="%s" correct="%s" />""" % (
                        sanitize(answer.label), sanitize(answer.value),
                        answer.correct))

            print >> xmlfile, "</question>"
        print >> xmlfile, "</quiz>"
Example #2
0
def export_node(node, xmlfile, zipfile):
    print >> xmlfile, \
        u"""<li><a href="%s">%s</a></li>""" % (
        node.get_absolute_url(), sanitize(node.label))

    if node.pageblock_set.count():
        fd, node_filename = tempfile.mkstemp(prefix="pagetree-site", suffix=".html")
        nodefile = codecs.open(node_filename, 'w', encoding='utf8')
        print >> nodefile, u"<html><head><title>%s</title></head><body>" % node.label

        for block in node.pageblock_set.all():
            data = export_block(block, nodefile, zipfile)
            print >> nodefile, block.render(**data)

        print >> nodefile, u"</body></html>"
        nodefile.close()
        basename = node.get_absolute_url().strip('/')
        if not basename:
            basename = 'index'
        arcname = "pageblocks/" + basename + '.html'
        zipfile.write(node_filename, arcname=arcname)
        os.unlink(node_filename)

    for child in node.get_children():
        print >> xmlfile, u"<ul>"
        export_node(child, xmlfile, zipfile)
        print >> xmlfile, u"</ul>"
def export_node(node, xmlfile, zipfile):
    print >> xmlfile, u"""<section slug="%s" label="%s" is_root="%s">""" % (
        node.slug,
        sanitize(node.label),
        node.is_root(),
    )
    for block in node.pageblock_set.all():
        export_block(block, xmlfile, zipfile)
    for child in node.get_children():
        export_node(child, xmlfile, zipfile)
    print >> xmlfile, "</section>"
def export_block(block, xmlfile, zipfile):
    object = block.content_object
    type, export_fn = get_exporter(object.__class__)
    print >> xmlfile, u"""<pageblock id="%s" type="%s" label="%s" ordinality="%s">""" % (
        block.pk,
        type,
        sanitize(block.label),
        block.ordinality,
    )
    export_fn(object, xmlfile, zipfile)
    print >> xmlfile, "</pageblock>"