Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
Fixes #45
Browse files Browse the repository at this point in the history
  • Loading branch information
danielquinn committed Feb 17, 2016
1 parent eb01bcf commit 1e7ece8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 1 addition & 5 deletions src/documents/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,7 @@ def get_tags(tags):
def _store(self, text, doc):

sender, title, tags, file_type = self._guess_attributes_from_name(doc)
tags = list(tags)

lower_text = text.lower()
relevant_tags = set(
[t for t in Tag.objects.all() if t.matches(lower_text)] + tags)
relevant_tags = set(list(Tag.match_all(text)) + list(tags))

stats = os.stat(doc)

Expand Down
9 changes: 5 additions & 4 deletions src/documents/management/commands/document_retagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ def handle(self, *args, **options):
self.verbosity = options["verbosity"]

for document in Document.objects.all():

tags = Tag.objects.exclude(
pk__in=document.tags.values_list("pk", flat=True))
for tag in tags:
if tag.matches(document.content):
print('Tagging {} with "{}"'.format(document, tag))
document.tags.add(tag)

for tag in Tag.match_all(document.content, tags):
print('Tagging {} with "{}"'.format(document, tag))
document.tags.add(tag)
12 changes: 12 additions & 0 deletions src/documents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,19 @@ def conditions(self):
return "{}: \"{}\" ({})".format(
self.name, self.match, self.get_matching_algorithm_display())

@classmethod
def match_all(cls, text, tags=None):

if tags is None:
tags = cls.objects.all()

text = text.lower()
for tag in tags:
if tag.matches(text):
yield tag

def matches(self, text):

# Check that match is not empty
if self.match.strip() == "":
return False
Expand Down

0 comments on commit 1e7ece8

Please sign in to comment.