Commits

Virgil Dupras committed ae79151

Added support for Python 3 (3.3+)

Now that the last dependency to not support py3 (django-pagination) has been
converted, it's possible to also convert djangobb, which this commit does.

I've tried basic forum functions but I might have missed something.

  • Participants
  • Parent commits 39ad424

Comments (0)

Files changed (6)

djangobb_forum/fields.py

 Details about AutoOneToOneField:
     http://softwaremaniacs.org/blog/2007/03/07/auto-one-to-one-field/
 """
+from django.utils import six
 try:
     from cStringIO import StringIO
 except ImportError:
-    from StringIO import StringIO
+    StringIO = six.StringIO
 import random
 from hashlib import sha1
 import json
         return string.getvalue()
 
 
-class JSONField(models.TextField):
+class JSONField(six.with_metaclass(models.SubfieldBase, models.TextField)):
     """
     JSONField is a generic textfield that neatly serializes/unserializes
     JSON objects seamlessly.
             return None
 
         try:
-            if isinstance(value, basestring):
+            if isinstance(value, six.string_types):
                 return json.loads(value)
         except ValueError:
             pass

djangobb_forum/subscription.py

+from __future__ import print_function
+
 from django.core.mail import EmailMultiAlternatives
 from django.conf import settings
 from django.core.urlresolvers import reverse
         if html:
             msg.attach_alternative(html, "text/html")
         if forum_settings.EMAIL_DEBUG:
-            print '---begin---'
-            print 'To:', rec_list
-            print 'Subject:', subject
-            print 'Body:', text
-            print '---end---'
+            print('---begin---')
+            print('To:', rec_list)
+            print('Subject:', subject)
+            print('Body:', text)
+            print('---end---')
         else:
             msg.send(fail_silently=True)
 

djangobb_forum/templatetags/forum_extras.py

 # -*- coding: utf-8
-import urllib
 import hashlib
 
 from django import template
 from django.core.urlresolvers import reverse
 from django.core.cache import cache
 from django.utils.safestring import mark_safe
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
 from django.conf import settings
 from django.utils.html import escape
 from django.utils import timezone
 from django.contrib.humanize.templatetags.humanize import naturalday
+from django.utils.six.moves.urllib.parse import urlencode
 
 from linaro_django_pagination.templatetags.pagination_tags import paginate
 
     """
 
     url = hasattr(object, 'get_absolute_url') and object.get_absolute_url() or None
-    anchor = anchor or smart_unicode(object)
+    anchor = anchor or smart_text(object)
     return mark_safe('<a href="%s">%s</a>' % (url, escape(anchor)))
 
 
     """
 
     url = hasattr(object, 'get_absolute_url') and object.get_absolute_url() or None
-    anchor = anchor or smart_unicode(object)
+    anchor = anchor or smart_text(object)
     return mark_safe('<a href="%slofi/">%s</a>' % (url, escape(anchor)))
 
 
         size = max(forum_settings.AVATAR_WIDTH, forum_settings.AVATAR_HEIGHT)
         url = 'https://secure.gravatar.com/avatar/%s?' if is_secure \
             else 'http://www.gravatar.com/avatar/%s?'
-        url = url % hashlib.md5(email.lower()).hexdigest()
-        url += urllib.urlencode({
+        url = url % hashlib.md5(email.lower().encode('ascii')).hexdigest()
+        url += urlencode({
             'size': size,
             'default': forum_settings.GRAVATAR_DEFAULT,
         })

djangobb_forum/util.py

 # coding: utf-8
 
 import re
-from HTMLParser import HTMLParser, HTMLParseError
+from django.utils.six.moves import html_parser
+HTMLParser = html_parser.HTMLParser
+HTMLParseError = html_parser.HTMLParseError
 from postmarkup import render_bbcode
 from json import JSONEncoder
 try:
 from django.http import HttpResponse, Http404
 from django.utils.functional import Promise
 from django.utils.translation import check_for_language
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
 from django.template.defaultfilters import urlize as django_urlize
 from django.core.paginator import Paginator, EmptyPage, InvalidPage
 from django.contrib.sites.models import Site
 
     def default(self, o):
         if isinstance(o, Promise):
-            return force_unicode(o)
+            return force_text(o)
         else:
             return super(LazyJSONEncoder, self).default(o)
 

djangobb_forum/views.py

         cat['forums'].append(forum)
         forums[forum.id] = forum
 
-    cmpdef = lambda a, b: cmp(a['cat'].position, b['cat'].position)
-    cats = sorted(cats.values(), cmpdef)
+    cmpkey = lambda x: x['cat'].position
+    cats = sorted(cats.values(), key=cmpkey)
 
     to_return = {'cats': cats,
                 'posts': Post.objects.count(),

extras/requirements.txt

 south
 pygments
 postmarkup
-linaro-django-pagination
+# As soon as a release after v2.0.2 is made, we can revert to a normal PyPI requirement
+# Python 3 support is brand new in this package
+-e git://github.com/zyga/django-pagination.git#egg=linaro-django-pagination
 pytz>=2013b