Show More
@@ -0,0 +1,77 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | import datetime | |||
|
3 | from south.db import db | |||
|
4 | from south.v2 import SchemaMigration | |||
|
5 | from django.db import models | |||
|
6 | ||||
|
7 | ||||
|
8 | class Migration(SchemaMigration): | |||
|
9 | ||||
|
10 | def forwards(self, orm): | |||
|
11 | # Adding M2M table for field threads on 'Tag' | |||
|
12 | m2m_table_name = db.shorten_name(u'boards_tag_threads') | |||
|
13 | db.create_table(m2m_table_name, ( | |||
|
14 | ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), | |||
|
15 | ('tag', models.ForeignKey(orm[u'boards.tag'], null=False)), | |||
|
16 | ('post', models.ForeignKey(orm[u'boards.post'], null=False)) | |||
|
17 | )) | |||
|
18 | db.create_unique(m2m_table_name, ['tag_id', 'post_id']) | |||
|
19 | ||||
|
20 | ||||
|
21 | def backwards(self, orm): | |||
|
22 | # Removing M2M table for field threads on 'Tag' | |||
|
23 | db.delete_table(db.shorten_name(u'boards_tag_threads')) | |||
|
24 | ||||
|
25 | ||||
|
26 | models = { | |||
|
27 | u'boards.ban': { | |||
|
28 | 'Meta': {'object_name': 'Ban'}, | |||
|
29 | u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |||
|
30 | 'ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}) | |||
|
31 | }, | |||
|
32 | u'boards.post': { | |||
|
33 | 'Meta': {'object_name': 'Post'}, | |||
|
34 | '_text_rendered': ('django.db.models.fields.TextField', [], {}), | |||
|
35 | u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |||
|
36 | 'image': ('boards.thumbs.ImageWithThumbsField', [], {'max_length': '100', 'blank': 'True'}), | |||
|
37 | 'image_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), | |||
|
38 | 'image_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}), | |||
|
39 | 'last_edit_time': ('django.db.models.fields.DateTimeField', [], {}), | |||
|
40 | 'parent': ('django.db.models.fields.BigIntegerField', [], {'default': '-1'}), | |||
|
41 | 'poster_ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}), | |||
|
42 | 'poster_user_agent': ('django.db.models.fields.TextField', [], {}), | |||
|
43 | 'pub_time': ('django.db.models.fields.DateTimeField', [], {}), | |||
|
44 | 'replies': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'re+'", 'null': 'True', 'symmetrical': 'False', 'to': u"orm['boards.Post']"}), | |||
|
45 | 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['boards.Tag']", 'symmetrical': 'False'}), | |||
|
46 | 'text': ('markupfield.fields.MarkupField', [], {'rendered_field': 'True'}), | |||
|
47 | 'text_markup_type': ('django.db.models.fields.CharField', [], {'default': "'markdown'", 'max_length': '30'}), | |||
|
48 | 'thread': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': u"orm['boards.Post']", 'null': 'True'}), | |||
|
49 | 'title': ('django.db.models.fields.CharField', [], {'max_length': '50'}), | |||
|
50 | 'user': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': u"orm['boards.User']", 'null': 'True'}) | |||
|
51 | }, | |||
|
52 | u'boards.setting': { | |||
|
53 | 'Meta': {'object_name': 'Setting'}, | |||
|
54 | u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |||
|
55 | 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}), | |||
|
56 | 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['boards.User']"}), | |||
|
57 | 'value': ('django.db.models.fields.CharField', [], {'max_length': '50'}) | |||
|
58 | }, | |||
|
59 | u'boards.tag': { | |||
|
60 | 'Meta': {'object_name': 'Tag'}, | |||
|
61 | u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |||
|
62 | 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | |||
|
63 | 'threads': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'tag+'", 'null': 'True', 'symmetrical': 'False', 'to': u"orm['boards.Post']"}) | |||
|
64 | }, | |||
|
65 | u'boards.user': { | |||
|
66 | 'Meta': {'object_name': 'User'}, | |||
|
67 | 'fav_tags': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['boards.Tag']", 'null': 'True', 'blank': 'True'}), | |||
|
68 | 'fav_threads': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'symmetrical': 'False', 'to': u"orm['boards.Post']"}), | |||
|
69 | u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |||
|
70 | 'last_access_time': ('django.db.models.fields.DateTimeField', [], {}), | |||
|
71 | 'rank': ('django.db.models.fields.IntegerField', [], {}), | |||
|
72 | 'registration_time': ('django.db.models.fields.DateTimeField', [], {}), | |||
|
73 | 'user_id': ('django.db.models.fields.CharField', [], {'max_length': '50'}) | |||
|
74 | } | |||
|
75 | } | |||
|
76 | ||||
|
77 | complete_apps = ['boards'] No newline at end of file |
@@ -140,13 +140,8 b' class PostManager(models.Manager):' | |||||
140 | class TagManager(models.Manager): |
|
140 | class TagManager(models.Manager): | |
141 |
|
141 | |||
142 | def get_not_empty_tags(self): |
|
142 | def get_not_empty_tags(self): | |
143 | all_tags = self.all().order_by('name') |
|
143 | tags = self.annotate(Count('threads')) \ | |
144 | tags = [] |
|
144 | .filter(threads__count__gt=0).order_by('name') | |
145 |
|
||||
146 | # TODO Use query here |
|
|||
147 | for tag in all_tags: |
|
|||
148 | if not tag.is_empty(): |
|
|||
149 | tags.append(tag) |
|
|||
150 |
|
145 | |||
151 | return tags |
|
146 | return tags | |
152 |
|
147 | |||
@@ -160,6 +155,8 b' class Tag(models.Model):' | |||||
160 | objects = TagManager() |
|
155 | objects = TagManager() | |
161 |
|
156 | |||
162 | name = models.CharField(max_length=100) |
|
157 | name = models.CharField(max_length=100) | |
|
158 | threads = models.ManyToManyField('Post', null=True, | |||
|
159 | blank=True, related_name='tag+') | |||
163 |
|
160 | |||
164 | def __unicode__(self): |
|
161 | def __unicode__(self): | |
165 | return self.name |
|
162 | return self.name | |
@@ -168,8 +165,7 b' class Tag(models.Model):' | |||||
168 | return self.get_post_count() == 0 |
|
165 | return self.get_post_count() == 0 | |
169 |
|
166 | |||
170 | def get_post_count(self): |
|
167 | def get_post_count(self): | |
171 | posts_with_tag = Post.objects.get_threads(tag=self) |
|
168 | return self.threads.count() | |
172 | return posts_with_tag.count() |
|
|||
173 |
|
169 | |||
174 | def get_popularity(self): |
|
170 | def get_popularity(self): | |
175 | posts_with_tag = Post.objects.get_threads(tag=self) |
|
171 | posts_with_tag = Post.objects.get_threads(tag=self) | |
@@ -303,7 +299,10 b' class User(models.Model):' | |||||
303 | return RANK_MODERATOR >= self.rank |
|
299 | return RANK_MODERATOR >= self.rank | |
304 |
|
300 | |||
305 | def get_sorted_fav_tags(self): |
|
301 | def get_sorted_fav_tags(self): | |
306 |
|
|
302 | tags = self.fav_tags.annotate(Count('threads'))\ | |
|
303 | .filter(threads__count__gt=0).order_by('name') | |||
|
304 | ||||
|
305 | return tags | |||
307 |
|
306 | |||
308 | def __unicode__(self): |
|
307 | def __unicode__(self): | |
309 | return self.user_id + '(' + str(self.rank) + ')' |
|
308 | return self.user_id + '(' + str(self.rank) + ')' |
@@ -28,10 +28,8 b'' | |||||
28 | <div class="navigation_panel"> |
|
28 | <div class="navigation_panel"> | |
29 | <a class="link" href="{% url 'index' %}">{% trans "All threads" %}</a> |
|
29 | <a class="link" href="{% url 'index' %}">{% trans "All threads" %}</a> | |
30 | {% for tag in tags %} |
|
30 | {% for tag in tags %} | |
31 | {% if not tag.is_empty %} |
|
31 | <a class="tag" href="{% url 'tag' tag_name=tag.name %}" | |
32 | <a class="tag" href="{% url 'tag' tag_name=tag.name %}" |
|
32 | >{{ tag.name }}</a> | |
33 | >{{ tag.name }}</a> |
|
|||
34 | {% endif %} |
|
|||
35 | {% endfor %} |
|
33 | {% endfor %} | |
36 | <a class="tag" href="{% url 'tags' %}" alt="{% trans 'Tag management' %}" |
|
34 | <a class="tag" href="{% url 'tags' %}" alt="{% trans 'Tag management' %}" | |
37 | >[...]</a> |
|
35 | >[...]</a> |
@@ -55,7 +55,7 b'' | |||||
55 | [<a class="link" href="{% url 'thread' thread.thread.id %}#form" |
|
55 | [<a class="link" href="{% url 'thread' thread.thread.id %}#form" | |
56 | >{% trans "Reply" %}</a>] |
|
56 | >{% trans "Reply" %}</a>] | |
57 |
|
57 | |||
58 |
{% if |
|
58 | {% if moderator %} | |
59 | <span class="moderator_info"> |
|
59 | <span class="moderator_info"> | |
60 | [<a href="{% url 'delete' post_id=thread.thread.id %}?next={{ request.path }}" |
|
60 | [<a href="{% url 'delete' post_id=thread.thread.id %}?next={{ request.path }}" | |
61 | >{% trans 'Delete' %}</a>] |
|
61 | >{% trans 'Delete' %}</a>] |
@@ -39,7 +39,7 b'' | |||||
39 | [<a href="#" onclick="javascript:addQuickReply('{{ post.id }}') |
|
39 | [<a href="#" onclick="javascript:addQuickReply('{{ post.id }}') | |
40 | ; return false;">>></a>] |
|
40 | ; return false;">>></a>] | |
41 |
|
41 | |||
42 |
{% if |
|
42 | {% if moderator %} | |
43 | <span class="moderator_info"> |
|
43 | <span class="moderator_info"> | |
44 | [<a href="{% url 'delete' post_id=post.id %}" |
|
44 | [<a href="{% url 'delete' post_id=post.id %}" | |
45 | >{% trans 'Delete' %}</a>] |
|
45 | >{% trans 'Delete' %}</a>] |
@@ -318,6 +318,7 b' def _init_default_context(request):' | |||||
318 | context['user'] = user |
|
318 | context['user'] = user | |
319 | context['tags'] = user.get_sorted_fav_tags() |
|
319 | context['tags'] = user.get_sorted_fav_tags() | |
320 | context['theme'] = _get_theme(request, user) |
|
320 | context['theme'] = _get_theme(request, user) | |
|
321 | context['moderator'] = user.is_moderator() | |||
321 |
|
322 | |||
322 | return context |
|
323 | return context | |
323 |
|
324 |
General Comments 0
You need to be logged in to leave comments.
Login now