diff --git a/colab/solrutils.py b/colab/solrutils.py index 8466e7d..b61df7c 100644 --- a/colab/solrutils.py +++ b/colab/solrutils.py @@ -76,7 +76,9 @@ def get_document_from_addr(doc): """ - username = doc.get('Creator') + username = doc.get('last_author') + if not username: + username = doc.get('Creator') from_addresses = EmailAddress.objects.filter(user__username=username) if username and from_addresses: doc.update({'from_address': from_addresses[0]}) diff --git a/colab/super_archives/management/commands/import_emails.py b/colab/super_archives/management/commands/import_emails.py index 9c68096..ebeddb2 100644 --- a/colab/super_archives/management/commands/import_emails.py +++ b/colab/super_archives/management/commands/import_emails.py @@ -11,7 +11,6 @@ from optparse import make_option from django.db import transaction from django.template.defaultfilters import slugify -from django.core.exceptions import ObjectDoesNotExist from django.core.management.base import BaseCommand, CommandError from colab.super_archives.models import MailingList, Message, \ @@ -154,13 +153,16 @@ class Command(BaseCommand, object): mailinglist = MailingList.objects.get_or_create(name=list_name)[0] mailinglist.last_imported_index = index - try: - # If the message is already at the database don't do anything - message = Message.objects.get( - message_id=email_msg.get('Message-ID')) - if message.thread.mailinglist.name != mailinglist.name: - raise ObjectDoesNotExist - except ObjectDoesNotExist: + # If the message is already at the database don't do anything + messages = Message.objects.filter( + message_id=email_msg.get('Message-ID')) + create = False + if not messages: + create = True + elif messages[0].thread.mailinglist.name != mailinglist.name: + create = True + + if create: self.create_email(mailinglist, email_msg) mailinglist.save() diff --git a/colab/super_archives/queries.py b/colab/super_archives/queries.py index 75bae64..2ef00ff 100644 --- a/colab/super_archives/queries.py +++ b/colab/super_archives/queries.py @@ -1,4 +1,5 @@ +from django.core.exceptions import ObjectDoesNotExist from colab.super_archives.models import Thread, Vote, Message, PageHit @@ -29,7 +30,10 @@ def get_messages_by_voted(): def get_first_message_in_thread(mailinglist, thread_token): query = get_messages_by_date() query = query.filter(thread__mailinglist__name=mailinglist) - query = query.filter(thread__subject_token=thread_token)[0] + try: + query = query.filter(thread__subject_token=thread_token)[0] + except IndexError: + raise ObjectDoesNotExist return query diff --git a/colab/super_archives/templates/message-preview.html b/colab/super_archives/templates/message-preview.html index a992ef6..a7bbbdd 100644 --- a/colab/super_archives/templates/message-preview.html +++ b/colab/super_archives/templates/message-preview.html @@ -5,6 +5,9 @@ {% if doc.Type %} {{ doc.Type }} + {% else %} + thread {% endif %} {% if doc.mailinglist %} @@ -29,13 +32,13 @@
- {% trans "criado por" %} + {% trans "por" %} {% if doc.from_address.get_full_name %} {{ doc.from_address.get_full_name }} {% else %} - {% firstof doc.Creator _("anĂ´nimo") %} + {% firstof doc.last_author doc.Creator _("anĂ´nimo") %} {% endif %} diff --git a/colab/super_archives/views.py b/colab/super_archives/views.py index b37adfb..db169ef 100644 --- a/colab/super_archives/views.py +++ b/colab/super_archives/views.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- +from django.http import Http404 from django.template import RequestContext from django.core.paginator import Paginator +from django.core.exceptions import ObjectDoesNotExist from django.shortcuts import render_to_response, get_list_or_404 from colab.super_archives import queries @@ -10,7 +12,10 @@ from colab.super_archives.models import MailingList, Thread def thread(request, mailinglist, thread_token): - first_message = queries.get_first_message_in_thread(mailinglist, thread_token) + try: + first_message = queries.get_first_message_in_thread(mailinglist, thread_token) + except ObjectDoesNotExist: + raise Http404 order_by = request.GET.get('order') if order_by == 'voted': msgs_query = queries.get_messages_by_voted() diff --git a/solr-conf/data-config.xml b/solr-conf/data-config.xml index 084e838..23a5f1e 100644 --- a/solr-conf/data-config.xml +++ b/solr-conf/data-config.xml @@ -17,7 +17,7 @@ transformer="TemplateTransformer,DateFormatTransformer" query="SELECT name, - TIMESTAMP 'epoch' + (max(time)/1000000) * INTERVAL '1s' AS modified, + TIMESTAMP WITH TIME ZONE 'epoch' + (max(time)/1000000) * INTERVAL '1s' AS modified, max(version) AS version FROM wiki GROUP BY name" deltaQuery=" @@ -27,12 +27,11 @@ wiki WHERE time > (EXTRACT( - epoch FROM TIMESTAMP '${dataimporter.wiki.last_index_time}' + epoch FROM TIMESTAMP WITH TIME ZONE '${dataimporter.wiki.last_index_time}' ) * 1000000)" deltaImportQuery=" SELECT name, - TIMESTAMP 'epoch' + (max(time)/1000000) * INTERVAL '1s' AS modified, max(version) AS version FROM wiki @@ -44,13 +43,24 @@ dataSource="trac" query="SELECT author AS Creator, - TIMESTAMP 'epoch' + (time/1000000) * INTERVAL '1s' AS created + TIMESTAMP WITH TIME ZONE 'epoch' + (time/1000000) * INTERVAL '1s' AS created FROM wiki WHERE name = '${wiki.name}' AND version = 1" /> + + @@ -149,6 +159,18 @@ id = ${ticket.id} AND keywords != ''" /> + + + sam.id = ${thread.latest_message_id}" /> +