1 # vim: tabstop=4 shiftwidth=4
3 Walks through your blog root figuring out all the available monthly archives in
4 your blogs. It generates html with this information and stores it in the
5 $archivelinks variable which you can use in your head or foot templates.
7 The vars available with typical example values are:
13 Permission is hereby granted, free of charge, to any person
14 obtaining a copy of this software and associated documentation
15 files (the "Software"), to deal in the Software without restriction,
16 including without limitation the rights to use, copy, modify,
17 merge, publish, distribute, sublicense, and/or sell copies of the
18 Software, and to permit persons to whom the Software is furnished
19 to do so, subject to the following conditions:
21 The above copyright notice and this permission notice shall be
22 included in all copies or substantial portions of the Software.
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
26 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 Copyright 2004, 2005 Wari Wahab
34 Copyright 2006 Benjamin Mako Hill
36 __author__ = "Benjamin Mako Hill <mako@atdot.cc>"
37 __version__ = "$Id: pyarchives.py 883 2006-03-24 03:43:42Z willhelm $"
39 from Pyblosxom import tools
43 def __init__(self, request):
44 self._request = request
48 def linearArchive(self):
49 if self._archives == None:
50 self.genLinearArchive()
54 return self.linearArchive()
56 def genLinearArchive(self):
57 config = self._request.getConfiguration()
58 data = self._request.getData()
59 root = config["datadir"]
61 archiveList = tools.Walk(self._request, root)
63 fulldict.update(config)
66 month_template = config.get('archive_template_month',
67 '<li><a href="%(base_url)s/%(Y)s/%(b)s">%(b)s/%(Y)s</a></li>')
68 year_template = config.get('archive_template_year',
69 '<li>%(Y)s<ul id="archive_year_contents_%(Y)s">%(month_contents)s</ul></li>')
71 for mem in archiveList:
72 timetuple = tools.filestat(self._request, mem)
74 for x in ["B", "b", "m", "Y", "y"]:
75 timedict[x] = time.strftime("%" + x, timetuple)
77 fulldict.update(timedict)
78 if not archives.has_key(timedict['Y']):
79 archives[timedict['Y']] = {}
80 elif not archives[timedict['Y']].has_key(timedict['m']):
81 archives[timedict['Y']][timedict['m']] = (month_template % fulldict)
83 years = archives.keys()
86 ordered_year_strings = []
88 # store years for possible use later
91 # we're not done with the dictionary, so please clear it
92 for x in ["B", "b", "m", "Y", "y"]:
96 month_templates = archives[year]
97 months = month_templates.keys()
100 ordered_month_strings = []
103 ordered_month_strings.append(month_templates[month])
105 fulldict['month_contents'] = '\n'.join(ordered_month_strings)
107 ordered_year_strings.append(year_template % fulldict)
109 self._archives = '\n'.join(ordered_year_strings)
111 def linearYearlist(self):
112 config = self._request.getConfiguration()
113 template = config.get('archive_template_yearlist',
114 'Element.hide(\'archive_year_contents_%s\');')
116 for year in self._years:
117 outgoing_lines.append(template % year)
118 return("\n".join(outgoing_lines))
120 def cb_prepare(args):
121 request = args["request"]
122 data = request.getData()
123 archives = PyblArchives(request)
124 data["archivelinks"] = archives.linearArchive()
125 data["archiveyears"] = archives.linearYearlist()