Exemplo n.º 1
0
def create_zip_deck_file(deck):
    """Creates a zipped file containing the contents of the deck (XLS and media objects."""

    # create the string buffer to hold the contents of the zip file
    s = StringIO()

    # create the zipfile object
    zfile = zipfile.ZipFile(s, "w")

    # write the deck XLS file to the zip
    deck_file_output = utils.create_deck_file(deck.id)
    temp_dirpath = tempfile.mkdtemp()
    temp_filepath = os.path.join(temp_dirpath, "deck.xls")
    deck_file_output.save(temp_filepath)
    zfile.write(temp_filepath, arcname=os.path.split(temp_filepath)[1])
    shutil.rmtree(temp_dirpath) # must delete temp dir when we're done

    # lookup the unique field values in the deck of cards,
    # where the field values are the media object names
    card_list = queries.getDeckCardsList(deck.id)
    field_set = set()
    for c in card_list:
        for f in c['fields']:
            if f['type'] not in ('T', 'M'):
                field_set.add(f['value'])

    # add each media object ot the zip file
    for file_name in field_set:
        file_contents = MediaStoreService.readFileContents(file_name)
        if file_contents is not None:
            zfile.writestr(file_name, file_contents)

    zfile.close()

    return s.getvalue()
Exemplo n.º 2
0
def create_zip_deck_file(deck):
    """Creates a zipped file containing the contents of the deck (XLS and media objects."""

    # create the string buffer to hold the contents of the zip file
    s = StringIO()

    # create the zipfile object
    zfile = zipfile.ZipFile(s, "w")

    # write the deck XLS file to the zip
    deck_file_output = utils.create_deck_file(deck.id)
    temp_dirpath = tempfile.mkdtemp()
    temp_filepath = os.path.join(temp_dirpath, "deck.xls")
    deck_file_output.save(temp_filepath)
    zfile.write(temp_filepath, arcname=os.path.split(temp_filepath)[1])
    shutil.rmtree(temp_dirpath)  # must delete temp dir when we're done

    # lookup the unique field values in the deck of cards,
    # where the field values are the media object names
    card_list = queries.getDeckCardsList(deck.id)
    field_set = set()
    for c in card_list:
        for f in c['fields']:
            if f['type'] not in ('T', 'M'):
                field_set.add(f['value'])

    # add each media object ot the zip file
    for file_name in field_set:
        file_contents = MediaStoreService.readFileContents(file_name)
        if file_contents is not None:
            zfile.writestr(file_name, file_contents)

    zfile.close()

    return s.getvalue()
Exemplo n.º 3
0
def handle_uploaded_media_file(file, file_type=None):
    """Handles an uploaded file and returns the path to the file object."""
    store_service = MediaStoreService(file=file, file_type=file_type)
    store_service.save()
    return store_service.storeFileName()
Exemplo n.º 4
0
def handle_uploaded_media_file(file, file_type=None):
    """Handles an uploaded file and returns the path to the file object."""
    store_service = MediaStoreService(file=file, file_type=file_type)
    store_service.save()
    return store_service.storeFileName()