1. Gustavo Picon
  2. django-taggable

Commits

Gustavo Picon  committed ae2e815

style/docs

  • Participants
  • Parent commits dfe998c
  • Branches default

Comments (0)

Files changed (5)

File taggable/__init__.py

View file
+"django-taggable"
+
 from taggable import signals
 
 __version__ = '0.01'

File taggable/managers.py

View file
 
 
 class TaggedManager(models.Manager):
-    """ Manager for the Tagged abstract class.
-    """
+    "Manager for the Tagged abstract class. Subclass if needed."
 
     def _kwargs(self):
+        "Returns **kwargs to be used by the get query set methods"
         try:
             # django 1.2+
             return {'using': self._db}
             return {}
 
     def get_empty_query_set(self):
-        """ TODO: docstring
-        """
         return EmptyTaggedQuerySet(self.model, **self._kwargs())
 
     def get_query_set(self):
-        """ TODO: docstring
-        """
         return TaggedQuerySet(self.model, **self._kwargs())

File taggable/models.py

View file
 
 from django.db import models
 from taggable.managers import TaggedManager
-from taggable.querysets import _queryset_filter_with_counts
+from taggable.querysets import queryset_filter_with_counts
 from taggable.exceptions import InvalidFields
 
 
 class Tagged(models.Model):
-    """ TODO: Tagged abstract class.
-    """
-
     objects = TaggedManager()
 
     def taggable_get_fields(self, fields):
-        """ TODO: taggable_get_fields docstring.
-        """
         results = []
         for field in fields:
             val = self.__getattribute__(field)
         return results
 
     def save(self, *args, **kwargs):
-        """ Saves the tagged object and handles the stats table maintenance.
-        """
+        "Saves the tagged object and handles the stats table maintenance."
         super(Tagged, self).save(*args, **kwargs)
 
         for fields, statsmodel in self.taggable_stats.items():
 
     @classmethod
     def tag_count(cls, **fields):
-        """ TODO: tag_count docstring
-        """
         key = tuple(sorted(fields.keys()))
         if key in cls.taggable_stats:
             model = cls.taggable_stats[key]
 
     @classmethod
     def _check_fields(cls, allfields=False, includetag=False, **fields):
-        """ TODO: _check_fields docstring
-        """
         keys_set = set(fields.keys())
         if includetag:
             tagged_fields = cls.taggable_taggedfields
 
     @classmethod
     def add_tag(cls, tag, **fields):
-        """ TODO: add_tag docstring
-        """
         cls._check_fields(allfields=True, includetag=False, **fields)
         fields['tag'] = tag
         try:
 
     @classmethod
     def update_tags(cls, tags, **fields):
-        """ TODO: update_tags docstring
-        """
         cls._check_fields(allfields=True, includetag=False, **fields)
         if not tags:
             tags = []
 
     @classmethod
     def get_tags(cls, counts=False, qfilter=None, **fields):
-        """ TODO: update_tags docstring
-        """
         return cls.get_tagged_fields(fieldname='tag',
                                      counts=counts,
                                      qfilter=qfilter,
     @classmethod
     def get_tagged_fields(cls, fieldname, counts=False, qfilter=None,
                           **fields):
-        """ TODO: get_tagged_fields docstring
-        """
         cls._check_fields(allfields=False, includetag=True, **fields)
         if cls.taggable_sorted_stats:
             model = cls._meta.get_field_by_name(fieldname)[0].rel.to
                     qset = qset.values(*tagfields + ['count'])
                 else:
                     qset = qset.values(*tagfields).distinct()
-                return _queryset_filter_with_counts(qset, fieldname,
+                return queryset_filter_with_counts(qset, fieldname,
                                                     qfilter, model, counts)
         # no usable stats table
         # we fall back to queryset.get_tagged_fields()
             counts=counts, qfilter=qfilter)
 
     class Meta:
-        """
-        Abstract model.
-        """
+        "Abstract model."
         abstract = True
 
     class Taggable:
-        """ TODO: Taggable subclass docstring
-        """
         pass

File taggable/querysets.py

View file
 from django.db import models
 
 
-def _fieldname2model(queryset, fieldname):
+def fieldname_to_model(queryset, fieldname):
     return queryset.model._meta.get_field_by_name(fieldname)[0].rel.to
 
 
-def _queryset_filter_with_counts(qset, fieldname, qfilter, model, counts):
+def queryset_filter_with_counts(qset, fieldname, qfilter, model, counts):
     if qfilter is not None:
         qset = qfilter(qset)
     for tagdata in qset:
 
 
 class TaggedQuerySet(models.query.QuerySet):
-    """ Queryset for the Tagged abstract class.
-    """
+    "Queryset for the Tagged abstract class."
 
     def delete(self):
-        """ Removes a set of tagged objects and updates the stats tables.
-        """
-
+        "Removes a set of tagged objects and updates the stats tables."
         for tagged in self:
             for fields, statsmodel in tagged.taggable_stats.items():
                 qdict = dict(tagged.taggable_get_fields(fields))
                     count__lte=1).delete()
                 statsmodel.objects.filter(**qdict).filter(
                     count__gte=2).update(count=models.F('count') - 1)
-
         super(TaggedQuerySet, self).delete()
 
     def get_tags(self, counts=False, qfilter=None):
-        """ TODO: get_tags docstring
-        """
         return self.get_tagged_fields(fieldname='tag',
                                       counts=counts,
                                       qfilter=qfilter)
 
     def get_tagged_fields(self, fieldname, counts=False, qfilter=None):
-        """ TODO: get_tagged_fields docstring
-        """
-        model = _fieldname2model(self, fieldname)
+        model = fieldname_to_model(self, fieldname)
         tagfields = ['%s__%s' % (fieldname, t) for t in
                      model.taggable_fields]
         qset = self.select_related(fieldname).values(*tagfields)
             qset = qset.annotate(count=models.Count('%s__id' % fieldname))
         else:
             qset = qset.distinct()
-        return _queryset_filter_with_counts(qset, fieldname, qfilter,
+        return queryset_filter_with_counts(qset, fieldname, qfilter,
                                             model, counts)
 
     def get_tagged_related(self, fieldname):
-        """ TODO: get_tagged_related docstring
-        """
-        return _fieldname2model(self, fieldname).objects.filter(
+        return fieldname_to_model(self, fieldname).objects.filter(
             id__in=self.values('%s__id' % fieldname).distinct())
 
 
                                       qfilter=qfilter)
 
     def get_tagged_fields(self, fieldname, counts=False, qfilter=None):
-        return _fieldname2model(self, fieldname).objects.none()
+        return fieldname_to_model(self, fieldname).objects.none()
 
     def get_tagged_related(self, fieldname):
-        return _fieldname2model(self, fieldname).objects.none()
+        return fieldname_to_model(self, fieldname).objects.none()

File taggable/signals.py

View file
     """ Removes all related tagged stats objects
 
     Called when a tagged/tag object is delete()d
-
     """
     try:
-        # we assume that if we have a this property, we're fine
+        # we assume that if we have this property, we're fine
         instance.taggable_on_delete
     except AttributeError:
         # this is not an object associated to a Tagged model
 
 
 def _handler_tagged_subclass(signal, sender, **named):
-    """ Handler for the class_prepared signal.
-    """
+    "Handler for the class_prepared signal."
+
     from taggable.models import Tagged
 
     if not issubclass(sender, Tagged):
 
 
 def register():
-    """Internal function to register all known signals
-    """
+    "Internal function to register all known signals"
     models.signals.class_prepared.connect(_handler_tagged_subclass)
     models.signals.pre_delete.connect(_handler_obj_delete)