Parser.Mylist
from db import Pagedb
from py.handler import BaseHTML
import py.util
import re
from reSource0 import moduleConversion
 
'''
input : [[module pagelist]]
output : the list of page formats html
'''
class Mylist(moduleConversion):
    def __init__(self):
        self.pattren = r'(\[){2}module pagelist(\]){2}'
 
    def conver(self, content, page):
        strlist = self.split(content)
        res = ''
        for line in strlist:
            match = re.search(self.pattren,line)
            if match:
                res = self.match(page)
                #res += match.group()
            else:
                res += line
            res += '\n'
        return res
 
    def match(self, page):
        pages = Pagedb.gql('where author = :1', page.author).fetch(1000)
        for page in pages:
            page.pagetitle = py.util.quote(page.pagetitle)
        html = BaseHTML("mylistTemplete.html")
        html.content.update({'pagelist':pages})
        return html.render()