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 theMANIFESTfile 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
Trueif 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.TarInfoandio.BytesIOinstance 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.Allowanceselected instance,
And related to this instance:
the
pharmaship.inventory.models.Moleculeobjects list,the
pharmaship.inventory.models.Equipmentobjects list,the
pharmaship.inventory.models.MoleculeReqQtyobjects list,the
pharmaship.inventory.models.EquipmentReqQtyobjects list,the
pharmaship.inventory.models.RescueBagReqQtyobjects list,the
pharmaship.inventory.models.FirstAidKitReqQtyobjects list,the
pharmaship.inventory.models.TelemedicalReqQtyobjects list,the
pharmaship.inventory.models.LaboratoryReqQtyobjects 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)