X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/3756a9d667b0207137d004f2bb5a7731b671073c..81f4a0e5709e2bf818244a07cbb715a54c96f3eb:/apps/picture/models.py?ds=sidebyside diff --git a/apps/picture/models.py b/apps/picture/models.py index 01f9b8d48..6ac54fe82 100644 --- a/apps/picture/models.py +++ b/apps/picture/models.py @@ -63,7 +63,7 @@ class Picture(models.Model): return self.slug @classmethod - def from_xml_file(cls, xml_file, images_path=None, overwrite=False): + def from_xml_file(cls, xml_file, image_file=None, overwrite=False): """ Import xml and it's accompanying image file. """ @@ -86,11 +86,12 @@ class Picture(models.Model): picture.tags = catalogue.models.Tag.tags_from_info(picture_xml.picture_info) - img = picture_xml.image_file() - try: - picture.image_file.save(path.basename(picture_xml.image_path), File(img)) - finally: - img.close() + if image_file is not None: + img = image_file + else: + img = picture_xml.image_file() + + picture.image_file.save(path.basename(picture_xml.image_path), File(img)) picture.xml_file.save("%s.xml" % picture.slug, File(xml_file)) picture.save()