mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	fixes #125
This commit is contained in:
		| @@ -7,6 +7,7 @@ from django.contrib.admin.models import ADDITION, LogEntry | |||||||
| from django.contrib.auth.models import User | from django.contrib.auth.models import User | ||||||
| from django.contrib.contenttypes.models import ContentType | from django.contrib.contenttypes.models import ContentType | ||||||
| from django.db import models, DatabaseError | from django.db import models, DatabaseError | ||||||
|  | from django.db.models import Q | ||||||
| from django.dispatch import receiver | from django.dispatch import receiver | ||||||
| from django.utils import timezone | from django.utils import timezone | ||||||
| from filelock import FileLock | from filelock import FileLock | ||||||
| @@ -121,10 +122,13 @@ def set_tags(sender, | |||||||
|              classifier=None, |              classifier=None, | ||||||
|              replace=False, |              replace=False, | ||||||
|              **kwargs): |              **kwargs): | ||||||
|  |  | ||||||
|     if replace: |     if replace: | ||||||
|         document.tags.clear() |         document.tags.exclude( | ||||||
|         current_tags = set([]) |             Q(is_inbox_tag=True) | | ||||||
|     else: |             (Q(match="") & ~Q(matching_algorithm=Tag.MATCH_AUTO)) | ||||||
|  |         ).delete() | ||||||
|  |  | ||||||
|     current_tags = set(document.tags.all()) |     current_tags = set(document.tags.all()) | ||||||
|  |  | ||||||
|     matched_tags = matching.match_tags(document.content, classifier) |     matched_tags = matching.match_tags(document.content, classifier) | ||||||
|   | |||||||
| @@ -14,6 +14,11 @@ class TestRetagger(DirectoriesMixin, TestCase): | |||||||
|  |  | ||||||
|         self.tag_first = Tag.objects.create(name="tag1", match="first", matching_algorithm=Tag.MATCH_ANY) |         self.tag_first = Tag.objects.create(name="tag1", match="first", matching_algorithm=Tag.MATCH_ANY) | ||||||
|         self.tag_second = Tag.objects.create(name="tag2", match="second", matching_algorithm=Tag.MATCH_ANY) |         self.tag_second = Tag.objects.create(name="tag2", match="second", matching_algorithm=Tag.MATCH_ANY) | ||||||
|  |         self.tag_inbox = Tag.objects.create(name="test", is_inbox_tag=True) | ||||||
|  |         self.tag_no_match = Tag.objects.create(name="test2") | ||||||
|  |  | ||||||
|  |         self.d3.tags.add(self.tag_inbox) | ||||||
|  |         self.d3.tags.add(self.tag_no_match) | ||||||
|  |  | ||||||
|         self.correspondent_first = Correspondent.objects.create( |         self.correspondent_first = Correspondent.objects.create( | ||||||
|             name="c1", match="first", matching_algorithm=Correspondent.MATCH_ANY) |             name="c1", match="first", matching_algorithm=Correspondent.MATCH_ANY) | ||||||
| @@ -38,7 +43,7 @@ class TestRetagger(DirectoriesMixin, TestCase): | |||||||
|  |  | ||||||
|         self.assertEqual(d_first.tags.count(), 1) |         self.assertEqual(d_first.tags.count(), 1) | ||||||
|         self.assertEqual(d_second.tags.count(), 1) |         self.assertEqual(d_second.tags.count(), 1) | ||||||
|         self.assertEqual(d_unrelated.tags.count(), 0) |         self.assertEqual(d_unrelated.tags.count(), 2) | ||||||
|  |  | ||||||
|         self.assertEqual(d_first.tags.first(), self.tag_first) |         self.assertEqual(d_first.tags.first(), self.tag_first) | ||||||
|         self.assertEqual(d_second.tags.first(), self.tag_second) |         self.assertEqual(d_second.tags.first(), self.tag_second) | ||||||
| @@ -56,3 +61,10 @@ class TestRetagger(DirectoriesMixin, TestCase): | |||||||
|  |  | ||||||
|         self.assertEqual(d_first.correspondent, self.correspondent_first) |         self.assertEqual(d_first.correspondent, self.correspondent_first) | ||||||
|         self.assertEqual(d_second.correspondent, self.correspondent_second) |         self.assertEqual(d_second.correspondent, self.correspondent_second) | ||||||
|  |  | ||||||
|  |     def test_force_preserve_inbox(self): | ||||||
|  |         call_command('document_retagger', '--tags', '--overwrite') | ||||||
|  |  | ||||||
|  |         d_first, d_second, d_unrelated = self.get_updated_docs() | ||||||
|  |  | ||||||
|  |         self.assertCountEqual([tag.id for tag in d_unrelated.tags.all()], [self.tag_inbox.id, self.tag_no_match.id]) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 jonaswinkler
					jonaswinkler