Ticket #2561: attachment-search.patch
| File attachment-search.patch, 2.3 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 ISearchSource, 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 … … 297 298 298 299 implements(IEnvironmentSetupParticipant, IRequestHandler, 299 300 INavigationContributor, IWikiSyntaxProvider, 300 IResourceManager )301 IResourceManager, ISearchSource) 301 302 302 303 change_listeners = ExtensionPoint(IAttachmentChangeListener) 303 304 manipulators = ExtensionPoint(IAttachmentManipulator) … … 515 516 return _("Attachments of %(parent)s", 516 517 parent=get_resource_name(self.env, resource.parent)) 517 518 519 # ISearchSource methods 520 521 def get_search_filters(self, req): 522 yield ('attachment', _('Attachments')) 523 524 def get_search_results(self, req, terms, filters): 525 if not 'attachment' in filters: 526 return 527 db = self.env.get_db_cnx() 528 sql_query, args = search_to_sql(db, ['filename', 'description', 529 'author'], terms) 530 cursor = db.cursor() 531 cursor.execute("SELECT type,id,time,filename,description,author " 532 "FROM attachment " 533 "WHERE " + sql_query, args) 534 535 for type, id, time, filename, desc, author in cursor: 536 attachment = Resource(type, id).child('attachment', filename) 537 if 'ATTACHMENT_VIEW' in req.perm(attachment): 538 yield (get_resource_url(self.env, attachment, req.href), 539 "%s: %s" % (get_resource_shortname(self.env, 540 attachment.parent), 541 filename), 542 datetime.fromtimestamp(time, utc), author, 543 shorten_result(desc, terms)) 544 518 545 # Internal methods 519 546 520 547 def _do_save(self, req, attachment):
