Changeset 3882
- Timestamp:
- 06/22/08 01:39:36 (3 months ago)
- Files:
-
- tagsplugin/trunk/tractags/api.py (modified) (4 diffs)
- tagsplugin/trunk/tractags/htdocs/js/controls.js (deleted)
- tagsplugin/trunk/tractags/htdocs/js/dragdrop.js (deleted)
- tagsplugin/trunk/tractags/htdocs/js/effects.js (deleted)
- tagsplugin/trunk/tractags/htdocs/js/prototype.js (deleted)
- tagsplugin/trunk/tractags/htdocs/js/scriptaculous.js (deleted)
- tagsplugin/trunk/tractags/htdocs/js/slider.js (deleted)
- tagsplugin/trunk/tractags/htdocs/js/util.js (deleted)
- tagsplugin/trunk/tractags/macros.py (modified) (4 diffs)
- tagsplugin/trunk/tractags/templates/tag_view.html (modified) (1 diff)
- tagsplugin/trunk/tractags/ticket.py (modified) (1 diff)
- tagsplugin/trunk/tractags/web_ui.py (modified) (3 diffs)
- tagsplugin/trunk/tractags/wiki.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tagsplugin/trunk/tractags/api.py
r3881 r3882 48 48 """Remove all tags from a resource.""" 49 49 50 def describe_tagged_resource(re source):50 def describe_tagged_resource(req, resource): 51 51 """Return a one line description of the tagged resource.""" 52 52 … … 157 157 raise 158 158 159 def describe_tagged_resource(self, re source):159 def describe_tagged_resource(self, req, resource): 160 160 return '' 161 161 … … 204 204 yield resource, tags 205 205 206 def get_all_tags(self, req, query=''): 207 """Return all tags, optionally only on resources matching query. 208 209 Returns a dictionary with tag name as the key and tag frequency as the 210 value. 211 """ 212 all_tags = {} 213 for resource, tags in self.query(req, query): 214 for tag in tags: 215 if tag in all_tags: 216 all_tags[tag] += 1 217 else: 218 all_tags[tag] = 1 219 return all_tags 220 206 221 def get_tags(self, req, resource): 207 222 """Get tags for resource.""" … … 241 256 return set([t.strip() for t in self._tag_split.split(text) if t.strip()]) 242 257 243 def describe_tagged_resource(self, re source):258 def describe_tagged_resource(self, req, resource): 244 259 """Return a short description of a taggable resource.""" 245 260 provider = self._get_provider(resource.realm) 246 261 if hasattr(provider, 'describe_tagged_resource'): 247 return provider.describe_tagged_resource(re source)262 return provider.describe_tagged_resource(req, resource) 248 263 else: 249 264 self.env.log.warning('ITagProvider %r does not implement ' tagsplugin/trunk/tractags/macros.py
r3880 r3882 11 11 from trac.web.chrome import add_stylesheet 12 12 from trac.util.compat import sorted, set 13 from trac.util import embedded_numbers 13 14 from tractags.api import TagSystem 14 15 from genshi.builder import tag as builder … … 55 56 56 57 class TagCloudMacro(WikiMacroBase): 58 """Display a tag cloud. 59 60 Show a tag cloud for all tags on resources matching query. 61 62 Usage: 63 64 {{{ 65 [[TagCloud(query)]] 66 }}} 67 68 See tags documentation for the query syntax. 69 """ 57 70 def expand_macro(self, formatter, name, content): 71 if not content: 72 content = '' 58 73 req = formatter.req 59 query_result = TagSystem(self.env).query(req, content) 60 all_tags = {} 61 # Find tag counts 62 for resource, tags in query_result: 63 for tag in tags: 64 try: 65 all_tags[tag] += 1 66 except KeyError: 67 all_tags[tag] = 1 74 all_tags = TagSystem(self.env).get_all_tags(req, content) 68 75 return render_cloud(self.env, req, all_tags) 69 76 … … 71 78 72 79 class ListTaggedMacro(WikiMacroBase): 80 """List tagged resources. 81 82 Usage: 83 84 {{{ 85 [[ListTagged(query)]] 86 }}} 87 88 See tags documentation for the query syntax. 89 """ 73 90 def expand_macro(self, formatter, name, content): 74 91 req = formatter.req … … 83 100 ul = builder.ul(class_='taglist') 84 101 for resource, tags in sorted(query_result, 85 key=lambda r: unicode(r[0].id)):102 key=lambda r: embedded_numbers(unicode(r[0].id))): 86 103 tags = sorted(tags) 87 104 88 desc = tag_system.describe_tagged_resource(re source)105 desc = tag_system.describe_tagged_resource(req, resource) 89 106 90 107 if tags: tagsplugin/trunk/tractags/templates/tag_view.html
r2954 r3882 44 44 45 45 <div id="tag_body"> 46 <h1 py:if="tag_title">${tag_title}</h1> 46 <h1 py:if="tag_title"> 47 ${tag_title} 48 <py:if test="tag_page and 'WIKI_VIEW' in perm"> 49 <py:choose test="tag_page.exists"> 50 <py:when test="True">(go to <a href="${href.wiki(tag_page.name)}">Wiki page</a>)</py:when> 51 <py:when test="False"> 52 <py:if test="'WIKI_CREATE' in perm"> 53 (<a href="${href.wiki(tag_page.name, action='edit', text='= %s =\n\n[[ListTagged(%s)]]' % (tag_page.name, tag_page.name))}">Create Wiki page</a> for this tag) 54 </py:if> 55 </py:when> 56 </py:choose> 57 </py:if> 58 </h1> 47 59 ${tag_body} 48 60 </div> tagsplugin/trunk/tractags/ticket.py
r3880 r3882 98 98 ticket.save_changes(req.username, u'') 99 99 100 def describe_tagged_resource(self, resource): 101 assert resource.realm == 'ticket' 100 def describe_tagged_resource(self, req, resource): 101 if not 'TICKET_VIEW' in req.perm(resource): 102 return '' 102 103 ticket = Ticket(self.env, resource.id) 103 104 if ticket.exists: tagsplugin/trunk/tractags/web_ui.py
r2954 r3882 15 15 from genshi.builder import tag as builder 16 16 from trac.util import to_unicode 17 from trac.util.text import CRLF 17 18 from trac.util.compat import sorted, set, any 18 19 from tractags.api import TagSystem, ITagProvider … … 21 22 from trac.mimeview import Context 22 23 from trac.wiki.formatter import Formatter 24 from trac.wiki.model import WikiPage 23 25 24 26 … … 84 86 for realm in realms] 85 87 88 single_page = re.match(r"""(['"]?)(\w+)\1$""", query) 89 if single_page: 90 page_name = single_page.group(2) 91 page = WikiPage(self.env, page_name) 92 data['tag_page'] = page 93 86 94 if query: 87 95 data['tag_title'] = 'Showing objects matching "%s"' % query tagsplugin/trunk/tractags/wiki.py
r3880 r3882 10 10 from trac.core import * 11 11 from tractags.api import DefaultTagProvider, TagSystem 12 from trac.web.chrome import add_stylesheet 12 from trac.web.chrome import add_stylesheet, add_script 13 13 from trac.wiki.api import IWikiSyntaxProvider 14 14 from trac.resource import Resource, render_resource_link, get_resource_url … … 33 33 and map[operation] in perm 34 34 35 def describe_tagged_resource(self, resource): 36 assert resource.realm == 'wiki' 35 def describe_tagged_resource(self, req, resource): 36 if not self.check_permission(req.perm(resource), 'view'): 37 return '' 37 38 page = WikiPage(self.env, resource.id) 38 39 if page.exists: … … 132 133 133 134 def _wiki_edit(self, req, stream): 135 134 136 insert = tag.div(class_='field')( 135 137 tag.label( 136 138 'Tag under: (', tag.a('view all tags', href=req.href.tags()), ')', 137 139 tag.br(), 138 tag.input(id='tags', type='text', name='tags', size=' 30',140 tag.input(id='tags', type='text', name='tags', size='50', 139 141 value=req.args.get('tags', ' '.join(self._page_tags(req)))), 140 142 )
