mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-14 00:26:21 +00:00
Removed log components and introduced signals for tags & correspondents
This commit is contained in:
@@ -15,50 +15,7 @@ from django.utils import timezone
|
||||
from .managers import LogManager
|
||||
|
||||
|
||||
class SluggedModel(models.Model):
|
||||
|
||||
name = models.CharField(max_length=128, unique=True)
|
||||
slug = models.SlugField(blank=True)
|
||||
|
||||
class Meta(object):
|
||||
abstract = True
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.slug:
|
||||
self.slug = slugify(self.name)
|
||||
models.Model.save(self, *args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Correspondent(SluggedModel):
|
||||
|
||||
# This regex is probably more restrictive than it needs to be, but it's
|
||||
# better safe than sorry.
|
||||
SAFE_REGEX = re.compile(r"^[\w\- ,.']+$")
|
||||
|
||||
class Meta(object):
|
||||
ordering = ("name",)
|
||||
|
||||
|
||||
class Tag(SluggedModel):
|
||||
|
||||
COLOURS = (
|
||||
(1, "#a6cee3"),
|
||||
(2, "#1f78b4"),
|
||||
(3, "#b2df8a"),
|
||||
(4, "#33a02c"),
|
||||
(5, "#fb9a99"),
|
||||
(6, "#e31a1c"),
|
||||
(7, "#fdbf6f"),
|
||||
(8, "#ff7f00"),
|
||||
(9, "#cab2d6"),
|
||||
(10, "#6a3d9a"),
|
||||
(11, "#b15928"),
|
||||
(12, "#000000"),
|
||||
(13, "#cccccc")
|
||||
)
|
||||
class MatchingModel(models.Model):
|
||||
|
||||
MATCH_ANY = 1
|
||||
MATCH_ALL = 2
|
||||
@@ -71,7 +28,9 @@ class Tag(SluggedModel):
|
||||
(MATCH_REGEX, "Regular Expression"),
|
||||
)
|
||||
|
||||
colour = models.PositiveIntegerField(choices=COLOURS, default=1)
|
||||
name = models.CharField(max_length=128, unique=True)
|
||||
slug = models.SlugField(blank=True)
|
||||
|
||||
match = models.CharField(max_length=256, blank=True)
|
||||
matching_algorithm = models.PositiveIntegerField(
|
||||
choices=MATCHING_ALGORITHMS,
|
||||
@@ -88,6 +47,12 @@ class Tag(SluggedModel):
|
||||
)
|
||||
)
|
||||
|
||||
class Meta(object):
|
||||
abstract = True
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@property
|
||||
def conditions(self):
|
||||
return "{}: \"{}\" ({})".format(
|
||||
@@ -131,8 +96,44 @@ class Tag(SluggedModel):
|
||||
raise NotImplementedError("Unsupported matching algorithm")
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
||||
self.match = self.match.lower()
|
||||
SluggedModel.save(self, *args, **kwargs)
|
||||
|
||||
if not self.slug:
|
||||
self.slug = slugify(self.name)
|
||||
|
||||
models.Model.save(self, *args, **kwargs)
|
||||
|
||||
|
||||
class Correspondent(MatchingModel):
|
||||
|
||||
# This regex is probably more restrictive than it needs to be, but it's
|
||||
# better safe than sorry.
|
||||
SAFE_REGEX = re.compile(r"^[\w\- ,.']+$")
|
||||
|
||||
class Meta(object):
|
||||
ordering = ("name",)
|
||||
|
||||
|
||||
class Tag(MatchingModel):
|
||||
|
||||
COLOURS = (
|
||||
(1, "#a6cee3"),
|
||||
(2, "#1f78b4"),
|
||||
(3, "#b2df8a"),
|
||||
(4, "#33a02c"),
|
||||
(5, "#fb9a99"),
|
||||
(6, "#e31a1c"),
|
||||
(7, "#fdbf6f"),
|
||||
(8, "#ff7f00"),
|
||||
(9, "#cab2d6"),
|
||||
(10, "#6a3d9a"),
|
||||
(11, "#b15928"),
|
||||
(12, "#000000"),
|
||||
(13, "#cccccc")
|
||||
)
|
||||
|
||||
colour = models.PositiveIntegerField(choices=COLOURS, default=1)
|
||||
|
||||
|
||||
class Document(models.Model):
|
||||
@@ -219,17 +220,9 @@ class Log(models.Model):
|
||||
(logging.CRITICAL, "Critical"),
|
||||
)
|
||||
|
||||
COMPONENT_CONSUMER = 1
|
||||
COMPONENT_MAIL = 2
|
||||
COMPONENTS = (
|
||||
(COMPONENT_CONSUMER, "Consumer"),
|
||||
(COMPONENT_MAIL, "Mail Fetcher")
|
||||
)
|
||||
|
||||
group = models.UUIDField(blank=True)
|
||||
message = models.TextField()
|
||||
level = models.PositiveIntegerField(choices=LEVELS, default=logging.INFO)
|
||||
component = models.PositiveIntegerField(choices=COMPONENTS)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
|
Reference in New Issue
Block a user