def sync_db(self): # circular from collective.documentviewer.async import celeryInstalled if celeryInstalled(): from collective.celery.utils import getCelery if not getCelery().conf.task_always_eager: self.context._p_jar.sync()
def sync_db(self): # circular from collective.documentviewer. async import celeryInstalled if celeryInstalled(): from collective.celery.utils import getCelery if not getCelery().conf.task_always_eager: self.context._p_jar.sync()
def convert_all(only_unconverted=True): """Convert all files. Defaults to convert only files, which haven't been converted yet. """ site = getSite() qi = getToolByName(site, 'portal_quickinstaller', None) if not qi: return if not qi.isProductInstalled('collective.documentviewer'): return if getRequest().get('plone.app.contenttypes_migration_running', False): """Don't migrate while running a plone.app.contenttypes migration. """ return cat = getToolByName(site, 'portal_catalog') res = cat(portal_type='File') length = len(res) async_enabled = celeryInstalled() for cnt, item in enumerate(res, 1): logger.info('processing %s/%s', cnt, length) obj = item.getObject() settings = Settings(obj) if only_unconverted and settings.successfully_converted: continue gsettings = GlobalSettings(site) if not allowedDocumentType(obj, gsettings.auto_layout_file_types): continue auto_layout = gsettings.auto_select_layout if auto_layout and obj.getLayout() != 'documentviewer': obj.setLayout('documentviewer') if obj.getLayout() == 'documentviewer' and gsettings.auto_convert: queueJob(obj) if not async_enabled: # conversion lasts an eternity. commit the results immediately. transaction.commit()
def __call__(self): """ - handle queuing - csrf protection - async - queue position """ mtool = getToolByName(self.context, 'portal_membership') self.manager = mtool.checkPermission('cmf.ManagePortal', self.context) self.async_installed = asyncInstalled() or celeryInstalled() self.converting = False if self.enabled(): req = self.request if req.get('REQUEST_METHOD', 'POST') and \ 'form.action.queue' in req.form.keys(): authenticator = getMultiAdapter((self.context, self.request), name=u"authenticator") if not authenticator.verify(): raise Unauthorized settings = Settings(self.context) settings.last_updated = DateTime('1999/01/01').ISO8601() settings.filehash = '--foobar--' queueJob(self.context) self.converting = True return self.request.response.redirect( self.context.absolute_url() + '/view') else: if self.async_installed: self.position = getJobRunner(self.context).find_position() if self.position > -1: self.converting = True return super(Convert, self).__call__() self.request.response.redirect(self.context.absolute_url() + '/view')
def __call__(self): """ - handle queuing - csrf protection - async - queue position """ mtool = getToolByName(self.context, 'portal_membership') self.manager = mtool.checkPermission('cmf.ManagePortal', self.context) self.async_installed = celeryInstalled() self.converting = False if self.enabled(): req = self.request if (req.get('REQUEST_METHOD', 'POST') and 'form.action.queue' in req.form.keys()): authenticator = getMultiAdapter((self.context, self.request), name=u"authenticator") if not authenticator.verify(): raise Unauthorized settings = Settings(self.context) settings.last_updated = DateTime('1999/01/01').ISO8601() settings.filehash = '--foobar--' queueJob(self.context) self.converting = True return self.request.response.redirect( self.context.absolute_url() + '/view') else: if self.async_installed: self.position = getJobRunner(self.context).find_position() if self.position > -1: self.converting = True return super(Convert, self).__call__() self.request.response.redirect(self.context.absolute_url() + '/view')
def async_enabled(self): return asyncInstalled() or celeryInstalled()
def async_enabled(self): return celeryInstalled()