Пример #1
0
def download_txt(user_slug, doc_slug):
    """
    Creates a single text file to download.
    """
    document = Document(data)
    document.set_host(domain_name(bottle.request))
    if not document.load(user_slug, doc_slug):
        msg = "Document '{:s}' not found."
        bottle.abort(HTTP_NOT_FOUND, msg.format(doc_slug))
    file_name, text = document.export_txt_file()
    attach_as_file = 'attachment; filename="{:s}"'.format(file_name)
    bottle.response.set_header('Content-Type', 'text/plain')
    bottle.response.set_header('Content-Disposition', attach_as_file)
    return text
Пример #2
0
def test_import_and_export_document():
    """
    Generates an archive file and then turns it back into the original parts.
    """
    doc1 = Document(data)
    user_slug = random_slug('test-user-')
    doc_slug = random_slug('test-doc-')
    doc1.set_parts(user_slug, doc_slug, minimal_document)
    file_name, file_text = doc1.export_txt_file()
    assert user_slug in file_name
    assert doc_slug in file_name
    doc2 = Document(data)
    doc2.import_txt_file(user_slug, doc_slug, file_text)
    assert doc1 == doc2