def clean_url(self): from utils.contenttype import is_allowed from mimetypes import guess_type url = self.cleaned_data.get('url') print url file_type = guess_type(url) print file_type if is_allowed(file_type): return url raise ValidationError(_(u"The file type is not supported."))
def clean_file(self): from profile import settings as _settings from profile.avatars import handle_avatar from utils.contenttype import is_allowed file = self.cleaned_data.get('file') if file.size > _settings.MAX_AVATAR_SIZE: raise ValidationError( _(u"File too big. The maximum size allowed is %iMB \ (megabytes)") % (_settings.MAX_AVATAR_SIZE / (1024^2))) if not is_allowed(file): raise ValidationError(_(u"The file type is not supported.")) return file