示例#1
0
文件: utils.py 项目: darrenkuo/SP
def findPreviousNext(path, user):
    f = open('static/course_flow', 'r')
    flow = eval(f.read())
    f.close()

    p = path.split('-')[-1]

    start = -1
    for i in range(len(flow)):
        if flow[i] == p:
            start = i + 1
            break

    if start == -1:
        return '/magic?page=/summary'

    
    while True and start < len(flow):
        real_path = getRealPath(flow[start])
        data = readLessonData(real_path)
        html_path = '-'.join(real_path.split("/")[1:])
        if checkReadable(data, user):
            return '/magic?page=/display?page=%s' % (html_path)

        start += 1

    return '/magic?page=/summary'
示例#2
0
文件: utils.py 项目: darrenkuo/SP
def regenerateNext(root='.'):
    from utils import readLessonData
    stack = []
    data = readLessonData(root)
    stack.extend(data['chapters'])

    done = []

    while len(stack) != 0:
        c = stack[0]
        done.append(c)
        stack = stack[1:]
        data = readLessonData(getRealPath(c))
        d = list(data['chapters'])
        d.extend(stack)
        stack = d
    
    done = map(str, done)
    f = open('static/course_flow', 'w')
    f.write(str(done))
    f.close()