Show More
@@ -2,7 +2,6 b' import re' | |||
|
2 | 2 | import time |
|
3 | 3 | import hashlib |
|
4 | 4 | |
|
5 | from captcha.fields import CaptchaField | |
|
6 | 5 | from django import forms |
|
7 | 6 | from django.forms.util import ErrorList |
|
8 | 7 | from django.utils.translation import ugettext_lazy as _ |
@@ -32,7 +31,7 b" LABEL_SEARCH = _('Search')" | |||
|
32 | 31 | |
|
33 | 32 | TAG_MAX_LENGTH = 20 |
|
34 | 33 | |
|
35 |
REGEX_TAG = |
|
|
34 | REGEX_TAG = r'^[\w\d]+$' | |
|
36 | 35 | |
|
37 | 36 | |
|
38 | 37 | class FormatPanel(forms.Textarea): |
@@ -208,7 +207,7 b' class PostForm(NeboardForm):' | |||
|
208 | 207 | |
|
209 | 208 | class ThreadForm(PostForm): |
|
210 | 209 | |
|
211 |
regex_tags = re.compile( |
|
|
210 | regex_tags = re.compile(r'^[\w\s\d]+$', re.UNICODE) | |
|
212 | 211 | |
|
213 | 212 | tags = forms.CharField( |
|
214 | 213 | widget=forms.TextInput(attrs={ATTRIBUTE_PLACEHOLDER: TAGS_PLACEHOLDER}), |
@@ -229,48 +228,6 b' class ThreadForm(PostForm):' | |||
|
229 | 228 | return cleaned_data |
|
230 | 229 | |
|
231 | 230 | |
|
232 | class PostCaptchaForm(PostForm): | |
|
233 | captcha = CaptchaField() | |
|
234 | ||
|
235 | def __init__(self, *args, **kwargs): | |
|
236 | self.request = kwargs['request'] | |
|
237 | del kwargs['request'] | |
|
238 | ||
|
239 | super(PostCaptchaForm, self).__init__(*args, **kwargs) | |
|
240 | ||
|
241 | def clean(self): | |
|
242 | cleaned_data = super(PostCaptchaForm, self).clean() | |
|
243 | ||
|
244 | success = self.is_valid() | |
|
245 | utils.update_captcha_access(self.request, success) | |
|
246 | ||
|
247 | if success: | |
|
248 | return cleaned_data | |
|
249 | else: | |
|
250 | raise forms.ValidationError(_("Captcha validation failed")) | |
|
251 | ||
|
252 | ||
|
253 | class ThreadCaptchaForm(ThreadForm): | |
|
254 | captcha = CaptchaField() | |
|
255 | ||
|
256 | def __init__(self, *args, **kwargs): | |
|
257 | self.request = kwargs['request'] | |
|
258 | del kwargs['request'] | |
|
259 | ||
|
260 | super(ThreadCaptchaForm, self).__init__(*args, **kwargs) | |
|
261 | ||
|
262 | def clean(self): | |
|
263 | cleaned_data = super(ThreadCaptchaForm, self).clean() | |
|
264 | ||
|
265 | success = self.is_valid() | |
|
266 | utils.update_captcha_access(self.request, success) | |
|
267 | ||
|
268 | if success: | |
|
269 | return cleaned_data | |
|
270 | else: | |
|
271 | raise forms.ValidationError(_("Captcha validation failed")) | |
|
272 | ||
|
273 | ||
|
274 | 231 | class SettingsForm(NeboardForm): |
|
275 | 232 | |
|
276 | 233 | theme = forms.ChoiceField(choices=settings.THEMES, |
@@ -17,7 +17,7 b' class Migration(DataMigration):' | |||
|
17 | 17 | thread.replies.add(post) |
|
18 | 18 | post.thread_new = thread |
|
19 | 19 | post.save() |
|
20 |
print |
|
|
20 | print(str(post.thread_new.id)) | |
|
21 | 21 | |
|
22 | 22 | for reply in post.replies.all(): |
|
23 | 23 | thread.replies.add(reply) |
@@ -36,7 +36,7 b" NO_IP = '0.0.0.0'" | |||
|
36 | 36 | # TODO Real user agent should be saved instead of this |
|
37 | 37 | UNKNOWN_UA = '' |
|
38 | 38 | |
|
39 |
REGEX_REPLY = re.compile( |
|
|
39 | REGEX_REPLY = re.compile(r'\[post\](\d+)\[/post\]') | |
|
40 | 40 | |
|
41 | 41 | logger = logging.getLogger(__name__) |
|
42 | 42 |
@@ -248,7 +248,7 b' class ViewTest(TestCase):' | |||
|
248 | 248 | except NoReverseMatch: |
|
249 | 249 | # This view just needs additional arguments |
|
250 | 250 | pass |
|
251 |
except Exception |
|
|
251 | except Exception as e: | |
|
252 | 252 | self.fail('Got exception %s at %s view' % (e, view_name)) |
|
253 | 253 | except AttributeError: |
|
254 | 254 | # This is normal, some views do not have names |
@@ -8,7 +8,7 b' from django.db.models import ImageField' | |||
|
8 | 8 | from django.db.models.fields.files import ImageFieldFile |
|
9 | 9 | from PIL import Image |
|
10 | 10 | from django.core.files.base import ContentFile |
|
11 |
import |
|
|
11 | import io | |
|
12 | 12 | |
|
13 | 13 | |
|
14 | 14 | def generate_thumb(img, thumb_size, format): |
@@ -51,13 +51,13 b' def generate_thumb(img, thumb_size, form' | |||
|
51 | 51 | image2 = image |
|
52 | 52 | image2.thumbnail(thumb_size, Image.ANTIALIAS) |
|
53 | 53 | |
|
54 |
io = |
|
|
54 | string_io = io.StringIO() | |
|
55 | 55 | # PNG and GIF are the same, JPG is JPEG |
|
56 | 56 | if format.upper() == 'JPG': |
|
57 | 57 | format = 'JPEG' |
|
58 | 58 | |
|
59 | image2.save(io, format) | |
|
60 | return ContentFile(io.getvalue()) | |
|
59 | image2.save(string_io, format) | |
|
60 | return ContentFile(string_io.getvalue()) | |
|
61 | 61 | |
|
62 | 62 | |
|
63 | 63 | class ImageWithThumbsFieldFile(ImageFieldFile): |
@@ -45,7 +45,6 b" urlpatterns = patterns(''," | |||
|
45 | 45 | |
|
46 | 46 | url(r'^settings/$', settings.SettingsView.as_view(), name='settings'), |
|
47 | 47 | url(r'^tags/$', all_tags.AllTagsView.as_view(), name='tags'), |
|
48 | url(r'^captcha/', include('captcha.urls')), | |
|
49 | 48 | url(r'^authors/$', AuthorsView.as_view(), name='authors'), |
|
50 | 49 | url(r'^delete/(?P<post_id>\w+)/$', DeletePostView.as_view(), |
|
51 | 50 | name='delete'), |
@@ -39,8 +39,6 b' def need_include_captcha(request):' | |||
|
39 | 39 | if current_delay < delay_time: |
|
40 | 40 | enable_captcha = True |
|
41 | 41 | |
|
42 | print 'ENABLING' + str(enable_captcha) | |
|
43 | ||
|
44 | 42 | return enable_captcha |
|
45 | 43 | |
|
46 | 44 | |
@@ -56,8 +54,6 b' def update_captcha_access(request, passe' | |||
|
56 | 54 | if KEY_CAPTCHA_DELAY_TIME in request.session |
|
57 | 55 | else settings.CAPTCHA_DEFAULT_SAFE_TIME) |
|
58 | 56 | |
|
59 | print "DELAY TIME = " + str(delay_time) | |
|
60 | ||
|
61 | 57 | if passed: |
|
62 | 58 | delay_time -= 2 if delay_time >= 7 else 5 |
|
63 | 59 | else: |
@@ -79,4 +75,4 b' def get_client_ip(request):' | |||
|
79 | 75 | def datetime_to_epoch(datetime): |
|
80 | 76 | return int(time.mktime(timezone.localtime( |
|
81 | 77 | datetime,timezone.get_current_timezone()).timetuple()) |
|
82 | * 1000000 + datetime.microsecond) No newline at end of file | |
|
78 | * 1000000 + datetime.microsecond) |
General Comments 0
You need to be logged in to leave comments.
Login now