X-Git-Url: https://git.mdrn.pl/audio.git/blobdiff_plain/d64f05ea901ccb7e61eacd9a5579bb81138b193d..5c11ba52a0f81411f3b3a092e2547e3722a8ee59:/apps/archive/forms.py diff --git a/apps/archive/forms.py b/apps/archive/forms.py old mode 100755 new mode 100644 index c551cf8..81568c6 --- a/apps/archive/forms.py +++ b/apps/archive/forms.py @@ -5,9 +5,10 @@ import os.path from django import forms from django.utils.translation import ugettext_lazy as _ import mutagen +from django.utils.encoding import force_bytes from archive.models import Audiobook -from archive.settings import FILES_PATH +from archive.settings import FILES_PATH, NEW_PATH from archive.utils import ExistingFile, sha1_file class AudiobookForm(forms.ModelForm): @@ -15,6 +16,10 @@ class AudiobookForm(forms.ModelForm): model = Audiobook def save(self, commit=True, path=None): + """ Performs normal save, with given file as an source audiobook. + + `path' is relative to NEW_PATH. + """ m = super(AudiobookForm, self).save(commit=False) m.modified = datetime.now() @@ -24,13 +29,14 @@ class AudiobookForm(forms.ModelForm): os.makedirs(FILES_PATH) # save the file in model + abs_path = os.path.join(NEW_PATH, path) m.source_file.save( - os.path.basename(path), - ExistingFile(path)) + path, + ExistingFile(abs_path)) - f = open(m.source_file.path) - m.source_sha1 = sha1_file(f) - f.close() +# f = open(force_bytes(m.source_file.path)) +# m.source_sha1 = sha1_file(f) +# f.close() if commit: m.save()