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,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 | from_addresses = EmailAddress.objects.filter(user__username=username) | 82 | from_addresses = EmailAddress.objects.filter(user__username=username) |
| 81 | if username and from_addresses: | 83 | if username and from_addresses: |
| 82 | doc.update({'from_address': from_addresses[0]}) | 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,7 +11,6 @@ from optparse import make_option | ||
| 11 | 11 | ||
| 12 | from django.db import transaction | 12 | from django.db import transaction |
| 13 | from django.template.defaultfilters import slugify | 13 | from django.template.defaultfilters import slugify |
| 14 | -from django.core.exceptions import ObjectDoesNotExist | ||
| 15 | from django.core.management.base import BaseCommand, CommandError | 14 | from django.core.management.base import BaseCommand, CommandError |
| 16 | 15 | ||
| 17 | from colab.super_archives.models import MailingList, Message, \ | 16 | from colab.super_archives.models import MailingList, Message, \ |
| @@ -154,13 +153,16 @@ class Command(BaseCommand, object): | @@ -154,13 +153,16 @@ class Command(BaseCommand, object): | ||
| 154 | mailinglist = MailingList.objects.get_or_create(name=list_name)[0] | 153 | mailinglist = MailingList.objects.get_or_create(name=list_name)[0] |
| 155 | mailinglist.last_imported_index = index | 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 | self.create_email(mailinglist, email_msg) | 166 | self.create_email(mailinglist, email_msg) |
| 165 | 167 | ||
| 166 | mailinglist.save() | 168 | mailinglist.save() |
colab/super_archives/queries.py
| 1 | 1 | ||
| 2 | +from django.core.exceptions import ObjectDoesNotExist | ||
| 2 | from colab.super_archives.models import Thread, Vote, Message, PageHit | 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,7 +30,10 @@ def get_messages_by_voted(): | ||
| 29 | def get_first_message_in_thread(mailinglist, thread_token): | 30 | def get_first_message_in_thread(mailinglist, thread_token): |
| 30 | query = get_messages_by_date() | 31 | query = get_messages_by_date() |
| 31 | query = query.filter(thread__mailinglist__name=mailinglist) | 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 | return query | 37 | return query |
| 34 | 38 | ||
| 35 | 39 |
colab/super_archives/templates/message-preview.html
| @@ -5,6 +5,9 @@ | @@ -5,6 +5,9 @@ | ||
| 5 | {% if doc.Type %} | 5 | {% if doc.Type %} |
| 6 | <img alt="{{ doc.Type }}" title="{{ doc.Type }}" | 6 | <img alt="{{ doc.Type }}" title="{{ doc.Type }}" |
| 7 | src="{{ STATIC_URL }}img/{{ doc.Type }}.png" /> | 7 | src="{{ STATIC_URL }}img/{{ doc.Type }}.png" /> |
| 8 | + {% else %} | ||
| 9 | + <img alt="thread" title="thread" | ||
| 10 | + src="{{ STATIC_URL }}img/thread.png" /> | ||
| 8 | {% endif %} | 11 | {% endif %} |
| 9 | 12 | ||
| 10 | {% if doc.mailinglist %} | 13 | {% if doc.mailinglist %} |
| @@ -29,13 +32,13 @@ | @@ -29,13 +32,13 @@ | ||
| 29 | 32 | ||
| 30 | <div class="quiet"> | 33 | <div class="quiet"> |
| 31 | <span class="left"> | 34 | <span class="left"> |
| 32 | - {% trans "criado por" %} | 35 | + {% trans "por" %} |
| 33 | {% if doc.from_address.get_full_name %} | 36 | {% if doc.from_address.get_full_name %} |
| 34 | <a href="{{ doc.from_address.get_profile_link }}"> | 37 | <a href="{{ doc.from_address.get_profile_link }}"> |
| 35 | {{ doc.from_address.get_full_name }} | 38 | {{ doc.from_address.get_full_name }} |
| 36 | </a> | 39 | </a> |
| 37 | {% else %} | 40 | {% else %} |
| 38 | - {% firstof doc.Creator _("anônimo") %} | 41 | + {% firstof doc.last_author doc.Creator _("anônimo") %} |
| 39 | {% endif %} | 42 | {% endif %} |
| 40 | </span> | 43 | </span> |
| 41 | 44 |
colab/super_archives/views.py
| 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
| 2 | 2 | ||
| 3 | +from django.http import Http404 | ||
| 3 | from django.template import RequestContext | 4 | from django.template import RequestContext |
| 4 | from django.core.paginator import Paginator | 5 | from django.core.paginator import Paginator |
| 6 | +from django.core.exceptions import ObjectDoesNotExist | ||
| 5 | from django.shortcuts import render_to_response, get_list_or_404 | 7 | from django.shortcuts import render_to_response, get_list_or_404 |
| 6 | 8 | ||
| 7 | from colab.super_archives import queries | 9 | from colab.super_archives import queries |
| @@ -10,7 +12,10 @@ from colab.super_archives.models import MailingList, Thread | @@ -10,7 +12,10 @@ from colab.super_archives.models import MailingList, Thread | ||
| 10 | 12 | ||
| 11 | def thread(request, mailinglist, thread_token): | 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 | order_by = request.GET.get('order') | 19 | order_by = request.GET.get('order') |
| 15 | if order_by == 'voted': | 20 | if order_by == 'voted': |
| 16 | msgs_query = queries.get_messages_by_voted() | 21 | msgs_query = queries.get_messages_by_voted() |
solr-conf/data-config.xml
| @@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
| 17 | transformer="TemplateTransformer,DateFormatTransformer" | 17 | transformer="TemplateTransformer,DateFormatTransformer" |
| 18 | query="SELECT | 18 | query="SELECT |
| 19 | name, | 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 | max(version) AS version | 21 | max(version) AS version |
| 22 | FROM wiki GROUP BY name" | 22 | FROM wiki GROUP BY name" |
| 23 | deltaQuery=" | 23 | deltaQuery=" |
| @@ -27,12 +27,11 @@ | @@ -27,12 +27,11 @@ | ||
| 27 | wiki | 27 | wiki |
| 28 | WHERE | 28 | WHERE |
| 29 | time > (EXTRACT( | 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 | ) * 1000000)" | 31 | ) * 1000000)" |
| 32 | deltaImportQuery=" | 32 | deltaImportQuery=" |
| 33 | SELECT | 33 | SELECT |
| 34 | name, | 34 | name, |
| 35 | - TIMESTAMP 'epoch' + (max(time)/1000000) * INTERVAL '1s' AS modified, | ||
| 36 | max(version) AS version | 35 | max(version) AS version |
| 37 | FROM | 36 | FROM |
| 38 | wiki | 37 | wiki |
| @@ -44,13 +43,24 @@ | @@ -44,13 +43,24 @@ | ||
| 44 | dataSource="trac" | 43 | dataSource="trac" |
| 45 | query="SELECT | 44 | query="SELECT |
| 46 | author AS Creator, | 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 | FROM | 47 | FROM |
| 49 | wiki | 48 | wiki |
| 50 | WHERE | 49 | WHERE |
| 51 | name = '${wiki.name}' | 50 | name = '${wiki.name}' |
| 52 | AND version = 1" /> | 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 | <entity name="wiki_collaborators" | 64 | <entity name="wiki_collaborators" |
| 55 | dataSource="trac" | 65 | dataSource="trac" |
| 56 | query="SELECT DISTINCT | 66 | query="SELECT DISTINCT |
| @@ -93,7 +103,7 @@ | @@ -93,7 +103,7 @@ | ||
| 93 | ticket | 103 | ticket |
| 94 | WHERE | 104 | WHERE |
| 95 | time > (EXTRACT( | 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 | ) * 1000000)" | 107 | ) * 1000000)" |
| 98 | query="SELECT | 108 | query="SELECT |
| 99 | id, | 109 | id, |
| @@ -107,8 +117,8 @@ | @@ -107,8 +117,8 @@ | ||
| 107 | reporter, | 117 | reporter, |
| 108 | owner, | 118 | owner, |
| 109 | status, | 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 | FROM | 122 | FROM |
| 113 | ticket"> | 123 | ticket"> |
| 114 | 124 | ||
| @@ -149,6 +159,18 @@ | @@ -149,6 +159,18 @@ | ||
| 149 | id = ${ticket.id} AND | 159 | id = ${ticket.id} AND |
| 150 | keywords != ''" /> | 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 | <entity name="ticket_comments" | 174 | <entity name="ticket_comments" |
| 153 | dataSource="trac" | 175 | dataSource="trac" |
| 154 | query="SELECT | 176 | query="SELECT |
| @@ -183,7 +205,7 @@ | @@ -183,7 +205,7 @@ | ||
| 183 | revision | 205 | revision |
| 184 | WHERE | 206 | WHERE |
| 185 | time > (EXTRACT( | 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 | ) * 1000000)" | 209 | ) * 1000000)" |
| 188 | 210 | ||
| 189 | query="SELECT | 211 | query="SELECT |
| @@ -191,8 +213,8 @@ | @@ -191,8 +213,8 @@ | ||
| 191 | author AS Creator, | 213 | author AS Creator, |
| 192 | author AS collaborator, | 214 | author AS collaborator, |
| 193 | repos.value AS repos_name, | 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 | message | 218 | message |
| 197 | FROM | 219 | FROM |
| 198 | revision AS rev JOIN | 220 | revision AS rev JOIN |
| @@ -274,7 +296,6 @@ | @@ -274,7 +296,6 @@ | ||
| 274 | dataSource="colab" | 296 | dataSource="colab" |
| 275 | transformer="TemplateTransformer" | 297 | transformer="TemplateTransformer" |
| 276 | query="SELECT DISTINCT ON (sam.thread_id) | 298 | query="SELECT DISTINCT ON (sam.thread_id) |
| 277 | - sam.body AS Description, | ||
| 278 | sam.received_time AS created, | 299 | sam.received_time AS created, |
| 279 | sam.subject_clean AS subject, | 300 | sam.subject_clean AS subject, |
| 280 | saea.real_name AS creator_real_name, | 301 | saea.real_name AS creator_real_name, |
| @@ -299,11 +320,17 @@ | @@ -299,11 +320,17 @@ | ||
| 299 | <entity name="latest_message" | 320 | <entity name="latest_message" |
| 300 | dataSource="colab" | 321 | dataSource="colab" |
| 301 | query="SELECT | 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 | FROM | 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 | WHERE | 332 | WHERE |
| 306 | - id = ${thread.latest_message_id}" /> | 333 | + sam.id = ${thread.latest_message_id}" /> |
| 307 | 334 | ||
| 308 | <entity name="thread_collaborators" | 335 | <entity name="thread_collaborators" |
| 309 | dataSource="colab" | 336 | dataSource="colab" |
solr-conf/schema.xml
| @@ -470,6 +470,8 @@ | @@ -470,6 +470,8 @@ | ||
| 470 | stored="true" required="false" multiValued="false"/> | 470 | stored="true" required="false" multiValued="false"/> |
| 471 | <field name="Creator" type="string" indexed="true" | 471 | <field name="Creator" type="string" indexed="true" |
| 472 | stored="true" required="false" multiValued="false"/> | 472 | stored="true" required="false" multiValued="false"/> |
| 473 | + <field name="last_author" type="string" indexed="true" | ||
| 474 | + stored="true" required="false" multiValued="false"/> | ||
| 473 | <field name="created" type="date" indexed="true" | 475 | <field name="created" type="date" indexed="true" |
| 474 | stored="true" required="false" multiValued="false"/> | 476 | stored="true" required="false" multiValued="false"/> |
| 475 | <field name="modified" type="date" indexed="true" | 477 | <field name="modified" type="date" indexed="true" |