Changeset 3882

Show
Ignore:
Timestamp:
06/22/08 01:39:36 (3 months ago)
Author:
athomas
Message:
  • Remove redundant js files.
  • Add link to existing Wiki page, or new page "template" if tag query was a
    single term. Fixes #2509.
  • Added TagSystem.get_all_tags().
  • Added req argument to describe_tagged_resources().
  • Added docstrings to macros.
  • Widened Wiki tag input field slightly.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tagsplugin/trunk/tractags/api.py

    r3881 r3882  
    4848        """Remove all tags from a resource.""" 
    4949 
    50     def describe_tagged_resource(resource): 
     50    def describe_tagged_resource(req, resource): 
    5151        """Return a one line description of the tagged resource.""" 
    5252 
     
    157157            raise 
    158158 
    159     def describe_tagged_resource(self, resource): 
     159    def describe_tagged_resource(self, req, resource): 
    160160        return '' 
    161161 
     
    204204                    yield resource, tags 
    205205 
     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 
    206221    def get_tags(self, req, resource): 
    207222        """Get tags for resource.""" 
     
    241256        return set([t.strip() for t in self._tag_split.split(text) if t.strip()]) 
    242257 
    243     def describe_tagged_resource(self, resource): 
     258    def describe_tagged_resource(self, req, resource): 
    244259        """Return a short description of a taggable resource.""" 
    245260        provider = self._get_provider(resource.realm) 
    246261        if hasattr(provider, 'describe_tagged_resource'): 
    247             return provider.describe_tagged_resource(resource) 
     262            return provider.describe_tagged_resource(req, resource) 
    248263        else: 
    249264            self.env.log.warning('ITagProvider %r does not implement ' 
  • tagsplugin/trunk/tractags/macros.py

    r3880 r3882  
    1111from trac.web.chrome import add_stylesheet 
    1212from trac.util.compat import sorted, set 
     13from trac.util import embedded_numbers 
    1314from tractags.api import TagSystem 
    1415from genshi.builder import tag as builder 
     
    5556 
    5657class 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    """ 
    5770    def expand_macro(self, formatter, name, content): 
     71        if not content: 
     72            content = '' 
    5873        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) 
    6875        return render_cloud(self.env, req, all_tags) 
    6976 
     
    7178 
    7279class 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    """ 
    7390    def expand_macro(self, formatter, name, content): 
    7491        req = formatter.req 
     
    83100        ul = builder.ul(class_='taglist') 
    84101        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))): 
    86103            tags = sorted(tags) 
    87104 
    88             desc = tag_system.describe_tagged_resource(resource) 
     105            desc = tag_system.describe_tagged_resource(req, resource) 
    89106 
    90107            if tags: 
  • tagsplugin/trunk/tractags/templates/tag_view.html

    r2954 r3882  
    4444 
    4545      <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> 
    4759        ${tag_body} 
    4860      </div> 
  • tagsplugin/trunk/tractags/ticket.py

    r3880 r3882  
    9898        ticket.save_changes(req.username, u'') 
    9999 
    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 '' 
    102103        ticket = Ticket(self.env, resource.id) 
    103104        if ticket.exists: 
  • tagsplugin/trunk/tractags/web_ui.py

    r2954 r3882  
    1515from genshi.builder import tag as builder 
    1616from trac.util import to_unicode 
     17from trac.util.text import CRLF 
    1718from trac.util.compat import sorted, set, any 
    1819from tractags.api import TagSystem, ITagProvider 
     
    2122from trac.mimeview import Context 
    2223from trac.wiki.formatter import Formatter 
     24from trac.wiki.model import WikiPage 
    2325 
    2426 
     
    8486                              for realm in realms] 
    8587 
     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 
    8694        if query: 
    8795            data['tag_title'] = 'Showing objects matching "%s"' % query 
  • tagsplugin/trunk/tractags/wiki.py

    r3880 r3882  
    1010from trac.core import * 
    1111from tractags.api import DefaultTagProvider, TagSystem 
    12 from trac.web.chrome import add_stylesheet 
     12from trac.web.chrome import add_stylesheet, add_script 
    1313from trac.wiki.api import IWikiSyntaxProvider 
    1414from trac.resource import Resource, render_resource_link, get_resource_url 
     
    3333            and map[operation] in perm 
    3434 
    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 '' 
    3738        page = WikiPage(self.env, resource.id) 
    3839        if page.exists: 
     
    132133 
    133134    def _wiki_edit(self, req, stream): 
     135 
    134136        insert = tag.div(class_='field')( 
    135137            tag.label( 
    136138                'Tag under: (', tag.a('view all tags', href=req.href.tags()), ')', 
    137139                tag.br(), 
    138                 tag.input(id='tags', type='text', name='tags', size='30', 
     140                tag.input(id='tags', type='text', name='tags', size='50', 
    139141                          value=req.args.get('tags', ' '.join(self._page_tags(req)))), 
    140142                )