minimalistic archive view
This commit is contained in:
parent
41cf2f66f1
commit
2a7143c985
|
@ -1,6 +1,8 @@
|
|||
""" RevuesDePresse Class """
|
||||
|
||||
import os
|
||||
import time
|
||||
import calendar
|
||||
|
||||
from interfaces import IRevuesDePresse
|
||||
from zope.interface import implements
|
||||
|
@ -46,7 +48,7 @@ class RevuesDePresse(BaseContent):
|
|||
return self.pressreviewsbaseurl + 'revue.PDF'
|
||||
|
||||
def getLinks(self, num=None, offset=0):
|
||||
'''Return a list of tuples (url, label)'''
|
||||
'''Return a list of tuples (url, label, (y,m,d))'''
|
||||
if not self.pressreviewsbaseurl[-1] == '/':
|
||||
self.pressreviewsbaseurl += '/'
|
||||
filenames = os.listdir(self.pressreviewspath)
|
||||
|
@ -62,10 +64,36 @@ class RevuesDePresse(BaseContent):
|
|||
if not os.path.splitext(filename)[-1].lower() == '.pdf':
|
||||
continue
|
||||
url = self.pressreviewsbaseurl + filename
|
||||
label = '%s/%s/%s' % (filename[6:8], filename[8:10], filename[10:14])
|
||||
all_links.append((url, label))
|
||||
y, m, d = filename[10:14], filename[8:10], filename[6:8]
|
||||
label = '%s/%s/%s' % (d, m, y)
|
||||
all_links.append((url, label, (int(y), int(m), int(d))))
|
||||
if num is None:
|
||||
return all_links[offset:]
|
||||
return all_links[offset:offset+num]
|
||||
|
||||
def getArchives(self, year):
|
||||
if not year:
|
||||
year = time.localtime()[0]
|
||||
links_dict = {}
|
||||
for url, label, date in self.getLinks():
|
||||
links_dict[date] = url
|
||||
t = []
|
||||
for month in range(12):
|
||||
caltuples = calendar.monthcalendar(int(year), month+1)
|
||||
t.append('<table>')
|
||||
for weektuple in caltuples:
|
||||
t.append('<tr>')
|
||||
for day in weektuple:
|
||||
t.append('<td>')
|
||||
if day:
|
||||
date = (int(year), int(month+1), int(day))
|
||||
if date in links_dict:
|
||||
t.append('<a href="%s">%s</a>' % (links_dict[date], day))
|
||||
else:
|
||||
t.append('%s' % day)
|
||||
t.append('</td>')
|
||||
t.append('</tr>')
|
||||
t.append('</table>')
|
||||
return '\n'.join(t)
|
||||
|
||||
registerType(RevuesDePresse)
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
<metal:main fill-slot="main">
|
||||
<tal:main-macro metal:define-macro="main"
|
||||
tal:define="kssClassesView context/@@kss_field_decorator_view;
|
||||
getKssClasses nocall:kssClassesView/getKssClassesInlineEditable;">
|
||||
getKssClasses nocall:kssClassesView/getKssClassesInlineEditable;
|
||||
year python:context.REQUEST.get('year')">
|
||||
|
||||
<div tal:replace="structure provider:plone.abovecontenttitle" />
|
||||
<h1 metal:use-macro="here/kss_generic_macros/macros/generic_title_view">
|
||||
|
@ -34,6 +35,8 @@
|
|||
|
||||
<div tal:replace="structure provider:plone.abovecontentbody" />
|
||||
|
||||
<div tal:replace="structure python: context.getArchives(year)"/>
|
||||
|
||||
<div tal:replace="structure provider:plone.belowcontentbody" />
|
||||
</tal:main-macro>
|
||||
</metal:main>
|
||||
|
|
Reference in New Issue