Example #1
0
def process_file(request: SignalRequest, doc_id: int):
    """
    :param request:
    :param doc_id:
    """
    for doc in UploadDoc.objects.filter(id=doc_id):
        doc.delete()
        call('df.messages.info', request, sharing=SESSION, html=_('%(name)s has been deleted') % {'name': doc.name})
        call('updoc.delete_doc_info', request, sharing=SESSION, doc_id=doc_id)
Example #2
0
def process_file(request: SignalRequest, doc_id: int, filename: str, original_filename: str):
    """
    * uncompress file if needed otherwise copy it
    * index its content
    * remove it

    Remove all if an error occurred

    :param request:
    :param doc_id:
    :param filename:
    :param original_filename:
    """
    temp_file = None
    destination_root = None
    doc = None
    # noinspection PyBroadException
    try:
        temp_file = open(filename, 'rb')
        doc = UploadDoc.query(request).get(pk=doc_id)
        destination_root = os.path.join(settings.MEDIA_ROOT, 'docs', doc.uid[0:2], doc.uid)
        process_uploaded_file(doc, temp_file, original_filename=original_filename, destination_root=destination_root)
        call('df.messages.info', request, sharing=SESSION, html=_('%(name)s has been uploaded and indexed') % {'name': doc.name})
    except Exception as e:
        if destination_root and os.path.isdir(destination_root):
            shutil.rmtree(destination_root)
        UploadDoc.query(request).filter(pk=doc_id).delete()
        if doc:
            call('df.messages.error', request, sharing=SESSION, html=_('An error happened during the processing of %(name)s: %(error)s') % {'name': doc.name, 'error': str(e)})
        else:
            call('df.messages.error', request, sharing=SESSION, html=_('Unable to process query'))
    finally:
        if temp_file:
            temp_file.close()
        os.remove(filename)
Example #3
0
    def call(self, window_info, **kwargs):
        from djangofloor.tasks import call, SERVER

        call(window_info, self.path, to=SERVER, kwargs=kwargs)
Example #4
0
def test_celery(request):
    print('celery task done')
    call('df.messages.warning', request, BROADCAST, html='[BROADCAST] This message has been received and sent through Celery and websockets.')
    call('df.messages.error', request, SESSION, html='[SESSION] This message has been received and sent through Celery and websockets.')
    call('df.messages.info', request, USER, html='[USER] This message has been received and sent through Celery and websockets.')
Example #5
0
def test_websocket(request):
    call('df.messages.warning', request, BROADCAST, html='[BROADCAST] This message has been received and sent through websockets.')
    call('df.messages.error', request, SESSION, html='[SESSION] This message has been received and sent through websockets.')
    call('df.messages.info', request, USER, html='[USER] This message has been received and sent through websockets.')
Example #6
0
    def call(self, window_info, **kwargs):
        from djangofloor.tasks import call, SERVER

        call(window_info, self.path, to=SERVER, kwargs=kwargs)
Example #7
0
def ws_call(signal_name, request, sharing, kwargs):
    if isinstance(sharing, bytes):
        sharing = str(sharing)
    to = _sharing_to_topics(request, sharing)
    window_info = WindowInfo.from_request(request)
    call(window_info, signal_name, to=to, kwargs=kwargs)
Example #8
0
def ws_call(signal_name, request, sharing, kwargs):
    if isinstance(sharing, bytes):
        sharing = str(sharing)
    to = _sharing_to_topics(request, sharing)
    window_info = WindowInfo.from_request(request)
    call(window_info, signal_name, to=to, kwargs=kwargs)