pharmaship.inventory.import_data¶
Import methods for Inventory application.
-
class
pharmaship.inventory.import_data.
DataImport
(tar, conf, key)¶ Class to import allowance inside the inventory module.
- Parameters
tar (tarfile.TarFile) – Tarfile data to import.
conf (dict) – Validated package configuration (not used).
key (dict) – GPG key data used for signing the package archive.
-
import_allowance
()¶ Import an Allowance from a YAML file.
Update the
pharmaship.inventory.models.Allowance
info or create it from scratch.- Returns
Allowance instance or
False
in case of import error.- Return type
-
import_equipment
()¶ Import Equipment objects from a YAML file.
Use Django’s update_or_create method for
pharmaship.inventory.models.Equipment
.- Returns
True
if successful import,False
otherwise.- Return type
-
import_molecule
()¶ Import Molecule objects from a YAML file.
Use Django’s update_or_create method for
pharmaship.inventory.models.Molecule
.- Returns
True
if successful import,False
otherwise.- Return type
-
update
()¶ Launch the importation.
Import first the
pharmaship.inventory.models.Allowance
. Then, import allpharmaship.inventory.models.Molecule
andpharmaship.inventory.models.Equipment
objects (update or create them).When this is done, parse each JSON file for required quantities:
pharmaship.inventory.models.Molecule
andpharmaship.inventory.models.Equipment
objects without required quantity after import are affected to the defaultpharmaship.inventory.models.Allowance
(id=0
) with a required quantity of 0.- Returns
True
if import successful,False
otherwise.- Return type
-
pharmaship.inventory.import_data.
deserialize_json_file
(data, tar, allowance)¶ Deserialize a JSON file contained in the tar file.
- Parameters
data (dict) –
Dictionnary with filename and model related. The following keys must be present:
filename
: the name of the JSON file to extract from the tar archive;model
: the class of model to deserialize (ie:pharmaship.inventory.models.MoleculeReqQty
).
tar (tarfile.TarFile) – tar file archive containing the file to extract
allowance (models.Allowance) – allowance instance to rattach
- Returns
List of model instances.
- Return type
-
pharmaship.inventory.import_data.
get_base
(type, content, model=None)¶ Return a model instance according to the type and model if provided.
If the model is not provided, it is retrieved from the type structure. On some model (ie:
pharmaship.inventory.models.RescueBagReqQty
), the type can be eitherpharmaship.inventory.models.Equipment
orpharmaship.inventory.models.Molecule
.- Parameters
type (models.Equipment or models.Molecule) – Model class of base field (Django internal).
content (dict) – Dictionnary with all natural key fields for the related base.
model (models.Equipment or models.Molecule) – Model class of base item to serialize.
- Returns
A model instance or
None
if not found.- Return type
-
pharmaship.inventory.import_data.
get_file
(filename, tar)¶ Extract a file from a tar archive.
- Parameters
filename (str) – Filename to extract from tar file.
tar (tarfile.TarFile) – tar file instance.
- Returns
Content of the file or
False
if the file cannot be accessed.- Return type
-
pharmaship.inventory.import_data.
get_model
(data)¶ Return the related ContentType from data.
- Parameters
data (dict) –
Dictionnary containing at least following keys:
app_label
: the application name,name
: the name of the model
- Returns
The Django ContentType instance or
None
if it does not exist.- Return type
-
pharmaship.inventory.import_data.
pictures_files
(members)¶ Change the picture path in TarInfo instance.
- Parameters
members (list(tarfile.TarInfo)) – files in the tar file.
- Returns
An iterator with tar file members containing
pictures
as first path part.
-
pharmaship.inventory.import_data.
required_quantity
(data, tar, allowance)¶ Update the required quantities for deserialized items.
After successful deserialization, delete all related required quantity for the selected allowance. Then create all deserialized objects.
- Parameters
data (dict) –
Dictionnary with filename and model related. The following keys must be present:
filename
: the name of the JSON file to extract from the tar archive;model
: the class of model to deserialize (ie:pharmaship.inventory.models.MoleculeReqQty
).
tar (tarfile.TarFile) – tar file archive containing the file to extract
allowance (models.Allowance) – allowance instance to rattach
- Returns
True
if there is no error,False
otherwise.- Return type
-
pharmaship.inventory.import_data.
update_allowance
(allowance, key)¶ Update or create an allowance instance from serialized allowance data.
- Parameters
allowance (models.Allowance) – Up-to-date Allowance instance.
key (str) – GPG key ID used for signing the package archive.
- Returns
the updated (or create) allowance instance
- Return type