# HG changeset patch # User neko259 # Date 2014-08-11 13:07:57 # Node ID b8db9e2d300f55515c11240907c9b7f8a47c4df1 # Parent e1e1b7d87b7428d82cd7dc2769fb2ff2d9b0d4f4 # Parent 1be2c5776d6d163c816ceca33200c77a2dbc64f4 Synced with default branch changes diff --git a/boards/__init__.py b/boards/__init__.py --- a/boards/__init__.py +++ b/boards/__init__.py @@ -1,1 +0,0 @@ -import settings \ No newline at end of file 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,18 +31,18 @@ LABEL_SEARCH = _('Search') TAG_MAX_LENGTH = 20 -REGEX_TAG = ur'^[\w\d]+$' +REGEX_TAG = r'^[\w\d]+$' class FormatPanel(forms.Textarea): def render(self, name, value, attrs=None): output = '
' for formatter in formatters: - output += u'' + \ formatter.preview_left + formatter.name + \ - formatter.preview_right + u'' + formatter.preview_right + '' output += '
' output += super(FormatPanel, self).render(name, value, attrs=None) @@ -56,7 +55,7 @@ class PlainErrorList(ErrorList): return self.as_text() def as_text(self): - return ''.join([u'(!) %s ' % e for e in self]) + return ''.join(['(!) %s ' % e for e in self]) class NeboardForm(forms.Form): @@ -88,7 +87,7 @@ class NeboardForm(forms.Form): def as_json_errors(self): errors = [] - for name, field in self.fields.items(): + for name, field in list(self.fields.items()): if self[name].errors: errors.append({ 'field': name, @@ -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__) @@ -48,6 +48,9 @@ class PostManager(models.Manager): Creates new post """ + if not tags: + tags = [] + posting_time = timezone.now() if not thread: thread = Thread.objects.create(bump_time=posting_time, @@ -75,8 +78,7 @@ class PostManager(models.Manager): post.id)) thread.replies.add(post) - if tags: - map(thread.add_tag, tags) + list(map(thread.add_tag, tags)) if new_thread: Thread.objects.process_oldest_threads() @@ -112,7 +114,8 @@ class PostManager(models.Manager): """ posts = self.filter(poster_ip=ip) - map(self.delete_post, posts) + for post in posts: + self.delete_post(post) def connect_replies(self, post): """ diff --git a/boards/static/css/md/base_page.css b/boards/static/css/md/base_page.css --- a/boards/static/css/md/base_page.css +++ b/boards/static/css/md/base_page.css @@ -222,13 +222,12 @@ blockquote { } .multiquote { - border-left: solid 4px #ccc; padding: 3px; display: inline-block; background: #222; - border-right: solid 1px #ccc; - border-top: solid 1px #ccc; - border-bottom: solid 1px #ccc; + border-style: solid; + border-width: 1px 1px 1px 4px; + font-size: 0.9em; } .spoiler { diff --git a/boards/tests.py b/boards/tests.py --- a/boards/tests.py +++ b/boards/tests.py @@ -182,10 +182,6 @@ class PagesTest(TestCase): class FormTest(TestCase): def test_post_validation(self): - # Disable captcha for the test - captcha_enabled = neboard.settings.ENABLE_CAPTCHA - neboard.settings.ENABLE_CAPTCHA = False - client = Client() valid_tags = u'tag1 tag_2 тег_3' @@ -222,9 +218,6 @@ class FormTest(TestCase): self.assertEqual(2, Post.objects.count(), msg=u'No posts were created') - # Restore captcha setting - settings.ENABLE_CAPTCHA = captcha_enabled - class ViewTest(TestCase): @@ -248,7 +241,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() + output = io.BytesIO() # 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(output, format) + return ContentFile(output.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/boards/views/all_threads.py b/boards/views/all_threads.py --- a/boards/views/all_threads.py +++ b/boards/views/all_threads.py @@ -86,7 +86,7 @@ class AllThreadsView(PostMixin, BaseBoar if tag_strings: tag_strings = tag_strings.split(TAG_DELIMITER) for tag_name in tag_strings: - tag_name = string.lower(tag_name.strip()) + tag_name = tag_name.strip().lower() if len(tag_name) > 0: tag, created = Tag.objects.get_or_create(name=tag_name) tags.append(tag) @@ -115,7 +115,7 @@ class AllThreadsView(PostMixin, BaseBoar text = self._remove_invalid_links(text) - if FORM_IMAGE in data.keys(): + if FORM_IMAGE in list(data.keys()): image = data[FORM_IMAGE] else: image = None diff --git a/boards/views/api.py b/boards/views/api.py --- a/boards/views/api.py +++ b/boards/views/api.py @@ -7,6 +7,7 @@ from django.shortcuts import get_object_ from django.template import RequestContext from django.utils import timezone from django.core import serializers +from django.template.loader import render_to_string from boards.forms import PostForm, PlainErrorList from boards.models import Post, Thread, Tag @@ -219,7 +220,14 @@ def api_get_post(request, post_id): def _get_post_data(post_id, format_type=DIFF_TYPE_JSON, request=None, include_last_update=False): if format_type == DIFF_TYPE_HTML: - return get_post(request, post_id).content.strip() + post = get_object_or_404(Post, id=post_id) + + context = RequestContext(request) + context['post'] = post + if PARAMETER_TRUNCATED in request.GET: + context[PARAMETER_TRUNCATED] = True + + return render_to_string('boards/api_post.html', context) elif format_type == DIFF_TYPE_JSON: post = get_object_or_404(Post, id=post_id) post_json = { diff --git a/boards/views/thread.py b/boards/views/thread.py --- a/boards/views/thread.py +++ b/boards/views/thread.py @@ -119,7 +119,7 @@ class ThreadView(BaseBoardView, PostMixi text = self._remove_invalid_links(text) - if FORM_IMAGE in data.keys(): + if FORM_IMAGE in list(data.keys()): image = data[FORM_IMAGE] else: image = None diff --git a/neboard/__init__.py b/neboard/__init__.py --- a/neboard/__init__.py +++ b/neboard/__init__.py @@ -1,1 +0,0 @@ -import settings \ No newline at end of file diff --git a/neboard/settings.py b/neboard/settings.py --- a/neboard/settings.py +++ b/neboard/settings.py @@ -148,8 +148,6 @@ INSTALLED_APPS = ( 'south', 'debug_toolbar', - 'captcha', - # Search 'haystack', @@ -168,11 +166,6 @@ DEBUG_TOOLBAR_PANELS = ( 'debug_toolbar.panels.logger.LoggingPanel', ) -# TODO: NEED DESIGN FIXES -CAPTCHA_OUTPUT_FORMAT = (u' %(hidden_field)s ' - u'
%(image)s
' - u'
%(text_field)s
') - # A sample logging configuration. The only tangible logging # performed by this configuration is to send an email to # the site admins on every HTTP 500 error when DEBUG=False. @@ -229,9 +222,6 @@ THEMES = [ POPULAR_TAGS = 10 -ENABLE_CAPTCHA = False -# if user tries to post before CAPTCHA_DEFAULT_SAFE_TIME. Captcha will be shown -CAPTCHA_DEFAULT_SAFE_TIME = 30 # seconds POSTING_DELAY = 20 # seconds COMPRESS_HTML = True @@ -239,7 +229,7 @@ COMPRESS_HTML = True # Debug mode middlewares if DEBUG: MIDDLEWARE_CLASSES += ( - 'boards.profiler.ProfilerMiddleware', + #'boards.profiler.ProfilerMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware', ) diff --git a/requirements.txt b/requirements.txt --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,7 @@ south>=0.8.4 -line_profiler haystack pillow django>=1.6 django_cleanup django-markupfield -django-simple-captcha -line-profiler bbcode