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