1 from datetime import datetime
5 from django import forms
6 from django.utils.translation import ugettext_lazy as _
9 from archive.models import Audiobook
10 from archive.settings import FILES_PATH
11 from archive.utils import ExistingFile, sha1_file
13 class AudiobookForm(forms.ModelForm):
17 def save(self, commit=True, path=None):
18 m = super(AudiobookForm, self).save(commit=False)
19 m.modified = datetime.now()
22 # adding a new audiobook
23 if not os.path.isdir(FILES_PATH):
24 os.makedirs(FILES_PATH)
25 # save the file in model
28 os.path.basename(path),
31 f = open(m.source_file.path)
32 m.source_sha1 = sha1_file(f)