Exemplo n.º 1
0
def queue_document_conversion(content, event):
    """
    This method queues the document for conversion.
    One job is queued for the jodconverter if required, and for pdfpeek.
    """

    registry = getUtility(IRegistry)
    settings = registry.forInterface(interfaces.IPDFPeekConfiguration)

    if not settings.eventhandler_toggle:
        return

    converter = interfaces.IPDFDataExtractor(content)
    if converter.content_type not in interfaces.ALLOWED_CONVERSION_TYPES:
        queue_image_removal(content)
        return

    # get the queue
    portal = api.portal.get()
    conversion_queue = get_queue('collective.pdfpeek.conversion_' + portal.id)
    # create a converter job
    converter_job = Job(handle_pdf, content)
    # add it to the queue
    conversion_queue.pending.append(converter_job)
    logger.info('Document Conversion Job Queued')
Exemplo n.º 2
0
def queue_document_conversion(content, event):
    """
    This method queues the document for conversion.
    One job is queued for the jodconverter if required, and for pdfpeek.
    """

    registry = getUtility(IRegistry)
    settings = registry.forInterface(interfaces.IPDFPeekConfiguration)

    if not settings.eventhandler_toggle:
        return

    converter = interfaces.IPDFDataExtractor(content)
    if converter.content_type not in interfaces.ALLOWED_CONVERSION_TYPES:
        queue_image_removal(content)
        return

    # get the queue
    portal = content.portal_url.getPortalObject()
    conversion_queue = get_queue('collective.pdfpeek.conversion_' + portal.id)
    # create a converter job
    converter_job = Job(handle_pdf, content)
    # add it to the queue
    conversion_queue.pending.append(converter_job)
    logger.info("Document Conversion Job Queued")
Exemplo n.º 3
0
def queue_image_removal(content):
    """
    Queues the image removal if there is no longer a pdf
    file stored on the object
    """
    portal = getSite()
    conversion_queue = get_queue('collective.pdfpeek.conversion_' + portal.id)
    removal_job = Job(remove_image_previews, content)
    conversion_queue.pending.append(removal_job)
    logger.info("Document Preview Image Removal Job Queued")
Exemplo n.º 4
0
def queue_image_removal(content):
    """
    Queues the image removal if there is no longer a pdf
    file stored on the object
    """
    portal = content.portal_url.getPortalObject()
    conversion_queue = get_queue('collective.pdfpeek.conversion_' + portal.id)
    removal_job = Job(remove_image_previews, content)
    conversion_queue.pending.append(removal_job)
    logger.info("Document Preview Image Removal Job Queued")
Exemplo n.º 5
0
 def _process_conversion_queue(self):
     msg = u''
     num = 0
     queue = get_queue('collective.pdfpeek.conversion_' + self.context.id)
     num = queue.process()
     if num:
         msg += u'%d Jobs in queue. Processing queue...\n' % num
         for job in queue.finished[-1:]:
             msg += job.value + u'\n'
             msg += u'Finished Job'
     if num == 0:
         msg += u'No Jobs in Queue. No Action Required, None Taken.'
     return msg
Exemplo n.º 6
0
 def _process_conversion_queue(self):
     msg = u''
     num = 0
     queue = get_queue('collective.pdfpeek.conversion_' + self.context.id)
     num = queue.process()
     if num:
         msg += u'%d Jobs in queue. Processing queue...\n' % num
         for job in queue.finished[-1:]:
             msg += job.value + u'\n'
             msg += u'Finished Job'
     if num == 0:
         msg += u'No Jobs in Queue. No Action Required, None Taken.'
     return msg
Exemplo n.º 7
0
def queue_document_conversion(content, event):
    """
    This method queues the document for conversion.
    One job is queued for the jodconverter if required, and for pdfpeek.
    """
    portal = getSite()
    if 'collective.pdfpeek' in portal.portal_quickinstaller.objectIds():
        ALLOWED_CONVERSION_TYPES = ['application/pdf']
        # if we have a document in the file field, add the jobs to the queue
        content_type = content.getFile().getContentType()
        if (content_type in ALLOWED_CONVERSION_TYPES):
            # get the queue
            conversion_queue = get_queue('collective.pdfpeek.conversion_' + portal.id)
            # create a converter job
            converter_job = Job(convert_pdf_to_image, content)
            # add it to the queue
            conversion_queue.pending.append(converter_job)
            logger.info("Document Conversion Job Queued")
        else:
            queue_image_removal(content)
Exemplo n.º 8
0
def queue_document_conversion(content, event):
    """
    This method queues the document for conversion.
    One job is queued for the jodconverter if required, and for pdfpeek.
    """
    portal = getSite()
    if "collective.pdfpeek" in portal.portal_quickinstaller.objectIds():
        ALLOWED_CONVERSION_TYPES = ["application/pdf"]
        # if we have a document in the file field, add the jobs to the queue
        content_type = content.getFile().getContentType()
        if content_type in ALLOWED_CONVERSION_TYPES:
            # get the queue
            conversion_queue = get_queue("collective.pdfpeek.conversion_" + portal.id)
            # create a converter job
            converter_job = Job(convert_pdf_to_image, content)
            # add it to the queue
            conversion_queue.pending.append(converter_job)
            logger.info("Document Conversion Job Queued")
        else:
            queue_image_removal(content)