Commits

codekoala  committed e996740

Trying to fix some badness that came about from using signals. Inspecting more fields for auto-tagging.

  • Participants
  • Parent commits 6a4f4c2
  • Tags 2.1.1

Comments (0)

Files changed (6)

 by default (and enable it on a per-article basis), set ``ARTICLES_AUTO_TAG`` to
 ``False`` in your ``settings.py`` file.
 
+Auto-Tagging **does not** attempt to produce any keywords that magically
+represent the content of your articles.  Only **existing** tags are used!!
+
 ===================
 Help & Contributing
 ===================

File articles/__init__.py

-__version__ = '2.1.0'
+__version__ = '2.1.1'
 
 try:
     import listeners

File articles/admin.py

         obj.save()
 
         # this requires an Article object already
-        obj.do_auto_tag()
+        obj.do_auto_tag('default')
         form.cleaned_data['tags'] += list(obj.tags.all())
 
     def queryset(self, request):

File articles/listeners.py

 from django.db.models import signals
 from models import Article, Tag
 
-def article_post_processing(sender, instance, created, **kwargs):
-    """
-    Performs the auto-tagging for certain Articles and other things
-    that require and Article instance first.
-    """
-
-    requires_save = instance.do_auto_tag()
-    requires_save |= instance.do_tags_to_keywords()
-    requires_save |= instance.do_default_site()
-
-    if requires_save:
-        # bypass the other processing
-        super(Article, instance).save()
-
 def apply_new_tag(sender, instance, created, **kwargs):
     """
     Applies new tags to existing articles that are marked for auto-tagging
     """
 
     for article in Article.objects.filter(auto_tag=True):
-        if article.do_auto_tag():
-            # bypass the other processing
-            super(Article, article).save()
+        article.do_auto_tag()
 
-signals.post_save.connect(article_post_processing, sender=Article)
 signals.post_save.connect(apply_new_tag, sender=Tag)

File articles/models.py

 
         super(Article, self).save(*args, **kwargs)
 
+        # do some things that require an ID first
+        requires_save = self.do_auto_tag(using)
+        requires_save |= self.do_tags_to_keywords()
+        requires_save |= self.do_default_site(using)
+
+        if requires_save:
+            # bypass the other processing
+            super(Article, self).save()
+
     def do_render_markup(self):
         """Turns any markup into HTML"""
 
 
         return False
 
-    def do_auto_tag(self, using=None):
+    def do_auto_tag(self, using):
         """
         Performs the auto-tagging work if necessary.
 
             existing_ids = [t.id for t in self.tags.all()]
             unused = Tag.objects.using(using).exclude(id__in=existing_ids)
             for tag in unused:
-                if re.search(r'\b%s\b' % tag.name, self.content, re.I):
+                regex = re.compile(r'\b%s\b' % tag.name, re.I)
+                if regex.search(self.content) or regex.search(self.title) or \
+                   regex.search(self.description) or regex.search(self.keywords):
                     self.tags.add(tag)
                     found = True
 
         return found
 
-    def do_default_site(self, using=None):
+    def do_default_site(self, using):
         """
         If no site was selected, selects the site used to create the article
         as the default site.

File sample/articles_demo/demo.db

Binary file modified.