##// END OF EJS Templates
Version bump
Version bump

File last commit:

r2026:1acac3a8 default
r2109:2f9d7bc7 4.11.0 default
Show More
tripcode.py
49 lines | 1.3 KiB | text/x-python | PythonLexer
from django.urls import reverse
from boards.utils import cached_result
TRIPCODE_VIEW = '<a href="{url}?tripcode={full_text}"' \
'class="tripcode" title="{full_text}"' \
'style="border: solid 2px #{color}; border-left: solid 1ex #{color};">' \
'{short_text}</a>'
SHORT_TEXT_CHARS = 8
COLOR_CHARS = 6
class Tripcode:
def __init__(self, code_str):
self.tripcode = code_str
def get_color(self):
return self.tripcode[:COLOR_CHARS]
def get_background(self):
code = self.get_color()
result = ''
for i in range(0, len(code), 2):
p = code[i:i+2]
background = hex(255 - int(p, 16))[2:]
if len(background) < 2:
background = '0' + background
result += background
return result
def get_short_text(self):
return self.tripcode[:SHORT_TEXT_CHARS]
def get_full_text(self):
return self.tripcode
def _get_cache_key(self):
return [self.tripcode]
@cached_result(key_method=_get_cache_key)
def get_view(self):
return TRIPCODE_VIEW.format(url=reverse('feed'),
short_text=self.get_short_text(),
full_text=self.get_full_text(),
color=self.get_color())