Beispiel #1
0
 def test_metadata(self):
     metaTrad = SourceMetadata(name="Traductor")
     metaTrad.save()
     metaInfo = SourceInfos(metadata=metaTrad, value="Thomas Hobbes")
     metaInfo.save()
     self.odyssey.metadatas.add(metaInfo)
     self.assertEqual(self.odyssey.metadatas.count(), 1)
Beispiel #2
0
 def test_to_dict(self):
     homer = Author(surname="Homer", folder=self.folder)
     homer.save()
     metaTrad = SourceMetadata(name="Traductor")
     metaTrad.save()
     metaInfo = SourceInfos(metadata=metaTrad, value="Thomas Hobbes")
     metaInfo.save()
     self.odyssey.authors.add(homer)
     self.odyssey.metadatas.add(metaInfo)
     self.assertEqual(self.odyssey.to_dict(),
                      {'title': 'Odyssey', 'authors': [homer.pk],
                       'metadata': [{metaTrad.name: metaInfo.value}]})
Beispiel #3
0
def read_metadatas(metadatas_string):
    metadatas_dictionary = transform_metadatas_to_dict(metadatas_string)
    metadatas_with_objects = {}
    # We get or add the metadatas
    for metadata in metadatas_dictionary:
        obj, cr = SourceMetadata.objects.get_or_create(
            name__icontains=metadata.lower(),
            defaults={'name': metadata}
        )
        metadatas_with_objects[obj] = metadatas_dictionary[metadata]
    # We save the metadata values
    infos = []
    for metadata_object in metadatas_with_objects:
        info = SourceInfos(metadata=metadata_object,
                           value=metadatas_with_objects[metadata_object])
        info.save()
        infos.append(info)
    return infos