web/views/wdoc.py
changeset 8632 fa044b9157d7
parent 8190 2a3c1b787688
child 8969 b37ce419ce26
equal deleted inserted replaced
8631:1053b9d0fdf7 8632:fa044b9157d7
   203         else:
   203         else:
   204             raise NotFound
   204             raise NotFound
   205         self.w(open(join(resourcedir, rid)).read())
   205         self.w(open(join(resourcedir, rid)).read())
   206 
   206 
   207 
   207 
   208 class ChangeLogView(StartupView):
       
   209     __regid__ = 'changelog'
       
   210     title = _('What\'s new?')
       
   211     maxentries = 25
       
   212 
       
   213     def call(self):
       
   214         rid = 'ChangeLog_%s' % (self._cw.lang)
       
   215         allentries = []
       
   216         title = self._cw._(self.title)
       
   217         restdata = ['.. -*- coding: utf-8 -*-', '', title, '='*len(title), '']
       
   218         w = restdata.append
       
   219         today = date.today()
       
   220         for fpath in self._cw.vreg.config.locate_all_files(rid):
       
   221             cl = ChangeLog(fpath)
       
   222             encoding = 'utf-8'
       
   223             # additional content may be found in title
       
   224             for line in (cl.title + cl.additional_content).splitlines():
       
   225                 m = CHARSET_DECL_RGX.search(line)
       
   226                 if m is not None:
       
   227                     encoding = m.group(1)
       
   228                     continue
       
   229                 elif line.startswith('.. '):
       
   230                     w(unicode(line, encoding))
       
   231             for entry in cl.entries:
       
   232                 if entry.date:
       
   233                     edate = todate(strptime(entry.date, '%Y-%m-%d'))
       
   234                 else:
       
   235                     edate = today
       
   236                 messages = []
       
   237                 for msglines, submsgs in entry.messages:
       
   238                     msgstr = unicode(' '.join(l.strip() for l in msglines), encoding)
       
   239                     msgstr += u'\n\n'
       
   240                     for submsglines in submsgs:
       
   241                         msgstr += '     - ' + unicode(' '.join(l.strip() for l in submsglines), encoding)
       
   242                         msgstr += u'\n'
       
   243                     messages.append(msgstr)
       
   244                 entry = (edate, messages)
       
   245                 allentries.insert(bisect_right(allentries, entry), entry)
       
   246         latestdate = None
       
   247         i = 0
       
   248         for edate, messages in reversed(allentries):
       
   249             if latestdate != edate:
       
   250                 fdate = self._cw.format_date(edate)
       
   251                 w(u'\n%s' % fdate)
       
   252                 w('~' * len(fdate))
       
   253                 latestdate = edate
       
   254             for msg in messages:
       
   255                 w(u'* %s' % msg)
       
   256                 i += 1
       
   257                 if i > self.maxentries:
       
   258                     break
       
   259         w('') # blank line
       
   260         self.w(rest_publish(self, '\n'.join(restdata)))
       
   261 
       
   262 
   208 
   263 class HelpAction(action.Action):
   209 class HelpAction(action.Action):
   264     __regid__ = 'help'
   210     __regid__ = 'help'
   265     __select__ = yes()
   211     __select__ = yes()
   266 
   212 
   269     title = _('Help')
   215     title = _('Help')
   270 
   216 
   271     def url(self):
   217     def url(self):
   272         return self._cw.build_url('doc/main')
   218         return self._cw.build_url('doc/main')
   273 
   219 
   274 class ChangeLogAction(action.Action):
       
   275     __regid__ = 'changelog'
       
   276     __select__ = yes()
       
   277 
       
   278     category = 'footer'
       
   279     order = 1
       
   280     title = ChangeLogView.title
       
   281 
       
   282     def url(self):
       
   283         return self._cw.build_url('changelog')
       
   284 
       
   285 
   220 
   286 class AboutAction(action.Action):
   221 class AboutAction(action.Action):
   287     __regid__ = 'about'
   222     __regid__ = 'about'
   288     __select__ = yes()
   223     __select__ = yes()
   289 
   224