Example #1
0
 def clean(self):
     format = self.cleaned_data.get('format', '')
     the_file = self.cleaned_data.get('file', None)
     url = self.cleaned_data.get('url', None)
     test_file(the_file, format)
     if not the_file and not url:
         raise forms.ValidationError(_("Either a link or a file is required."))
     if the_file and url:
         self.cleaned_data['url'] = ''
     return self.cleaned_data
Example #2
0
def load_ebookfile(url, etype):
    '''
    return a ContentFile if a new ebook has been loaded
    '''
    ebfs = models.EbookFile.objects.filter(source=url)
    if ebfs:
        return None
    try:
        r = requests.get(url)
        contentfile = ContentFile(r.content)
        test_file(contentfile, etype)
        return contentfile
    except IOError, e:
        logger.error(u'could not open {}'.format(url))
Example #3
0
 def clean(self):
     fformat = self.cleaned_data['format']
     the_file = self.cleaned_data.get('file', None)
     test_file(the_file, fformat)
     return self.cleaned_data