Show More
@@ -0,0 +1,13 b'' | |||||
|
1 | """ | |||
|
2 | This module contains helper functions and helper classes. | |||
|
3 | """ | |||
|
4 | ||||
|
5 | ||||
|
6 | def check_if_human(request): | |||
|
7 | """ | |||
|
8 | Check if request is made by a user. | |||
|
9 | It contains rules which check for bots. | |||
|
10 | """ | |||
|
11 | ||||
|
12 | # FIXME: need to insert checking logic | |||
|
13 | return True |
@@ -1,4 +1,5 b'' | |||||
1 | import re |
|
1 | import re | |
|
2 | from captcha.fields import CaptchaField | |||
2 | from django import forms |
|
3 | from django import forms | |
3 | from django.forms.util import ErrorList |
|
4 | from django.forms.util import ErrorList | |
4 | from boards.models import TITLE_MAX_LENGTH |
|
5 | from boards.models import TITLE_MAX_LENGTH | |
@@ -66,6 +67,10 b' class PostForm(forms.Form):' | |||||
66 | self._errors['image'] = self.error_class([error_message]) |
|
67 | self._errors['image'] = self.error_class([error_message]) | |
67 |
|
68 | |||
68 |
|
69 | |||
|
70 | class PostCaptchaForm(PostForm): | |||
|
71 | captcha = CaptchaField() | |||
|
72 | ||||
|
73 | ||||
69 | class ThreadForm(PostForm): |
|
74 | class ThreadForm(PostForm): | |
70 | regex_tags = re.compile(ur'^[\w\s\d]+$', re.UNICODE) |
|
75 | regex_tags = re.compile(ur'^[\w\s\d]+$', re.UNICODE) | |
71 | tags = forms.CharField(max_length=100) |
|
76 | tags = forms.CharField(max_length=100) | |
@@ -86,5 +91,10 b' class ThreadForm(PostForm):' | |||||
86 | return cleaned_data |
|
91 | return cleaned_data | |
87 |
|
92 | |||
88 |
|
93 | |||
|
94 | class ThreadCaptchaForm(ThreadForm): | |||
|
95 | captcha = CaptchaField() | |||
|
96 | ||||
|
97 | ||||
|
98 | ||||
89 | class SettingsForm(forms.Form): |
|
99 | class SettingsForm(forms.Form): | |
90 | theme = forms.ChoiceField(choices=settings.THEMES, widget=forms.RadioSelect) No newline at end of file |
|
100 | theme = forms.ChoiceField(choices=settings.THEMES, widget=forms.RadioSelect) |
@@ -1,4 +1,4 b'' | |||||
1 | from django.conf.urls import patterns, url |
|
1 | from django.conf.urls import patterns, url, include | |
2 | from boards import views |
|
2 | from boards import views | |
3 |
|
3 | |||
4 | urlpatterns = patterns('', |
|
4 | urlpatterns = patterns('', | |
@@ -23,3 +23,8 b" urlpatterns = patterns(''," | |||||
23 | url(r'^settings$', views.settings, name='settings'), |
|
23 | url(r'^settings$', views.settings, name='settings'), | |
24 | url(r'^tags$', views.all_tags, name='tags'), |
|
24 | url(r'^tags$', views.all_tags, name='tags'), | |
25 | ) |
|
25 | ) | |
|
26 | ||||
|
27 | #enable captcha support | |||
|
28 | urlpatterns += patterns('', | |||
|
29 | url(r'^captcha/', include('captcha.urls')), | |||
|
30 | ) |
@@ -5,7 +5,10 b' from django.http import HttpResponseRedi' | |||||
5 |
|
5 | |||
6 | from boards import forms |
|
6 | from boards import forms | |
7 | import boards |
|
7 | import boards | |
8 | from boards.forms import ThreadForm, PostForm, SettingsForm, PlainErrorList |
|
8 | from boards import utils | |
|
9 | from boards.forms import ThreadForm, PostForm, SettingsForm, PlainErrorList, \ | |||
|
10 | ThreadCaptchaForm, PostCaptchaForm | |||
|
11 | ||||
9 | from boards.models import Post, Admin, Tag |
|
12 | from boards.models import Post, Admin, Tag | |
10 | import neboard |
|
13 | import neboard | |
11 |
|
14 | |||
@@ -13,13 +16,18 b' import neboard' | |||||
13 | def index(request, page=0): |
|
16 | def index(request, page=0): | |
14 | context = RequestContext(request) |
|
17 | context = RequestContext(request) | |
15 |
|
18 | |||
|
19 | threadFormClass = (ThreadForm | |||
|
20 | if utils.check_if_human(request) | |||
|
21 | else ThreadCaptchaForm) | |||
|
22 | ||||
16 | if request.method == 'POST': |
|
23 | if request.method == 'POST': | |
17 |
form = |
|
24 | form = threadFormClass(request.POST, request.FILES, | |
18 | error_class=PlainErrorList) |
|
25 | error_class=PlainErrorList) | |
|
26 | ||||
19 | if form.is_valid(): |
|
27 | if form.is_valid(): | |
20 | return _new_post(request, form) |
|
28 | return _new_post(request, form) | |
21 | else: |
|
29 | else: | |
22 |
form = |
|
30 | form = threadFormClass(error_class=PlainErrorList) | |
23 |
|
31 | |||
24 | threads = Post.objects.get_threads(page=int(page)) |
|
32 | threads = Post.objects.get_threads(page=int(page)) | |
25 |
|
33 | |||
@@ -111,13 +119,17 b' def tag(request, tag_name, page=0):' | |||||
111 | def thread(request, post_id): |
|
119 | def thread(request, post_id): | |
112 | """Get all thread posts""" |
|
120 | """Get all thread posts""" | |
113 |
|
121 | |||
|
122 | postFormClass = (PostForm | |||
|
123 | if utils.check_if_human(request) | |||
|
124 | else PostCaptchaForm) | |||
|
125 | ||||
114 | if request.method == 'POST': |
|
126 | if request.method == 'POST': | |
115 |
form = |
|
127 | form = postFormClass(request.POST, request.FILES, | |
116 | error_class=PlainErrorList) |
|
128 | error_class=PlainErrorList) | |
117 | if form.is_valid(): |
|
129 | if form.is_valid(): | |
118 | return _new_post(request, form, post_id) |
|
130 | return _new_post(request, form, post_id) | |
119 | else: |
|
131 | else: | |
120 |
form = |
|
132 | form = postFormClass(error_class=PlainErrorList) | |
121 |
|
133 | |||
122 | posts = Post.objects.get_thread(post_id) |
|
134 | posts = Post.objects.get_thread(post_id) | |
123 |
|
135 |
@@ -3,4 +3,4 b' django >= 1.5' | |||||
3 | django_cleanup |
|
3 | django_cleanup | |
4 | django-markupfield |
|
4 | django-markupfield | |
5 | markdown |
|
5 | markdown | |
6 |
|
6 | django-simple-captcha |
@@ -138,8 +138,14 b' INSTALLED_APPS = (' | |||||
138 | 'django.contrib.markup', |
|
138 | 'django.contrib.markup', | |
139 | 'django_cleanup', |
|
139 | 'django_cleanup', | |
140 | 'boards', |
|
140 | 'boards', | |
|
141 | 'captcha', | |||
141 | ) |
|
142 | ) | |
142 |
|
143 | |||
|
144 | # TODO: NEED DESIGN FIXES | |||
|
145 | CAPTCHA_OUTPUT_FORMAT = (u' %(hidden_field)s ' | |||
|
146 | u'<div class="form-label">%(image)s</div>' | |||
|
147 | u'<div class="form-text">%(text_field)s</div>') | |||
|
148 | ||||
143 | # A sample logging configuration. The only tangible logging |
|
149 | # A sample logging configuration. The only tangible logging | |
144 | # performed by this configuration is to send an email to |
|
150 | # performed by this configuration is to send an email to | |
145 | # the site admins on every HTTP 500 error when DEBUG=False. |
|
151 | # the site admins on every HTTP 500 error when DEBUG=False. |
@@ -103,6 +103,7 b'' | |||||
103 |
|
103 | |||
104 | <form enctype="multipart/form-data" method="post">{% csrf_token %} |
|
104 | <form enctype="multipart/form-data" method="post">{% csrf_token %} | |
105 | <div class="post-form-w"> |
|
105 | <div class="post-form-w"> | |
|
106 | ||||
106 | <div class="form-title">{% trans "Create new thread" %}</div> |
|
107 | <div class="form-title">{% trans "Create new thread" %}</div> | |
107 | <div class="post-form"> |
|
108 | <div class="post-form"> | |
108 | <div class="form-row"> |
|
109 | <div class="form-row"> | |
@@ -126,8 +127,12 b'' | |||||
126 | <div class="form-errors">{{ form.tags.errors }}</div> |
|
127 | <div class="form-errors">{{ form.tags.errors }}</div> | |
127 | </div> |
|
128 | </div> | |
128 | </div> |
|
129 | </div> | |
129 |
<div class="form-submit"> |
|
130 | <div class="form-submit"> | |
130 | value="{% trans "Post" %}"/></div> |
|
131 | <BR /> | |
|
132 | {{ form.captcha }} | |||
|
133 | <BR /> | |||
|
134 | ||||
|
135 | <input type="submit" value="{% trans "Post" %}"/></div> | |||
131 | <div>Tags must be delimited by spaces. Text or image is required |
|
136 | <div>Tags must be delimited by spaces. Text or image is required | |
132 | </div> |
|
137 | </div> | |
133 | <div>Use <a |
|
138 | <div>Use <a |
@@ -82,6 +82,11 b'' | |||||
82 | <div class="form-errors">{{ form.image.errors }}</div> |
|
82 | <div class="form-errors">{{ form.image.errors }}</div> | |
83 | </div> |
|
83 | </div> | |
84 | </div> |
|
84 | </div> | |
|
85 | ||||
|
86 | <BR /> | |||
|
87 | {{ form.captcha }} | |||
|
88 | <BR /> | |||
|
89 | ||||
85 | <div class="form-submit"><input type="submit" |
|
90 | <div class="form-submit"><input type="submit" | |
86 | value="{% trans "Post" %}"/></div> |
|
91 | value="{% trans "Post" %}"/></div> | |
87 | <div>Use <a |
|
92 | <div>Use <a |
General Comments 0
You need to be logged in to leave comments.
Login now