2 from datetime import datetime
4 # Map of special chars to ascii from Quake's console.c.
6 '\0', '#', '#', '#', '#', '.', '#', '#',
7 '#', '\t', '\n', '#', ' ', '\r', '.', '.',
8 '[', ']', '0', '1', '2', '3', '4', '5',
9 '6', '7', '8', '9', '.', '<', '=', '>',
10 ' ', '!', '"', '#', '$', '%', '&', '\'',
11 '(', ')', '*', '+', ',', '-', '.', '/',
12 '0', '1', '2', '3', '4', '5', '6', '7',
13 '8', '9', ':', ';', '<', '=', '>', '?',
14 '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
15 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
16 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
17 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
18 '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
19 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
20 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
21 'x', 'y', 'z', '{', '|', '}', '~', '<',
23 '<', '=', '>', '#', '#', '.', '#', '#',
24 '#', '#', ' ', '#', ' ', '>', '.', '.',
25 '[', ']', '0', '1', '2', '3', '4', '5',
26 '6', '7', '8', '9', '.', '<', '=', '>',
27 ' ', '!', '"', '#', '$', '%', '&', '\'',
28 '(', ')', '*', '+', ',', '-', '.', '/',
29 '0', '1', '2', '3', '4', '5', '6', '7',
30 '8', '9', ':', ';', '<', '=', '>', '?',
31 '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
32 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
33 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
34 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
35 '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
36 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
37 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
38 'x', 'y', 'z', '{', '|', '}', '~', '<'
42 def qfont_decode(qstr=''):
44 Convert the qfont characters in a string to ascii.
48 if c >= u'\ue000' and c <= u'\ue0ff':
49 c = qfont_table[ord(c) - 0xe000]
54 def strip_colors(str=''):
58 str = re.sub(r'\^x\w\w\w', '', str)
59 str = re.sub(r'\^\d', '', str)
63 def html_colors(str=''):
68 str = re.sub(r'\^x(\w)(\w)(\w)',
69 "<span style='color:#\g<1>\g<1>\g<2>\g<2>\g<3>\g<3>'>", str)
70 str = re.sub(r'\^1', "<span style='color:#FF9900'>", str)
71 str = re.sub(r'\^2', "<span style='color:#33FF00'>", str)
72 str = re.sub(r'\^3', "<span style='color:#FFFF00'>", str)
73 str = re.sub(r'\^4', "<span style='color:#3366FF'>", str)
74 str = re.sub(r'\^5', "<span style='color:#33FFFF'>", str)
75 str = re.sub(r'\^6', "<span style='color:#FF3366'>", str)
76 str = re.sub(r'\^7', "<span style='color:#FFFFFF'>", str)
77 str = re.sub(r'\^8', "<span style='color:#999999'>", str)
78 str = re.sub(r'\^9', "<span style='color:#666666'>", str)
79 str = re.sub(r'\^0', "<span style='color:#333333'>", str)
81 for span in range(len(re.findall(r'\^x\w\w\w|\^\d', orig))):
88 return current_route_url(request, page=page, _query=request.GET)
91 def pretty_date(time=False):
93 Get a datetime object or a int() Epoch timestamp and return a
94 pretty string like 'an hour ago', 'Yesterday', '3 months ago',
99 diff = now - datetime.fromtimestamp(time)
100 elif isinstance(time,datetime):
104 second_diff = diff.seconds
114 return str(second_diff) + " seconds ago"
115 if second_diff < 120:
116 return "a minute ago"
117 if second_diff < 3600:
118 return str( second_diff / 60 ) + " minutes ago"
119 if second_diff < 7200:
121 if second_diff < 86400:
122 return str( second_diff / 3600 ) + " hours ago"
126 return str(day_diff) + " days ago"
131 return str(day_diff/7) + " weeks ago"
136 return str(day_diff/30) + " months ago"
138 if day_diff/365 == 1:
141 return str(day_diff/365) + " years ago"