pharmaship.inventory.export¶
Export methods for Inventory application.
-
pharmaship.inventory.export.
create_archive
(allowance, file_obj)¶ Create an archive from the given Allowance instance.
The response is a tar.gz file containing YAML files generated by the function serialize_allowance.
Pictures are added if any.
The package description file (
package.yaml
) and theMANIFEST
file are created at the end.- Parameters
allowance (pharmaship.inventory.models.Allowance) – Allowance instance to export
file_obj (argparse.FileType or any compatible file object) – Destination file object
- Returns
True
if success- Return type
-
pharmaship.inventory.export.
create_manifest
(items)¶ Create the data to write into the MANIFEST file.
-
pharmaship.inventory.export.
create_package_yaml
(allowance)¶ Export package info in YAML string.
- Parameters
allowance (pharmaship.inventory.models.Allowance) – Allowance instance to export
- Returns
YAML string containing Allowance data.
- Return type
-
pharmaship.inventory.export.
create_tarinfo
(name, content)¶ Return a the TarInfo for a virtual file.
- Parameters
- Returns
tarfile.TarInfo
andio.BytesIO
instance of the file content.- Return type
-
pharmaship.inventory.export.
get_hash
(name, content=None, filename=None)¶ Return sha256 hash and filename for MANIFEST file.
-
pharmaship.inventory.export.
get_pictures
(equipment_list)¶ Return a list of picture paths to include in the archive.
- Parameters
equipment_list (django.db.models.query.QuerySet) – List of equipment for serialized allowance.
- Returns
List of pictures filenames.
- Return type
-
pharmaship.inventory.export.
serialize_allowance
(allowance, content_types)¶ Export an allowance using the YAML format.
To have an usable export, the user needs:
the
pharmaship.inventory.models.Allowance
selected instance,
And related to this instance:
the
pharmaship.inventory.models.Molecule
objects list,the
pharmaship.inventory.models.Equipment
objects list,the
pharmaship.inventory.models.MoleculeReqQty
objects list,the
pharmaship.inventory.models.EquipmentReqQty
objects list,the
pharmaship.inventory.models.RescueBagReqQty
objects list,the
pharmaship.inventory.models.FirstAidKitReqQty
objects list,the
pharmaship.inventory.models.TelemedicalReqQty
objects list,the
pharmaship.inventory.models.LaboratoryReqQty
objects list.
This function grabs all these together in a list of tuples:
[('filename.yaml', <yaml content string>)]
In addition, it returns the Equipment list for getting pictures if any.
- Parameters
allowance (pharmaship.inventory.models.Allowance) – Allowance to serialize.
- Returns
List of tuples filenames and streams
- Return type
tuple(list(tuple(str, str)), django.db.models.query.QuerySet)