##// END OF EJS Templates
Show only threads created in the favorite tag, not all its posts
Show only threads created in the favorite tag, not all its posts

File last commit:

r2026:1acac3a8 default
r2055:ef4735f5 default
Show More
tripcode.py
49 lines | 1.3 KiB | text/x-python | PythonLexer
neko259
Create tripcode view in the tripcode class instead of template
r2024 from django.urls import reverse
neko259
Cache tripcode view
r2026 from boards.utils import cached_result
neko259
Create tripcode view in the tripcode class instead of template
r2024 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>'
neko259
Cache tripcode view
r2026 SHORT_TEXT_CHARS = 8
COLOR_CHARS = 6
neko259
Create tripcode view in the tripcode class instead of template
r2024
neko259
Added ability to reset tripcode
r1296 class Tripcode:
def __init__(self, code_str):
self.tripcode = code_str
def get_color(self):
neko259
Cache tripcode view
r2026 return self.tripcode[:COLOR_CHARS]
neko259
Added ability to reset tripcode
r1296
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):
neko259
Cache tripcode view
r2026 return self.tripcode[:SHORT_TEXT_CHARS]
neko259
Added ability to reset tripcode
r1296
neko259
Tripcode collision preventer
r1297 def get_full_text(self):
return self.tripcode
neko259
Cache tripcode view
r2026 def _get_cache_key(self):
return [self.tripcode]
@cached_result(key_method=_get_cache_key)
neko259
Create tripcode view in the tripcode class instead of template
r2024 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())
neko259
Cache tripcode view
r2026