示例#1
0
def pre_document_save(**kwargs):
    assert kwargs['sender'] == models.Document

    document = kwargs['instance']
    try:
        old_doc = models.Document.objects.get(pk=document.pk)
    except models.Document.DoesNotExist:
        # New Document => do nothing
        pass
    else:
        if not old_doc.state == document.state:  # State changed
            if document.state == 'DONE':
                Notification.direct(
                    user=document.user,
                    text='Conversion de "{}" terminée'.format(document.name),
                    node=document,
                    url=reverse('document_show', args=[document.id]),
                    icon="check"
                )

                PreNotification.objects.create(
                    node=document,
                    text="Nouveau document : {} dans {}".format(document.name, document.parent.slug),
                    url=reverse('document_show', args=[document.id]),
                    user=document.user,
                    sender_type="Document",
                    icon="page-copy"
                )

        else:  # State not changed => do nothing
            pass
示例#2
0
文件: tasks.py 项目: datogam/Dochub
def on_failure(self, exc, task_id, args, kwargs, einfo):
    if isinstance(exc, SkipException):
        return None

    doc_id = args[0]
    print("Document {} failed.".format(doc_id))

    document = Document.objects.get(id=doc_id)
    document.state = "ERROR"
    document.save()

    # Notify the uploader
    Notification.direct(
        user=document.user,
        text="Une erreur c'est produite pendant la conversion de : {}".format(
            document.name),
        node=document.parent,
        url=reverse('node_canonic', args=[document.parent.id]),
        icon="x",
    )

    # Warn the admins
    DocumentError.objects.create(
        document=document,
        task_id=task_id,
        exception=exc,
        traceback=einfo.traceback,
    )
示例#3
0
文件: signals.py 项目: datogam/Dochub
def pre_document_save(**kwargs):
    assert kwargs['sender'] == models.Document

    document = kwargs['instance']
    try:
        old_doc = models.Document.objects.get(pk=document.pk)
    except models.Document.DoesNotExist:
        # New Document => do nothing
        pass
    else:
        if not old_doc.state == document.state:  # State changed
            if document.state == 'DONE':
                Notification.direct(user=document.user,
                                    text='Conversion de "{}" terminée'.format(
                                        document.name),
                                    node=document,
                                    url=reverse('document_show',
                                                args=[document.id]),
                                    icon="check")

                PreNotification.objects.create(
                    node=document,
                    text="Nouveau document : {} dans {}".format(
                        document.name, document.parent.slug),
                    url=reverse('document_show', args=[document.id]),
                    user=document.user,
                    sender_type="Document",
                    icon="page-copy")

        else:  # State not changed => do nothing
            pass
示例#4
0
文件: tasks.py 项目: datogam/Dochub
def checksum(self, document_id):
    document = Document.objects.get(pk=document_id)

    contents = document.original.read()

    hashed = hashlib.md5(contents).hexdigest()
    query = Document.objects.filter(md5=hashed).exclude(md5='')
    if query.count() != 0:
        dup = query.first()
        Notification.direct(
            user=document.user,
            text=
            'Votre document "{}" a été refusé car c\'est une copie conforme de {}'
            .format(document.name, dup.name),
            node=document.parent,
            url=reverse('node_canonic', args=[dup.id]),
            icon="x",
        )
        did = document.id
        document.delete()
        raise ExisingChecksum("Document {} has the same checksum as {}".format(
            did, dup.id))
    else:
        document.md5 = hashed
        document.save()

    return document_id
示例#5
0
文件: tasks.py 项目: blackboat/Dochub
def on_failure(self, exc, task_id, args, kwargs, einfo):
    if isinstance(exc, SkipException):
        return None

    doc_id = args[0]
    print("Document {} failed.".format(doc_id))

    document = Document.objects.get(id=doc_id)
    document.state = "ERROR"
    document.save()

    # Notify the uploader
    Notification.direct(
        user=document.user,
        text="Une erreur c'est produite pendant la conversion de : {}".format(document.name),
        node=document.parent,
        url=reverse('node_canonic', args=[document.parent.id]),
        icon="x",
    )

    # Warn the admins
    DocumentError.objects.create(
        document=document,
        task_id=task_id,
        exception=exc,
        traceback=einfo.traceback,
    )
示例#6
0
def document_delete(**kwargs):
    assert kwargs['sender'] == models.Document

    document = kwargs['instance']
    if document.e:
        Notification.direct(
            user=document.user.user,
            text="Error when processing document: "+str(document.e),
            node=document.parent,
            url=reverse('node_canonic',args=[nodeid]),
        )
示例#7
0
def pending_document_save(**kwargs):
    assert kwargs['sender'] == models.PendingDocument

    pending = kwargs['instance']
    if pending.state == 'done':
        # Send notification to the uploader
        Notification.direct(
            user=pending.document.user.user,
            text="Finished processing document "+pending.document.name,
            node=pending.document,
            url=reverse('document_show', args=[pending.document.id])
        )

        PreNotification.objects.create(
            node=pending.document,
            text="Nouveau document: "+pending.document.name,
            url=reverse('document_show', args=[pending.document.id]),
            user=pending.document.user.user
        )
示例#8
0
文件: tasks.py 项目: blackboat/Dochub
def checksum(self, document_id):
    document = Document.objects.get(pk=document_id)

    contents = document.original.read()

    hashed = hashlib.md5(contents).hexdigest()
    query = Document.objects.filter(md5=hashed).exclude(md5='')
    if query.count() != 0:
        dup = query.first()
        Notification.direct(
            user=document.user,
            text='Votre document "{}" a été refusé car c\'est une copie conforme de {}'.format(document.name, dup.name),
            node=document.parent,
            url=reverse('node_canonic', args=[dup.id]),
            icon="x",
        )
        did = document.id
        document.delete()
        raise ExisingChecksum("Document {} has the same checksum as {}".format(did, dup.id))
    else:
        document.md5 = hashed
        document.save()

    return document_id