##// END OF EJS Templates
Cache tripcode view
neko259 -
r2026:1acac3a8 default
parent child Browse files
Show More
@@ -1,17 +1,22 b''
1 from django.urls import reverse
1 from django.urls import reverse
2
2
3 from boards.utils import cached_result
4
3 TRIPCODE_VIEW = '<a href="{url}?tripcode={full_text}"' \
5 TRIPCODE_VIEW = '<a href="{url}?tripcode={full_text}"' \
4 'class="tripcode" title="{full_text}"' \
6 'class="tripcode" title="{full_text}"' \
5 'style="border: solid 2px #{color}; border-left: solid 1ex #{color};">' \
7 'style="border: solid 2px #{color}; border-left: solid 1ex #{color};">' \
6 '{short_text}</a>'
8 '{short_text}</a>'
7
9
10 SHORT_TEXT_CHARS = 8
11 COLOR_CHARS = 6
12
8
13
9 class Tripcode:
14 class Tripcode:
10 def __init__(self, code_str):
15 def __init__(self, code_str):
11 self.tripcode = code_str
16 self.tripcode = code_str
12
17
13 def get_color(self):
18 def get_color(self):
14 return self.tripcode[:6]
19 return self.tripcode[:COLOR_CHARS]
15
20
16 def get_background(self):
21 def get_background(self):
17 code = self.get_color()
22 code = self.get_color()
@@ -27,13 +32,18 b' class Tripcode:'
27 return result
32 return result
28
33
29 def get_short_text(self):
34 def get_short_text(self):
30 return self.tripcode[:8]
35 return self.tripcode[:SHORT_TEXT_CHARS]
31
36
32 def get_full_text(self):
37 def get_full_text(self):
33 return self.tripcode
38 return self.tripcode
34
39
40 def _get_cache_key(self):
41 return [self.tripcode]
42
43 @cached_result(key_method=_get_cache_key)
35 def get_view(self):
44 def get_view(self):
36 return TRIPCODE_VIEW.format(url=reverse('feed'),
45 return TRIPCODE_VIEW.format(url=reverse('feed'),
37 short_text=self.get_short_text(),
46 short_text=self.get_short_text(),
38 full_text=self.get_full_text(),
47 full_text=self.get_full_text(),
39 color=self.get_color())
48 color=self.get_color())
49
General Comments 0
You need to be logged in to leave comments. Login now