regluit/utils/fields.py

15 lines
550 B
Python
Raw Normal View History

2013-08-27 03:54:19 +00:00
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