Add natural key support to the document parsing app.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import logging
|
|||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
@@ -48,3 +49,16 @@ class DocumentPageContentManager(models.Manager):
|
|||||||
action_object=document_version.document,
|
action_object=document_version.document,
|
||||||
target=document_version
|
target=document_version
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class DocumentTypeSettingsManager(models.Manager):
|
||||||
|
def get_by_natural_key(self, document_type_natural_key):
|
||||||
|
DocumentType = apps.get_model(
|
||||||
|
app_label='documents', model_name='DocumentType'
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
document_type = DocumentType.objects.get_by_natural_key(document_type_natural_key)
|
||||||
|
except DocumentType.DoesNotExist:
|
||||||
|
raise self.model.DoesNotExist
|
||||||
|
|
||||||
|
return self.get(document_type__pk=document_type.pk)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
|
|
||||||
from documents.models import DocumentPage, DocumentType, DocumentVersion
|
from documents.models import DocumentPage, DocumentType, DocumentVersion
|
||||||
|
|
||||||
from .managers import DocumentPageContentManager
|
from .managers import DocumentPageContentManager, DocumentTypeSettingsManager
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
@@ -37,6 +37,12 @@ class DocumentTypeSettings(models.Model):
|
|||||||
verbose_name=_('Automatically queue newly created documents for parsing.')
|
verbose_name=_('Automatically queue newly created documents for parsing.')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
objects = DocumentTypeSettingsManager()
|
||||||
|
|
||||||
|
def natural_key(self):
|
||||||
|
return self.document_type.natural_key()
|
||||||
|
natural_key.dependencies = ['documents.DocumentType']
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('Document type settings')
|
verbose_name = _('Document type settings')
|
||||||
verbose_name_plural = _('Document types settings')
|
verbose_name_plural = _('Document types settings')
|
||||||
|
|||||||
Reference in New Issue
Block a user