Commits

Luke Plant committed 7b73ef3

Fixed Python 2.3 compatibility issues

  • Participants
  • Parent commits 73c7d92

Comments (0)

Files changed (2)

File django/tagging/models.py

 import django.contrib.contenttypes
 from lukeplant_me_uk.django.tagging import utils
 
+# For Python 2.3
+if not hasattr(__builtins__, 'set'):
+    from sets import Set as set
+
 try:
     _normaliser = settings.TAGGING_NORMALISER
 except AttributeError:
         self.target_id, self.target_ct_id = target_id, target_ct_id
         self.text, self.count = text, count
 
-    @property
     def target(self):
         try:
             return self._target
             target = utils.get_object(self.target_id, self.target_ct_id)
             self._target = target
             return target
+    target = property(target)
 
     def render(self):
         """Renders the target using the registered renderer."""
         return utils.get_renderer(self.target_ct_id)(self.target)
 
-    @property
     def target_ct(self):
         return django.contrib.contenttypes.models.ContentType.objects.get(pk=self.target_ct_id)
+    target = property(target)
         
     # Possible TODO : add a 'creator_list' property that dynamically returns all
     # objects that have tagged the target
         cursor.execute(sql, params)
         return TagSummaryCollection([TagSummary(r[0], r[1]) for r in cursor.fetchall()])
 
-    @staticmethod
     def _normalise_text_textlist(text):
         # Normalise 'text'
         if isinstance(text, basestring):
         textlist = list(set(textlist)) # eliminate dupes
         text = ' '.join(textlist)
         return text, textlist
+    _normalise_text_textlist = staticmethod(_normalise_text_textlist)
 
     def get_targets(self, text, limit=None, offset=None, target_model=None):
         """Returns target items that match the text value, as a sequence
         
         
         """
-        text, textlist = TagManager._normalise_text_textlist(text)
+        text, textlist = self._normalise_text_textlist(text)
         
         # Normalise other vals.
         target, target_model, target_id, target_ct_id = self._normalise_target_info(None, target_model)
         (with no limits), but more efficiently than len(get_targets())"""
         qn = backend.quote_name
         tablename = qn(Tag._meta.db_table)        
-        text, textlist = TagManager._normalise_text_textlist(text)
+        text, textlist = self._normalise_text_textlist(text)
         target, target_model, target_id, target_ct_id = self._normalise_target_info(None, target_model)
         
         tablealias = 0

File django/tagging/views.py

 from lukeplant_me_uk.django.tagging import utils as tagging_utils
 from lukeplant_me_uk.django.tagging.models import Tag
 
+# For Python 2.3
+if not hasattr(__builtins__, 'set'):
+    from sets import Set as set
+
 POPULAR_TAGS_LIMIT = 20
 
 def _get_base_attrs_for_objs(creator, target):
     return retval
 
 def _get_search_attrs(base_attrs):
+    """Turns 'base attributes' dictionary into a dict
+    that can be passed to QuerySet.filter()"""
     return dict([(k.replace('_ct_id', '_ct__id__exact'), v) 
                     for k, v in base_attrs.iteritems()])
 
     search_attrs = _get_search_attrs(base_attrs)
     tags = Tag.objects.filter(**search_attrs)
 
-    # TODO - python 2.3 compat
-    currenttagset = set(tag.text for tag in tags)
+    currenttagset = set([tag.text for tag in tags])
     
     if request.POST.get('save'):
         newtagset = set(request.POST.get('text', '').split())
             
         # Get the new set
         tags = Tag.objects.filter(**search_attrs)
-        currenttagset = set(tag.text for tag in tags)
+        currenttagset = set([tag.text for tag in tags])
     
     # context dict
     c = {}