Commit f5e7f652fa875da54dc7feed1e8a60f3b3eb9407
1 parent
beb38b3b
Exists in
master
and in
39 other branches
Merge com https://bitbucket.org/seocam/atu-colab/src/e5452b943276
git-svn-id: http://repositorio.interlegis.gov.br/colab/trunk@6216 bee1b3ed-c3eb-0310-9994-b88e04532788
Showing
7 changed files
with
72 additions
and
27 deletions
Show diff stats
colab/solrutils.py
... | ... | @@ -76,7 +76,9 @@ def get_document_from_addr(doc): |
76 | 76 | |
77 | 77 | """ |
78 | 78 | |
79 | - username = doc.get('Creator') | |
79 | + username = doc.get('last_author') | |
80 | + if not username: | |
81 | + username = doc.get('Creator') | |
80 | 82 | from_addresses = EmailAddress.objects.filter(user__username=username) |
81 | 83 | if username and from_addresses: |
82 | 84 | doc.update({'from_address': from_addresses[0]}) | ... | ... |
colab/super_archives/management/commands/import_emails.py
... | ... | @@ -11,7 +11,6 @@ from optparse import make_option |
11 | 11 | |
12 | 12 | from django.db import transaction |
13 | 13 | from django.template.defaultfilters import slugify |
14 | -from django.core.exceptions import ObjectDoesNotExist | |
15 | 14 | from django.core.management.base import BaseCommand, CommandError |
16 | 15 | |
17 | 16 | from colab.super_archives.models import MailingList, Message, \ |
... | ... | @@ -154,13 +153,16 @@ class Command(BaseCommand, object): |
154 | 153 | mailinglist = MailingList.objects.get_or_create(name=list_name)[0] |
155 | 154 | mailinglist.last_imported_index = index |
156 | 155 | |
157 | - try: | |
158 | - # If the message is already at the database don't do anything | |
159 | - message = Message.objects.get( | |
160 | - message_id=email_msg.get('Message-ID')) | |
161 | - if message.thread.mailinglist.name != mailinglist.name: | |
162 | - raise ObjectDoesNotExist | |
163 | - except ObjectDoesNotExist: | |
156 | + # If the message is already at the database don't do anything | |
157 | + messages = Message.objects.filter( | |
158 | + message_id=email_msg.get('Message-ID')) | |
159 | + create = False | |
160 | + if not messages: | |
161 | + create = True | |
162 | + elif messages[0].thread.mailinglist.name != mailinglist.name: | |
163 | + create = True | |
164 | + | |
165 | + if create: | |
164 | 166 | self.create_email(mailinglist, email_msg) |
165 | 167 | |
166 | 168 | mailinglist.save() | ... | ... |
colab/super_archives/queries.py
1 | 1 | |
2 | +from django.core.exceptions import ObjectDoesNotExist | |
2 | 3 | from colab.super_archives.models import Thread, Vote, Message, PageHit |
3 | 4 | |
4 | 5 | |
... | ... | @@ -29,7 +30,10 @@ def get_messages_by_voted(): |
29 | 30 | def get_first_message_in_thread(mailinglist, thread_token): |
30 | 31 | query = get_messages_by_date() |
31 | 32 | query = query.filter(thread__mailinglist__name=mailinglist) |
32 | - query = query.filter(thread__subject_token=thread_token)[0] | |
33 | + try: | |
34 | + query = query.filter(thread__subject_token=thread_token)[0] | |
35 | + except IndexError: | |
36 | + raise ObjectDoesNotExist | |
33 | 37 | return query |
34 | 38 | |
35 | 39 | ... | ... |
colab/super_archives/templates/message-preview.html
... | ... | @@ -5,6 +5,9 @@ |
5 | 5 | {% if doc.Type %} |
6 | 6 | <img alt="{{ doc.Type }}" title="{{ doc.Type }}" |
7 | 7 | src="{{ STATIC_URL }}img/{{ doc.Type }}.png" /> |
8 | + {% else %} | |
9 | + <img alt="thread" title="thread" | |
10 | + src="{{ STATIC_URL }}img/thread.png" /> | |
8 | 11 | {% endif %} |
9 | 12 | |
10 | 13 | {% if doc.mailinglist %} |
... | ... | @@ -29,13 +32,13 @@ |
29 | 32 | |
30 | 33 | <div class="quiet"> |
31 | 34 | <span class="left"> |
32 | - {% trans "criado por" %} | |
35 | + {% trans "por" %} | |
33 | 36 | {% if doc.from_address.get_full_name %} |
34 | 37 | <a href="{{ doc.from_address.get_profile_link }}"> |
35 | 38 | {{ doc.from_address.get_full_name }} |
36 | 39 | </a> |
37 | 40 | {% else %} |
38 | - {% firstof doc.Creator _("anônimo") %} | |
41 | + {% firstof doc.last_author doc.Creator _("anônimo") %} | |
39 | 42 | {% endif %} |
40 | 43 | </span> |
41 | 44 | ... | ... |
colab/super_archives/views.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | |
3 | +from django.http import Http404 | |
3 | 4 | from django.template import RequestContext |
4 | 5 | from django.core.paginator import Paginator |
6 | +from django.core.exceptions import ObjectDoesNotExist | |
5 | 7 | from django.shortcuts import render_to_response, get_list_or_404 |
6 | 8 | |
7 | 9 | from colab.super_archives import queries |
... | ... | @@ -10,7 +12,10 @@ from colab.super_archives.models import MailingList, Thread |
10 | 12 | |
11 | 13 | def thread(request, mailinglist, thread_token): |
12 | 14 | |
13 | - first_message = queries.get_first_message_in_thread(mailinglist, thread_token) | |
15 | + try: | |
16 | + first_message = queries.get_first_message_in_thread(mailinglist, thread_token) | |
17 | + except ObjectDoesNotExist: | |
18 | + raise Http404 | |
14 | 19 | order_by = request.GET.get('order') |
15 | 20 | if order_by == 'voted': |
16 | 21 | msgs_query = queries.get_messages_by_voted() | ... | ... |
solr-conf/data-config.xml
... | ... | @@ -17,7 +17,7 @@ |
17 | 17 | transformer="TemplateTransformer,DateFormatTransformer" |
18 | 18 | query="SELECT |
19 | 19 | name, |
20 | - TIMESTAMP 'epoch' + (max(time)/1000000) * INTERVAL '1s' AS modified, | |
20 | + TIMESTAMP WITH TIME ZONE 'epoch' + (max(time)/1000000) * INTERVAL '1s' AS modified, | |
21 | 21 | max(version) AS version |
22 | 22 | FROM wiki GROUP BY name" |
23 | 23 | deltaQuery=" |
... | ... | @@ -27,12 +27,11 @@ |
27 | 27 | wiki |
28 | 28 | WHERE |
29 | 29 | time > (EXTRACT( |
30 | - epoch FROM TIMESTAMP '${dataimporter.wiki.last_index_time}' | |
30 | + epoch FROM TIMESTAMP WITH TIME ZONE '${dataimporter.wiki.last_index_time}' | |
31 | 31 | ) * 1000000)" |
32 | 32 | deltaImportQuery=" |
33 | 33 | SELECT |
34 | 34 | name, |
35 | - TIMESTAMP 'epoch' + (max(time)/1000000) * INTERVAL '1s' AS modified, | |
36 | 35 | max(version) AS version |
37 | 36 | FROM |
38 | 37 | wiki |
... | ... | @@ -44,13 +43,24 @@ |
44 | 43 | dataSource="trac" |
45 | 44 | query="SELECT |
46 | 45 | author AS Creator, |
47 | - TIMESTAMP 'epoch' + (time/1000000) * INTERVAL '1s' AS created | |
46 | + TIMESTAMP WITH TIME ZONE 'epoch' + (time/1000000) * INTERVAL '1s' AS created | |
48 | 47 | FROM |
49 | 48 | wiki |
50 | 49 | WHERE |
51 | 50 | name = '${wiki.name}' |
52 | 51 | AND version = 1" /> |
53 | 52 | |
53 | + <entity name="wiki_modification" | |
54 | + dataSource="trac" | |
55 | + query="SELECT | |
56 | + author AS last_author, | |
57 | + TIMESTAMP WITH TIME ZONE 'epoch' + (time/1000000) * INTERVAL '1s' AS modified | |
58 | + FROM | |
59 | + wiki | |
60 | + WHERE | |
61 | + name = '${wiki.name}' | |
62 | + AND version = '${wiki.version}'" /> | |
63 | + | |
54 | 64 | <entity name="wiki_collaborators" |
55 | 65 | dataSource="trac" |
56 | 66 | query="SELECT DISTINCT |
... | ... | @@ -93,7 +103,7 @@ |
93 | 103 | ticket |
94 | 104 | WHERE |
95 | 105 | time > (EXTRACT( |
96 | - epoch FROM TIMESTAMP '${dataimporter.ticket.last_index_time}' | |
106 | + epoch FROM TIMESTAMP WITH TIME ZONE '${dataimporter.ticket.last_index_time}' | |
97 | 107 | ) * 1000000)" |
98 | 108 | query="SELECT |
99 | 109 | id, |
... | ... | @@ -107,8 +117,8 @@ |
107 | 117 | reporter, |
108 | 118 | owner, |
109 | 119 | status, |
110 | - TIMESTAMP 'epoch' + (time/1000000)* INTERVAL '1s' AS created, | |
111 | - TIMESTAMP 'epoch' + (changetime/1000000) * INTERVAL '1s' AS modified | |
120 | + TIMESTAMP WITH TIME ZONE 'epoch' + (time/1000000)* INTERVAL '1s' AS created, | |
121 | + TIMESTAMP WITH TIME ZONE 'epoch' + (changetime/1000000) * INTERVAL '1s' AS modified | |
112 | 122 | FROM |
113 | 123 | ticket"> |
114 | 124 | |
... | ... | @@ -149,6 +159,18 @@ |
149 | 159 | id = ${ticket.id} AND |
150 | 160 | keywords != ''" /> |
151 | 161 | |
162 | + <entity name="ticket_modification" | |
163 | + dataSource="trac" | |
164 | + query="SELECT DISTINCT | |
165 | + author AS last_author | |
166 | + FROM | |
167 | + ticket_change | |
168 | + WHERE | |
169 | + ticket = ${ticket.id} AND | |
170 | + time = (SELECT max(time) | |
171 | + FROM ticket_change | |
172 | + WHERE ticket = ${ticket.id});" /> | |
173 | + | |
152 | 174 | <entity name="ticket_comments" |
153 | 175 | dataSource="trac" |
154 | 176 | query="SELECT |
... | ... | @@ -183,7 +205,7 @@ |
183 | 205 | revision |
184 | 206 | WHERE |
185 | 207 | time > (EXTRACT( |
186 | - epoch FROM TIMESTAMP '${dataimporter.changeset.last_index_time}' | |
208 | + epoch FROM TIMESTAMP WITH TIME ZONE '${dataimporter.changeset.last_index_time}' | |
187 | 209 | ) * 1000000)" |
188 | 210 | |
189 | 211 | query="SELECT |
... | ... | @@ -191,8 +213,8 @@ |
191 | 213 | author AS Creator, |
192 | 214 | author AS collaborator, |
193 | 215 | repos.value AS repos_name, |
194 | - TIMESTAMP 'epoch' + (time/1000000) * INTERVAL '1s' AS created, | |
195 | - TIMESTAMP 'epoch' + (time/1000000) * INTERVAL '1s' AS modified, | |
216 | + TIMESTAMP WITH TIME ZONE 'epoch' + (time/1000000) * INTERVAL '1s' AS created, | |
217 | + TIMESTAMP WITH TIME ZONE 'epoch' + (time/1000000) * INTERVAL '1s' AS modified, | |
196 | 218 | message |
197 | 219 | FROM |
198 | 220 | revision AS rev JOIN |
... | ... | @@ -274,7 +296,6 @@ |
274 | 296 | dataSource="colab" |
275 | 297 | transformer="TemplateTransformer" |
276 | 298 | query="SELECT DISTINCT ON (sam.thread_id) |
277 | - sam.body AS Description, | |
278 | 299 | sam.received_time AS created, |
279 | 300 | sam.subject_clean AS subject, |
280 | 301 | saea.real_name AS creator_real_name, |
... | ... | @@ -299,11 +320,17 @@ |
299 | 320 | <entity name="latest_message" |
300 | 321 | dataSource="colab" |
301 | 322 | query="SELECT |
302 | - received_time AS modified | |
323 | + sam.body AS Description, | |
324 | + sam.received_time AS modified, | |
325 | + au.username AS last_author | |
303 | 326 | FROM |
304 | - super_archives_message | |
327 | + super_archives_message AS sam | |
328 | + JOIN super_archives_emailaddress AS saea | |
329 | + ON sam.from_address_id = saea.id | |
330 | + LEFT JOIN auth_user AS au | |
331 | + ON au.id = saea.user_id | |
305 | 332 | WHERE |
306 | - id = ${thread.latest_message_id}" /> | |
333 | + sam.id = ${thread.latest_message_id}" /> | |
307 | 334 | |
308 | 335 | <entity name="thread_collaborators" |
309 | 336 | dataSource="colab" | ... | ... |
solr-conf/schema.xml
... | ... | @@ -470,6 +470,8 @@ |
470 | 470 | stored="true" required="false" multiValued="false"/> |
471 | 471 | <field name="Creator" type="string" indexed="true" |
472 | 472 | stored="true" required="false" multiValued="false"/> |
473 | + <field name="last_author" type="string" indexed="true" | |
474 | + stored="true" required="false" multiValued="false"/> | |
473 | 475 | <field name="created" type="date" indexed="true" |
474 | 476 | stored="true" required="false" multiValued="false"/> |
475 | 477 | <field name="modified" type="date" indexed="true" | ... | ... |