Commit 183cb97cc606d48c359507833db1a915d1ea4047

Authored by Luan
1 parent dacfcb1a

Normalizing superarchives models #52

src/accounts/templates/accounts/user_detail.html
@@ -91,7 +91,7 @@ @@ -91,7 +91,7 @@
91 <h3>{% trans "Latest posted" %} </h3> 91 <h3>{% trans "Latest posted" %} </h3>
92 <ul class="message-list"> 92 <ul class="message-list">
93 {% for doc in emails %} 93 {% for doc in emails %}
94 - {% include "message-preview.html" %} 94 + {% include "message-preview.html" with result=doc %}
95 {% empty %} 95 {% empty %}
96 <li>{% trans "There are no posts by this user so far." %}</li> 96 <li>{% trans "There are no posts by this user so far." %}</li>
97 {% endfor %} 97 {% endfor %}
@@ -102,7 +102,7 @@ @@ -102,7 +102,7 @@
102 <h3>{% trans "Community inside participations" %}</h3> 102 <h3>{% trans "Community inside participations" %}</h3>
103 <ul class="message-list"> 103 <ul class="message-list">
104 {% for result in results %} 104 {% for result in results %}
105 - {% include "search/preview-search.html" %} 105 + {% include "message-preview.html" %}
106 {% empty %} 106 {% empty %}
107 <li>{% trans "No contributions of this user so far." %}</li> 107 <li>{% trans "No contributions of this user so far." %}</li>
108 {% endfor %} 108 {% endfor %}
src/super_archives/models.py
@@ -283,7 +283,7 @@ class Message(models.Model): @@ -283,7 +283,7 @@ class Message(models.Model):
283 283
284 @property 284 @property
285 def mailinglist(self): 285 def mailinglist(self):
286 - if not self.thread or not self.thread.mailinglist: 286 + if not self.thread:
287 return None 287 return None
288 288
289 return self.thread.mailinglist 289 return self.thread.mailinglist
@@ -314,12 +314,12 @@ class Message(models.Model): @@ -314,12 +314,12 @@ class Message(models.Model):
314 self.thread.subject_token]) 314 self.thread.subject_token])
315 315
316 @property 316 @property
317 - def Description(self): 317 + def description(self):
318 """Alias to self.body""" 318 """Alias to self.body"""
319 return self.body 319 return self.body
320 320
321 @property 321 @property
322 - def Title(self): 322 + def title(self):
323 """Alias to self.subject_clean""" 323 """Alias to self.subject_clean"""
324 return self.subject_clean 324 return self.subject_clean
325 325
@@ -328,6 +328,28 @@ class Message(models.Model): @@ -328,6 +328,28 @@ class Message(models.Model):
328 """Alias to self.modified""" 328 """Alias to self.modified"""
329 return self.received_time 329 return self.received_time
330 330
  331 + @property
  332 + def tag(self):
  333 + if not self.thread:
  334 + return None
  335 + return self.mailinglist.name
  336 +
  337 + @property
  338 + def author(self):
  339 + return self.from_address.get_full_name()
  340 +
  341 + @property
  342 + def author_url(self):
  343 + return self.from_address.user.get_absolute_url()
  344 +
  345 + @property
  346 + def icon_name(self):
  347 + return u'envelope'
  348 +
  349 + @property
  350 + def type(self):
  351 + return u'thread'
  352 +
331 353
332 class MessageBlock(models.Model): 354 class MessageBlock(models.Model):
333 message = models.ForeignKey(Message, related_name='blocks') 355 message = models.ForeignKey(Message, related_name='blocks')
src/super_archives/templates/message-list.html
@@ -50,7 +50,7 @@ @@ -50,7 +50,7 @@
50 <div class="col-xs-12 col-sm-12 col-md-10 col-lg-10"> 50 <div class="col-xs-12 col-sm-12 col-md-10 col-lg-10">
51 <ul class="unstyled-list"> 51 <ul class="unstyled-list">
52 {% for thread in threads.object_list %} 52 {% for thread in threads.object_list %}
53 - {% include "message-preview.html" with doc=thread.latest_message %} 53 + {% include "message-preview.html" with result=thread.latest_message %}
54 {% empty %} 54 {% empty %}
55 <br/><br/> 55 <br/><br/>
56 <span> 56 <span>
src/super_archives/templates/message-preview.html
1 {% load i18n %} 1 {% load i18n %}
  2 +{% load highlight %}
2 3
3 -{% if doc.Title %}  
4 <li class="preview-message"> 4 <li class="preview-message">
5 - {% if doc.Type %}  
6 - <img alt="{{ doc.Type }}" title="{{ doc.Type }}"  
7 - src="{{ STATIC_URL }}img/{{ doc.Type }}.png" />  
8 - {% else %}  
9 - <span class="glyphicon glyphicon-envelope"></span>  
10 - {% endif %} 5 +<span class="glyphicon glyphicon-{{ result.icon_name }}" title="{{ result.type }}"></span>
11 6
12 - {% if doc.mailinglist %}  
13 - <a href="{% url 'super_archives.views.list_messages' %}?list={{ doc.mailinglist }}">  
14 - <span class="label label-primary">{{ doc.mailinglist }}</span>  
15 - </a>  
16 - {% endif %}  
17 -  
18 - <span class="subject">  
19 - <a href="{{ doc.url }}#msg-{{ doc.id }}"  
20 - {% if  
21 - title="{% filter striptags|truncatewords:50 %}  
22 - {{ doc.Description|escape }}  
23 - {% endfilter %}">  
24 - {{ doc.Title }}  
25 - </a>  
26 - </span>  
27 -  
28 - <span class="quiet">-  
29 - {{ doc.Description|striptags }}  
30 - </span>  
31 -  
32 - <div class="quiet">  
33 - <span class="pull-left">  
34 - {% if doc.from_address.user.get_absolute_url or doc.from_address.get_full_name or doc.last_author or doc.Creator %}  
35 - {% trans "by" %}  
36 - {% endif %} 7 +{% if result.tag %}
  8 +<a href="{% firstof result.mailinglist_url result.url %}">
  9 + <span class="label label-primary">{{ result.tag }}</span>
  10 +</a>
  11 +{% endif %}
37 12
38 - {% if doc.from_address.user.get_absolute_url %}  
39 - <a href="{{ doc.from_address.user.get_absolute_url }}">  
40 - {{ doc.from_address.user.get_full_name }}  
41 - </a>  
42 - {% elif doc.from_address.get_full_name %}  
43 - <span>{{ doc.from_address.get_full_name }}</span> 13 +{% if result.title %}
  14 + <a href="{{ result.url }}" {% if result.description %}title="{{ result.description|escape|truncatechars:200 }}"{% endif %}>
  15 + <span class="subject">
  16 + <!-- a striptags filter was raising an error here because using with highlight -->
  17 + {% if query %}
  18 + {% highlight result.title with query max_length "1000" %}
44 {% else %} 19 {% else %}
45 - {% firstof doc.last_author doc.Creator "" %} 20 + {{ result.title }}
46 {% endif %} 21 {% endif %}
47 </span> 22 </span>
  23 + </a>
  24 +{% endif %}
48 25
49 - <span class="pull-right">  
50 - {{ doc.modified|timesince }}  
51 - {% trans "ago" %}  
52 - </span> 26 +{% if result.description %}
  27 + <!-- a striptags filter was raising an error here because using with highlight -->
  28 + <span class="quiet">- {% if query %}{% highlight result.description with query max_length "150" %}{% else %}{{ result.description }}{% endif %}</span>
  29 +{% endif %}
  30 +
  31 +{% if result.author or result.modified %}
  32 + <div class="quiet">
  33 + {% if result.author %}
  34 + <span class="pull-left">{% trans "by" %}
  35 + {% if result.author and result.author_url %}
  36 + <a href="{{ result.author_url }}">
  37 + {% if query %}
  38 + {% highlight result.author with query %}
  39 + {% else %}
  40 + {{ result.author }}
  41 + {% endif %}
  42 + </a>
  43 + {% else %}
  44 + <span>{{ result.author }}</span>
  45 + {% endif %}
  46 + </span>
  47 + {% endif %}
  48 + {% if result.modified %}
  49 + <span class="pull-right">{{ result.modified|timesince }} {% trans "ago" %}</span>
  50 + {% endif %}
53 </div> 51 </div>
54 -</li>  
55 {% endif %} 52 {% endif %}
  53 +</li>
src/templates/home.html
@@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
22 </a> 22 </a>
23 <ul class="message-list"> 23 <ul class="message-list">
24 {% for result in latest_results %} 24 {% for result in latest_results %}
25 - {% include "search/preview-search.html" %} 25 + {% include "message-preview.html" %}
26 {% endfor %} 26 {% endfor %}
27 </ul> 27 </ul>
28 <a class="column-align" 28 <a class="column-align"
@@ -50,7 +50,7 @@ @@ -50,7 +50,7 @@
50 </a> 50 </a>
51 <ul class="message-list"> 51 <ul class="message-list">
52 {% for thread in hottest_threads %} 52 {% for thread in hottest_threads %}
53 - {% include "message-preview.html" with doc=thread.latest_message %} 53 + {% include "message-preview.html" with result=thread.latest_message %}
54 {% endfor %} 54 {% endfor %}
55 </ul> 55 </ul>
56 <a class="column-align" 56 <a class="column-align"
@@ -70,7 +70,7 @@ @@ -70,7 +70,7 @@
70 </a> 70 </a>
71 <ul class="message-list"> 71 <ul class="message-list">
72 {% for thread in latest_threads %} 72 {% for thread in latest_threads %}
73 - {% include "message-preview.html" with doc=thread.latest_message %} 73 + {% include "message-preview.html" with result=thread.latest_message %}
74 {% endfor %} 74 {% endfor %}
75 </ul> 75 </ul>
76 <a class="column-align" href="{% url 'thread_list' %}"> 76 <a class="column-align" href="{% url 'thread_list' %}">
src/templates/search/preview-search.html
@@ -1,53 +0,0 @@ @@ -1,53 +0,0 @@
1 -{% load i18n %}  
2 -{% load highlight %}  
3 -  
4 -<li class="preview-message">  
5 -<span class="glyphicon glyphicon-{{ result.icon_name }}" title="{{ result.type }}"></span>  
6 -  
7 -{% if result.tag %}  
8 -<a href="{% firstof result.mailinglist_url result.url %}">  
9 - <span class="label label-primary">{{ result.tag }}</span>  
10 -</a>  
11 -{% endif %}  
12 -  
13 -{% if result.title %}  
14 - <a href="{{ result.url }}" {% if result.description %}title="{{ result.description|escape|truncatechars:200 }}"{% endif %}>  
15 - <span class="subject">  
16 - <!-- a striptags filter was raising an error here because using with highlight -->  
17 - {% if query %}  
18 - {% highlight result.title with query max_length "1000" %}  
19 - {% else %}  
20 - {{ result.title }}  
21 - {% endif %}  
22 - </span>  
23 - </a>  
24 -{% endif %}  
25 -  
26 -{% if result.description %}  
27 - <!-- a striptags filter was raising an error here because using with highlight -->  
28 - <span class="quiet">- {% if query %}{% highlight result.description with query max_length "150" %}{% else %}{{ result.description }}{% endif %}</span>  
29 -{% endif %}  
30 -  
31 -{% if result.author or result.modified %}  
32 - <div class="quiet">  
33 - {% if result.author %}  
34 - <span class="pull-left">{% trans "by" %}  
35 - {% if result.author and result.author_url %}  
36 - <a href="{{ result.author_url }}">  
37 - {% if query %}  
38 - {% highlight result.author with query %}  
39 - {% else %}  
40 - {{ result.author }}  
41 - {% endif %}  
42 - </a>  
43 - {% else %}  
44 - <span>{{ result.author }}</span>  
45 - {% endif %}  
46 - </span>  
47 - {% endif %}  
48 - {% if result.modified %}  
49 - <span class="pull-right">{{ result.modified|timesince }} {% trans "ago" %}</span>  
50 - {% endif %}  
51 - </div>  
52 -{% endif %}  
53 -</li>  
src/templates/search/search.html
@@ -214,7 +214,7 @@ @@ -214,7 +214,7 @@
214 <div class="col-lg-10"> 214 <div class="col-lg-10">
215 <ul class="list-unstyled"> 215 <ul class="list-unstyled">
216 {% for result in page.object_list %} 216 {% for result in page.object_list %}
217 - {% include "search/preview-search.html" %} 217 + {% include "message-preview.html" %}
218 {% empty %} 218 {% empty %}
219 <li class="text-center"> 219 <li class="text-center">
220 {% trans "No results for your search." %} 220 {% trans "No results for your search." %}