Example #1
0
File: forms.py Project: Mihkorz/AMD
    def clean_document(self):
        try:
            uploaded_file = self.cleaned_data['document']
        
            temp_doc = NamedTemporaryFile(mode='w+', delete=True)
            temp_doc.write(uploaded_file.read())
            temp_doc.flush()
            temp_doc.seek(0)
            
            temp_doc._size = uploaded_file._size
            temp_doc._content_type = uploaded_file.content_type
            
            validate_file(temp_doc)
            
            temp_doc.close()            
  
        except forms.ValidationError:
            logger.error(u'User was trying to upload file with wrong format.')
            raise 

        return uploaded_file