forked from phonelab/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.py
60 lines (49 loc) · 1.45 KB
/
default.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import re
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic import View
from django.core.urlresolvers import reverse
"""
Human Sorting
http://nedbatchelder.com/blog/200712/human_sorting.html
Sort log file name by time order
@date 02/20/2012
@author Kate Rhodes
@adder Taeyeon Ki
"""
"""
def tryint(s):
try:
return int(s)
except:
return s
"""
def alphanum_key(s):
""" Turn a string into a list of string and number chunks.
"z23a" -> ["z", 23, "a"]
"""
return [int(c) if c.isdigit() else c for c in re.split('([0-9]+)', s) ]
def sort_nicely(l):
""" Sort the given list in the way that humans expect.
"""
l.sort(key=alphanum_key)
def re_sort_nicely(l):
""" Sort the given list in the way that humans expect.
"""
l.sort(key=alphanum_key)
l.reverse()
"""
Login and Logout function to control session
@date 05/08/2012
@author Taeyeon Ki
"""
class ProtectedView(View):
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(ProtectedView, self).dispatch(*args, **kwargs)
class AuthorProtectedView(ProtectedView):
def dispatch(self, *args, **kwargs):
post = self.get_queryset()
if not post.author != self.request.user:
return redirect('access_denied')
return super(AuthorProtectedView, self).dispatch(*args, **kwargs)