예제 #1
0
def renderGuidPage(item):

    s = time.time()
    thispage = getGuidPageFilename(item['guid'])

    ns = {'item': itemNamespace(item, thispage=thispage),
          'pagetype': 'guidpage',
          'daypage': getRelativePath(getDayPageFilename(item['date']), thispage),
          'escape': escape,
          #'googleit': 'unset',
          #'trackback': 'unset',
          #'translate': 'unset',
          'calendar': genCalendar(item['date'], thispage=thispage)}

    previousGuid = tv.weblog.db.getPreviousItem(item)
    nextGuid = tv.weblog.db.getNextItem(item)
    if previousGuid:
        previousItem = tv.weblog.db.getItem(previousGuid)
        ns['previousitem'] = itemNamespace(previousItem)
        ns['previousitemlink'] = '<a href="%s">&lt;&lt; %s</a>' % (getRelativePath(getGuidPageUrl(previousItem['guid']),
                                                                   getGuidPageUrl(item['guid'])),
                                                                   previousItem['title'])
    else:
        ns['previousitem'] = None
        ns['previousitemlink'] = ''

    if nextGuid:
        nextItem = tv.weblog.db.getItem(nextGuid)
        ns['nextitem'] = itemNamespace(nextItem)
        ns['nextitemlink'] = '<a href="%s">%s &gt;&gt;</a>' % (getRelativePath(getGuidPageUrl(nextItem['guid']),
                                                               getGuidPageUrl(item['guid'])),
                                                               nextItem['title'])
        
    else:        
        ns['nextitem'] = None
        ns['nextitemlink'] = ''

    sidebarTemplate = templates.sidebar.sidebar(searchList=[ns])
    pageTemplate =  templates.guidpage.guidpage(searchList=[ns, {'sidebar': str(sidebarTemplate)}])

    # check dependencies
    for category in (item['categories'].keys() + [None]):
        if not os.path.exists(thispage) and tv.weblog.db.getItemsAtDay(item['date'], category) == 1:
            # first time we have a item at this day - all pages of this month need rerendering
            todo.addWholeMonth(item['date'], category)
        else:
            todo.addDayPage(item['date'], category)
            todo.addMonthPage(item['date'], category)
    if not os.path.exists(thispage):
        if previousGuid:
            todo.addGuidPage(previousGuid)
        if nextGuid:
            todo.addGuidPage(nextGuid)

    fp = open(ensurePath(thispage), 'w')
    fp.write(str(pageTemplate))
    fp.close()
    print "renderGuidPage(%s) \t%.2f" % (item['guid'], time.time() - s)
예제 #2
0
def renderMonthPage(date, category=None):
    """Render the month overview page for a certain Month"""
    
    s = time.time()
    thispage = getMonthPageFilename(date, category)


    daylist = []
    for day in range(1, date.days_in_month+1):
        thisday = mx.DateTime.DateTime(date.year, date.month, day)
        dayitems = tv.weblog.db.getItemsAtDay(thisday, category)
        if not dayitems:
            continue

        itemlist = []
        for guid in dayitems:
            ns = {'pagetype': 'monthpage',
                  'item': itemNamespace(tv.weblog.db.getItem(guid), thispage=thispage)}
            itemTemplate = templates.item.item(searchList=[ns])
            ns['rendered'] = str(itemTemplate)
            itemlist.append(ns)

        daylist.append({'itemlist': itemlist,
                        'daypage': getRelativePath(getDayPageUrl(thisday), filenameToUrl(thispage)),
                        'date': dateNamespace(thisday)})

    # no empty pages
    if len(daylist) == 0:
        return
    
    ns = {'daylist': daylist,
          'date': dateNamespace(date),
          'escape': escape,
          #'googleit': 'unset',
          #'trackback': 'unset',
          #'translate': 'unset',
          #'previousitemlink': '',
          #'nextitemlink': '',
          'calendar': genCalendar(date, category=category,
                                  thispage=thispage, nohighlight=1)}

    sidebarTemplate = templates.sidebar.sidebar(searchList=[ns])
    pageTemplate =  templates.monthpage.monthpage(searchList=[ns, {'sidebar': str(sidebarTemplate)}])

    # check dependencies
    if not os.path.exists(thispage):
        todo.addWholeMonth(tv.weblog.db.getPreviousMonthWithItems(date), category)
        todo.addWholeMonth(tv.weblog.db.getNextMonthWithItems(date), category)
     
    fp = open(ensurePath(thispage), 'w')
    fp.write(str(pageTemplate))
    fp.close()

    print "renderMonthPage(%s, %s)\t%.2f" % (str(date), category, time.time() - s)
예제 #3
0
def renderDayPage(date, category=None):
    """Render the category or main page for a certain day of the year"""

    s = time.time()
    
    thispage = getDayPageFilename(date, category)
 
    itemlist = []
    for guid in tv.weblog.db.getItemsAtDay(date, category):
        item = tv.weblog.db.getItem(guid)
        ns = {'pagetype': 'daypage',
              'item': itemNamespace(item, thispage=thispage)}
        itemTemplate = templates.item.item(searchList=[ns])
        #print "   ", category, item['title'], item['date'], ns['item']['title']
        ns['rendered'] = str(itemTemplate)

        itemlist.append(ns)

    # no empty pages
    if len(itemlist) == 0:
        return

    ns = {'itemlist': itemlist,
          'date': dateNamespace(date),
          'daypage': getRelativePath(getDayPageUrl(date), filenameToUrl(thispage)),
          'monthpage': getRelativePath(getMonthPageUrl(date), filenameToUrl(thispage)),
          'escape': escape,
          #'googleit': 'unset',
          #'trackback': 'unset',
          #'translate': 'unset',
          #'previousitemlink': '',
          #'nextitemlink': '',
          'calendar': genCalendar(date, category=category,
                                  thispage=thispage)}

    sidebarTemplate = templates.sidebar.sidebar(searchList=[ns])
    pageTemplate =  templates.daypage.daypage(searchList=[ns, {'sidebar': str(sidebarTemplate)}])

    # check dependencies
    if not os.path.exists(thispage):
        # all pages of this month need rerendering
        todo.addWholeMonth(date, category)
    else:
        todo.addMonthPage(date, category)

    fp = open(ensurePath(thispage), 'w')
    fp.write(str(pageTemplate))
    fp.close()
    print "renderDayPage(%s, %s)\t%.2f" % (str(date), category, time.time() - s)