Ticket #2561: attachment-search-2.patch
| File attachment-search-2.patch, 3.0 KB (added by Remy Blank <remy.blank@…>, 4 months ago) |
|---|
-
trac/attachment.py
diff --git a/trac/attachment.py b/trac/attachment.py
a b 32 32 from trac.mimeview import * 33 33 from trac.perm import PermissionError, PermissionSystem, IPermissionPolicy 34 34 from trac.resource import * 35 from trac.search import search_to_sql, shorten_result 35 36 from trac.util import get_reporter_id, create_unique_file, content_disposition 36 37 from trac.util.datefmt import to_timestamp, utc 37 38 from trac.util.text import unicode_quote, unicode_unquote, pretty_size … … 476 477 return format_to_oneliner(self.env, context(attachment.parent), 477 478 descr) 478 479 480 def get_search_results(self, req, resource_realm, terms): 481 """Return a search result generator suitable for ISearchSource. 482 483 Search results are attachments on resources of the given 484 `resource_realm.realm` whose filename, description or author match 485 the given terms. 486 """ 487 db = self.env.get_db_cnx() 488 sql_query, args = search_to_sql(db, ['filename', 'description', 489 'author'], terms) 490 cursor = db.cursor() 491 cursor.execute("SELECT id,time,filename,description,author " 492 "FROM attachment " 493 "WHERE type = %s " 494 "AND " + sql_query, (resource_realm.realm, ) + args) 495 496 for id, time, filename, desc, author in cursor: 497 attachment = resource_realm(id=id).child('attachment', filename) 498 if 'ATTACHMENT_VIEW' in req.perm(attachment): 499 yield (get_resource_url(self.env, attachment, req.href), 500 "%s: %s" % (get_resource_shortname(self.env, 501 attachment.parent), 502 filename), 503 datetime.fromtimestamp(time, utc), author, 504 shorten_result(desc, terms)) 505 479 506 # IResourceManager methods 480 507 481 508 def get_resource_realms(self): -
trac/ticket/web_ui.py
diff --git a/trac/ticket/web_ui.py b/trac/ticket/web_ui.py
a b 197 197 resolution, type)), 198 198 datetime.fromtimestamp(ts, utc), author, 199 199 shorten_result(desc, terms)) 200 201 # Attachments 202 for result in AttachmentModule(self.env).get_search_results( 203 req, ticket_realm, terms): 204 yield result 200 205 201 206 # ITimelineEventProvider methods 202 207 -
trac/wiki/web_ui.py
diff --git a/trac/wiki/web_ui.py b/trac/wiki/web_ui.py
a b 617 617 '%s: %s' % (name, shorten_line(text)), 618 618 datetime.fromtimestamp(ts, utc), author, 619 619 shorten_result(text, terms)) 620 621 # Attachments 622 for result in AttachmentModule(self.env).get_search_results( 623 req, wiki_realm, terms): 624 yield result
