diff -r a64f48dd5fe4 -r 9ab2b4c74baf web/views/old_calendar.py --- a/web/views/old_calendar.py Thu May 20 20:47:13 2010 +0200 +++ b/web/views/old_calendar.py Thu May 20 20:47:55 2010 +0200 @@ -15,9 +15,7 @@ # # You should have received a copy of the GNU Lesser General Public License along # with CubicWeb. If not, see . -"""html calendar views - -""" +"""html calendar views""" from datetime import date, time, timedelta @@ -26,8 +24,25 @@ next_month, first_day, last_day, date_range) from cubicweb.interfaces import ICalendarViews -from cubicweb.selectors import implements -from cubicweb.view import EntityView +from cubicweb.selectors import implements, adaptable +from cubicweb.view import EntityView, EntityAdapter, implements_adapter_compat + +class ICalendarViewsAdapter(EntityAdapter): + """calendar views interface""" + __regid__ = 'ICalendarViews' + __select__ = implements(ICalendarViews) # XXX for bw compat, should be abstract + + @implements_adapter_compat('ICalendarViews') + def matching_dates(self, begin, end): + """ + :param begin: day considered as begin of the range (`DateTime`) + :param end: day considered as end of the range (`DateTime`) + + :return: + a list of dates (`DateTime`) in the range [`begin`, `end`] on which + this entity apply + """ + raise NotImplementedError # used by i18n tools WEEKDAYS = [_("monday"), _("tuesday"), _("wednesday"), _("thursday"), @@ -39,7 +54,7 @@ class _CalendarView(EntityView): """base calendar view containing helpful methods to build calendar views""" - __select__ = implements(ICalendarViews,) + __select__ = adaptable('ICalendarViews') paginable = False # Navigation building methods / views #################################### @@ -126,7 +141,7 @@ infos = u'
' infos += self._cw.view(itemvid, self.cw_rset, row=row) infos += u'
' - for date_ in entity.matching_dates(begin, end): + for date_ in entity.cw_adapt_to('ICalendarViews').matching_dates(begin, end): day = date(date_.year, date_.month, date_.day) try: dt = time(date_.hour, date_.minute, date_.second) @@ -288,7 +303,7 @@ monthlink = '%s' % (xml_escape(url), umonth) self.w(u'%s %s (%s)' \ % (_('week'), monday.isocalendar()[1], monthlink)) - for day in date_range(monday, sunday): + for day in date_range(monday, sunday+ONEDAY): self.w(u'') self.w(u'%s' % _(WEEKDAYS[day.weekday()])) self.w(u'%s' % (day.strftime('%Y-%m-%d'))) @@ -478,7 +493,7 @@ w(u'%s' % ( WEEK_TITLE % (_('week'), monday.isocalendar()[1], monthlink))) w(u'%s '% _(u'Date')) - for day in date_range(monday, sunday): + for day in date_range(monday, sunday+ONEDAY): events = schedule.get(day) style = day.weekday() % 2 and "even" or "odd" w(u'' % style)