##// END OF EJS Templates
Removed the old and unneeded jumper view
neko259 -
r554:11802a56 1.7-dev
parent child Browse files
Show More
@@ -1,82 +1,81 b''
1 from django.conf.urls import patterns, url, include
1 from django.conf.urls import patterns, url, include
2 from boards import views
2 from boards import views
3 from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed
3 from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed
4 from boards.views import api, tag_threads, all_threads, archived_threads, \
4 from boards.views import api, tag_threads, all_threads, archived_threads, \
5 login, settings, all_tags
5 login, settings, all_tags
6 from boards.views.authors import AuthorsView
6 from boards.views.authors import AuthorsView
7 from boards.views.delete_post import DeletePostView
7 from boards.views.delete_post import DeletePostView
8 from boards.views.ban import BanUserView
8 from boards.views.ban import BanUserView
9
9
10 js_info_dict = {
10 js_info_dict = {
11 'packages': ('boards',),
11 'packages': ('boards',),
12 }
12 }
13
13
14 urlpatterns = patterns('',
14 urlpatterns = patterns('',
15
15
16 # /boards/
16 # /boards/
17 url(r'^$', all_threads.AllThreadsView.as_view(), name='index'),
17 url(r'^$', all_threads.AllThreadsView.as_view(), name='index'),
18 # /boards/page/
18 # /boards/page/
19 url(r'^page/(?P<page>\w+)/$', all_threads.AllThreadsView.as_view(),
19 url(r'^page/(?P<page>\w+)/$', all_threads.AllThreadsView.as_view(),
20 name='index'),
20 name='index'),
21
21
22 url(r'^archive/$', archived_threads.ArchiveView.as_view(), name='archive'),
22 url(r'^archive/$', archived_threads.ArchiveView.as_view(), name='archive'),
23 url(r'^archive/page/(?P<page>\w+)/$',
23 url(r'^archive/page/(?P<page>\w+)/$',
24 archived_threads.ArchiveView.as_view(), name='archive'),
24 archived_threads.ArchiveView.as_view(), name='archive'),
25
25
26 # login page
26 # login page
27 url(r'^login/$', login.LoginView.as_view(), name='login'),
27 url(r'^login/$', login.LoginView.as_view(), name='login'),
28
28
29 # /boards/tag/tag_name/
29 # /boards/tag/tag_name/
30 url(r'^tag/(?P<tag_name>\w+)/$', tag_threads.TagView.as_view(),
30 url(r'^tag/(?P<tag_name>\w+)/$', tag_threads.TagView.as_view(),
31 name='tag'),
31 name='tag'),
32 # /boards/tag/tag_id/page/
32 # /boards/tag/tag_id/page/
33 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/$',
33 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/$',
34 tag_threads.TagView.as_view(), name='tag'),
34 tag_threads.TagView.as_view(), name='tag'),
35
35
36 # /boards/tag/tag_name/unsubscribe/
36 # /boards/tag/tag_name/unsubscribe/
37 url(r'^tag/(?P<tag_name>\w+)/subscribe/$', views.tag_subscribe,
37 url(r'^tag/(?P<tag_name>\w+)/subscribe/$', views.tag_subscribe,
38 name='tag_subscribe'),
38 name='tag_subscribe'),
39 # /boards/tag/tag_name/unsubscribe/
39 # /boards/tag/tag_name/unsubscribe/
40 url(r'^tag/(?P<tag_name>\w+)/unsubscribe/$', views.tag_unsubscribe,
40 url(r'^tag/(?P<tag_name>\w+)/unsubscribe/$', views.tag_unsubscribe,
41 name='tag_unsubscribe'),
41 name='tag_unsubscribe'),
42
42
43 # /boards/thread/
43 # /boards/thread/
44 url(r'^thread/(?P<post_id>\w+)/$', views.thread.ThreadView.as_view(),
44 url(r'^thread/(?P<post_id>\w+)/$', views.thread.ThreadView.as_view(),
45 name='thread'),
45 name='thread'),
46 url(r'^thread/(?P<post_id>\w+)/(?P<mode>\w+)/$', views.thread.ThreadView
46 url(r'^thread/(?P<post_id>\w+)/(?P<mode>\w+)/$', views.thread.ThreadView
47 .as_view(), name='thread_mode'),
47 .as_view(), name='thread_mode'),
48
48
49 url(r'^settings/$', settings.SettingsView.as_view(), name='settings'),
49 url(r'^settings/$', settings.SettingsView.as_view(), name='settings'),
50 url(r'^tags/$', all_tags.AllTagsView.as_view(), name='tags'),
50 url(r'^tags/$', all_tags.AllTagsView.as_view(), name='tags'),
51 url(r'^captcha/', include('captcha.urls')),
51 url(r'^captcha/', include('captcha.urls')),
52 url(r'^jump/(?P<post_id>\w+)/$', views.jump_to_post, name='jumper'),
53 url(r'^authors/$', AuthorsView.as_view(), name='authors'),
52 url(r'^authors/$', AuthorsView.as_view(), name='authors'),
54 url(r'^delete/(?P<post_id>\w+)/$', DeletePostView.as_view(),
53 url(r'^delete/(?P<post_id>\w+)/$', DeletePostView.as_view(),
55 name='delete'),
54 name='delete'),
56 url(r'^ban/(?P<post_id>\w+)/$', BanUserView.as_view(), name='ban'),
55 url(r'^ban/(?P<post_id>\w+)/$', BanUserView.as_view(), name='ban'),
57
56
58 url(r'^banned/$', views.banned.BannedView.as_view(), name='banned'),
57 url(r'^banned/$', views.banned.BannedView.as_view(), name='banned'),
59 url(r'^staticpage/(?P<name>\w+)/$', views.static_page, name='staticpage'),
58 url(r'^staticpage/(?P<name>\w+)/$', views.static_page, name='staticpage'),
60
59
61 # RSS feeds
60 # RSS feeds
62 url(r'^rss/$', AllThreadsFeed()),
61 url(r'^rss/$', AllThreadsFeed()),
63 url(r'^page/(?P<page>\w+)/rss/$', AllThreadsFeed()),
62 url(r'^page/(?P<page>\w+)/rss/$', AllThreadsFeed()),
64 url(r'^tag/(?P<tag_name>\w+)/rss/$', TagThreadsFeed()),
63 url(r'^tag/(?P<tag_name>\w+)/rss/$', TagThreadsFeed()),
65 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/rss/$', TagThreadsFeed()),
64 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/rss/$', TagThreadsFeed()),
66 url(r'^thread/(?P<post_id>\w+)/rss/$', ThreadPostsFeed()),
65 url(r'^thread/(?P<post_id>\w+)/rss/$', ThreadPostsFeed()),
67
66
68 # i18n
67 # i18n
69 url(r'^jsi18n/$', 'boards.views.cached_js_catalog', js_info_dict, name='js_info_dict'),
68 url(r'^jsi18n/$', 'boards.views.cached_js_catalog', js_info_dict, name='js_info_dict'),
70
69
71 # API
70 # API
72 url(r'^api/post/(?P<post_id>\w+)/$', api.get_post, name="get_post"),
71 url(r'^api/post/(?P<post_id>\w+)/$', api.get_post, name="get_post"),
73 url(r'^api/diff_thread/(?P<thread_id>\w+)/(?P<last_update_time>\w+)/$',
72 url(r'^api/diff_thread/(?P<thread_id>\w+)/(?P<last_update_time>\w+)/$',
74 api.api_get_threaddiff, name="get_thread_diff"),
73 api.api_get_threaddiff, name="get_thread_diff"),
75 url(r'^api/threads/(?P<count>\w+)/$', api.api_get_threads,
74 url(r'^api/threads/(?P<count>\w+)/$', api.api_get_threads,
76 name='get_threads'),
75 name='get_threads'),
77 url(r'^api/tags/$', api.api_get_tags, name='get_tags'),
76 url(r'^api/tags/$', api.api_get_tags, name='get_tags'),
78 url(r'^api/thread/(?P<opening_post_id>\w+)/$', api.api_get_thread_posts,
77 url(r'^api/thread/(?P<opening_post_id>\w+)/$', api.api_get_thread_posts,
79 name='get_thread'),
78 name='get_thread'),
80 url(r'^api/add_post/(?P<opening_post_id>\w+)/$', api.api_add_post, name='add_post'),
79 url(r'^api/add_post/(?P<opening_post_id>\w+)/$', api.api_add_post, name='add_post'),
81
80
82 )
81 )
@@ -1,193 +1,177 b''
1 __author__ = 'neko259'
1 __author__ = 'neko259'
2
2
3 import hashlib
3 import hashlib
4
4
5 from django.core import serializers
5 from django.core import serializers
6 from django.core.urlresolvers import reverse
6 from django.core.urlresolvers import reverse
7 from django.http import HttpResponseRedirect
7 from django.http import HttpResponseRedirect
8 from django.http.response import HttpResponse
8 from django.http.response import HttpResponse
9 from django.template import RequestContext
9 from django.template import RequestContext
10 from django.shortcuts import render, redirect, get_object_or_404
10 from django.shortcuts import render, redirect, get_object_or_404
11 from django.utils import timezone
11 from django.utils import timezone
12 from django.db import transaction
12 from django.db import transaction
13 from django.views.decorators.cache import cache_page
13 from django.views.decorators.cache import cache_page
14 from django.views.i18n import javascript_catalog
14 from django.views.i18n import javascript_catalog
15
15
16 import boards
16 import boards
17 from boards.forms import PlainErrorList
17 from boards.forms import PlainErrorList
18 from boards.models import Post, Tag, Ban, User
18 from boards.models import Post, Tag, Ban, User
19 from boards.models.post import SETTING_MODERATE
19 from boards.models.post import SETTING_MODERATE
20 from boards.models.user import RANK_USER
20 from boards.models.user import RANK_USER
21 from boards import authors
21 from boards import authors
22 import neboard
22 import neboard
23
23
24
24
25 BAN_REASON_SPAM = 'Autoban: spam bot'
25 BAN_REASON_SPAM = 'Autoban: spam bot'
26
26
27 DEFAULT_PAGE = 1
27 DEFAULT_PAGE = 1
28
28
29
29
30 # TODO Maybe this jumper is not needed any more? Only as a hack to find some
31 # post without knowing its thread
32 def jump_to_post(request, post_id):
33 """Determine thread in which the requested post is and open it's page"""
34
35 post = get_object_or_404(Post, id=post_id)
36
37 if not post.thread:
38 return redirect('thread', post_id=post.id)
39 else:
40 return redirect(reverse('thread', kwargs={'post_id': post.thread.id})
41 + '#' + str(post.id))
42
43
44
45
46 def page_404(request):
30 def page_404(request):
47 """Show page 404 (not found error)"""
31 """Show page 404 (not found error)"""
48
32
49 context = _init_default_context(request)
33 context = _init_default_context(request)
50 return render(request, 'boards/404.html', context)
34 return render(request, 'boards/404.html', context)
51
35
52
36
53 @transaction.atomic
37 @transaction.atomic
54 def tag_subscribe(request, tag_name):
38 def tag_subscribe(request, tag_name):
55 """Add tag to favorites"""
39 """Add tag to favorites"""
56
40
57 user = _get_user(request)
41 user = _get_user(request)
58 tag = get_object_or_404(Tag, name=tag_name)
42 tag = get_object_or_404(Tag, name=tag_name)
59
43
60 if not tag in user.fav_tags.all():
44 if not tag in user.fav_tags.all():
61 user.add_tag(tag)
45 user.add_tag(tag)
62
46
63 return _redirect_to_next(request)
47 return _redirect_to_next(request)
64
48
65
49
66 @transaction.atomic
50 @transaction.atomic
67 def tag_unsubscribe(request, tag_name):
51 def tag_unsubscribe(request, tag_name):
68 """Remove tag from favorites"""
52 """Remove tag from favorites"""
69
53
70 user = _get_user(request)
54 user = _get_user(request)
71 tag = get_object_or_404(Tag, name=tag_name)
55 tag = get_object_or_404(Tag, name=tag_name)
72
56
73 if tag in user.fav_tags.all():
57 if tag in user.fav_tags.all():
74 user.remove_tag(tag)
58 user.remove_tag(tag)
75
59
76 return _redirect_to_next(request)
60 return _redirect_to_next(request)
77
61
78
62
79 def static_page(request, name):
63 def static_page(request, name):
80 """Show a static page that needs only tags list and a CSS"""
64 """Show a static page that needs only tags list and a CSS"""
81
65
82 context = _init_default_context(request)
66 context = _init_default_context(request)
83 return render(request, 'boards/staticpages/' + name + '.html', context)
67 return render(request, 'boards/staticpages/' + name + '.html', context)
84
68
85
69
86 # TODO This has to be moved under the api module
70 # TODO This has to be moved under the api module
87 def api_get_post(request, post_id):
71 def api_get_post(request, post_id):
88 """
72 """
89 Get the JSON of a post. This can be
73 Get the JSON of a post. This can be
90 used as and API for external clients.
74 used as and API for external clients.
91 """
75 """
92
76
93 post = get_object_or_404(Post, id=post_id)
77 post = get_object_or_404(Post, id=post_id)
94
78
95 json = serializers.serialize("json", [post], fields=(
79 json = serializers.serialize("json", [post], fields=(
96 "pub_time", "_text_rendered", "title", "text", "image",
80 "pub_time", "_text_rendered", "title", "text", "image",
97 "image_width", "image_height", "replies", "tags"
81 "image_width", "image_height", "replies", "tags"
98 ))
82 ))
99
83
100 return HttpResponse(content=json)
84 return HttpResponse(content=json)
101
85
102
86
103 @cache_page(86400)
87 @cache_page(86400)
104 def cached_js_catalog(request, domain='djangojs', packages=None):
88 def cached_js_catalog(request, domain='djangojs', packages=None):
105 return javascript_catalog(request, domain, packages)
89 return javascript_catalog(request, domain, packages)
106
90
107
91
108 # TODO This method is deprecated and should be removed after switching to
92 # TODO This method is deprecated and should be removed after switching to
109 # class-based view
93 # class-based view
110 def _get_theme(request, user=None):
94 def _get_theme(request, user=None):
111 """Get user's CSS theme"""
95 """Get user's CSS theme"""
112
96
113 if not user:
97 if not user:
114 user = _get_user(request)
98 user = _get_user(request)
115 theme = user.get_setting('theme')
99 theme = user.get_setting('theme')
116 if not theme:
100 if not theme:
117 theme = neboard.settings.DEFAULT_THEME
101 theme = neboard.settings.DEFAULT_THEME
118
102
119 return theme
103 return theme
120
104
121
105
122 # TODO This method is deprecated and should be removed after switching to
106 # TODO This method is deprecated and should be removed after switching to
123 # class-based view
107 # class-based view
124 def _init_default_context(request):
108 def _init_default_context(request):
125 """Create context with default values that are used in most views"""
109 """Create context with default values that are used in most views"""
126
110
127 context = RequestContext(request)
111 context = RequestContext(request)
128
112
129 user = _get_user(request)
113 user = _get_user(request)
130 context['user'] = user
114 context['user'] = user
131 context['tags'] = user.get_sorted_fav_tags()
115 context['tags'] = user.get_sorted_fav_tags()
132 context['posts_per_day'] = float(Post.objects.get_posts_per_day())
116 context['posts_per_day'] = float(Post.objects.get_posts_per_day())
133
117
134 theme = _get_theme(request, user)
118 theme = _get_theme(request, user)
135 context['theme'] = theme
119 context['theme'] = theme
136 context['theme_css'] = 'css/' + theme + '/base_page.css'
120 context['theme_css'] = 'css/' + theme + '/base_page.css'
137
121
138 # This shows the moderator panel
122 # This shows the moderator panel
139 moderate = user.get_setting(SETTING_MODERATE)
123 moderate = user.get_setting(SETTING_MODERATE)
140 if moderate == 'True':
124 if moderate == 'True':
141 context['moderator'] = user.is_moderator()
125 context['moderator'] = user.is_moderator()
142 else:
126 else:
143 context['moderator'] = False
127 context['moderator'] = False
144
128
145 return context
129 return context
146
130
147
131
148 # TODO This method is deprecated and should be removed after switching to
132 # TODO This method is deprecated and should be removed after switching to
149 # class-based view
133 # class-based view
150 def _get_user(request):
134 def _get_user(request):
151 """
135 """
152 Get current user from the session. If the user does not exist, create
136 Get current user from the session. If the user does not exist, create
153 a new one.
137 a new one.
154 """
138 """
155
139
156 session = request.session
140 session = request.session
157 if not 'user_id' in session:
141 if not 'user_id' in session:
158 request.session.save()
142 request.session.save()
159
143
160 md5 = hashlib.md5()
144 md5 = hashlib.md5()
161 md5.update(session.session_key)
145 md5.update(session.session_key)
162 new_id = md5.hexdigest()
146 new_id = md5.hexdigest()
163
147
164 while User.objects.filter(user_id=new_id).exists():
148 while User.objects.filter(user_id=new_id).exists():
165 md5.update(str(timezone.now()))
149 md5.update(str(timezone.now()))
166 new_id = md5.hexdigest()
150 new_id = md5.hexdigest()
167
151
168 time_now = timezone.now()
152 time_now = timezone.now()
169 user = User.objects.create(user_id=new_id, rank=RANK_USER,
153 user = User.objects.create(user_id=new_id, rank=RANK_USER,
170 registration_time=time_now)
154 registration_time=time_now)
171
155
172 # TODO This is just a test. This method should be removed
156 # TODO This is just a test. This method should be removed
173 # _delete_old_users()
157 # _delete_old_users()
174
158
175 session['user_id'] = user.id
159 session['user_id'] = user.id
176 else:
160 else:
177 user = User.objects.get(id=session['user_id'])
161 user = User.objects.get(id=session['user_id'])
178
162
179 return user
163 return user
180
164
181
165
182 def _redirect_to_next(request):
166 def _redirect_to_next(request):
183 """
167 """
184 If a 'next' parameter was specified, redirect to the next page. This is
168 If a 'next' parameter was specified, redirect to the next page. This is
185 used when the user is required to return to some page after the current
169 used when the user is required to return to some page after the current
186 view has finished its work.
170 view has finished its work.
187 """
171 """
188
172
189 if 'next' in request.GET:
173 if 'next' in request.GET:
190 next_page = request.GET['next']
174 next_page = request.GET['next']
191 return HttpResponseRedirect(next_page)
175 return HttpResponseRedirect(next_page)
192 else:
176 else:
193 return redirect('index')
177 return redirect('index')
General Comments 0
You need to be logged in to leave comments. Login now