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