Commit 1ae741fb6f6a02c95545c992493ee635f511d130

Authored by Sergio Oliveira
1 parent eaa3aa9f

Adding related messages. closes #40 and #43

requirements.txt
... ... @@ -10,6 +10,7 @@ django-cliauth==0.9
10 10 django-mobile==0.3.0
11 11 etiquetando==0.1
12 12 html2text
  13 +django-taggit
13 14  
14 15 gunicorn
15 16 gevent
... ... @@ -28,7 +29,6 @@ django-conversejs
28 29 # Feedzilla (planet) and deps
29 30 feedzilla==0.22
30 31 django-common
31   -django-taggit
32 32 feedparser
33 33 lxml
34 34 grab
... ... @@ -37,4 +37,3 @@ transliterate
37 37 # Diazo
38 38 #diazo
39 39 git+https://github.com/TracyWebTech/diazo@escape_curly_brackets
40   -#lxml
... ...
src/super_archives/models.py
... ... @@ -12,6 +12,7 @@ from django.core.urlresolvers import reverse, NoReverseMatch
12 12 from django.utils.translation import ugettext_lazy as _
13 13  
14 14 from html2text import html2text
  15 +from taggit.managers import TaggableManager
15 16  
16 17 from .utils import blocks
17 18 from .utils.etiquetador import etiquetador
... ... @@ -117,6 +118,7 @@ class Thread(models.Model):
117 118  
118 119 all_objects = models.Manager()
119 120 objects = NotSpamManager()
  121 + tags = TaggableManager()
120 122  
121 123 class Meta:
122 124 verbose_name = _(u"Thread")
... ... @@ -127,6 +129,8 @@ class Thread(models.Model):
127 129 blocks = MessageBlock.objects.filter(message__thread__pk=self.pk,
128 130 is_reply=False)
129 131  
  132 + self.tags.clear()
  133 +
130 134 text = u'\n'.join(map(unicode, blocks))
131 135 tags = etiquetador(html2text(text))
132 136  
... ... @@ -137,10 +141,18 @@ class Thread(models.Model):
137 141 keyword.weight = weight
138 142 keyword.save()
139 143  
140   - # removing old tags
141   - qs = Keyword.objects.filter(thread=self)
142   - qs = qs.exclude(keyword__in=zip(*tags)[0])
143   - qs.delete()
  144 + if weight >= 3:
  145 + self.tags.add(tag)
  146 +
  147 + # removing old tags not used anylonger
  148 + if tags:
  149 + qs = Keyword.objects.filter(thread=self)
  150 + qs = qs.exclude(keyword__in=zip(*tags)[0])
  151 + qs.delete()
  152 +
  153 + def save(self, *args, **kwargs):
  154 + super(Thread, self).save(*args, **kwargs)
  155 + self.update_keywords()
144 156  
145 157 def __unicode__(self):
146 158 return '%s - %s (%s)' % (self.id,
... ...
src/super_archives/templates/message-thread.html
... ... @@ -96,7 +96,7 @@
96 96 <hr />
97 97 </div>
98 98  
99   - <div class="col-lg-10 col-md-10 col-sm-12">
  99 + <div class="col-lg-9 col-md-9 col-sm-12">
100 100 <ul class="unstyled-list">
101 101 {% for email in emails %}
102 102 {% with email.from_address.user.get_absolute_url as profile_link %}
... ... @@ -152,7 +152,7 @@
152 152 </ul>
153 153 </div>
154 154  
155   - <div class="col-lg-2 col-md-2 hidden-sm hidden-xs">
  155 + <div class="col-lg-3 col-md-3 hidden-sm hidden-xs">
156 156 <h4><strong>{% trans "Order by" %}:</strong></h4>
157 157 <ul class="unstyled-list">
158 158 <li>
... ... @@ -165,8 +165,21 @@
165 165 </li>
166 166 </ul>
167 167  
168   - <h4><strong>{% trans "Statistics:" %}</strong></h4>
  168 + {% if thread.tags.similar_objects %}
  169 + <h4><strong>{% trans "Releated:" %}</strong></h4>
  170 + <ul class="unstyled-list">
  171 + {% for similar in thread.tags.similar_objects|slice:":10" %}
  172 + {% with similar.message_set.first as message %}
  173 + <li>
  174 + <span class="label label-primary label-small">{{ similar.mailinglist.name }}</span>
  175 + <a href="{% url 'thread_view' similar.mailinglist.name similar.subject_token %}">{{ message.subject_clean|truncatechars:50 }}</a>
  176 + </li>
  177 + {% endwith %}
  178 + {% endfor %}
  179 + </ul>
  180 + {% endif %}
169 181  
  182 + <h4><strong>{% trans "Statistics:" %}</strong></h4>
170 183 <ul class="unstyled-list">
171 184 <li>
172 185 <span class="glyphicon glyphicon-chevron-right"></span>
... ... @@ -189,16 +202,17 @@
189 202 {% trans "voted" %}
190 203 <h5>{{ total_votes }} {% trans "times" %}</h5>
191 204 </li>
192   - <li>
193   - <span class="glyphicon glyphicon-chevron-right"></span>
194   - {% trans "tags" %}
195   - <div class="tag-cloud">
196   - {% for keyword in thread.keyword_set.iterator %}
197   - <a class="tag size-{{ keyword.weight }}" href="#">{{ keyword|escape }}</a>
198   - {% endfor %}
199   - </div>
200   - </li>
201 205 </ul>
  206 +
  207 + {% if thread.keyword_set.count %}
  208 + <h4><strong>{% trans "Tags:" %}</strong></h4>
  209 + <div class="tag-cloud">
  210 + {% for keyword in thread.keyword_set.all %}
  211 + <a class="tag size-{{ keyword.weight }}" href="#">{{ keyword|escape }}</a>
  212 + {% endfor %}
  213 + </div>
  214 + {% endif %}
  215 +
202 216 </div>
203 217  
204 218 </div>
... ...