+from datetime import datetime
import os
import os.path
-from datetime import datetime
from django import forms
from django.utils.translation import ugettext_lazy as _
from archive.models import Audiobook
from archive.settings import FILES_PATH
-from archive.utils import ExistingFile
+from archive.utils import ExistingFile, sha1_file
class AudiobookForm(forms.ModelForm):
class Meta:
if not os.path.isdir(FILES_PATH):
os.makedirs(FILES_PATH)
# save the file in model
- bn = os.path.basename(path)
- ef = ExistingFile(path)
-
- m.source_file.save(bn, ef)
+
+ m.source_file.save(
+ os.path.basename(path),
+ ExistingFile(path))
+
+ f = open(m.source_file.path)
+ m.source_sha1 = sha1_file(f)
+ f.close()
if commit:
m.save()
-