only epub files to be uploaded for now

pull/1/head
eric 2013-08-26 23:54:19 -04:00
parent ef3de5bd88
commit e5a162061d
3 changed files with 23 additions and 2 deletions

View File

@ -55,6 +55,7 @@ from regluit.core.lookups import (
EditionLookup
)
from regluit.utils.localdatetime import now
from regluit.utils.fields import EpubFileField
logger = logging.getLogger(__name__)
@ -135,10 +136,15 @@ class EditionForm(forms.ModelForm):
'add_subject': forms.TextInput(attrs={'size': 30}),
'unglued': forms.CheckboxInput(),
}
class EbookFileForm(forms.ModelForm):
file = EpubFileField(max_length=16777216)
def clean_format(self):
return 'epub'
class Meta:
model = EbookFile
widgets = { 'edition': forms.HiddenInput, }
widgets = { 'edition': forms.HiddenInput, 'format': forms.HiddenInput }
exclude = { 'created', }
class EbookForm(forms.ModelForm):

View File

@ -410,4 +410,5 @@ MARC_CHOICES = (
BOOXTREAM_API_KEY = '7ynRCsx4q21zEY67it7yk8u5rc6EXY'
BOOXTREAM_API_USER = 'ungluetest'
BOOXTREAM_TEST_EPUB = STATIC_ROOT+'/test/134221.0.epub'
BOOXTREAM_TEST_EPUB = STATIC_ROOT+'/test/134221.0.epub'
FILE_UPLOAD_MAX_MEMORY_SIZE = 20971520 #20MB

14
utils/fields.py Normal file
View File

@ -0,0 +1,14 @@
import zipfile
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.template.defaultfilters import filesizeformat
class EpubFileField(forms.FileField):
"""
does some epub checking; currently only checks its a zip:
"""
def clean(self, data, initial=None):
data = super(EpubFileField, self).clean(data, initial)
if data.name and not zipfile.is_zipfile(data.file):
raise forms.ValidationError(_('%s is not a valid EPUB file' % data.name) )
return data