# HG changeset patch # User Paul Boddie # Date 1318804714 -7200 # Node ID cbe6e54714d1201d262ae7c1a90bb6030a565a8c # Parent 40cc09e46089c0e2aed0d8ece39b6c5dd9cdde2a Switched to using attachments instead of the caching framework. This makes it easier to manually refresh charts. diff -r 40cc09e46089 -r cbe6e54714d1 parsers/SVGChart.py --- a/parsers/SVGChart.py Sun Oct 16 23:21:17 2011 +0200 +++ b/parsers/SVGChart.py Mon Oct 17 00:38:34 2011 +0200 @@ -6,10 +6,15 @@ @license: GNU GPL (v2 or later), see COPYING.txt for details. """ -from MoinMoin.action import cache from MoinMoin import wikiutil +from MoinMoin.action import AttachFile from SVGChartSupport import get_chart, get_dimensions +try: + from hashlib import sha1 +except ImportError: + from sha import new as sha1 + Dependencies = ["pages"] # Parser support. @@ -52,18 +57,19 @@ page = request.page _ = request.getText - cache_key = cache.key(request, itemname=page.page_name, content="%s,%s,%s,%s,%s" % ( - self.width, self.height, self.xorigin, self.yorigin, self.raw)) + data = "%s,%s,%s,%s,%s" % (self.width, self.height, self.xorigin, self.yorigin, self.raw) + filename = "SVGChart-%s.svg" % sha1(data).hexdigest() + pagename = page.page_name - if not cache.exists(request, cache_key): + if not AttachFile.exists(request, pagename, filename): width, height, chart = get_chart(self.data, self.width, self.height, self.xorigin, self.yorigin, styles_url="%s/%s/css/svgchart.css" % (request.cfg.url_prefix_static, request.theme.name)) - cache.put(request, cache_key, chart, content_type="image/svg+xml") + AttachFile.add_attachment(request, pagename, filename, chart.encode("utf-8")) else: width, height = get_dimensions(self.data, self.width, self.height, self.xorigin, self.yorigin) request.write(fmt.div(1, css_class="svgchart")) - request.write(fmt.transclusion(1, data=cache.url(request, cache_key), width=width, height=height)) + request.write(fmt.transclusion(1, data=AttachFile.getAttachUrl(pagename, filename, request), width=width, height=height)) request.write(fmt.text(_("SVG chart of CSV data."))) request.write(fmt.transclusion(0)) request.write(fmt.div(0)) diff -r 40cc09e46089 -r cbe6e54714d1 to-do/delete-redundant-chart-attachments.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/to-do/delete-redundant-chart-attachments.txt Mon Oct 17 00:38:34 2011 +0200 @@ -0,0 +1,2 @@ +Redundant chart attachments need deleting when no SVGChart region corresponds +to them any more. diff -r 40cc09e46089 -r cbe6e54714d1 to-do/use-attachments-for-chart-output.txt --- a/to-do/use-attachments-for-chart-output.txt Sun Oct 16 23:21:17 2011 +0200 +++ b/to-do/use-attachments-for-chart-output.txt Mon Oct 17 00:38:34 2011 +0200 @@ -1,2 +1,3 @@ -Change the parser to use attachments for chart storage instead of the annoying -caching framework. +Done! +(Change the parser to use attachments for chart storage instead of the annoying +caching framework.)