web/views/wdoc.py
changeset 3451 6b46d73823f5
parent 3377 dd9d292b6a6d
child 3460 e4843535db25
equal deleted inserted replaced
3448:495862266785 3451:6b46d73823f5
    89     __select__ = match_form_params('fid')
    89     __select__ = match_form_params('fid')
    90     __regid__ = 'wdoc'
    90     __regid__ = 'wdoc'
    91     title = _('site documentation')
    91     title = _('site documentation')
    92 
    92 
    93     def call(self):
    93     def call(self):
    94         fid = self.req.form['fid']
    94         fid = self._cw.form['fid']
    95         for lang in chain((self.req.lang, self.vreg.property_value('ui.language')),
    95         for lang in chain((self._cw.lang, self._cw.vreg.property_value('ui.language')),
    96                           self.config.available_languages()):
    96                           self._cw.config.available_languages()):
    97             rid = '%s_%s.rst' % (fid, lang)
    97             rid = '%s_%s.rst' % (fid, lang)
    98             resourcedir = self.config.locate_doc_file(rid)
    98             resourcedir = self._cw.config.locate_doc_file(rid)
    99             if resourcedir:
    99             if resourcedir:
   100                 break
   100                 break
   101         else:
   101         else:
   102             raise NotFound
   102             raise NotFound
   103         self.tocindex = build_toc(self.config)
   103         self.tocindex = build_toc(self._cw.config)
   104         try:
   104         try:
   105             node = self.tocindex[fid]
   105             node = self.tocindex[fid]
   106         except KeyError:
   106         except KeyError:
   107             node = None
   107             node = None
   108         else:
   108         else:
   109             self.navigation_links(node)
   109             self.navigation_links(node)
   110             self.w(u'<div class="hr"></div>')
   110             self.w(u'<div class="hr"></div>')
   111             self.w(u'<h1>%s</h1>' % (title_for_lang(node, self.req.lang)))
   111             self.w(u'<h1>%s</h1>' % (title_for_lang(node, self._cw.lang)))
   112         data = open(join(resourcedir, rid)).read()
   112         data = open(join(resourcedir, rid)).read()
   113         self.w(rest_publish(self, data))
   113         self.w(rest_publish(self, data))
   114         if node is not None:
   114         if node is not None:
   115             self.subsections_links(node)
   115             self.subsections_links(node)
   116             self.w(u'<div class="hr"></div>')
   116             self.w(u'<div class="hr"></div>')
   117             self.navigation_links(node)
   117             self.navigation_links(node)
   118 
   118 
   119     def navigation_links(self, node):
   119     def navigation_links(self, node):
   120         req = self.req
   120         req = self._cw
   121         parent = node.parent
   121         parent = node.parent
   122         if parent is None:
   122         if parent is None:
   123             return
   123             return
   124         brothers = subsections(parent)
   124         brothers = subsections(parent)
   125         self.w(u'<div class="docnav">\n')
   125         self.w(u'<div class="docnav">\n')
   137                'up': ('', 'data/up.png', _('i18nprevnext_up'))}
   137                'up': ('', 'data/up.png', _('i18nprevnext_up'))}
   138 
   138 
   139     def navsection(self, node, navtype):
   139     def navsection(self, node, navtype):
   140         htmlclass, imgpath, msgid = self.navinfo[navtype]
   140         htmlclass, imgpath, msgid = self.navinfo[navtype]
   141         self.w(u'<span class="%s">' % htmlclass)
   141         self.w(u'<span class="%s">' % htmlclass)
   142         self.w(u'%s : ' % self.req._(msgid))
   142         self.w(u'%s : ' % self._cw._(msgid))
   143         self.w(u'<a href="%s">%s</a>' % (
   143         self.w(u'<a href="%s">%s</a>' % (
   144             self.req.build_url('doc/'+node.attrib['resource']),
   144             self._cw.build_url('doc/'+node.attrib['resource']),
   145             title_for_lang(node, self.req.lang)))
   145             title_for_lang(node, self._cw.lang)))
   146         self.w(u'</span>\n')
   146         self.w(u'</span>\n')
   147 
   147 
   148     def subsections_links(self, node, first=True):
   148     def subsections_links(self, node, first=True):
   149         sub = subsections(node)
   149         sub = subsections(node)
   150         if not sub:
   150         if not sub:
   152         if first:
   152         if first:
   153             self.w(u'<div class="hr"></div>')
   153             self.w(u'<div class="hr"></div>')
   154         self.w(u'<ul class="docsum">')
   154         self.w(u'<ul class="docsum">')
   155         for child in sub:
   155         for child in sub:
   156             self.w(u'<li><a href="%s">%s</a>' % (
   156             self.w(u'<li><a href="%s">%s</a>' % (
   157                 self.req.build_url('doc/'+child.attrib['resource']),
   157                 self._cw.build_url('doc/'+child.attrib['resource']),
   158                 title_for_lang(child, self.req.lang)))
   158                 title_for_lang(child, self._cw.lang)))
   159             self.subsections_links(child, False)
   159             self.subsections_links(child, False)
   160             self.w(u'</li>')
   160             self.w(u'</li>')
   161         self.w(u'</ul>\n')
   161         self.w(u'</ul>\n')
   162 
   162 
   163 
   163 
   168     binary = True
   168     binary = True
   169     templatable = False
   169     templatable = False
   170     content_type = 'image/png'
   170     content_type = 'image/png'
   171 
   171 
   172     def call(self):
   172     def call(self):
   173         fid = self.req.form['fid']
   173         fid = self._cw.form['fid']
   174         for lang in chain((self.req.lang, self.vreg.property_value('ui.language')),
   174         for lang in chain((self._cw.lang, self._cw.vreg.property_value('ui.language')),
   175                           self.config.available_languages()):
   175                           self._cw.config.available_languages()):
   176             rid = join('images', '%s_%s.png' % (fid, lang))
   176             rid = join('images', '%s_%s.png' % (fid, lang))
   177             resourcedir = self.config.locate_doc_file(rid)
   177             resourcedir = self._cw.config.locate_doc_file(rid)
   178             if resourcedir:
   178             if resourcedir:
   179                 break
   179                 break
   180         else:
   180         else:
   181             raise NotFound
   181             raise NotFound
   182         self.w(open(join(resourcedir, rid)).read())
   182         self.w(open(join(resourcedir, rid)).read())
   186     __regid__ = 'changelog'
   186     __regid__ = 'changelog'
   187     title = _('What\'s new?')
   187     title = _('What\'s new?')
   188     maxentries = 25
   188     maxentries = 25
   189 
   189 
   190     def call(self):
   190     def call(self):
   191         rid = 'ChangeLog_%s' % (self.req.lang)
   191         rid = 'ChangeLog_%s' % (self._cw.lang)
   192         allentries = []
   192         allentries = []
   193         title = self.req._(self.title)
   193         title = self._cw._(self.title)
   194         restdata = ['.. -*- coding: utf-8 -*-', '', title, '='*len(title), '']
   194         restdata = ['.. -*- coding: utf-8 -*-', '', title, '='*len(title), '']
   195         w = restdata.append
   195         w = restdata.append
   196         today = date.today()
   196         today = date.today()
   197         for fpath in self.config.locate_all_files(rid):
   197         for fpath in self._cw.config.locate_all_files(rid):
   198             cl = ChangeLog(fpath)
   198             cl = ChangeLog(fpath)
   199             encoding = 'utf-8'
   199             encoding = 'utf-8'
   200             # additional content may be found in title
   200             # additional content may be found in title
   201             for line in (cl.title + cl.additional_content).splitlines():
   201             for line in (cl.title + cl.additional_content).splitlines():
   202                 m = CHARSET_DECL_RGX.search(line)
   202                 m = CHARSET_DECL_RGX.search(line)