##// END OF EJS Templates
Show localized tags under the proper letter section in all tags list. Cache localized tag name, not the whole view
neko259 -
r1892:0808e889 default
parent child Browse files
Show More
@@ -52,7 +52,7 b' class TagManager(models.Manager):'
52
52
53 return self.annotate(num_threads=Count('thread_tags'))\
53 return self.annotate(num_threads=Count('thread_tags'))\
54 .filter(num_threads__gt=0)\
54 .filter(num_threads__gt=0)\
55 .filter(aliases__locale=DEFAULT_LOCALE)\
55 .filter(aliases__in=TagAlias.objects.filter_localized())\
56 .order_by('aliases__name')
56 .order_by('aliases__name')
57
57
58 def get_tag_url_list(self, tags: list) -> str:
58 def get_tag_url_list(self, tags: list) -> str:
@@ -138,7 +138,7 b' class Tag(models.Model, Viewable):'
138 return '{}_{}'.format(self.id, get_language())
138 return '{}_{}'.format(self.id, get_language())
139
139
140 @cached_result(key_method=_get_locale_cache_key)
140 @cached_result(key_method=_get_locale_cache_key)
141 def get_view(self):
141 def get_localized_name(self):
142 locale = get_language()
142 locale = get_language()
143
143
144 aliases = self.aliases.filter(Q(locale=locale) | Q(locale=DEFAULT_LOCALE))
144 aliases = self.aliases.filter(Q(locale=locale) | Q(locale=DEFAULT_LOCALE))
@@ -152,7 +152,10 b' class Tag(models.Model, Viewable):'
152 elif alias.locale == DEFAULT_LOCALE:
152 elif alias.locale == DEFAULT_LOCALE:
153 default_tag_name = alias.name
153 default_tag_name = alias.name
154
154
155 name = localized_tag_name if localized_tag_name else default_tag_name
155 return localized_tag_name if localized_tag_name else default_tag_name
156
157 def get_view(self):
158 name = self.get_localized_name()
156 link = '<a class="tag" href="{}">{}</a>'.format(
159 link = '<a class="tag" href="{}">{}</a>'.format(
157 self.get_absolute_url(), name)
160 self.get_absolute_url(), name)
158 if self.is_required():
161 if self.is_required():
@@ -175,7 +178,7 b' class Tag(models.Model, Viewable):'
175 return posts.order_by('?').first()
178 return posts.order_by('?').first()
176
179
177 def get_first_letter(self):
180 def get_first_letter(self):
178 name = self.get_name()
181 name = self.get_localized_name()
179 return name and name[0] or ''
182 return name and name[0] or ''
180
183
181 def get_related_tags(self):
184 def get_related_tags(self):
General Comments 0
You need to be logged in to leave comments. Login now