Django 4.
[wolnelektury.git] / src / catalogue / fields.py
index 1efc769..c592c55 100644 (file)
@@ -173,7 +173,8 @@ class EbookField(models.FileField):
         out = self.transform(
             book.wldocument2() if self.librarian2_api else book.wldocument(),
         )
         out = self.transform(
             book.wldocument2() if self.librarian2_api else book.wldocument(),
         )
-        fieldfile.save(None, File(open(out.get_filename(), 'rb')), save=False)
+        with open(out.get_filename(), 'rb') as f:
+            fieldfile.save(None, File(f), save=False)
         self.set_file_permissions(fieldfile)
         if book.pk is not None:
             book.save(update_fields=[self.attname])
         self.set_file_permissions(fieldfile)
         if book.pk is not None:
             book.save(update_fields=[self.attname])
@@ -358,6 +359,10 @@ class CoverField(EbookField):
     ext = 'jpg'
     directory = 'cover'
 
     ext = 'jpg'
     directory = 'cover'
 
+    @staticmethod
+    def transform(wldoc):
+        return wldoc.as_cover()
+
     def set_file_permissions(self, fieldfile):
         pass
 
     def set_file_permissions(self, fieldfile):
         pass