Permalink
Browse files

#2429: shows versioned wiki page and the versioned tags

  • Loading branch information...
1 parent 58bf794 commit f41d59ccbf1105721e0ac7003de5f533d094ff00 @jun66j5 committed Nov 6, 2013
Showing with 39 additions and 19 deletions.
  1. +5 −5 tractags/api.py
  2. +22 −10 tractags/model.py
  3. +12 −4 tractags/wiki.py
View
10 tractags/api.py
@@ -214,7 +214,7 @@ def get_all_tags(req, filter=None):
"""
- def get_resource_tags(req, resource):
+ def get_resource_tags(req, resource, when=None):
"""Get tags for a Resource object."""
def set_resource_tags(req, resource, tags, comment=u''):
@@ -281,11 +281,11 @@ def get_all_tags(self, req, filter=None):
all_tags[tag] = count
return all_tags
- def get_resource_tags(self, req, resource):
+ def get_resource_tags(self, req, resource, when=None):
assert resource.realm == self.realm
if not self.check_permission(req.perm(resource), 'view'):
return
- return resource_tags(self.env, resource)
+ return resource_tags(self.env, resource, when=when)
def set_resource_tags(self, req, resource, tags, comment=u''):
assert resource.realm == self.realm
@@ -390,10 +390,10 @@ def get_all_tags(self, req, realms=[]):
all_tags.update(tags)
return all_tags
- def get_tags(self, req, resource):
+ def get_tags(self, req, resource, when=None):
"""Get tags for resource."""
return set(self._get_provider(resource.realm) \
- .get_resource_tags(req, resource))
+ .get_resource_tags(req, resource, when=when))
def set_tags(self, req, resource, tags, comment=u''):
"""Set tags on a resource.
View
32 tractags/model.py
@@ -175,19 +175,31 @@ def tagged_resources(env, perm_check, perm, realm, tags=None, filter=None,
resource = resources[name]
yield resource, set([tag[1] for tag in tags])
-def resource_tags(env, resource, db=None):
+def resource_tags(env, resource, db=None, when=None):
"""Return all tags for a Trac resource by realm and ID."""
db = _get_db(env, db)
cursor = db.cursor()
-
- cursor.execute("""
- SELECT tag
- FROM tags
- WHERE tagspace=%s
- AND name=%s
- """, (resource.realm, to_unicode(resource.id)))
- for row in cursor:
- yield row[0]
+ id = to_unicode(resource.id)
+ if when is None:
+ cursor.execute("""
+ SELECT tag
+ FROM tags
+ WHERE tagspace=%s
+ AND name=%s
+ """, (resource.realm, id))
+ for row in cursor:
+ yield row[0]
+ else:
+ if isinstance(when, datetime):
+ when = to_utimestamp(when)
+ cursor.execute("SELECT newtags FROM tags_change "
+ "WHERE tagspace=%s AND name=%s AND time<=%s "
+ "ORDER BY time DESC LIMIT 1",
+ (resource.realm, id, when))
+ row = cursor.fetchone()
+ if row:
+ for tag in filter(None, row[0].split()):
+ yield tag
# Internal functions
View
16 tractags/wiki.py
@@ -27,6 +27,7 @@
from tractags.api import Counter, DefaultTagProvider, TagSystem, _, ngettext, \
tag_
+from tractags.compat import to_utimestamp
from tractags.macros import TagTemplateProvider
from tractags.model import delete_tags, tag_changes
from tractags.query import Query
@@ -134,11 +135,13 @@ def post_process_request(self, req, template, data, content_type):
"%(tags)s removed",
len(removed)),
tags=tag.em(', '.join(removed))))
+ date = tags_history[0][0]
history.append({
'version': '*',
'url': req.href(resource.realm, resource.id,
- version=page_history[i]['version']),
- 'date': tags_history[0][0],
+ version=page_history[i]['version'],
+ tags_version=to_utimestamp(date)),
+ 'date': date,
'author': tags_history[0][1],
'comment': comment,
'ipnr': ''
@@ -217,10 +220,15 @@ def wiki_page_version_deleted(self, page):
# Internal methods
def _page_tags(self, req):
pagename = req.args.get('page', 'WikiStart')
+ version = req.args.get('version')
+ tags_version = req.args.get('tags_version')
+ page = WikiPage(self.env, pagename, version=version)
+ resource = page.resource
+ if version and not tags_version:
+ tags_version = page.time
tag_system = TagSystem(self.env)
- resource = Resource('wiki', pagename)
- tags = sorted(tag_system.get_tags(req, resource))
+ tags = sorted(tag_system.get_tags(req, resource, when=tags_version))
return tags
def _wiki_view(self, req, stream):

1 comment on commit f41d59c

@hasienda

Works well according to my own tests. Good to go with it.

Please sign in to comment.