def __init__(self, context): self.context = aq_inner(context) self.settings = Settings(self.context) fw = IFileWrapper(self.context) self.blob = fw.blob self.initialize_blob_filepath() self.filehash = None self.gsettings = GlobalSettings(getPortal(context)) self.storage_dir = self.get_storage_dir() self.doc_type = getDocumentType(self.context, self.gsettings.auto_layout_file_types)
def enabled(self): try: fw = IFileWrapper(self.context) if fw.has_enclosure: if self.context.getLayout() == 'documentviewer': return True else: settings = GlobalSettings(api.portal.get()) return allowedDocumentType(self.context, settings.auto_layout_file_types) else: return False except Exception: return False
def getDocumentType(obj, allowed_types): ct = IFileWrapper(obj).file_type if ct is None: return None mime_registry = getToolByName(obj, 'mimetypes_registry') for _type in mime_registry.lookup(ct): for ext in _type.extensions: if ext in EXTENSION_TO_ID_MAPPING: id = EXTENSION_TO_ID_MAPPING[ext] if id in allowed_types: return CONVERTABLE_TYPES[id] return None
def enabled(self): try: fw = IFileWrapper(self.context) if fw.has_enclosure: if self.context.getLayout() == 'documentviewer': return True else: return allowedDocumentType(self.context, GlobalSettings( getPortal(self.context)).auto_layout_file_types) else: return False except: return False
def run_conversion(self): context = self.context gsettings = self.gsettings fw = IFileWrapper(context) filename = fw.filename language = IOCRLanguage(context).getLanguage() args = dict(sizes=(('large', gsettings.large_size), ('normal', gsettings.normal_size), ('small', gsettings.thumb_size)), enable_indexation=self.isIndexationEnabled(), ocr=gsettings.ocr, detect_text=gsettings.detect_text, format=gsettings.pdf_image_format, converttopdf=self.doc_type.requires_conversion, language=language, filename=filename) if self.blob_filepath is None: args['filedata'] = str(fw.file.data) else: args['inputfilepath'] = self.blob_filepath return docsplit.convert(self.storage_dir, **args)