Show More
@@ -0,0 +1,20 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | # Generated by Django 1.10.5 on 2017-02-24 19:40 | |
|
3 | from __future__ import unicode_literals | |
|
4 | ||
|
5 | from django.db import migrations, models | |
|
6 | ||
|
7 | ||
|
8 | class Migration(migrations.Migration): | |
|
9 | ||
|
10 | dependencies = [ | |
|
11 | ('boards', '0056_auto_20170123_1620'), | |
|
12 | ] | |
|
13 | ||
|
14 | operations = [ | |
|
15 | migrations.AddField( | |
|
16 | model_name='tag', | |
|
17 | name='aliases', | |
|
18 | field=models.TextField(blank=True), | |
|
19 | ), | |
|
20 | ] |
@@ -464,13 +464,18 b' class ThreadForm(PostForm):' | |||
|
464 | 464 | required_tag_exists = False |
|
465 | 465 | tag_set = set() |
|
466 | 466 | for tag_string in tags.split(): |
|
467 |
|
|
|
467 | tag_name = tag_string.strip().lower() | |
|
468 | if tag_name == default_tag_name: | |
|
468 | 469 | required_tag_exists = True |
|
469 | 470 | tag, created = Tag.objects.get_or_create( |
|
470 |
name=tag_ |
|
|
471 | name=tag_name, required=True) | |
|
471 | 472 | else: |
|
472 |
tag |
|
|
473 | name=tag_string.strip().lower()) | |
|
473 | tag = Tag.objects.get_by_alias(tag_name) | |
|
474 | if tag: | |
|
475 | created = False | |
|
476 | else: | |
|
477 | tag, created = Tag.objects.get_or_create( | |
|
478 | name=tag_name) | |
|
474 | 479 | tag_set.add(tag) |
|
475 | 480 | |
|
476 | 481 | # If this is a new tag, don't check for its parents because nobody |
@@ -1,9 +1,12 b'' | |||
|
1 | 1 | import hashlib |
|
2 | import re | |
|
3 | ||
|
2 | 4 | from boards.models.attachment import FILE_TYPES_IMAGE |
|
3 | 5 | from django.template.loader import render_to_string |
|
4 | 6 | from django.db import models |
|
5 | 7 | from django.db.models import Count |
|
6 | 8 | from django.core.urlresolvers import reverse |
|
9 | from django.utils.translation import get_language | |
|
7 | 10 | |
|
8 | 11 | from boards.models import Attachment |
|
9 | 12 | from boards.models.base import Viewable |
@@ -16,9 +19,10 b' import boards' | |||
|
16 | 19 | |
|
17 | 20 | RELATED_TAGS_COUNT = 5 |
|
18 | 21 | |
|
22 | REGEX_TAG_ALIAS = r'{}:(\w+),' | |
|
23 | ||
|
19 | 24 | |
|
20 | 25 | class TagManager(models.Manager): |
|
21 | ||
|
22 | 26 | def get_not_empty_tags(self): |
|
23 | 27 | """ |
|
24 | 28 | Gets tags that have non-archived threads. |
@@ -34,6 +38,9 b' class TagManager(models.Manager):' | |||
|
34 | 38 | |
|
35 | 39 | return ', '.join([tag.get_view() for tag in tags]) |
|
36 | 40 | |
|
41 | def get_by_alias(self, alias): | |
|
42 | return self.filter(aliases__contains=":{},".format(alias)).first() | |
|
43 | ||
|
37 | 44 | |
|
38 | 45 | class Tag(models.Model, Viewable): |
|
39 | 46 | """ |
@@ -53,6 +60,7 b' class Tag(models.Model, Viewable):' | |||
|
53 | 60 | |
|
54 | 61 | parent = models.ForeignKey('Tag', null=True, blank=True, |
|
55 | 62 | related_name='children') |
|
63 | aliases = models.TextField(blank=True) | |
|
56 | 64 | |
|
57 | 65 | def __str__(self): |
|
58 | 66 | return self.name |
@@ -89,8 +97,17 b' class Tag(models.Model, Viewable):' | |||
|
89 | 97 | return self.required |
|
90 | 98 | |
|
91 | 99 | def get_view(self): |
|
100 | locale = get_language() | |
|
101 | ||
|
102 | if self.aliases: | |
|
103 | match = re.search(REGEX_TAG_ALIAS.format(locale), self.aliases) | |
|
104 | if match: | |
|
105 | localized_tag_name = match.group(1) | |
|
106 | else: | |
|
107 | localized_tag_name = self.name | |
|
108 | ||
|
92 | 109 | link = '<a class="tag" href="{}">{}</a>'.format( |
|
93 |
self.get_absolute_url(), |
|
|
110 | self.get_absolute_url(), localized_tag_name) | |
|
94 | 111 | if self.is_required(): |
|
95 | 112 | link = '<b>{}</b>'.format(link) |
|
96 | 113 | return link |
General Comments 0
You need to be logged in to leave comments.
Login now