Add LogEntry after document consumption

See #319
This commit is contained in:
CkuT 2018-03-11 17:09:43 +01:00
parent 93bed91937
commit 45e18d7094
2 changed files with 21 additions and 1 deletions

View File

@ -15,13 +15,15 @@ class DocumentsConfig(AppConfig):
set_tags, set_tags,
run_pre_consume_script, run_pre_consume_script,
run_post_consume_script, run_post_consume_script,
cleanup_document_deletion cleanup_document_deletion,
set_log_entry
) )
document_consumption_started.connect(run_pre_consume_script) document_consumption_started.connect(run_pre_consume_script)
document_consumption_finished.connect(set_tags) document_consumption_finished.connect(set_tags)
document_consumption_finished.connect(set_correspondent) document_consumption_finished.connect(set_correspondent)
document_consumption_finished.connect(set_log_entry)
document_consumption_finished.connect(run_post_consume_script) document_consumption_finished.connect(run_post_consume_script)
post_delete.connect(cleanup_document_deletion) post_delete.connect(cleanup_document_deletion)

View File

@ -3,6 +3,9 @@ import os
from subprocess import Popen from subprocess import Popen
from django.conf import settings from django.conf import settings
from django.contrib.admin.models import LogEntry, ADDITION
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
from ..models import Correspondent, Document, Tag from ..models import Correspondent, Document, Tag
@ -93,3 +96,18 @@ def cleanup_document_deletion(sender, instance, using, **kwargs):
os.unlink(f) os.unlink(f)
except FileNotFoundError: except FileNotFoundError:
pass # The file's already gone, so we're cool with it. pass # The file's already gone, so we're cool with it.
def set_log_entry(sender, document=None, logging_group=None, **kwargs):
ct = ContentType.objects.get(model="document")
user = User.objects.first()
LogEntry.objects.create(
action_flag=ADDITION,
action_time=document.created,
content_type=ct,
object_id=document.id,
user=user,
object_repr=document.__str__(),
)