Next / Previous / Contents / Shipman's homepage

23.3. MonthCell.writePage(): Render as XHTML

This method creates the page containing one month's notes, provided the page is out of date.

noteweb
# - - -   M o n t h C e l l . w r i t e P a g e

    def writePage ( self ):
        '''Render self as XHTML.
        '''

We don't want to rewrite every HTML file every time, so we use the self.birdNoteSet.newestTime timestamp to see if all of the source files are older than the output file and, if so, return.

noteweb
        #-- 1 --
        # [ if (not Args().forceSwitch) and
        #   (self.fileName() names an existing file whose modification
        #   time is greater than self.birdNoteSet.newestTime) ->
        #     return
        #   else ->
        #     outFileName  :=  self.fileName() ]
        outFileName  =  self.fileName()
        if not Args().forceSwitch:
            if  os.path.exists ( outFileName ):
                status  =  os.stat ( outFileName )
                modTime  =  status[stat.ST_MTIME]
                if  ( (self.birdNoteSet.newestTime is not None) and
                      (modTime > self.birdNoteSet.newestTime) ):
                    return

Before we can create the page, we need to find the previous and next page so this page's Previous and Next links can point to them.

noteweb
        #-- 2 --
        # [ prev  :=  the 'yyyy-mm' key of the preceding month's
        #             page, or None if self is the first month
        #   next  :=  the 'yyyy-mm' key of the following month's
        #             page, or None if self is the last month ]
        prev, next  =  self.yearRow.yearCollection.neighbors (
                       self.yyyy_mm )        

At this point we call the tccpage2.TCCPage() constructor to set up a basic page structure. See Section 23.4, “MonthCell.__pageFrame(): Set up a basic page”.

noteweb
        #-- 3 --
        # [ page  :=  a tccpage2.TCCPage instance with
        #       navigation links (prev, next) ]
        page  =  self.__pageFrame ( prev, next )

For the method that generates the page's variable content, see Section 23.5, “MonthCell.__renderPage(): Add the notes content”.

noteweb
        #-- 4 --
        # [ page  :=  page with self.birdNoteSet rendered as XHTML ]
        self.__renderPage(page)

Open the page's file for writing (if possible) and write the content there.

noteweb
        #-- 5 --
        # [ if a file named self.fileName() can be opened new ->
        #     outFile  :=  that file, so opened
        #   else ->
        #     sys.stderr  +:=  error message
        #     stop execution ]
        try:
            outFile  =  open ( outFileName, 'w' )
        except IOError, detail:
            print >>sys.stderr, ( "*** Can't create monthly page "
                "'%s': %s" % (outFileName, detail) )
            raise SystemExit

        #-- 6 --
        # [ outFile  +:=  page, rendered as XHTML ]
        page.write ( outFile )
        outFile.close()