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 | required_tag_exists = False |
|
464 | required_tag_exists = False | |
465 | tag_set = set() |
|
465 | tag_set = set() | |
466 | for tag_string in tags.split(): |
|
466 | for tag_string in tags.split(): | |
467 |
|
|
467 | tag_name = tag_string.strip().lower() | |
|
468 | if tag_name == default_tag_name: | |||
468 | required_tag_exists = True |
|
469 | required_tag_exists = True | |
469 | tag, created = Tag.objects.get_or_create( |
|
470 | tag, created = Tag.objects.get_or_create( | |
470 |
name=tag_ |
|
471 | name=tag_name, required=True) | |
471 | else: |
|
472 | else: | |
472 |
tag |
|
473 | tag = Tag.objects.get_by_alias(tag_name) | |
473 | name=tag_string.strip().lower()) |
|
474 | if tag: | |
|
475 | created = False | |||
|
476 | else: | |||
|
477 | tag, created = Tag.objects.get_or_create( | |||
|
478 | name=tag_name) | |||
474 | tag_set.add(tag) |
|
479 | tag_set.add(tag) | |
475 |
|
480 | |||
476 | # If this is a new tag, don't check for its parents because nobody |
|
481 | # If this is a new tag, don't check for its parents because nobody |
@@ -1,9 +1,12 b'' | |||||
1 | import hashlib |
|
1 | import hashlib | |
|
2 | import re | |||
|
3 | ||||
2 | from boards.models.attachment import FILE_TYPES_IMAGE |
|
4 | from boards.models.attachment import FILE_TYPES_IMAGE | |
3 | from django.template.loader import render_to_string |
|
5 | from django.template.loader import render_to_string | |
4 | from django.db import models |
|
6 | from django.db import models | |
5 | from django.db.models import Count |
|
7 | from django.db.models import Count | |
6 | from django.core.urlresolvers import reverse |
|
8 | from django.core.urlresolvers import reverse | |
|
9 | from django.utils.translation import get_language | |||
7 |
|
10 | |||
8 | from boards.models import Attachment |
|
11 | from boards.models import Attachment | |
9 | from boards.models.base import Viewable |
|
12 | from boards.models.base import Viewable | |
@@ -16,9 +19,10 b' import boards' | |||||
16 |
|
19 | |||
17 | RELATED_TAGS_COUNT = 5 |
|
20 | RELATED_TAGS_COUNT = 5 | |
18 |
|
21 | |||
|
22 | REGEX_TAG_ALIAS = r'{}:(\w+),' | |||
|
23 | ||||
19 |
|
24 | |||
20 | class TagManager(models.Manager): |
|
25 | class TagManager(models.Manager): | |
21 |
|
||||
22 | def get_not_empty_tags(self): |
|
26 | def get_not_empty_tags(self): | |
23 | """ |
|
27 | """ | |
24 | Gets tags that have non-archived threads. |
|
28 | Gets tags that have non-archived threads. | |
@@ -34,6 +38,9 b' class TagManager(models.Manager):' | |||||
34 |
|
38 | |||
35 | return ', '.join([tag.get_view() for tag in tags]) |
|
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 | class Tag(models.Model, Viewable): |
|
45 | class Tag(models.Model, Viewable): | |
39 | """ |
|
46 | """ | |
@@ -53,6 +60,7 b' class Tag(models.Model, Viewable):' | |||||
53 |
|
60 | |||
54 | parent = models.ForeignKey('Tag', null=True, blank=True, |
|
61 | parent = models.ForeignKey('Tag', null=True, blank=True, | |
55 | related_name='children') |
|
62 | related_name='children') | |
|
63 | aliases = models.TextField(blank=True) | |||
56 |
|
64 | |||
57 | def __str__(self): |
|
65 | def __str__(self): | |
58 | return self.name |
|
66 | return self.name | |
@@ -89,8 +97,17 b' class Tag(models.Model, Viewable):' | |||||
89 | return self.required |
|
97 | return self.required | |
90 |
|
98 | |||
91 | def get_view(self): |
|
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 | link = '<a class="tag" href="{}">{}</a>'.format( |
|
109 | link = '<a class="tag" href="{}">{}</a>'.format( | |
93 |
self.get_absolute_url(), |
|
110 | self.get_absolute_url(), localized_tag_name) | |
94 | if self.is_required(): |
|
111 | if self.is_required(): | |
95 | link = '<b>{}</b>'.format(link) |
|
112 | link = '<b>{}</b>'.format(link) | |
96 | return link |
|
113 | return link |
General Comments 0
You need to be logged in to leave comments.
Login now