replaced usages of .id with .pk, fixed filename issue in exporter

This commit is contained in:
Jonas Winkler 2020-11-03 12:37:37 +01:00
parent dc59e0f257
commit 68df1cf4ee
5 changed files with 15 additions and 13 deletions

View File

@ -75,16 +75,16 @@ class DocumentClassifier(object):
y = -1 y = -1
if doc.document_type: if doc.document_type:
if doc.document_type.matching_algorithm == MatchingModel.MATCH_AUTO: if doc.document_type.matching_algorithm == MatchingModel.MATCH_AUTO:
y = doc.document_type.id y = doc.document_type.pk
labels_document_type.append(y) labels_document_type.append(y)
y = -1 y = -1
if doc.correspondent: if doc.correspondent:
if doc.correspondent.matching_algorithm == MatchingModel.MATCH_AUTO: if doc.correspondent.matching_algorithm == MatchingModel.MATCH_AUTO:
y = doc.correspondent.id y = doc.correspondent.pk
labels_correspondent.append(y) labels_correspondent.append(y)
tags = [tag.id for tag in doc.tags.filter( tags = [tag.pk for tag in doc.tags.filter(
matching_algorithm=MatchingModel.MATCH_AUTO matching_algorithm=MatchingModel.MATCH_AUTO
)] )]
labels_tags.append(tags) labels_tags.append(tags)

View File

@ -69,7 +69,7 @@ def open_index(recreate=False):
def update_document(writer, doc): def update_document(writer, doc):
logging.getLogger(__name__).debug("Updating index with document{}".format(str(doc))) logging.getLogger(__name__).debug("Updating index with document{}".format(str(doc)))
writer.update_document( writer.update_document(
id=doc.id, id=doc.pk,
title=doc.title, title=doc.title,
content=doc.content content=doc.content
) )
@ -87,7 +87,7 @@ def remove_document_from_index(sender, instance, **kwargs):
logging.getLogger(__name__).debug("Removing document {} from index".format(str(instance))) logging.getLogger(__name__).debug("Removing document {} from index".format(str(instance)))
ix = open_index() ix = open_index()
with AsyncWriter(ix) as writer: with AsyncWriter(ix) as writer:
writer.delete_by_term('id', instance.id) writer.delete_by_term('id', instance.pk)
def autocomplete(ix, term, limit=10): def autocomplete(ix, term, limit=10):

View File

@ -64,12 +64,14 @@ class Command(Renderable, BaseCommand):
document = document_map[document_dict["pk"]] document = document_map[document_dict["pk"]]
file_target = os.path.join(self.target, document.file_name) unique_filename = "{:07}_{}".format(document.pk, document.file_name)
thumbnail_name = document.file_name + "-thumbnail.png" file_target = os.path.join(self.target, unique_filename)
thumbnail_name = unique_filename + "-thumbnail.png"
thumbnail_target = os.path.join(self.target, thumbnail_name) thumbnail_target = os.path.join(self.target, thumbnail_name)
document_dict[EXPORTER_FILE_NAME] = document.file_name document_dict[EXPORTER_FILE_NAME] = unique_filename
document_dict[EXPORTER_THUMBNAIL_NAME] = thumbnail_name document_dict[EXPORTER_THUMBNAIL_NAME] = thumbnail_name
print("Exporting: {}".format(file_target)) print("Exporting: {}".format(file_target))

View File

@ -9,7 +9,7 @@ def match_correspondents(document_content, classifier):
correspondents = Correspondent.objects.all() correspondents = Correspondent.objects.all()
predicted_correspondent_id = classifier.predict_correspondent(document_content) if classifier else None predicted_correspondent_id = classifier.predict_correspondent(document_content) if classifier else None
matched_correspondents = [o for o in correspondents if matches(o, document_content) or o.id == predicted_correspondent_id] matched_correspondents = [o for o in correspondents if matches(o, document_content) or o.pk == predicted_correspondent_id]
return matched_correspondents return matched_correspondents
@ -17,7 +17,7 @@ def match_document_types(document_content, classifier):
document_types = DocumentType.objects.all() document_types = DocumentType.objects.all()
predicted_document_type_id = classifier.predict_document_type(document_content) if classifier else None predicted_document_type_id = classifier.predict_document_type(document_content) if classifier else None
matched_document_types = [o for o in document_types if matches(o, document_content) or o.id == predicted_document_type_id] matched_document_types = [o for o in document_types if matches(o, document_content) or o.pk == predicted_document_type_id]
return matched_document_types return matched_document_types
@ -25,7 +25,7 @@ def match_tags(document_content, classifier):
objects = Tag.objects.all() objects = Tag.objects.all()
predicted_tag_ids = classifier.predict_tags(document_content) if classifier else [] predicted_tag_ids = classifier.predict_tags(document_content) if classifier else []
matched_tags = [o for o in objects if matches(o, document_content) or o.id in predicted_tag_ids] matched_tags = [o for o in objects if matches(o, document_content) or o.pk in predicted_tag_ids]
return matched_tags return matched_tags

View File

@ -134,7 +134,7 @@ def run_post_consume_script(sender, document, **kwargs):
Popen(( Popen((
settings.POST_CONSUME_SCRIPT, settings.POST_CONSUME_SCRIPT,
str(document.id), str(document.pk),
document.file_name, document.file_name,
document.source_path, document.source_path,
document.thumbnail_path, document.thumbnail_path,
@ -166,7 +166,7 @@ def set_log_entry(sender, document=None, logging_group=None, **kwargs):
action_flag=ADDITION, action_flag=ADDITION,
action_time=timezone.now(), action_time=timezone.now(),
content_type=ct, content_type=ct,
object_id=document.id, object_id=document.pk,
user=user, user=user,
object_repr=document.__str__(), object_repr=document.__str__(),
) )