From 3dfea19e0aaf40ae14f7fb7c32d3fbeab0aeadb0 Mon Sep 17 00:00:00 2001 From: Luan Date: Fri, 8 Nov 2013 12:13:15 -0200 Subject: [PATCH] Changing author to fullname --- src/accounts/views.py | 2 +- src/proxy/templates/search/indexes/proxy/wiki_text.txt | 3 ++- src/search/base_indexes.py | 13 ++++++++++--- src/search/forms.py | 2 +- src/super_archives/models.py | 7 +++++++ src/super_archives/search_indexes.py | 8 +++++++- src/super_archives/templates/message-preview.html | 12 ++++++------ 7 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/accounts/views.py b/src/accounts/views.py index db32dcb..0c423e1 100644 --- a/src/accounts/views.py +++ b/src/accounts/views.py @@ -56,7 +56,7 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): fields_or_lookup = ( {'collaborators__contains': user.username}, - {'author_and_username__contains': user.username}, + {'fullname_and_username__contains': user.username}, ) for type in ['thread', 'ticket', 'wiki', 'changeset', 'attachment']: diff --git a/src/proxy/templates/search/indexes/proxy/wiki_text.txt b/src/proxy/templates/search/indexes/proxy/wiki_text.txt index eba4907..d1b51c4 100644 --- a/src/proxy/templates/search/indexes/proxy/wiki_text.txt +++ b/src/proxy/templates/search/indexes/proxy/wiki_text.txt @@ -1,5 +1,6 @@ {{ object.author }} -{{ object.author|slugify }} +{{ object.get_author.get_full_name }} +{{ object.get_author.get_full_name|slugify }} {{ object.name }} {{ object.name|slugify }} {{ object.collaborators }} diff --git a/src/search/base_indexes.py b/src/search/base_indexes.py index f0e39b6..3d16866 100644 --- a/src/search/base_indexes.py +++ b/src/search/base_indexes.py @@ -10,13 +10,14 @@ class BaseIndex(indexes.SearchIndex): url = indexes.CharField(model_attr='get_absolute_url', indexed=False) title = indexes.CharField() description = indexes.CharField(null=True) + fullname = indexes.CharField(null=True) author = indexes.CharField(null=True) author_url = indexes.CharField(null=True, indexed=False) created = indexes.DateTimeField(model_attr='created', null=True) modified = indexes.DateTimeField(model_attr='modified', null=True) type = indexes.CharField() icon_name = indexes.CharField(indexed=False) - author_and_username = indexes.CharField(null=True, stored=False) + fullname_and_username = indexes.CharField(null=True, stored=False) hits = indexes.IntegerField(model_attr='hits') def get_updated_field(self): @@ -36,10 +37,10 @@ class BaseIndex(indexes.SearchIndex): def prepare_author(self, obj): author = obj.get_author() if author: - return author.get_full_name() + return author.username return obj.author - def prepare_author_and_username(self, obj): + def prepare_fullname_and_username(self, obj): author = obj.get_author() if not author: return obj.author @@ -53,3 +54,9 @@ class BaseIndex(indexes.SearchIndex): if author: return author.get_absolute_url() return None + + def prepare_fullname(self, obj): + author = obj.get_author() + if author: + return author.get_full_name() + return obj.author diff --git a/src/search/forms.py b/src/search/forms.py index 025cfd7..9125e59 100644 --- a/src/search/forms.py +++ b/src/search/forms.py @@ -117,7 +117,7 @@ class ColabSearchForm(SearchForm): if self.cleaned_data['author']: sqs = sqs.filter( - author_and_username__contains=self.cleaned_data['author'] + fullname_and_username__contains=self.cleaned_data['author'] ) if self.cleaned_data['milestone']: diff --git a/src/super_archives/models.py b/src/super_archives/models.py index ae55b76..221ba02 100644 --- a/src/super_archives/models.py +++ b/src/super_archives/models.py @@ -330,6 +330,13 @@ class Message(models.Model): @property def author(self): + from_address = self.from_address + if from_address.user: + return from_address.user.username + return None + + @property + def fullname(self): return self.from_address.get_full_name() @property diff --git a/src/super_archives/search_indexes.py b/src/super_archives/search_indexes.py index c79a7bc..7c4820f 100644 --- a/src/super_archives/search_indexes.py +++ b/src/super_archives/search_indexes.py @@ -34,9 +34,15 @@ class ThreadIndex(BaseIndex, indexes.Indexable): return 'latest_message__received_time' def prepare_author(self, obj): + from_address = obj.message_set.first().from_address + if from_address.user: + return from_address.user.username + return None + + def prepare_fullname(self, obj): return obj.message_set.first().from_address.get_full_name() - def prepare_author_and_username(self, obj): + def prepare_fullname_and_username(self, obj): from_address = obj.message_set.first().from_address if not from_address.user: return from_address.get_full_name() diff --git a/src/super_archives/templates/message-preview.html b/src/super_archives/templates/message-preview.html index d2ab086..a523588 100644 --- a/src/super_archives/templates/message-preview.html +++ b/src/super_archives/templates/message-preview.html @@ -28,20 +28,20 @@ - {% if query %}{% highlight result.description with query max_length "150" %}{% else %}{{ result.description }}{% endif %} {% endif %} -{% if result.author or result.modified %} +{% if result.fullname or result.modified %}
- {% if result.author %} + {% if result.fullname %} {% trans "by" %} - {% if result.author and result.author_url %} + {% if result.fullname and result.author_url %} {% if query %} - {% highlight result.author with query %} + {% highlight result.fullname with query %} {% else %} - {{ result.author }} + {{ result.fullname }} {% endif %} {% else %} - {{ result.author }} + {{ result.fullname }} {% endif %} {% endif %} -- libgit2 0.21.2