# HG changeset patch # User neko259 # Date 2014-08-07 09:55:20 # Node ID bb8477db7585d87b1699ff113d078f6e1644ef5d # Parent 76d8a0b614d3a17df681d64234be7d3144227581 Moving neboard to python3 support (no python2 for now until we figure out how to make them both work) diff --git a/boards/forms.py b/boards/forms.py --- a/boards/forms.py +++ b/boards/forms.py @@ -2,7 +2,6 @@ import re import time import hashlib -from captcha.fields import CaptchaField from django import forms from django.forms.util import ErrorList from django.utils.translation import ugettext_lazy as _ @@ -32,7 +31,7 @@ LABEL_SEARCH = _('Search') TAG_MAX_LENGTH = 20 -REGEX_TAG = ur'^[\w\d]+$' +REGEX_TAG = r'^[\w\d]+$' class FormatPanel(forms.Textarea): @@ -208,7 +207,7 @@ class PostForm(NeboardForm): class ThreadForm(PostForm): - regex_tags = re.compile(ur'^[\w\s\d]+$', re.UNICODE) + regex_tags = re.compile(r'^[\w\s\d]+$', re.UNICODE) tags = forms.CharField( widget=forms.TextInput(attrs={ATTRIBUTE_PLACEHOLDER: TAGS_PLACEHOLDER}), @@ -229,48 +228,6 @@ class ThreadForm(PostForm): return cleaned_data -class PostCaptchaForm(PostForm): - captcha = CaptchaField() - - def __init__(self, *args, **kwargs): - self.request = kwargs['request'] - del kwargs['request'] - - super(PostCaptchaForm, self).__init__(*args, **kwargs) - - def clean(self): - cleaned_data = super(PostCaptchaForm, self).clean() - - success = self.is_valid() - utils.update_captcha_access(self.request, success) - - if success: - return cleaned_data - else: - raise forms.ValidationError(_("Captcha validation failed")) - - -class ThreadCaptchaForm(ThreadForm): - captcha = CaptchaField() - - def __init__(self, *args, **kwargs): - self.request = kwargs['request'] - del kwargs['request'] - - super(ThreadCaptchaForm, self).__init__(*args, **kwargs) - - def clean(self): - cleaned_data = super(ThreadCaptchaForm, self).clean() - - success = self.is_valid() - utils.update_captcha_access(self.request, success) - - if success: - return cleaned_data - else: - raise forms.ValidationError(_("Captcha validation failed")) - - class SettingsForm(NeboardForm): theme = forms.ChoiceField(choices=settings.THEMES, diff --git a/boards/migrations/0015_post_to_thread.py b/boards/migrations/0015_post_to_thread.py --- a/boards/migrations/0015_post_to_thread.py +++ b/boards/migrations/0015_post_to_thread.py @@ -17,7 +17,7 @@ class Migration(DataMigration): thread.replies.add(post) post.thread_new = thread post.save() - print str(post.thread_new.id) + print(str(post.thread_new.id)) for reply in post.replies.all(): thread.replies.add(reply) diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -36,7 +36,7 @@ NO_IP = '0.0.0.0' # TODO Real user agent should be saved instead of this UNKNOWN_UA = '' -REGEX_REPLY = re.compile(ur'\[post\](\d+)\[/post\]') +REGEX_REPLY = re.compile(r'\[post\](\d+)\[/post\]') logger = logging.getLogger(__name__) diff --git a/boards/tests.py b/boards/tests.py --- a/boards/tests.py +++ b/boards/tests.py @@ -248,7 +248,7 @@ class ViewTest(TestCase): except NoReverseMatch: # This view just needs additional arguments pass - except Exception, e: + except Exception as e: self.fail('Got exception %s at %s view' % (e, view_name)) except AttributeError: # This is normal, some views do not have names diff --git a/boards/thumbs.py b/boards/thumbs.py --- a/boards/thumbs.py +++ b/boards/thumbs.py @@ -8,7 +8,7 @@ from django.db.models import ImageField from django.db.models.fields.files import ImageFieldFile from PIL import Image from django.core.files.base import ContentFile -import cStringIO +import io def generate_thumb(img, thumb_size, format): @@ -51,13 +51,13 @@ def generate_thumb(img, thumb_size, form image2 = image image2.thumbnail(thumb_size, Image.ANTIALIAS) - io = cStringIO.StringIO() + string_io = io.StringIO() # PNG and GIF are the same, JPG is JPEG if format.upper() == 'JPG': format = 'JPEG' - image2.save(io, format) - return ContentFile(io.getvalue()) + image2.save(string_io, format) + return ContentFile(string_io.getvalue()) class ImageWithThumbsFieldFile(ImageFieldFile): diff --git a/boards/urls.py b/boards/urls.py --- a/boards/urls.py +++ b/boards/urls.py @@ -45,7 +45,6 @@ urlpatterns = patterns('', url(r'^settings/$', settings.SettingsView.as_view(), name='settings'), url(r'^tags/$', all_tags.AllTagsView.as_view(), name='tags'), - url(r'^captcha/', include('captcha.urls')), url(r'^authors/$', AuthorsView.as_view(), name='authors'), url(r'^delete/(?P\w+)/$', DeletePostView.as_view(), name='delete'), diff --git a/boards/utils.py b/boards/utils.py --- a/boards/utils.py +++ b/boards/utils.py @@ -39,8 +39,6 @@ def need_include_captcha(request): if current_delay < delay_time: enable_captcha = True - print 'ENABLING' + str(enable_captcha) - return enable_captcha @@ -56,8 +54,6 @@ def update_captcha_access(request, passe if KEY_CAPTCHA_DELAY_TIME in request.session else settings.CAPTCHA_DEFAULT_SAFE_TIME) - print "DELAY TIME = " + str(delay_time) - if passed: delay_time -= 2 if delay_time >= 7 else 5 else: @@ -79,4 +75,4 @@ def get_client_ip(request): def datetime_to_epoch(datetime): return int(time.mktime(timezone.localtime( datetime,timezone.get_current_timezone()).timetuple()) - * 1000000 + datetime.microsecond) \ No newline at end of file + * 1000000 + datetime.microsecond) diff --git a/neboard/settings.py b/neboard/settings.py --- a/neboard/settings.py +++ b/neboard/settings.py @@ -239,7 +239,7 @@ COMPRESS_HTML = True # Debug mode middlewares if DEBUG: MIDDLEWARE_CLASSES += ( - 'boards.profiler.ProfilerMiddleware', + #'boards.profiler.ProfilerMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware', )