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