class SettingsForm(form.EditForm): """ The page that holds all the slider settings """ fields = field.Fields(IDocumentViewerSettings) label = _(u'heading_documentviewer_settings_form', default=u"Document Viewer Settings") description = _(u'description_documentviewer_settings_form', default=u"These settings override the global settings.") @button.buttonAndHandler(_('Save'), name='apply') def handleApply(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return self.applyChanges(data) url = getMultiAdapter( (self.context, self.request), name='absolute_url')() + '/view' self.request.response.redirect(url) self.context.plone_utils.addPortalMessage( PloneMessageFactory('Changes saved.'))
class IDocumentViewerSettings(Interface): width = schema.Int( title=_("Viewer Width"), description=_("Leave blank to take full width."), required=False, **_default(default_width, IGlobalDocumentViewerSettings['width'].default)) height = schema.Int( title=_("Viewer Height"), required=False, **_default(default_height, IGlobalDocumentViewerSettings['height'].default)) fullscreen = schema.Bool( title=_("Fullscreen Viewer"), description=_("Default to fullscreen viewer."), default=False) enable_indexation = schema.Bool( title=_("Make searchable"), description=_("If this is enabled, the text will be extracted from " "the PDF and will be searchable using the search widget and " "with the Plone search. You will need to run conversion again " "for this parameter to be taken into account." ), **_default(default_enable_indexation, IGlobalDocumentViewerSettings['width'].default)) show_sidebar = schema.Bool( title=_("Show sidebar"), description=_("Default to show sidebar."), required=False, **_default(default_show_sidebar, IGlobalDocumentViewerSettings['width'].default)) show_search = schema.Bool( title=_("Show search box"), **_default(default_show_search, IGlobalDocumentViewerSettings['width'].default))
class GlobalSettingsForm(form.EditForm): fields = field.Fields(IGlobalDocumentViewerSettings) label = _(u'heading_documentviewer_global_settings_form', default=u"Global Document Viewer Settings") description = _(u'description_documentviewer_global_settings_form', default=u"Configure the parameters for this Viewer.") @button.buttonAndHandler(_('Save'), name='apply') def handleApply(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return self.applyChanges(data) self.status = PloneMessageFactory('Changes saved.')
def __call__(self): self.site = getPortal(self.context) self.settings = Settings(self.context) self.global_settings = GlobalSettings(self.site) self.portal_url = getMultiAdapter( (self.context, self.request), name="plone_portal_state").portal_url() self.dvstatic = "%s/++resource++dv.resources" % (self.portal_url) resource_url = self.global_settings.override_base_resource_url rel_url = storage.getResourceRelURL(gsettings=self.global_settings, settings=self.settings) if resource_url: self.dvpdffiles = '%s/%s' % (resource_url.rstrip('/'), rel_url) else: self.dvpdffiles = '%s/%s' % (self.portal_url, rel_url) utils = getToolByName(self.context, 'plone_utils') msg = None self.enabled = True if allowedDocumentType(self.context, self.global_settings.auto_layout_file_types): if not self.installed: msg = _( "Since you do not have docsplit installed on this " "system, we can not render the pages of this document.") if self.settings.converting is not None and \ self.settings.converting: if self.settings.successfully_converted: # there is a version that is already converted, show it. self.enabled = True else: msg = _("The document is currently being converted to the " "Document Viewer view.") self.enabled = False elif self.settings.successfully_converted is not None and \ not self.settings.successfully_converted: msg = _("There was an error trying to convert the document. " "Maybe the document is encrypted, corrupt or " "malformed? Check log for details.") self.enabled = False elif self.settings.successfully_converted is None: # must have just switched to this view msg = _("This document is not yet converted to document " "viewer. Please click the `Document Viewer Convert` " "button in the actions menu to convert.") self.enabled = False else: self.enabled = False msg = _("The file is not a supported document type. " "Your type may be supported. Check out the document " "viewer configuration settings.") mtool = getToolByName(self.context, 'portal_membership') self.can_modify = mtool.checkPermission('cmf.ModifyPortalContent', self.context) if msg and self.can_modify: utils.addPortalMessage(_(msg)) return self.index()
def __call__(self): self.site = getPortal(self.context) self.settings = Settings(self.context) self.global_settings = GlobalSettings(self.site) self.portal_url = getMultiAdapter((self.context, self.request), name="plone_portal_state").portal_url() self.dvstatic = "%s/++resource++dv.resources" % ( self.portal_url) resource_url = self.global_settings.override_base_resource_url rel_url = storage.getResourceRelURL(gsettings=self.global_settings, settings=self.settings) if resource_url: self.dvpdffiles = '%s/%s' % (resource_url.rstrip('/'), rel_url) else: self.dvpdffiles = '%s/%s' % (self.portal_url, rel_url) utils = getToolByName(self.context, 'plone_utils') msg = None self.enabled = True if allowedDocumentType(self.context, self.global_settings.auto_layout_file_types): if not self.installed: msg = _("Since you do not have docsplit installed on this " "system, we can not render the pages of this document.") if self.settings.converting is not None and \ self.settings.converting: if self.settings.successfully_converted: # there is a version that is already converted, show it. self.enabled = True msg = _("A new conversion to the Document Viewer " "is currently being generated for this document." ) else: msg = _("The document is currently being converted to the " "Document Viewer view.") self.enabled = False elif self.settings.successfully_converted is not None and \ not self.settings.successfully_converted: msg = _("There was an error trying to convert the document. " "Maybe the document is encrypted, corrupt or " "malformed? Check log for details.") self.enabled = False elif self.settings.successfully_converted is None: # must have just switched to this view msg = _("This document is not yet converted to document " "viewer. Please click the `Document Viewer Convert` " "button in the actions menu to convert.") self.enabled = False else: self.enabled = False msg = _("The file is not a supported document type. " "Your type may be supported. Check out the document " "viewer configuration settings.") mtool = getToolByName(self.context, 'portal_membership') self.can_modify = mtool.checkPermission('Modify portal content', self.context) if msg and self.can_modify: utils.addPortalMessage(_(msg)) return self.index()
class IGlobalDocumentViewerSettings(Interface): large_size = schema.Int( title=_("Large Image Size"), default=1000) normal_size = schema.Int( title=_("Normal Image Size"), default=700) thumb_size = schema.Int( title=_("Thumb Image Size"), default=180) storage_type = schema.Choice( title=_("Storage Type"), description=_("Blob storage using the normal ZODB blob mechanism. " "File storage is for just storage the files on the " "file system with no hard reference on write to the " "ZODB. This allows you to easily push the files to " "be served off-site."), default='Blob', vocabulary=SimpleVocabulary.fromValues([ 'Blob', 'File'])) storage_location = schema.TextLine( title=_("Storage location"), description=_('Only for file storage not with zodb. ' 'Plone client must have write access to directory.'), default=u"/opt/dvpdffiles") storage_obfuscate = schema.Bool( title=_("Obfuscate private file paths"), description=_("*experimental* If you're serving files straight from " "a web server, there is no way to do permission checks " "on them. This provides a bit more security as the path " "to the resources will be more difficult to guess and " "never publisized. Of course, do not have your web " "server list directory contents. *If you don't know what " "this does, you probably do NOT want to enable it*"), default=False) pdf_image_format = schema.Choice( title=_("Image Format"), default=u"gif", vocabulary=SimpleVocabulary.fromValues([ 'gif', 'png', 'jpg' ])) enable_indexation = schema.Bool( title=_("Make searchable"), description=_("If this is enabled, the text will be extracted from " "the PDF and will be searchable using the search widget and " "with the Plone search. " "If this is disabled, the two following parameters 'OCR' " "and 'Detect text' are not taken into account. Take care " "that this will not make already converted elements searchable/" "not searchable, you will have to convert existing element yourself." ), default=True) ocr = schema.Bool( title=_("OCR"), description=_("Extract the text from the PDF using OCR technology."), default=False) detect_text = schema.Bool( title=_("Detect text"), description=_("Detect if pdf has text before performing OCR on it. " "If text is found, ocr will be skipped. " "If OCR is disabled, text will always try to be " "retrieved from the PDF file anyways."), default=True) auto_select_layout = schema.Bool( title=_("Auto select layout"), description=_("For pdf files."), default=True) auto_layout_file_types = schema.List( title=_("Auto layout file types"), description=_("Extra types only work with " "openoffice/libreoffice installed."), default=['pdf'], value_type=schema.Choice( vocabulary=SimpleVocabulary(FILE_TYPES_VOCAB)) ) auto_convert = schema.Bool( title=_("Auto Convert"), description=_("Automatically convert files on creation " "and modification."), default=True) show_contributor = schema.Bool( title=_("Show contributor"), default=True) override_contributor = schema.TextLine( title=_("Override Contributor"), description=_("What to override the contributor field on viewer with." "Leave blank to use document owner."), default=None, required=False) override_organization = schema.TextLine( title=_("Override Contributor Organization"), description=_("What to override the organization field on viewer with." "Leave blank to use site title."), default=None, required=False) override_base_resource_url = schema.URI( title=_("Override Base Resource URL"), description=_("If you're syncing your storage to another server you " "would like to serve the pdf resources from, please " "specify the base url path."), default=None, required=False) width = schema.Int( title=_("Viewer Width"), description=_("Leave blank to take full width."), default=None, required=False) height = schema.Int( title=_("Viewer Height"), description=_("Default height to use for viewer (only for " "non-fullscreen mode)."), default=700) show_sidebar = schema.Bool( title=_("Show sidebar"), description=_("Default to show sidebar on Document Viewer."), default=True) show_search = schema.Bool( title=_("Show search box"), description=_("On Document Viewer."), default=True) show_search_on_group_view = schema.Bool( title=_("Show search on group view"), description=_("Enable search on group view."), default=True) group_view_batch_size = schema.Int( title=_("Group View Batch Size"), description=_("For folders. Does not apply to topics."), default=20) async_quota_size = schema.Int( title=_("Async Quota Size"), description=_("Number of conversions to run at a time. " "The quota name assigned is `dv`."), default=3)