incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [22/40] git commit: [#2835] ticket:303 Get rid of `title_s`, use `title` instead
Date Mon, 01 Apr 2013 14:27:41 GMT
[#2835] ticket:303 Get rid of `title_s`, use `title` instead


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/f211493f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/f211493f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/f211493f

Branch: refs/heads/cj/5963
Commit: f211493fef93814cbbe27209e5346e339bdc9d4a
Parents: 186cf48
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Mar 15 10:46:49 2013 +0000
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Tue Mar 26 20:57:39 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/helpers.py                       |   12 ++++++++++++
 Allura/allura/model/artifact.py                    |   11 +++++------
 Allura/allura/model/discuss.py                     |    6 +++---
 Allura/allura/model/notification.py                |    6 +++---
 Allura/allura/model/repository.py                  |    4 ++--
 Allura/allura/templates/search_index.html          |    2 +-
 .../allura/templates/widgets/search_results.html   |    2 +-
 Allura/allura/tests/model/test_artifact.py         |    2 +-
 Allura/allura/tests/model/test_discussion.py       |    2 +-
 Allura/allura/tests/test_helpers.py                |    9 +++++++++
 ForgeBlog/forgeblog/model/blog.py                  |    4 ++--
 ForgeBlog/forgeblog/templates/blog/search.html     |    2 +-
 ForgeChat/forgechat/command.py                     |    2 +-
 ForgeChat/forgechat/templates/chat/search.html     |    2 +-
 ForgeShortUrl/forgeshorturl/model/shorturl.py      |    2 +-
 ForgeTracker/forgetracker/model/ticket.py          |    4 ++--
 ForgeWiki/forgewiki/model/wiki.py                  |    2 --
 17 files changed, 46 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 5e32882..eeee7bc 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -652,3 +652,15 @@ def get_tool_package(tool_name):
     "Return package for given tool (e.g. 'forgetracker' for 'tickets')"
     app = g.entry_points['tool'].get(tool_name.lower())
     return app.__module__.split('.')[0] if app else ''
+
+
+def get_first(d, key):
+    """Return value for d[key][0] if d[key] is a list with elements, else return d[key].
+
+    Useful to retrieve values from solr index (e.g. `title` and `text` fields),
+    which are stored as lists.
+    """
+    v = d.get(key)
+    if isinstance(v, list):
+        return v[0] if len(v) > 0 else None
+    return v

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 95da7dd..aa3ddfa 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -212,7 +212,7 @@ class Artifact(MappedClass):
 
         The _s and _t suffixes, for example, follow solr dynamic field naming
         pattern.
-        You probably want to override at least title, title_s and text to have
+        You probably want to override at least title and text to have
         meaningful search results and email senders.
         """
 
@@ -220,7 +220,6 @@ class Artifact(MappedClass):
         return dict(
             id=self.index_id(),
             mod_date_dt=self.mod_date,
-            title_s='Artifact %s' % self._id,
             title='Artifact %s' % self._id,
             project_id_s=str(project._id),
             project_name_t=project.name,
@@ -268,7 +267,7 @@ class Artifact(MappedClass):
             t = Thread.new(
                 discussion_id=self.app_config.discussion_id,
                 ref_id=idx['id'],
-                subject='%s discussion' % idx['title_s'])
+                subject='%s discussion' % h.get_first(idx, 'title'))
         parent_id = None
         if data:
             in_reply_to = data.get('in_reply_to', [])
@@ -316,8 +315,8 @@ class Snapshot(Artifact):
         if original:
             original_index = original.index()
             result.update(original_index)
-            result['title_s'] = 'Version %d of %s' % (
-                    self.version, original_index['title_s'])
+            result['title'] = 'Version %d of %s' % (
+                    self.version, h.get_first(original_index, 'title'))
         result.update(
             id=self.index_id(),
             version_i=self.version,
@@ -640,7 +639,7 @@ class Feed(MappedClass):
         if author_name is None:
             author_name = author.get_pref('display_name')
         if title is None:
-            title='%s modified by %s' % (idx['title_s'], author_name)
+            title='%s modified by %s' % (h.get_first(idx, 'title'), author_name)
         if description is None: description = title
         if pubdate is None:
             pubdate = datetime.utcnow()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index 9d26242..2ea6f4c 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -90,7 +90,7 @@ class Discussion(Artifact, ActivityObject):
     def index(self):
         result = Artifact.index(self)
         result.update(
-            title_s='Discussion: %s' % self.name,
+            title='Discussion: %s' % self.name,
             name_s=self.name,
             text=self.description)
         return result
@@ -339,7 +339,7 @@ class Thread(Artifact, ActivityObject):
     def index(self):
         result = Artifact.index(self)
         result.update(
-           title_s='Thread: %s' % (self.subject or '(no subject)'),
+           title='Thread: %s' % (self.subject or '(no subject)'),
            name_s=self.subject,
            views_i=self.num_views,
            text=self.subject)
@@ -459,7 +459,7 @@ class Post(Message, VersionedArtifact, ActivityObject):
     def index(self):
         result = super(Post, self).index()
         result.update(
-            title_s='Post by %s on %s' % (
+            title='Post by %s on %s' % (
                 self.author().username, self.subject),
             name_s=self.subject,
             type_s='Post',

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/Allura/allura/model/notification.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py
index 7003e29..c9b1e35 100644
--- a/Allura/allura/model/notification.py
+++ b/Allura/allura/model/notification.py
@@ -153,9 +153,9 @@ class Notification(MappedClass):
             return n
         else:
             subject = kwargs.pop('subject', '%s modified by %s' % (
-                    idx['title_s'],c.user.get_pref('display_name')))
+                    h.get_first(idx, 'title'),c.user.get_pref('display_name')))
             reply_to = '"%s" <%s>' % (
-                idx['title_s'],
+                h.get_first(idx, 'title'),
                 getattr(artifact, 'email_address', u'noreply@in.sf.net'))
             d = dict(
                 from_address=reply_to,
@@ -355,7 +355,7 @@ class Mailbox(MappedClass):
             artifact_index_id = None
         else:
             i = artifact.index()
-            artifact_title = i['title_s']
+            artifact_title = h.get_first(i, 'title')
             artifact_url = artifact.url()
             artifact_index_id = i['id']
             artifact_already_subscribed = cls.query.get(user_id=user_id,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index f822cc2..d6f843d 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -426,7 +426,7 @@ class Repository(Artifact, ActivityObject):
         result.update(
             name_s=self.name,
             type_s=self.type_s,
-            title_s='Repository %s %s' % (self.project.name, self.name))
+            title='Repository %s %s' % (self.project.name, self.name))
         return result
 
     @property
@@ -614,7 +614,7 @@ class MergeRequest(VersionedArtifact, ActivityObject):
         result.update(
             name_s='Merge Request #%d' % self.request_number,
             type_s=self.type_s,
-            title_s='Merge Request #%d of %s:%s' % (
+            title='Merge Request #%d of %s:%s' % (
                 self.request_number, self.project.name, self.app.repo.name))
         return result
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/Allura/allura/templates/search_index.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/search_index.html b/Allura/allura/templates/search_index.html
index 52033d8..6fd2107 100644
--- a/Allura/allura/templates/search_index.html
+++ b/Allura/allura/templates/search_index.html
@@ -27,7 +27,7 @@
   <ol>
   {% for doc in results %}
   <li>
-    <a href="{{doc['url_s']}}">{{doc.title_s}}</a>
+    <a href="{{doc['url_s']}}">{{h.get_first(doc, 'title')}}</a>
     {% if doc.get('snippet') %}
       <p>{{doc['snippet']|safe}}</p>
     {% endif %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/Allura/allura/templates/widgets/search_results.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/search_results.html b/Allura/allura/templates/widgets/search_results.html
index b5b0c5a..d1067cc 100644
--- a/Allura/allura/templates/widgets/search_results.html
+++ b/Allura/allura/templates/widgets/search_results.html
@@ -41,7 +41,7 @@
   <div class="grid-19">
     {# TODO: mark matches in title and snippet #}
     <p>
-    <a href="{{doc['url_paginated'] or doc['url_s']}}">{{ doc.title_s }}</a>
+    <a href="{{doc['url_paginated'] or doc['url_s']}}">{{ h.get_first(doc, 'title')
}}</a>
     {% if doc['type_s'] %}<span class="gray"><sup>{{ '(%s)' % doc['type_s'] }}</sup></span>{%
endif %}
     <br>
     {{ doc.snippet }}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/Allura/allura/tests/model/test_artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_artifact.py b/Allura/allura/tests/model/test_artifact.py
index 0ad9d49..ec02de9 100644
--- a/Allura/allura/tests/model/test_artifact.py
+++ b/Allura/allura/tests/model/test_artifact.py
@@ -72,7 +72,7 @@ def test_artifact():
     c.memoize_cache = {}
     assert not security.has_access(pg, 'delete')(user=u)
     idx = pg.index()
-    assert 'title_s' in idx
+    assert 'title' in idx
     assert 'url_s' in idx
     assert 'project_id_s' in idx
     assert 'mount_point_s' in idx

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/Allura/allura/tests/model/test_discussion.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_discussion.py b/Allura/allura/tests/model/test_discussion.py
index 861f665..7efe0c9 100644
--- a/Allura/allura/tests/model/test_discussion.py
+++ b/Allura/allura/tests/model/test_discussion.py
@@ -137,7 +137,7 @@ def test_post_methods():
     assert p.link_text() == p.subject
 
     ss = p.history().first()
-    assert 'Version' in ss.index()['title_s']
+    assert 'Version' in h.get_first(ss.index(), 'title')
     assert '#' in ss.shorthand_id()
 
     jsn = p.__json__()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/Allura/allura/tests/test_helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index 8407ef4..4829549 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -167,3 +167,12 @@ def test_get_tool_package():
     assert h.get_tool_package('tickets') == 'forgetracker'
     assert h.get_tool_package('Wiki') == 'forgewiki'
     assert h.get_tool_package('wrong_tool') == ''
+
+
+def test_get_first():
+    assert_equals(h.get_first({}, 'title'), None)
+    assert_equals(h.get_first({'title': None}, 'title'), None)
+    assert_equals(h.get_first({'title': 'Value'}, 'title'), 'Value')
+    assert_equals(h.get_first({'title': ['Value']}, 'title'), 'Value')
+    assert_equals(h.get_first({'title': []}, 'title'), None)
+    assert_equals(h.get_first({'title': ['Value']}, 'title'), 'Value')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/ForgeBlog/forgeblog/model/blog.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/model/blog.py b/ForgeBlog/forgeblog/model/blog.py
index a2dae6c..88e2204 100644
--- a/ForgeBlog/forgeblog/model/blog.py
+++ b/ForgeBlog/forgeblog/model/blog.py
@@ -57,7 +57,7 @@ class BlogPostSnapshot(M.Snapshot):
             return None
         result = super(BlogPostSnapshot, self).index()
         result.update(
-            title_s='Version %d of %s' % (
+            title='Version %d of %s' % (
                 self.version, orig.shorthand_id()),
             type_s=self.type_s,
             text=self.data.text)
@@ -184,7 +184,7 @@ class BlogPost(M.VersionedArtifact, ActivityObject):
     def index(self):
         result = super(BlogPost, self).index()
         result.update(
-            title_s=self.slug,
+            title=self.slug,
             type_s=self.type_s,
             state_s=self.state,
             snippet_s='%s: %s' % (self.title, h.text.truncate(self.text, 200)),

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/ForgeBlog/forgeblog/templates/blog/search.html
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/templates/blog/search.html b/ForgeBlog/forgeblog/templates/blog/search.html
index a4f7129..320f265 100644
--- a/ForgeBlog/forgeblog/templates/blog/search.html
+++ b/ForgeBlog/forgeblog/templates/blog/search.html
@@ -22,7 +22,7 @@
   {% endif %}
   {% for doc in results %}
   <div>
-    <div class="grid-19"><a href="{{doc['url_s']}}">{{doc.title_s}}</a></div>
+    <div class="grid-19"><a href="{{doc['url_s']}}">{{ h.get_first(doc, 'title')
}}</a></div>
     <p>{{doc.get('snippet_s', '...')}}</p>
     <hr/>
   </div>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/ForgeChat/forgechat/command.py
----------------------------------------------------------------------
diff --git a/ForgeChat/forgechat/command.py b/ForgeChat/forgechat/command.py
index 13b00fc..2a20414 100644
--- a/ForgeChat/forgechat/command.py
+++ b/ForgeChat/forgechat/command.py
@@ -146,7 +146,7 @@ class IRCBot(asynchat.async_chat):
         art = lnk.ref.artifact
         if security.has_access(art, 'read', user=M.User.anonymous())():
             index = art.index()
-            text = index['snippet_s'] or index['title_s']
+            text = index['snippet_s'] or h.get_first(index, 'title')
             url = urljoin(tg.config.get('base_url', 'http://sourceforge.net'), index['url_s'])
             self.notice(rcpt, '[%s] - [%s](%s)' % (lnk.link, text,url))
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/ForgeChat/forgechat/templates/chat/search.html
----------------------------------------------------------------------
diff --git a/ForgeChat/forgechat/templates/chat/search.html b/ForgeChat/forgechat/templates/chat/search.html
index debc1ec..bd64d04 100644
--- a/ForgeChat/forgechat/templates/chat/search.html
+++ b/ForgeChat/forgechat/templates/chat/search.html
@@ -24,7 +24,7 @@
 
   {% for doc in results %}
   <div class="grid-19">
-    <a href="{{doc['url_s']}}">{{doc.title_s}}</a><br/>
+    <a href="{{doc['url_s']}}">{{ h.get_first(doc, 'title') }}</a><br/>
     <pre>{{doc|pprint}}</pre>
     <hr/>
   </div>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/ForgeShortUrl/forgeshorturl/model/shorturl.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/model/shorturl.py b/ForgeShortUrl/forgeshorturl/model/shorturl.py
index 7e550b7..f38894a 100644
--- a/ForgeShortUrl/forgeshorturl/model/shorturl.py
+++ b/ForgeShortUrl/forgeshorturl/model/shorturl.py
@@ -45,7 +45,7 @@ class ShortUrl(M.Artifact):
             full_url_s=self.full_url,
             short_name_s=self.short_name,
             description_s=self.description,
-            title_s='%s => %s' % (self.url(), self.full_url),
+            title='%s => %s' % (self.url(), self.full_url),
             private_b=self.private,
             type_s=self.type_s)
         return result

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index db7113a..1abeaac 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -206,7 +206,7 @@ class TicketHistory(Snapshot):
             return None
         result = Snapshot.index(self)
         result.update(
-            title_s='Version %d of %s' % (
+            title='Version %d of %s' % (
                 self.version, orig.summary),
             type_s='Ticket Snapshot',
             text=self.data.summary)
@@ -303,7 +303,7 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
     def index(self):
         result = VersionedArtifact.index(self)
         result.update(
-            title_s='Ticket %s' % self.ticket_num,
+            title='Ticket %s' % self.ticket_num,
             version_i=self.version,
             type_s=self.type_s,
             ticket_num_i=self.ticket_num,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f211493f/ForgeWiki/forgewiki/model/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/model/wiki.py b/ForgeWiki/forgewiki/model/wiki.py
index c477b91..816a5ee 100644
--- a/ForgeWiki/forgewiki/model/wiki.py
+++ b/ForgeWiki/forgewiki/model/wiki.py
@@ -48,7 +48,6 @@ class PageHistory(Snapshot):
         result = Snapshot.index(self)
         title = '%s (version %d)' % (self.original().title, self.version)
         result.update(
-            title_s=title,
             title=title,
             type_s='WikiPage Snapshot',
             text=self.data.text)
@@ -130,7 +129,6 @@ class Page(VersionedArtifact, ActivityObject):
     def index(self):
         result = VersionedArtifact.index(self)
         result.update(
-            title_s=self.title,
             title=self.title,
             version_i=self.version,
             type_s='WikiPage',


Mime
View raw message