Commit 9c0fc2b40162ff2e2162cb0d6b56d0c07448c351
1 parent
87c02305
Exists in
master
and in
31 other branches
Moved voting to super_archives
Showing
8 changed files
with
41 additions
and
60 deletions
Show diff stats
colab/api/__init__.py
colab/api/urls.py
colab/api/views.py
... | ... | @@ -1,45 +0,0 @@ |
1 | - | |
2 | -from django import http | |
3 | -from django.db import IntegrityError | |
4 | -from django.views.generic import View | |
5 | -from django.core.exceptions import ObjectDoesNotExist | |
6 | - | |
7 | - | |
8 | -from colab.super_archives.models import Message | |
9 | - | |
10 | - | |
11 | -class VoteView(View): | |
12 | - | |
13 | - http_method_names = [u'get', u'put', u'delete', u'head'] | |
14 | - | |
15 | - def put(self, request, msg_id): | |
16 | - if not request.user.is_authenticated(): | |
17 | - return http.HttpResponseForbidden() | |
18 | - | |
19 | - try: | |
20 | - Message.objects.get(id=msg_id).vote(request.user) | |
21 | - except IntegrityError: | |
22 | - # 409 Conflict | |
23 | - # used for duplicated entries | |
24 | - return http.HttpResponse(status=409) | |
25 | - | |
26 | - # 201 Created | |
27 | - return http.HttpResponse(status=201) | |
28 | - | |
29 | - def get(self, request, msg_id): | |
30 | - votes = Message.objects.get(id=msg_id).votes_count() | |
31 | - return http.HttpResponse(votes, content_type='application/json') | |
32 | - | |
33 | - def delete(self, request, msg_id): | |
34 | - if not request.user.is_authenticated(): | |
35 | - return http.HttpResponseForbidden() | |
36 | - | |
37 | - try: | |
38 | - Message.objects.get(id=msg_id).unvote(request.user) | |
39 | - except ObjectDoesNotExist: | |
40 | - return http.HttpResponseGone() | |
41 | - | |
42 | - # 204 No Content | |
43 | - # empty body, as per RFC2616. | |
44 | - # object deleted | |
45 | - return http.HttpResponse(status=204) |
colab/settings.py
colab/super_archives/templates/message-thread.html
... | ... | @@ -59,7 +59,7 @@ |
59 | 59 | console.debug('trying to vote'); |
60 | 60 | $btn.button('loading'); |
61 | 61 | $ajax = $.ajax({ |
62 | - url: "/api/message/" + msg_id + "/vote", | |
62 | + url: "archives/message/" + msg_id + "/vote", | |
63 | 63 | type: method, |
64 | 64 | context: $btn.get(0), |
65 | 65 | beforeSend: function(xhr, settings) { | ... | ... |
colab/super_archives/urls.py
1 | 1 | from django.conf.urls import patterns, url |
2 | 2 | |
3 | -from .views import EmailView, EmailValidationView, ThreadView | |
4 | -from .views import ThreadDashboardView | |
3 | +from .views import (EmailView, EmailValidationView, ThreadView, | |
4 | + ThreadDashboardView, VoteView) | |
5 | 5 | |
6 | 6 | |
7 | 7 | urlpatterns = patterns( |
... | ... | @@ -13,4 +13,5 @@ urlpatterns = patterns( |
13 | 13 | name="archive_email_validation_view"), |
14 | 14 | url(r'manage/email/(?P<key>[0-9a-z]{32})?', EmailView.as_view(), |
15 | 15 | name="archive_email_view"), |
16 | + url(r'message/(?P<msg_id>\d+)/vote$', VoteView.as_view()), | |
16 | 17 | ) | ... | ... |
colab/super_archives/views.py
... | ... | @@ -294,3 +294,40 @@ class EmailValidationView(View): |
294 | 294 | return http.HttpResponseServerError() |
295 | 295 | |
296 | 296 | return http.HttpResponse(status=204) |
297 | + | |
298 | + | |
299 | +class VoteView(View): | |
300 | + | |
301 | + http_method_names = [u'get', u'put', u'delete', u'head'] | |
302 | + | |
303 | + def put(self, request, msg_id): | |
304 | + if not request.user.is_authenticated(): | |
305 | + return http.HttpResponseForbidden() | |
306 | + | |
307 | + try: | |
308 | + Message.objects.get(id=msg_id).vote(request.user) | |
309 | + except IntegrityError: | |
310 | + # 409 Conflict | |
311 | + # used for duplicated entries | |
312 | + return http.HttpResponse(status=409) | |
313 | + | |
314 | + # 201 Created | |
315 | + return http.HttpResponse(status=201) | |
316 | + | |
317 | + def get(self, request, msg_id): | |
318 | + votes = Message.objects.get(id=msg_id).votes_count() | |
319 | + return http.HttpResponse(votes, content_type='application/json') | |
320 | + | |
321 | + def delete(self, request, msg_id): | |
322 | + if not request.user.is_authenticated(): | |
323 | + return http.HttpResponseForbidden() | |
324 | + | |
325 | + try: | |
326 | + Message.objects.get(id=msg_id).unvote(request.user) | |
327 | + except ObjectDoesNotExist: | |
328 | + return http.HttpResponseGone() | |
329 | + | |
330 | + # 204 No Content | |
331 | + # empty body, as per RFC2616. | |
332 | + # object deleted | |
333 | + return http.HttpResponse(status=204) | ... | ... |
colab/urls.py
... | ... | @@ -12,7 +12,6 @@ urlpatterns = patterns('', |
12 | 12 | url(r'^robots.txt$', 'colab.home.views.robots', name='robots'), |
13 | 13 | url(r'^dashboard$', 'colab.home.views.dashboard', name='dashboard'), |
14 | 14 | url(r'^search/', include('colab.search.urls')), |
15 | - url(r'^api/', include('colab.api.urls')), | |
16 | 15 | url(r'^rss/', include('colab.rss.urls')), |
17 | 16 | |
18 | 17 | url(r'^account/', include('colab.accounts.urls')), | ... | ... |