patch to extract license data
Nathan Kinkade
nkinkade at creativecommons.org
Fri Dec 7 07:24:43 EST 2007
2007/11/11, Sam Ruby <rubys at intertwingly.net>:
<snip>
> >> Finally, I'd rather that the fetching and styling of the license
> >> information be moved into a plugin, and not placed inside the venus code
> >> itself. Ideally, the fetching would cache the results, but if it is in
> >> an optional plugin, I'm not overly concerned. You can look at
> >> mememe.plugin[4] for examples on how to do all this.
> >>
> >> - Sam Ruby
<snip>
I have finally got around to moving this functionality to a Planet
Venus plugin. So, there are still some minimal changes (10 or 12
lines, minus comments) to the core Planet Venus code, but only in one
file (tmpl.py) and only enough to expose a simple anchor tag to the
HTMLTMPL template. The patch is at the end of this mail.
This in itself could be useful for some people. The plugin takes
these anchor tags and then inserts some CC-specific stuff, namely a
more descriptive license name.
Unfortunately, I don't have everything in a Bazaar repository per the
contributing guidelines, but we do have everything in a Subversion
repository. The plugin is here:
http://cctools.svn.sourceforge.net/viewvc/cctools/planet/trunk/software/filters/cc_license.plugin?view=markup
As far as documentation for the template, as you mentioned in a
previous post, this case is simple enough that it may not really
require specific documentation. It simply requires adding <TMPL_VAR
license> and/or <TMPL_VAR default_license> somewhere in the template.
In our specific case, and this will probably be most useful, we check
for "license," if it doesn't exist we check for "default_license," if
it doesn't exist we print nothing.
The bit about "default_license" is a configuration that users can
apply to each feed's configuration. This was necessary for us,
because though every one of our jurisdiction's blogs are CC licensed,
only a small subset presently include this data as part of the feed,
so we needed a way to optionally specify the a default license for a
feed if none was found in the feed itself.
A working example of this is at http://planet.creativecommons.org.
The license data show up next to the title and date of each post.
Here is the diff to ./planet/shell/tmpl.py:
--- tmpl.py 2007-12-06 02:10:19.000000000 +0000
+++ tmpl.py.new 2007-12-06 02:10:19.000000000 +0000
@@ -120,6 +120,8 @@
['published', PlanetDate, 'published_parsed'],
['published_822', Rfc822, 'published_parsed'],
['published_iso', Rfc3399, 'published_parsed'],
+ ['license', String, 'source', 'links', {'rel': 'license'}, 'href'],
+ ['default_license', String, 'source', 'planet_default_license']
]
# Add additional rules for source information
@@ -141,6 +143,15 @@
elif node.get('type','')=='application/xhtml+xml':
node['value'] = empty.sub(r"<\1 />", node['value'])
node = node[path]
+
+ # This is a special-case elif needed to grab license info from the
+ # feed data. Normally node will be a simple list or dict, but in
+ # the case of license information, node is a list of lists, so we
+ # need to look inside the first item, which is where the license
+ # data seems to always be.
+ elif isinstance(path, str) and isinstance(node, list) and \
+ path in node[0]:
+ node = node[0][path]
elif isinstance(path, int):
node = node[path]
elif isinstance(path, dict):
@@ -155,8 +166,21 @@
else:
break
else:
- if node: output[rule[0]] = rule[1](node)
-
+ # If this node contains license information, indicated by rule[0]
+ # being 'license' or 'default_license' (from list Items), then
+ # drop the the license URI into a variable that will be accessible
+ # by the template. 'default_license' is specified in the config
+ # of each blog, and can be used if no other license data is found
+ # in the feed itself.
+ if node:
+ if rule[0] == 'license' or rule[0] == 'default_license':
+ output[rule[0]] = '<a about="%s" rel="license" \
+ href="%s" title="License information" \
+ style="font-size: x-small;">License</a>' \
+ % (source.link, node)
+ else:
+ output[rule[0]] = rule[1](node)
+
# copy over all planet namespaced elements from parent source
for name,value in source.items():
if name.startswith('planet_'):
More information about the devel
mailing list